fix(editor): Fix ts errors across the board (no-changelog) (#9561)

This commit is contained in:
Tomi Turtiainen 2024-05-31 10:48:09 +03:00 committed by GitHub
parent 5887ed6498
commit 93fb9b5393
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 66 additions and 52 deletions

View file

@ -430,8 +430,8 @@ export interface IExecutionsCurrentSummaryExtended {
id: string; id: string;
finished?: boolean; finished?: boolean;
mode: WorkflowExecuteMode; mode: WorkflowExecuteMode;
retryOf?: string; retryOf?: string | null;
retrySuccessId?: string; retrySuccessId?: string | null;
startedAt: Date; startedAt: Date;
stoppedAt?: Date; stoppedAt?: Date;
workflowId: string; workflowId: string;

View file

@ -2,18 +2,26 @@ import type { IRestApiContext } from '@/Interface';
import { makeRestApiRequest } from '@/utils/apiUtils'; import { makeRestApiRequest } from '@/utils/apiUtils';
import type { IDataObject, MessageEventBusDestinationOptions } from 'n8n-workflow'; import type { IDataObject, MessageEventBusDestinationOptions } from 'n8n-workflow';
export type ApiMessageEventBusDestinationOptions = MessageEventBusDestinationOptions & {
id: string;
};
export function hasDestinationId(
destination: MessageEventBusDestinationOptions,
): destination is ApiMessageEventBusDestinationOptions {
return destination.id !== undefined;
}
export async function saveDestinationToDb( export async function saveDestinationToDb(
context: IRestApiContext, context: IRestApiContext,
destination: MessageEventBusDestinationOptions, destination: ApiMessageEventBusDestinationOptions,
subscribedEvents: string[] = [], subscribedEvents: string[] = [],
) { ) {
if (destination.id) { const data: IDataObject = {
const data: IDataObject = { ...destination,
...destination, subscribedEvents,
subscribedEvents, };
}; return await makeRestApiRequest(context, 'POST', '/eventbus/destination', data);
return await makeRestApiRequest(context, 'POST', '/eventbus/destination', data);
}
} }
export async function deleteDestinationFromDb(context: IRestApiContext, destinationId: string) { export async function deleteDestinationFromDb(context: IRestApiContext, destinationId: string) {
@ -22,14 +30,12 @@ export async function deleteDestinationFromDb(context: IRestApiContext, destinat
export async function sendTestMessageToDestination( export async function sendTestMessageToDestination(
context: IRestApiContext, context: IRestApiContext,
destination: MessageEventBusDestinationOptions, destination: ApiMessageEventBusDestinationOptions,
) { ) {
if (destination.id) { const data: IDataObject = {
const data: IDataObject = { ...destination,
...destination, };
}; return await makeRestApiRequest(context, 'GET', '/eventbus/testmessage', data);
return await makeRestApiRequest(context, 'GET', '/eventbus/testmessage', data);
}
} }
export async function getEventNamesFromBackend(context: IRestApiContext): Promise<string[]> { export async function getEventNamesFromBackend(context: IRestApiContext): Promise<string[]> {

View file

@ -1,3 +1,4 @@
import type { RawAxiosRequestHeaders } from 'axios';
import type { import type {
ITemplatesCategory, ITemplatesCategory,
ITemplatesCollection, ITemplatesCollection,
@ -8,7 +9,6 @@ import type {
IWorkflowTemplate, IWorkflowTemplate,
TemplateSearchFacet, TemplateSearchFacet,
} from '@/Interface'; } from '@/Interface';
import type { IDataObject } from 'n8n-workflow';
import { get } from '@/utils/apiUtils'; import { get } from '@/utils/apiUtils';
function stringifyArray(arr: number[]) { function stringifyArray(arr: number[]) {
@ -21,7 +21,7 @@ export async function testHealthEndpoint(apiEndpoint: string) {
export async function getCategories( export async function getCategories(
apiEndpoint: string, apiEndpoint: string,
headers?: IDataObject, headers?: RawAxiosRequestHeaders,
): Promise<{ categories: ITemplatesCategory[] }> { ): Promise<{ categories: ITemplatesCategory[] }> {
return await get(apiEndpoint, '/templates/categories', undefined, headers); return await get(apiEndpoint, '/templates/categories', undefined, headers);
} }
@ -29,12 +29,12 @@ export async function getCategories(
export async function getCollections( export async function getCollections(
apiEndpoint: string, apiEndpoint: string,
query: ITemplatesQuery, query: ITemplatesQuery,
headers?: IDataObject, headers?: RawAxiosRequestHeaders,
): Promise<{ collections: ITemplatesCollection[] }> { ): Promise<{ collections: ITemplatesCollection[] }> {
return await get( return await get(
apiEndpoint, apiEndpoint,
'/templates/collections', '/templates/collections',
{ category: stringifyArray(query.categories || []), search: query.search }, { category: query.categories, search: query.search },
headers, headers,
); );
} }
@ -42,7 +42,7 @@ export async function getCollections(
export async function getWorkflows( export async function getWorkflows(
apiEndpoint: string, apiEndpoint: string,
query: { page: number; limit: number; categories: number[]; search: string }, query: { page: number; limit: number; categories: number[]; search: string },
headers?: IDataObject, headers?: RawAxiosRequestHeaders,
): Promise<{ ): Promise<{
totalWorkflows: number; totalWorkflows: number;
workflows: ITemplatesWorkflow[]; workflows: ITemplatesWorkflow[];
@ -64,7 +64,7 @@ export async function getWorkflows(
export async function getCollectionById( export async function getCollectionById(
apiEndpoint: string, apiEndpoint: string,
collectionId: string, collectionId: string,
headers?: IDataObject, headers?: RawAxiosRequestHeaders,
): Promise<{ collection: ITemplatesCollectionResponse }> { ): Promise<{ collection: ITemplatesCollectionResponse }> {
return await get(apiEndpoint, `/templates/collections/${collectionId}`, undefined, headers); return await get(apiEndpoint, `/templates/collections/${collectionId}`, undefined, headers);
} }
@ -72,7 +72,7 @@ export async function getCollectionById(
export async function getTemplateById( export async function getTemplateById(
apiEndpoint: string, apiEndpoint: string,
templateId: string, templateId: string,
headers?: IDataObject, headers?: RawAxiosRequestHeaders,
): Promise<{ workflow: ITemplatesWorkflowResponse }> { ): Promise<{ workflow: ITemplatesWorkflowResponse }> {
return await get(apiEndpoint, `/templates/workflows/${templateId}`, undefined, headers); return await get(apiEndpoint, `/templates/workflows/${templateId}`, undefined, headers);
} }
@ -80,7 +80,7 @@ export async function getTemplateById(
export async function getWorkflowTemplate( export async function getWorkflowTemplate(
apiEndpoint: string, apiEndpoint: string,
templateId: string, templateId: string,
headers?: IDataObject, headers?: RawAxiosRequestHeaders,
): Promise<IWorkflowTemplate> { ): Promise<IWorkflowTemplate> {
return await get(apiEndpoint, `/workflows/templates/${templateId}`, undefined, headers); return await get(apiEndpoint, `/workflows/templates/${templateId}`, undefined, headers);
} }

View file

@ -5,7 +5,12 @@ import type {
IWorkflowDb, IWorkflowDb,
NewWorkflowResponse, NewWorkflowResponse,
} from '@/Interface'; } from '@/Interface';
import type { ExecutionFilters, ExecutionOptions, IDataObject } from 'n8n-workflow'; import type {
ExecutionFilters,
ExecutionOptions,
ExecutionSummary,
IDataObject,
} from 'n8n-workflow';
import { makeRestApiRequest } from '@/utils/apiUtils'; import { makeRestApiRequest } from '@/utils/apiUtils';
export async function getNewWorkflow(context: IRestApiContext, data?: IDataObject) { export async function getNewWorkflow(context: IRestApiContext, data?: IDataObject) {
@ -40,7 +45,11 @@ export async function getActiveWorkflows(context: IRestApiContext) {
} }
export async function getActiveExecutions(context: IRestApiContext, filter: IDataObject) { export async function getActiveExecutions(context: IRestApiContext, filter: IDataObject) {
const output = await makeRestApiRequest(context, 'GET', '/executions', { filter }); const output = await makeRestApiRequest<{
results: ExecutionSummary[];
count: number;
estimated: boolean;
}>(context, 'GET', '/executions', { filter });
return output.results; return output.results;
} }

View file

@ -63,9 +63,7 @@ describe('BannerStack', () => {
it('should dismiss banner on click', async () => { it('should dismiss banner on click', async () => {
const { getByTestId } = renderComponent(); const { getByTestId } = renderComponent();
const dismissBannerSpy = vi const dismissBannerSpy = vi.spyOn(uiStore, 'dismissBanner').mockImplementation(async () => {});
.spyOn(uiStore, 'dismissBanner')
.mockImplementation(async (banner, mode) => {});
expect(getByTestId('banners-V1')).toBeInTheDocument(); expect(getByTestId('banners-V1')).toBeInTheDocument();
const closeTrialBannerButton = getByTestId('banner-V1-close'); const closeTrialBannerButton = getByTestId('banner-V1-close');
expect(closeTrialBannerButton).toBeInTheDocument(); expect(closeTrialBannerButton).toBeInTheDocument();
@ -75,9 +73,7 @@ describe('BannerStack', () => {
it('should permanently dismiss banner on click', async () => { it('should permanently dismiss banner on click', async () => {
const { getByTestId } = renderComponent(); const { getByTestId } = renderComponent();
const dismissBannerSpy = vi const dismissBannerSpy = vi.spyOn(uiStore, 'dismissBanner').mockImplementation(async () => {});
.spyOn(uiStore, 'dismissBanner')
.mockImplementation(async (banner, mode) => {});
const permanentlyDismissBannerLink = getByTestId('banner-confirm-v1'); const permanentlyDismissBannerLink = getByTestId('banner-confirm-v1');
expect(permanentlyDismissBannerLink).toBeInTheDocument(); expect(permanentlyDismissBannerLink).toBeInTheDocument();

View file

@ -4,6 +4,7 @@ import {
deleteDestinationFromDb, deleteDestinationFromDb,
getDestinationsFromBackend, getDestinationsFromBackend,
getEventNamesFromBackend, getEventNamesFromBackend,
hasDestinationId,
saveDestinationToDb, saveDestinationToDb,
sendTestMessageToDestination, sendTestMessageToDestination,
} from '../api/eventbus.ee'; } from '../api/eventbus.ee';
@ -186,29 +187,31 @@ export const useLogStreamingStore = defineStore('logStreaming', {
} }
}, },
async saveDestination(destination: MessageEventBusDestinationOptions): Promise<boolean> { async saveDestination(destination: MessageEventBusDestinationOptions): Promise<boolean> {
if (destination.id) { if (!hasDestinationId(destination)) {
const rootStore = useRootStore(); return false;
const selectedEvents = this.getSelectedEvents(destination.id); }
try {
await saveDestinationToDb(rootStore.getRestApiContext, destination, selectedEvents); const rootStore = useRootStore();
this.updateDestination(destination); const selectedEvents = this.getSelectedEvents(destination.id);
return true; try {
} catch (e) { await saveDestinationToDb(rootStore.getRestApiContext, destination, selectedEvents);
return false; this.updateDestination(destination);
} return true;
} catch (e) {
return false;
} }
return false;
}, },
async sendTestMessage(destination: MessageEventBusDestinationOptions) { async sendTestMessage(destination: MessageEventBusDestinationOptions) {
if (destination.id) { if (!hasDestinationId(destination)) {
const rootStore = useRootStore(); return false;
const testResult = await sendTestMessageToDestination(
rootStore.getRestApiContext,
destination,
);
return testResult;
} }
return false;
const rootStore = useRootStore();
const testResult = await sendTestMessageToDestination(
rootStore.getRestApiContext,
destination,
);
return testResult;
}, },
async fetchEventNames(): Promise<string[]> { async fetchEventNames(): Promise<string[]> {
const rootStore = useRootStore(); const rootStore = useRootStore();