mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
refactor(editor): Delete leftover restApi mixin file (no-changelog) (#6074)
* refactor(editor): Delete leftover `restApi` mixin file (no-changelog) * Removing leftover comment
This commit is contained in:
parent
871d4193e2
commit
8886516c9e
|
@ -510,12 +510,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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -234,13 +234,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -450,7 +450,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,224 +0,0 @@
|
|||
import { defineComponent } from 'vue';
|
||||
import { parse } from 'flatted';
|
||||
|
||||
import type { Method } from 'axios';
|
||||
import type {
|
||||
IActivationError,
|
||||
IExecutionsCurrentSummaryExtended,
|
||||
IExecutionDeleteFilter,
|
||||
IExecutionPushResponse,
|
||||
IExecutionResponse,
|
||||
IExecutionFlattedResponse,
|
||||
IExecutionsListResponse,
|
||||
IExecutionsStopData,
|
||||
IStartRunData,
|
||||
IWorkflowDb,
|
||||
IWorkflowShortResponse,
|
||||
IRestApi,
|
||||
IWorkflowDataUpdate,
|
||||
} from '@/Interface';
|
||||
import { INodeTranslationHeaders } from '@/Interface';
|
||||
import type { IAbstractEventMessage, IDataObject } from 'n8n-workflow';
|
||||
import {
|
||||
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<any> {
|
||||
return makeRestApiRequest(self.rootStore.getRestApiContext, method, endpoint, data);
|
||||
},
|
||||
getActiveWorkflows: (): Promise<string[]> => {
|
||||
return self.restApi().makeRestApiRequest('GET', '/active');
|
||||
},
|
||||
getActivationError: (id: string): Promise<IActivationError | undefined> => {
|
||||
return self.restApi().makeRestApiRequest('GET', `/active/error/${id}`);
|
||||
},
|
||||
getCurrentExecutions: (
|
||||
filter: IDataObject,
|
||||
): Promise<IExecutionsCurrentSummaryExtended[]> => {
|
||||
let sendData = {};
|
||||
if (filter) {
|
||||
sendData = {
|
||||
filter,
|
||||
};
|
||||
}
|
||||
return self.restApi().makeRestApiRequest('GET', '/executions-current', sendData);
|
||||
},
|
||||
stopCurrentExecution: (executionId: string): Promise<IExecutionsStopData> => {
|
||||
return self
|
||||
.restApi()
|
||||
.makeRestApiRequest('POST', `/executions-current/${executionId}/stop`);
|
||||
},
|
||||
|
||||
getCredentialTranslation: (credentialType): Promise<object> => {
|
||||
return self
|
||||
.restApi()
|
||||
.makeRestApiRequest('GET', '/credential-translation', { credentialType });
|
||||
},
|
||||
|
||||
// Removes a test webhook
|
||||
removeTestWebhook: (workflowId: string): Promise<boolean> => {
|
||||
return self.restApi().makeRestApiRequest('DELETE', `/test-webhook/${workflowId}`);
|
||||
},
|
||||
|
||||
// Execute a workflow
|
||||
runWorkflow: async (startRunData: IStartRunData): Promise<IExecutionPushResponse> => {
|
||||
return self.restApi().makeRestApiRequest('POST', '/workflows/run', startRunData);
|
||||
},
|
||||
|
||||
// Creates a new workflow
|
||||
createNewWorkflow: (sendData: IWorkflowDataUpdate): Promise<IWorkflowDb> => {
|
||||
return self.restApi().makeRestApiRequest('POST', '/workflows', sendData);
|
||||
},
|
||||
|
||||
// Updates an existing workflow
|
||||
updateWorkflow: (
|
||||
id: string,
|
||||
data: IWorkflowDataUpdate,
|
||||
forceSave = false,
|
||||
): Promise<IWorkflowDb> => {
|
||||
return self
|
||||
.restApi()
|
||||
.makeRestApiRequest(
|
||||
'PATCH',
|
||||
`/workflows/${id}${forceSave ? '?forceSave=true' : ''}`,
|
||||
data,
|
||||
);
|
||||
},
|
||||
|
||||
// Deletes a workflow
|
||||
deleteWorkflow: (name: string): Promise<void> => {
|
||||
return self.restApi().makeRestApiRequest('DELETE', `/workflows/${name}`);
|
||||
},
|
||||
|
||||
// Returns the workflow with the given name
|
||||
getWorkflow: (id: string): Promise<IWorkflowDb> => {
|
||||
return self.restApi().makeRestApiRequest('GET', `/workflows/${id}`);
|
||||
},
|
||||
|
||||
// Returns all saved workflows
|
||||
getWorkflows: (filter?: object): Promise<IWorkflowShortResponse[]> => {
|
||||
let sendData;
|
||||
if (filter) {
|
||||
sendData = {
|
||||
filter,
|
||||
};
|
||||
}
|
||||
return self.restApi().makeRestApiRequest('GET', '/workflows', sendData);
|
||||
},
|
||||
|
||||
// Returns a workflow from a given URL
|
||||
getWorkflowFromUrl: (url: string): Promise<IWorkflowDb> => {
|
||||
return self.restApi().makeRestApiRequest('GET', '/workflows/from-url', { url });
|
||||
},
|
||||
|
||||
// Returns the execution with the given name
|
||||
getExecution: async (id: string): Promise<IExecutionResponse | undefined> => {
|
||||
const response = await self.restApi().makeRestApiRequest('GET', `/executions/${id}`);
|
||||
return response && unflattenExecutionData(response);
|
||||
},
|
||||
|
||||
// Deletes executions
|
||||
deleteExecutions: (sendData: IExecutionDeleteFilter): Promise<void> => {
|
||||
return self.restApi().makeRestApiRequest('POST', '/executions/delete', sendData);
|
||||
},
|
||||
|
||||
// Returns the execution with the given name
|
||||
retryExecution: (id: string, loadWorkflow?: boolean): Promise<boolean> => {
|
||||
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<IExecutionsListResponse> => {
|
||||
let sendData = {};
|
||||
if (filter) {
|
||||
sendData = {
|
||||
filter,
|
||||
firstId,
|
||||
lastId,
|
||||
limit,
|
||||
};
|
||||
}
|
||||
|
||||
return self.restApi().makeRestApiRequest('GET', '/executions', sendData);
|
||||
},
|
||||
|
||||
// Returns all the available timezones
|
||||
getTimezones: (): Promise<IDataObject> => {
|
||||
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<IAbstractEventMessage[]> => {
|
||||
return self.restApi().makeRestApiRequest('GET', '/eventbus/execution/' + id);
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
|
@ -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",
|
||||
|
|
|
@ -373,7 +373,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
|
|||
return workflows;
|
||||
},
|
||||
|
||||
async fetchAndSetWorkflow(id: string): Promise<IWorkflowDb> {
|
||||
async fetchWorkflow(id: string): Promise<IWorkflowDb> {
|
||||
const rootStore = useRootStore();
|
||||
const workflow = await getWorkflow(rootStore.getRestApiContext, id);
|
||||
this.addWorkflow(workflow);
|
||||
|
@ -492,7 +492,9 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
|
|||
}, {});
|
||||
},
|
||||
|
||||
deleteWorkflow(id: string): void {
|
||||
async deleteWorkflow(id: string): Promise<void> {
|
||||
const rootStore = useRootStore();
|
||||
await makeRestApiRequest(rootStore.getRestApiContext, 'DELETE', `/workflows/${id}`);
|
||||
const { [id]: deletedWorkflow, ...workflows } = this.workflowsById;
|
||||
this.workflowsById = workflows;
|
||||
},
|
||||
|
@ -1119,11 +1121,6 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
|
|||
return response && unflattenExecutionData(response);
|
||||
},
|
||||
|
||||
async fetchWorkflow(id: string): Promise<IWorkflowDb> {
|
||||
const rootStore = useRootStore();
|
||||
return makeRestApiRequest(rootStore.getRestApiContext, 'GET', `/workflows/${id}`);
|
||||
},
|
||||
|
||||
// Creates a new workflow
|
||||
async createNewWorkflow(sendData: IWorkflowDataUpdate): Promise<IWorkflowDb> {
|
||||
const rootStore = useRootStore();
|
||||
|
@ -1135,12 +1132,6 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
|
|||
);
|
||||
},
|
||||
|
||||
// Deletes a workflow
|
||||
async deleteWorkflowAPI(name: string): Promise<void> {
|
||||
const rootStore = useRootStore();
|
||||
return makeRestApiRequest(rootStore.getRestApiContext, 'DELETE', `/workflows/${name}`);
|
||||
},
|
||||
|
||||
// Updates an existing workflow
|
||||
async updateWorkflow(
|
||||
id: string,
|
||||
|
|
Loading…
Reference in a new issue