fix(editor): Replace native Array.prototype.findLast with lodash.findLast (no-changelog) (#6885)

fix(editor): Replace native Array.findLast with lodash.findLast

Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
OlegIvaniv 2023-08-09 10:26:40 +02:00 committed by GitHub
parent b82cf5603a
commit 990068ff07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,6 +32,7 @@ import type {
IWorkflowDb,
IWorkflowsMap,
WorkflowsState,
NodeMetadataMap,
} from '@/Interface';
import { defineStore } from 'pinia';
import type {
@ -58,6 +59,7 @@ import type {
IWorkflowSettings,
} from 'n8n-workflow';
import { deepCopy, NodeHelpers, Workflow } from 'n8n-workflow';
import { findLast } from 'lodash-es';
import { useRootStore } from './n8nRoot.store';
import {
@ -84,7 +86,6 @@ import { useNDVStore } from './ndv.store';
import { useNodeTypesStore } from './nodeTypes.store';
import { useUsersStore } from '@/stores/users.store';
import { useSettingsStore } from '@/stores/settings.store';
import type { NodeMetadataMap } from '@/Interface';
const defaults: Omit<IWorkflowDb, 'id'> & { settings: NonNullable<IWorkflowDb['settings']> } = {
name: '',
@ -157,10 +158,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
workflowTriggerNodes(): INodeUi[] {
return this.workflow.nodes.filter((node: INodeUi) => {
const nodeTypesStore = useNodeTypesStore();
const nodeType = nodeTypesStore.getNodeType(
node.type as string,
node.typeVersion as number,
);
const nodeType = nodeTypesStore.getNodeType(node.type, node.typeVersion);
return nodeType && nodeType.group.includes('trigger');
});
},
@ -168,11 +166,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
return !!this.workflow.nodes.find((node: INodeUi) => !!node.webhookId);
},
getWorkflowRunData(): IRunData | null {
if (
!this.workflowExecutionData ||
!this.workflowExecutionData.data ||
!this.workflowExecutionData.data.resultData
) {
if (!this.workflowExecutionData?.data?.resultData) {
return null;
}
return this.workflowExecutionData.data.resultData.runData;
@ -260,13 +254,12 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
return this.workflowExecutionData ? this.workflowExecutionData.executedNode : undefined;
},
getParametersLastUpdate(): (name: string) => number | undefined {
return (nodeName: string) =>
this.nodeMetadata[nodeName] && this.nodeMetadata[nodeName].parametersLastUpdatedAt;
return (nodeName: string) => this.nodeMetadata[nodeName]?.parametersLastUpdatedAt;
},
isNodePristine(): (name: string) => boolean {
return (nodeName: string) =>
this.nodeMetadata[nodeName] === undefined || this.nodeMetadata[nodeName].pristine === true;
this.nodeMetadata[nodeName] === undefined || this.nodeMetadata[nodeName].pristine;
},
// Executions getters
getExecutionDataById(): (id: string) => IExecutionsSummary | undefined {
@ -452,7 +445,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
this.workflow.usedCredentials = data;
this.usedCredentials = data.reduce<{ [name: string]: IUsedCredential }>(
(accu, credential) => {
accu[credential.id!] = credential;
accu[credential.id] = credential;
return accu;
},
{},
@ -488,7 +481,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
const nodeCredentials: INodeCredentials | undefined = (node as unknown as INode)
.credentials;
if (!nodeCredentials || !nodeCredentials[data.type]) {
if (!nodeCredentials?.[data.type]) {
return;
}
@ -762,7 +755,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
break;
}
// Add the new connection if it does not exist already
if (connectionExists === false) {
if (!connectionExists) {
this.workflow.connections[sourceData.node][sourceData.type][sourceData.index].push(
destinationData,
);
@ -858,8 +851,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
// If node has any WorkflowResultData rename also that one that the data
// does still get displayed also after node got renamed
if (
this.workflowExecutionData !== null &&
this.workflowExecutionData.data &&
this.workflowExecutionData?.data &&
this.workflowExecutionData.data.resultData.runData.hasOwnProperty(nameData.old)
) {
this.workflowExecutionData.data.resultData.runData[nameData.new] =
@ -919,11 +911,11 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
return false;
}
const node = this.workflow.nodes[nodeIndex!];
const node = this.workflow.nodes[nodeIndex];
if (nodeIssueData.value === null) {
// Remove the value if one exists
if (node.issues === undefined || node.issues[nodeIssueData.type] === undefined) {
if (node.issues?.[nodeIssueData.type] === undefined) {
// No values for type exist so nothing has to get removed
return true;
}
@ -1079,7 +1071,8 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
},
setLastNodeParameters(updateInformation: IUpdateInformation) {
const latestNode = this.workflow.nodes.findLast(
const latestNode = findLast(
this.workflow.nodes,
(node) => node.type === updateInformation.key,
) as INodeUi;
const nodeType = useNodeTypesStore().getNodeType(latestNode.type);
@ -1097,7 +1090,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
},
addNodeExecutionData(pushData: IPushDataNodeExecuteAfter): void {
if (this.workflowExecutionData === null || !this.workflowExecutionData.data) {
if (!this.workflowExecutionData?.data) {
throw new Error('The "workflowExecutionData" is not initialized!');
}
if (this.workflowExecutionData.data.resultData.runData[pushData.nodeName] === undefined) {
@ -1119,7 +1112,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
this.workflowExecutionPairedItemMappings = getPairedItemsMapping(this.workflowExecutionData);
},
clearNodeExecutionData(nodeName: string): void {
if (this.workflowExecutionData === null || !this.workflowExecutionData.data) {
if (!this.workflowExecutionData?.data) {
return;
}
@ -1138,7 +1131,7 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, {
},
pinDataByNodeName(nodeName: string): INodeExecutionData[] | undefined {
if (!this.workflow.pinData || !this.workflow.pinData[nodeName]) return undefined;
if (!this.workflow.pinData?.[nodeName]) return undefined;
return this.workflow.pinData[nodeName].map((item) => item.json) as INodeExecutionData[];
},