refactor(editor): Apply Prettier (no-changelog) (#4920)
* ⚡ Adjust `format` script * 🔥 Remove exemption for `editor-ui` * 🎨 Prettify * 👕 Fix lint
This commit is contained in:
@@ -4,11 +4,18 @@
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
width="80%"
|
||||
:title="`${$locale.baseText('codeEdit.edit')} ${$locale.nodeText().inputLabelDisplayName(parameter, path)}`"
|
||||
:title="`${$locale.baseText('codeEdit.edit')} ${$locale
|
||||
.nodeText()
|
||||
.inputLabelDisplayName(parameter, path)}`"
|
||||
:before-close="closeDialog"
|
||||
>
|
||||
<div class="text-editor-wrapper ignore-key-press">
|
||||
<code-editor :value="value" :autocomplete="loadAutocompleteData" :readonly="readonly" @input="$emit('valueChanged', $event)" />
|
||||
<code-editor
|
||||
:value="value"
|
||||
:autocomplete="loadAutocompleteData"
|
||||
:readonly="readonly"
|
||||
@input="$emit('valueChanged', $event)"
|
||||
/>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
@@ -28,30 +35,21 @@ import {
|
||||
WorkflowDataProxy,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
PLACEHOLDER_FILLED_AT_EXECUTION_TIME,
|
||||
} from '@/constants';
|
||||
import { PLACEHOLDER_FILLED_AT_EXECUTION_TIME } from '@/constants';
|
||||
import { CodeEditor } from './forms';
|
||||
import { mapStores } from 'pinia';
|
||||
import { useWorkflowsStore } from '@/stores/workflows';
|
||||
import { useRootStore } from '@/stores/n8nRootStore';
|
||||
import { useNDVStore } from '@/stores/ndv';
|
||||
|
||||
export default mixins(
|
||||
genericHelpers,
|
||||
workflowHelpers,
|
||||
).extend({
|
||||
export default mixins(genericHelpers, workflowHelpers).extend({
|
||||
name: 'CodeEdit',
|
||||
components: {
|
||||
CodeEditor,
|
||||
},
|
||||
props: ['codeAutocomplete', 'parameter', 'path', 'type', 'value', 'readonly'],
|
||||
computed: {
|
||||
...mapStores(
|
||||
useNDVStore,
|
||||
useRootStore,
|
||||
useWorkflowsStore,
|
||||
),
|
||||
...mapStores(useNDVStore, useRootStore, useWorkflowsStore),
|
||||
},
|
||||
methods: {
|
||||
loadAutocompleteData(): string[] {
|
||||
@@ -65,7 +63,10 @@ export default mixins(
|
||||
const workflow = this.getCurrentWorkflow();
|
||||
const activeNode: INodeUi | null = this.ndvStore.activeNode;
|
||||
const parentNode = workflow.getParentNodes(activeNode!.name, inputName, 1);
|
||||
const nodeConnection = workflow.getNodeConnectionIndexes(activeNode!.name, parentNode[0]) || {
|
||||
const nodeConnection = workflow.getNodeConnectionIndexes(
|
||||
activeNode!.name,
|
||||
parentNode[0],
|
||||
) || {
|
||||
sourceIndex: 0,
|
||||
destinationIndex: 0,
|
||||
};
|
||||
@@ -86,7 +87,13 @@ export default mixins(
|
||||
}
|
||||
}
|
||||
|
||||
const connectionInputData = this.connectionInputData(parentNode, activeNode!.name, inputName, runIndex, nodeConnection);
|
||||
const connectionInputData = this.connectionInputData(
|
||||
parentNode,
|
||||
activeNode!.name,
|
||||
inputName,
|
||||
runIndex,
|
||||
nodeConnection,
|
||||
);
|
||||
|
||||
const additionalProxyKeys: IWorkflowDataProxyAdditionalKeys = {
|
||||
$execution: {
|
||||
@@ -100,7 +107,18 @@ export default mixins(
|
||||
$resumeWebhookUrl: PLACEHOLDER_FILLED_AT_EXECUTION_TIME,
|
||||
};
|
||||
|
||||
const dataProxy = new WorkflowDataProxy(workflow, runExecutionData, runIndex, itemIndex, activeNode!.name, connectionInputData || [], {}, mode, this.rootStore.timezone, additionalProxyKeys);
|
||||
const dataProxy = new WorkflowDataProxy(
|
||||
workflow,
|
||||
runExecutionData,
|
||||
runIndex,
|
||||
itemIndex,
|
||||
activeNode!.name,
|
||||
connectionInputData || [],
|
||||
{},
|
||||
mode,
|
||||
this.rootStore.timezone,
|
||||
additionalProxyKeys,
|
||||
);
|
||||
const proxy = dataProxy.getDataProxy();
|
||||
|
||||
const autoCompleteItems = [
|
||||
@@ -126,13 +144,7 @@ export default mixins(
|
||||
'Interval',
|
||||
];
|
||||
|
||||
const functionItemKeys = [
|
||||
'$json',
|
||||
'$binary',
|
||||
'$position',
|
||||
'$thisItem',
|
||||
'$thisItemIndex',
|
||||
];
|
||||
const functionItemKeys = ['$json', '$binary', '$position', '$thisItem', '$thisItemIndex'];
|
||||
|
||||
const additionalKeys: string[] = [];
|
||||
if (this.codeAutocomplete === 'functionItem') {
|
||||
@@ -142,13 +154,15 @@ export default mixins(
|
||||
if (executedWorkflow && connectionInputData && connectionInputData.length) {
|
||||
baseKeys.push(...additionalKeys);
|
||||
} else {
|
||||
additionalKeys.forEach(key => {
|
||||
additionalKeys.forEach((key) => {
|
||||
autoCompleteItems.push(`const ${key} = {}`);
|
||||
});
|
||||
}
|
||||
|
||||
for (const key of baseKeys) {
|
||||
autoCompleteItems.push(`const ${key} = ${JSON.stringify(this.createSimpleRepresentation(proxy[key]))}`);
|
||||
autoCompleteItems.push(
|
||||
`const ${key} = ${JSON.stringify(this.createSimpleRepresentation(proxy[key]))}`,
|
||||
);
|
||||
}
|
||||
|
||||
// Add the nodes and their simplified data
|
||||
@@ -159,24 +173,36 @@ export default mixins(
|
||||
// To not load to much data create a simple representation.
|
||||
nodes[nodeName] = {
|
||||
json: {} as IDataObject,
|
||||
parameter: this.createSimpleRepresentation(proxy.$node[nodeName].parameter) as IDataObject,
|
||||
parameter: this.createSimpleRepresentation(
|
||||
proxy.$node[nodeName].parameter,
|
||||
) as IDataObject,
|
||||
};
|
||||
|
||||
try {
|
||||
nodes[nodeName]!.json = this.createSimpleRepresentation(proxy.$node[nodeName].json) as IDataObject;
|
||||
nodes[nodeName]!.context = this.createSimpleRepresentation(proxy.$node[nodeName].context) as IDataObject;
|
||||
nodes[nodeName]!.json = this.createSimpleRepresentation(
|
||||
proxy.$node[nodeName].json,
|
||||
) as IDataObject;
|
||||
nodes[nodeName]!.context = this.createSimpleRepresentation(
|
||||
proxy.$node[nodeName].context,
|
||||
) as IDataObject;
|
||||
nodes[nodeName]!.runIndex = proxy.$node[nodeName].runIndex;
|
||||
if (Object.keys(proxy.$node[nodeName].binary).length) {
|
||||
nodes[nodeName]!.binary = this.createSimpleRepresentation(proxy.$node[nodeName].binary) as IBinaryKeyData;
|
||||
nodes[nodeName]!.binary = this.createSimpleRepresentation(
|
||||
proxy.$node[nodeName].binary,
|
||||
) as IBinaryKeyData;
|
||||
}
|
||||
} catch(error) {}
|
||||
} catch (error) {}
|
||||
}
|
||||
autoCompleteItems.push(`const $node = ${JSON.stringify(nodes)}`);
|
||||
autoCompleteItems.push(`function $jmespath(jsonDoc: object, query: string): {};`);
|
||||
|
||||
if (this.codeAutocomplete === 'function') {
|
||||
if (connectionInputData) {
|
||||
autoCompleteItems.push(`const items = ${JSON.stringify(this.createSimpleRepresentation(connectionInputData))}`);
|
||||
autoCompleteItems.push(
|
||||
`const items = ${JSON.stringify(
|
||||
this.createSimpleRepresentation(connectionInputData),
|
||||
)}`,
|
||||
);
|
||||
} else {
|
||||
autoCompleteItems.push(`const items: {json: {[key: string]: any}}[] = []`);
|
||||
}
|
||||
@@ -200,7 +226,29 @@ export default mixins(
|
||||
return false;
|
||||
},
|
||||
|
||||
createSimpleRepresentation(inputData: object | null | undefined | boolean | string | number | boolean[] | string[] | number[] | object[]): object | null | undefined | boolean | string | number | boolean[] | string[] | number[] | object[] {
|
||||
createSimpleRepresentation(
|
||||
inputData:
|
||||
| object
|
||||
| null
|
||||
| undefined
|
||||
| boolean
|
||||
| string
|
||||
| number
|
||||
| boolean[]
|
||||
| string[]
|
||||
| number[]
|
||||
| object[],
|
||||
):
|
||||
| object
|
||||
| null
|
||||
| undefined
|
||||
| boolean
|
||||
| string
|
||||
| number
|
||||
| boolean[]
|
||||
| string[]
|
||||
| number[]
|
||||
| object[] {
|
||||
if (inputData === null || inputData === undefined) {
|
||||
return inputData;
|
||||
} else if (typeof inputData === 'string') {
|
||||
@@ -210,10 +258,10 @@ export default mixins(
|
||||
} else if (typeof inputData === 'number') {
|
||||
return 1;
|
||||
} else if (Array.isArray(inputData)) {
|
||||
return inputData.map(value => this.createSimpleRepresentation(value));
|
||||
return inputData.map((value) => this.createSimpleRepresentation(value));
|
||||
} else if (typeof inputData === 'object') {
|
||||
const returnData: { [key: string]: object } = {};
|
||||
Object.keys(inputData).forEach(key => {
|
||||
Object.keys(inputData).forEach((key) => {
|
||||
// @ts-ignore
|
||||
returnData[key] = this.createSimpleRepresentation(inputData[key]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user