From 884b28952fc0d91976f419002cfabe2791e0717e Mon Sep 17 00:00:00 2001 From: Tomi Turtiainen <10324676+tomi@users.noreply.github.com> Date: Fri, 31 May 2024 09:40:41 +0300 Subject: [PATCH 1/4] style(editor): Remove unused arguments in BannerStack.test.ts --- .../src/components/__tests__/BannersStack.test.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/editor-ui/src/components/__tests__/BannersStack.test.ts b/packages/editor-ui/src/components/__tests__/BannersStack.test.ts index dc4df6bc6eb6a..309c2cc16822f 100644 --- a/packages/editor-ui/src/components/__tests__/BannersStack.test.ts +++ b/packages/editor-ui/src/components/__tests__/BannersStack.test.ts @@ -63,9 +63,7 @@ describe('BannerStack', () => { it('should dismiss banner on click', async () => { const { getByTestId } = renderComponent(); - const dismissBannerSpy = vi - .spyOn(uiStore, 'dismissBanner') - .mockImplementation(async (banner, mode) => {}); + const dismissBannerSpy = vi.spyOn(uiStore, 'dismissBanner').mockImplementation(async () => {}); expect(getByTestId('banners-V1')).toBeInTheDocument(); const closeTrialBannerButton = getByTestId('banner-V1-close'); expect(closeTrialBannerButton).toBeInTheDocument(); @@ -75,9 +73,7 @@ describe('BannerStack', () => { it('should permanently dismiss banner on click', async () => { const { getByTestId } = renderComponent(); - const dismissBannerSpy = vi - .spyOn(uiStore, 'dismissBanner') - .mockImplementation(async (banner, mode) => {}); + const dismissBannerSpy = vi.spyOn(uiStore, 'dismissBanner').mockImplementation(async () => {}); const permanentlyDismissBannerLink = getByTestId('banner-confirm-v1'); expect(permanentlyDismissBannerLink).toBeInTheDocument(); From fdac96a4c28268218a4cdce6ec95d4561d4d2d81 Mon Sep 17 00:00:00 2001 From: Tomi Turtiainen <10324676+tomi@users.noreply.github.com> Date: Fri, 31 May 2024 09:48:08 +0300 Subject: [PATCH 2/4] style(editor): Make sure all code paths return a value --- packages/editor-ui/src/api/eventbus.ee.ts | 36 +++++++++------- .../src/stores/logStreaming.store.ts | 41 ++++++++++--------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/packages/editor-ui/src/api/eventbus.ee.ts b/packages/editor-ui/src/api/eventbus.ee.ts index da9d798530095..a89fdb46430e3 100644 --- a/packages/editor-ui/src/api/eventbus.ee.ts +++ b/packages/editor-ui/src/api/eventbus.ee.ts @@ -2,18 +2,26 @@ import type { IRestApiContext } from '@/Interface'; import { makeRestApiRequest } from '@/utils/apiUtils'; 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( context: IRestApiContext, - destination: MessageEventBusDestinationOptions, + destination: ApiMessageEventBusDestinationOptions, subscribedEvents: string[] = [], ) { - if (destination.id) { - const data: IDataObject = { - ...destination, - subscribedEvents, - }; - return await makeRestApiRequest(context, 'POST', '/eventbus/destination', data); - } + const data: IDataObject = { + ...destination, + subscribedEvents, + }; + return await makeRestApiRequest(context, 'POST', '/eventbus/destination', data); } export async function deleteDestinationFromDb(context: IRestApiContext, destinationId: string) { @@ -22,14 +30,12 @@ export async function deleteDestinationFromDb(context: IRestApiContext, destinat export async function sendTestMessageToDestination( context: IRestApiContext, - destination: MessageEventBusDestinationOptions, + destination: ApiMessageEventBusDestinationOptions, ) { - if (destination.id) { - const data: IDataObject = { - ...destination, - }; - return await makeRestApiRequest(context, 'GET', '/eventbus/testmessage', data); - } + const data: IDataObject = { + ...destination, + }; + return await makeRestApiRequest(context, 'GET', '/eventbus/testmessage', data); } export async function getEventNamesFromBackend(context: IRestApiContext): Promise { diff --git a/packages/editor-ui/src/stores/logStreaming.store.ts b/packages/editor-ui/src/stores/logStreaming.store.ts index 6c7656d76871f..1ebe04bfecca8 100644 --- a/packages/editor-ui/src/stores/logStreaming.store.ts +++ b/packages/editor-ui/src/stores/logStreaming.store.ts @@ -4,6 +4,7 @@ import { deleteDestinationFromDb, getDestinationsFromBackend, getEventNamesFromBackend, + hasDestinationId, saveDestinationToDb, sendTestMessageToDestination, } from '../api/eventbus.ee'; @@ -186,29 +187,31 @@ export const useLogStreamingStore = defineStore('logStreaming', { } }, async saveDestination(destination: MessageEventBusDestinationOptions): Promise { - if (destination.id) { - const rootStore = useRootStore(); - const selectedEvents = this.getSelectedEvents(destination.id); - try { - await saveDestinationToDb(rootStore.getRestApiContext, destination, selectedEvents); - this.updateDestination(destination); - return true; - } catch (e) { - return false; - } + if (!hasDestinationId(destination)) { + return false; + } + + const rootStore = useRootStore(); + const selectedEvents = this.getSelectedEvents(destination.id); + try { + await saveDestinationToDb(rootStore.getRestApiContext, destination, selectedEvents); + this.updateDestination(destination); + return true; + } catch (e) { + return false; } - return false; }, async sendTestMessage(destination: MessageEventBusDestinationOptions) { - if (destination.id) { - const rootStore = useRootStore(); - const testResult = await sendTestMessageToDestination( - rootStore.getRestApiContext, - destination, - ); - return testResult; + if (!hasDestinationId(destination)) { + return false; } - return false; + + const rootStore = useRootStore(); + const testResult = await sendTestMessageToDestination( + rootStore.getRestApiContext, + destination, + ); + return testResult; }, async fetchEventNames(): Promise { const rootStore = useRootStore(); From e9a5a756213ec6163ec5d0a7db710d6cbce8560f Mon Sep 17 00:00:00 2001 From: Tomi Turtiainen <10324676+tomi@users.noreply.github.com> Date: Fri, 31 May 2024 09:53:55 +0300 Subject: [PATCH 3/4] style(editor): Fix ts errors in src/api/templates.ts --- packages/editor-ui/src/api/templates.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/editor-ui/src/api/templates.ts b/packages/editor-ui/src/api/templates.ts index 9938852f36645..8fa3f41aca44d 100644 --- a/packages/editor-ui/src/api/templates.ts +++ b/packages/editor-ui/src/api/templates.ts @@ -1,3 +1,4 @@ +import type { RawAxiosRequestHeaders } from 'axios'; import type { ITemplatesCategory, ITemplatesCollection, @@ -8,7 +9,6 @@ import type { IWorkflowTemplate, TemplateSearchFacet, } from '@/Interface'; -import type { IDataObject } from 'n8n-workflow'; import { get } from '@/utils/apiUtils'; function stringifyArray(arr: number[]) { @@ -21,7 +21,7 @@ export async function testHealthEndpoint(apiEndpoint: string) { export async function getCategories( apiEndpoint: string, - headers?: IDataObject, + headers?: RawAxiosRequestHeaders, ): Promise<{ categories: ITemplatesCategory[] }> { return await get(apiEndpoint, '/templates/categories', undefined, headers); } @@ -29,12 +29,12 @@ export async function getCategories( export async function getCollections( apiEndpoint: string, query: ITemplatesQuery, - headers?: IDataObject, + headers?: RawAxiosRequestHeaders, ): Promise<{ collections: ITemplatesCollection[] }> { return await get( apiEndpoint, '/templates/collections', - { category: stringifyArray(query.categories || []), search: query.search }, + { category: query.categories, search: query.search }, headers, ); } @@ -42,7 +42,7 @@ export async function getCollections( export async function getWorkflows( apiEndpoint: string, query: { page: number; limit: number; categories: number[]; search: string }, - headers?: IDataObject, + headers?: RawAxiosRequestHeaders, ): Promise<{ totalWorkflows: number; workflows: ITemplatesWorkflow[]; @@ -64,7 +64,7 @@ export async function getWorkflows( export async function getCollectionById( apiEndpoint: string, collectionId: string, - headers?: IDataObject, + headers?: RawAxiosRequestHeaders, ): Promise<{ collection: ITemplatesCollectionResponse }> { return await get(apiEndpoint, `/templates/collections/${collectionId}`, undefined, headers); } @@ -72,7 +72,7 @@ export async function getCollectionById( export async function getTemplateById( apiEndpoint: string, templateId: string, - headers?: IDataObject, + headers?: RawAxiosRequestHeaders, ): Promise<{ workflow: ITemplatesWorkflowResponse }> { return await get(apiEndpoint, `/templates/workflows/${templateId}`, undefined, headers); } @@ -80,7 +80,7 @@ export async function getTemplateById( export async function getWorkflowTemplate( apiEndpoint: string, templateId: string, - headers?: IDataObject, + headers?: RawAxiosRequestHeaders, ): Promise { return await get(apiEndpoint, `/workflows/templates/${templateId}`, undefined, headers); } From c3631c4abbf9d6a0e0333a7f96729a28dd8bc5c0 Mon Sep 17 00:00:00 2001 From: Tomi Turtiainen <10324676+tomi@users.noreply.github.com> Date: Fri, 31 May 2024 10:00:51 +0300 Subject: [PATCH 4/4] style(editor): Fix ts errors in src/api/workflows.ts --- packages/editor-ui/src/Interface.ts | 4 ++-- packages/editor-ui/src/api/workflows.ts | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/editor-ui/src/Interface.ts b/packages/editor-ui/src/Interface.ts index c4b441ee863df..d82a120f0be23 100644 --- a/packages/editor-ui/src/Interface.ts +++ b/packages/editor-ui/src/Interface.ts @@ -430,8 +430,8 @@ export interface IExecutionsCurrentSummaryExtended { id: string; finished?: boolean; mode: WorkflowExecuteMode; - retryOf?: string; - retrySuccessId?: string; + retryOf?: string | null; + retrySuccessId?: string | null; startedAt: Date; stoppedAt?: Date; workflowId: string; diff --git a/packages/editor-ui/src/api/workflows.ts b/packages/editor-ui/src/api/workflows.ts index b788e966ce849..c65c788ae277c 100644 --- a/packages/editor-ui/src/api/workflows.ts +++ b/packages/editor-ui/src/api/workflows.ts @@ -5,7 +5,12 @@ import type { IWorkflowDb, NewWorkflowResponse, } from '@/Interface'; -import type { ExecutionFilters, ExecutionOptions, IDataObject } from 'n8n-workflow'; +import type { + ExecutionFilters, + ExecutionOptions, + ExecutionSummary, + IDataObject, +} from 'n8n-workflow'; import { makeRestApiRequest } from '@/utils/apiUtils'; 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) { - 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; }