Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 21 additions & 15 deletions packages/editor-ui/src/api/eventbus.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<string[]> {
Expand Down
16 changes: 8 additions & 8 deletions packages/editor-ui/src/api/templates.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { RawAxiosRequestHeaders } from 'axios';
import type {
ITemplatesCategory,
ITemplatesCollection,
Expand All @@ -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[]) {
Expand All @@ -21,28 +21,28 @@ 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);
}

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,
);
}

export async function getWorkflows(
apiEndpoint: string,
query: { page: number; limit: number; categories: number[]; search: string },
headers?: IDataObject,
headers?: RawAxiosRequestHeaders,
): Promise<{
totalWorkflows: number;
workflows: ITemplatesWorkflow[];
Expand All @@ -64,23 +64,23 @@ 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);
}

export async function getTemplateById(
apiEndpoint: string,
templateId: string,
headers?: IDataObject,
headers?: RawAxiosRequestHeaders,
): Promise<{ workflow: ITemplatesWorkflowResponse }> {
return await get(apiEndpoint, `/templates/workflows/${templateId}`, undefined, headers);
}

export async function getWorkflowTemplate(
apiEndpoint: string,
templateId: string,
headers?: IDataObject,
headers?: RawAxiosRequestHeaders,
): Promise<IWorkflowTemplate> {
return await get(apiEndpoint, `/workflows/templates/${templateId}`, undefined, headers);
}
13 changes: 11 additions & 2 deletions packages/editor-ui/src/api/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
41 changes: 22 additions & 19 deletions packages/editor-ui/src/stores/logStreaming.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
deleteDestinationFromDb,
getDestinationsFromBackend,
getEventNamesFromBackend,
hasDestinationId,
saveDestinationToDb,
sendTestMessageToDestination,
} from '../api/eventbus.ee';
Expand Down Expand Up @@ -186,29 +187,31 @@ export const useLogStreamingStore = defineStore('logStreaming', {
}
},
async saveDestination(destination: MessageEventBusDestinationOptions): Promise<boolean> {
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<string[]> {
const rootStore = useRootStore();
Expand Down
Loading