From a4df8a62d7485f2d4f211ba27818c34cfd08b7dc Mon Sep 17 00:00:00 2001 From: Milorad Filipovic Date: Mon, 24 Apr 2023 13:45:41 +0200 Subject: [PATCH] refactor(editor): Delete leftover `restApi` mixin file (no-changelog) --- .../components/MainHeader/WorkflowDetails.vue | 7 +- .../components/UserActivationSurveyModal.vue | 2 +- .../editor-ui/src/components/WorkflowCard.vue | 8 +- .../src/components/WorkflowShareModal.ee.vue | 2 +- packages/editor-ui/src/mixins/restApi.ts | 225 ------------------ .../src/plugins/i18n/locales/en.json | 1 + packages/editor-ui/src/stores/workflows.ts | 22 +- 7 files changed, 16 insertions(+), 251 deletions(-) delete mode 100644 packages/editor-ui/src/mixins/restApi.ts diff --git a/packages/editor-ui/src/components/MainHeader/WorkflowDetails.vue b/packages/editor-ui/src/components/MainHeader/WorkflowDetails.vue index a3980e16372ba..bbd4483dd8c11 100644 --- a/packages/editor-ui/src/components/MainHeader/WorkflowDetails.vue +++ b/packages/editor-ui/src/components/MainHeader/WorkflowDetails.vue @@ -509,12 +509,9 @@ export default mixins(workflowHelpers).extend({ } try { - await this.workflowsStore.deleteWorkflowAPI(this.currentWorkflowId); + await this.workflowsStore.deleteWorkflow(this.currentWorkflowId); } catch (error) { - this.$showError( - error, - this.$locale.baseText('mainSidebar.showError.stopExecution.title'), - ); + this.$showError(error, this.$locale.baseText('generic.deleteWorkflowError')); return; } this.uiStore.stateIsDirty = false; diff --git a/packages/editor-ui/src/components/UserActivationSurveyModal.vue b/packages/editor-ui/src/components/UserActivationSurveyModal.vue index ec1714d63626d..3cab5fbf595da 100644 --- a/packages/editor-ui/src/components/UserActivationSurveyModal.vue +++ b/packages/editor-ui/src/components/UserActivationSurveyModal.vue @@ -86,7 +86,7 @@ const workflowName = ref(''); onMounted(async () => { const currentSettings = getCurrentSettings(); try { - const { name } = await workflowStore.fetchAndSetWorkflow( + const { name } = await workflowStore.fetchWorkflow( currentSettings?.firstSuccessfulWorkflowId ?? '', ); workflowName.value = name; diff --git a/packages/editor-ui/src/components/WorkflowCard.vue b/packages/editor-ui/src/components/WorkflowCard.vue index a62ced3c33a18..cf38bb498d461 100644 --- a/packages/editor-ui/src/components/WorkflowCard.vue +++ b/packages/editor-ui/src/components/WorkflowCard.vue @@ -233,13 +233,9 @@ export default mixins(showMessage).extend({ } try { - await this.workflowsStore.deleteWorkflowAPI(this.data.id); - this.workflowsStore.deleteWorkflow(this.data.id); + await this.workflowsStore.deleteWorkflow(this.data.id); } catch (error) { - this.$showError( - error, - this.$locale.baseText('mainSidebar.showError.stopExecution.title'), - ); + this.$showError(error, this.$locale.baseText('generic.deleteWorkflowError')); return; } diff --git a/packages/editor-ui/src/components/WorkflowShareModal.ee.vue b/packages/editor-ui/src/components/WorkflowShareModal.ee.vue index fc3597cd80704..3d645cdaeda34 100644 --- a/packages/editor-ui/src/components/WorkflowShareModal.ee.vue +++ b/packages/editor-ui/src/components/WorkflowShareModal.ee.vue @@ -448,7 +448,7 @@ export default mixins(showMessage).extend({ this.workflow.id !== PLACEHOLDER_EMPTY_WORKFLOW_ID && !this.workflow.sharedWith?.length // Sharing info already loaded ) { - await this.workflowsStore.fetchAndSetWorkflow(this.workflow.id); + await this.workflowsStore.fetchWorkflow(this.workflow.id); } } diff --git a/packages/editor-ui/src/mixins/restApi.ts b/packages/editor-ui/src/mixins/restApi.ts deleted file mode 100644 index 7663eb1a7b204..0000000000000 --- a/packages/editor-ui/src/mixins/restApi.ts +++ /dev/null @@ -1,225 +0,0 @@ -import { defineComponent } from 'vue'; -import { parse } from 'flatted'; - -import { Method } from 'axios'; -import { - IActivationError, - IExecutionsCurrentSummaryExtended, - IExecutionDeleteFilter, - IExecutionPushResponse, - IExecutionResponse, - IExecutionFlattedResponse, - IExecutionsListResponse, - IExecutionsStopData, - IStartRunData, - IWorkflowDb, - IWorkflowShortResponse, - IRestApi, - IWorkflowDataUpdate, - INodeTranslationHeaders, -} from '@/Interface'; -import { - IAbstractEventMessage, - IDataObject, - ILoadOptions, - INodeCredentials, - INodeParameters, - INodePropertyOptions, - INodeTypeDescription, - INodeTypeNameVersion, - IRunExecutionData, -} from 'n8n-workflow'; -import { makeRestApiRequest } from '@/utils'; -import { mapStores } from 'pinia'; -import { useRootStore } from '@/stores/n8nRootStore'; - -/** - * Unflattens the Execution data. - * - * @param {IExecutionFlattedResponse} fullExecutionData The data to unflatten - */ -function unflattenExecutionData(fullExecutionData: IExecutionFlattedResponse): IExecutionResponse { - // Unflatten the data - const returnData: IExecutionResponse = { - ...fullExecutionData, - workflowData: fullExecutionData.workflowData as IWorkflowDb, - data: parse(fullExecutionData.data), - }; - - returnData.finished = returnData.finished ? returnData.finished : false; - - if (fullExecutionData.id) { - returnData.id = fullExecutionData.id; - } - - return returnData; -} - -export const restApi = defineComponent({ - computed: { - ...mapStores(useRootStore), - }, - methods: { - restApi(): IRestApi { - const self = this; - return { - async makeRestApiRequest( - method: Method, - endpoint: string, - data?: IDataObject, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - ): Promise { - return makeRestApiRequest(self.rootStore.getRestApiContext, method, endpoint, data); - }, - getActiveWorkflows: (): Promise => { - return self.restApi().makeRestApiRequest('GET', '/active'); - }, - getActivationError: (id: string): Promise => { - return self.restApi().makeRestApiRequest('GET', `/active/error/${id}`); - }, - getCurrentExecutions: ( - filter: IDataObject, - ): Promise => { - let sendData = {}; - if (filter) { - sendData = { - filter, - }; - } - return self.restApi().makeRestApiRequest('GET', '/executions-current', sendData); - }, - stopCurrentExecution: (executionId: string): Promise => { - return self - .restApi() - .makeRestApiRequest('POST', `/executions-current/${executionId}/stop`); - }, - - getCredentialTranslation: (credentialType): Promise => { - return self - .restApi() - .makeRestApiRequest('GET', '/credential-translation', { credentialType }); - }, - - // Removes a test webhook - removeTestWebhook: (workflowId: string): Promise => { - return self.restApi().makeRestApiRequest('DELETE', `/test-webhook/${workflowId}`); - }, - - // Execute a workflow - runWorkflow: async (startRunData: IStartRunData): Promise => { - return self.restApi().makeRestApiRequest('POST', '/workflows/run', startRunData); - }, - - // Creates a new workflow - createNewWorkflow: (sendData: IWorkflowDataUpdate): Promise => { - return self.restApi().makeRestApiRequest('POST', '/workflows', sendData); - }, - - // Updates an existing workflow - updateWorkflow: ( - id: string, - data: IWorkflowDataUpdate, - forceSave = false, - ): Promise => { - return self - .restApi() - .makeRestApiRequest( - 'PATCH', - `/workflows/${id}${forceSave ? '?forceSave=true' : ''}`, - data, - ); - }, - - // Deletes a workflow - deleteWorkflow: (name: string): Promise => { - return self.restApi().makeRestApiRequest('DELETE', `/workflows/${name}`); - }, - - // Returns the workflow with the given name - getWorkflow: (id: string): Promise => { - return self.restApi().makeRestApiRequest('GET', `/workflows/${id}`); - }, - - // Returns all saved workflows - getWorkflows: (filter?: object): Promise => { - let sendData; - if (filter) { - sendData = { - filter, - }; - } - return self.restApi().makeRestApiRequest('GET', '/workflows', sendData); - }, - - // Returns a workflow from a given URL - getWorkflowFromUrl: (url: string): Promise => { - return self.restApi().makeRestApiRequest('GET', '/workflows/from-url', { url }); - }, - - // Returns the execution with the given name - getExecution: async (id: string): Promise => { - const response = await self.restApi().makeRestApiRequest('GET', `/executions/${id}`); - return response && unflattenExecutionData(response); - }, - - // Deletes executions - deleteExecutions: (sendData: IExecutionDeleteFilter): Promise => { - return self.restApi().makeRestApiRequest('POST', '/executions/delete', sendData); - }, - - // Returns the execution with the given name - retryExecution: (id: string, loadWorkflow?: boolean): Promise => { - let sendData; - if (loadWorkflow === true) { - sendData = { - loadWorkflow: true, - }; - } - return self.restApi().makeRestApiRequest('POST', `/executions/${id}/retry`, sendData); - }, - - // Returns all saved executions - // TODO: For sure needs some kind of default filter like last day, with max 10 results, ... - getPastExecutions: ( - filter: IDataObject, - limit: number, - lastId?: string, - firstId?: string, - ): Promise => { - let sendData = {}; - if (filter) { - sendData = { - filter, - firstId, - lastId, - limit, - }; - } - - return self.restApi().makeRestApiRequest('GET', '/executions', sendData); - }, - - // Returns all the available timezones - getTimezones: (): Promise => { - return self.restApi().makeRestApiRequest('GET', '/options/timezones'); - }, - - // Binary data - getBinaryUrl: (dataPath, mode, fileName, mimeType): string => { - let restUrl = self.rootStore.getRestUrl; - if (restUrl.startsWith('/')) restUrl = window.location.origin + restUrl; - const url = new URL(`${restUrl}/data/${dataPath}`); - url.searchParams.append('mode', mode); - if (fileName) url.searchParams.append('fileName', fileName); - if (mimeType) url.searchParams.append('mimeType', mimeType); - return url.toString(); - }, - - // Returns all the available timezones - getExecutionEvents: (id: string): Promise => { - return self.restApi().makeRestApiRequest('GET', '/eventbus/execution/' + id); - }, - }; - }, - }, -}); diff --git a/packages/editor-ui/src/plugins/i18n/locales/en.json b/packages/editor-ui/src/plugins/i18n/locales/en.json index 15f9225163095..b7ffaee648efa 100644 --- a/packages/editor-ui/src/plugins/i18n/locales/en.json +++ b/packages/editor-ui/src/plugins/i18n/locales/en.json @@ -19,6 +19,7 @@ "generic.any": "Any", "generic.cancel": "Cancel", "generic.confirm": "Confirm", + "generic.deleteWorkflowError": "Problem deleting workflow", "generic.filtersApplied": "Filters are currently applied.", "generic.learnMore": "Learn more", "generic.reset": "Reset", diff --git a/packages/editor-ui/src/stores/workflows.ts b/packages/editor-ui/src/stores/workflows.ts index bbfad903d9c50..e04da3d1e742c 100644 --- a/packages/editor-ui/src/stores/workflows.ts +++ b/packages/editor-ui/src/stores/workflows.ts @@ -375,7 +375,12 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, { return workflows; }, - async fetchAndSetWorkflow(id: string): Promise { + // async fetchWorkflow(id: string): Promise { + // const rootStore = useRootStore(); + // return makeRestApiRequest(rootStore.getRestApiContext, 'GET', `/workflows/${id}`); + // }, + + async fetchWorkflow(id: string): Promise { const rootStore = useRootStore(); const workflow = await getWorkflow(rootStore.getRestApiContext, id); this.addWorkflow(workflow); @@ -494,7 +499,9 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, { }, {}); }, - deleteWorkflow(id: string): void { + async deleteWorkflow(id: string): Promise { + const rootStore = useRootStore(); + await makeRestApiRequest(rootStore.getRestApiContext, 'DELETE', `/workflows/${id}`); const { [id]: deletedWorkflow, ...workflows } = this.workflowsById; this.workflowsById = workflows; }, @@ -1121,11 +1128,6 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, { return response && unflattenExecutionData(response); }, - async fetchWorkflow(id: string): Promise { - const rootStore = useRootStore(); - return makeRestApiRequest(rootStore.getRestApiContext, 'GET', `/workflows/${id}`); - }, - // Creates a new workflow async createNewWorkflow(sendData: IWorkflowDataUpdate): Promise { const rootStore = useRootStore(); @@ -1137,12 +1139,6 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, { ); }, - // Deletes a workflow - async deleteWorkflowAPI(name: string): Promise { - const rootStore = useRootStore(); - return makeRestApiRequest(rootStore.getRestApiContext, 'DELETE', `/workflows/${name}`); - }, - // Updates an existing workflow async updateWorkflow( id: string,