2022-10-06 06:03:55 -07:00
|
|
|
<template>
|
|
|
|
<div :class="$style.jsonDisplay">
|
|
|
|
<run-data-json-actions
|
|
|
|
v-if="!editMode.enabled"
|
|
|
|
:node="node"
|
|
|
|
:sessioId="sessionId"
|
|
|
|
:displayMode="displayMode"
|
|
|
|
:distanceFromActive="distanceFromActive"
|
|
|
|
:selectedJsonPath="selectedJsonPath"
|
|
|
|
:jsonData="jsonData"
|
|
|
|
:paneType="paneType"
|
|
|
|
/>
|
|
|
|
<draggable
|
|
|
|
type="mapping"
|
|
|
|
targetDataKey="mappable"
|
|
|
|
:disabled="!mappingEnabled"
|
|
|
|
@dragstart="onDragStart"
|
|
|
|
@dragend="onDragEnd"
|
|
|
|
>
|
|
|
|
<template #preview="{ canDrop, el }">
|
2022-12-23 04:37:32 -08:00
|
|
|
<MappingPill v-if="el" :html="getShortKey(el)" :can-drop="canDrop" />
|
2022-10-06 06:03:55 -07:00
|
|
|
</template>
|
|
|
|
<template>
|
|
|
|
<vue-json-pretty
|
|
|
|
:data="jsonData"
|
|
|
|
:deep="10"
|
|
|
|
:showLength="true"
|
|
|
|
:selected-value.sync="selectedJsonPath"
|
|
|
|
rootPath=""
|
|
|
|
selectableType="single"
|
|
|
|
class="json-data"
|
|
|
|
>
|
|
|
|
<template #nodeKey="{ node }">
|
2022-12-14 01:04:10 -08:00
|
|
|
<span
|
|
|
|
data-target="mappable"
|
|
|
|
:data-value="getJsonParameterPath(node.path)"
|
|
|
|
:data-name="node.key"
|
|
|
|
:data-path="node.path"
|
|
|
|
:data-depth="node.level"
|
|
|
|
:class="{
|
|
|
|
[$style.mappable]: mappingEnabled,
|
|
|
|
[$style.dragged]: draggingPath === node.path,
|
|
|
|
}"
|
|
|
|
>"{{ node.key }}"</span
|
|
|
|
>
|
2022-10-06 06:03:55 -07:00
|
|
|
</template>
|
|
|
|
<template #nodeValue="{ node }">
|
2023-03-23 03:20:11 -07:00
|
|
|
<span v-if="isNaN(node.index)" class="ph-no-capture">{{
|
|
|
|
getContent(node.content)
|
|
|
|
}}</span>
|
2022-12-01 00:33:34 -08:00
|
|
|
<span
|
|
|
|
v-else
|
|
|
|
data-target="mappable"
|
|
|
|
:data-value="getJsonParameterPath(node.path)"
|
|
|
|
:data-name="getListItemName(node.path)"
|
|
|
|
:data-path="node.path"
|
|
|
|
:data-depth="node.level"
|
|
|
|
:class="{
|
2022-12-14 01:04:10 -08:00
|
|
|
[$style.mappable]: mappingEnabled,
|
|
|
|
[$style.dragged]: draggingPath === node.path,
|
|
|
|
}"
|
2023-03-23 03:20:11 -07:00
|
|
|
class="ph-no-capture"
|
2022-12-14 01:04:10 -08:00
|
|
|
>{{ getContent(node.content) }}</span
|
|
|
|
>
|
2022-10-06 06:03:55 -07:00
|
|
|
</template>
|
|
|
|
</vue-json-pretty>
|
|
|
|
</template>
|
|
|
|
</draggable>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-05-16 02:43:46 -07:00
|
|
|
import { defineComponent } from 'vue';
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { PropType } from 'vue';
|
2022-10-06 06:03:55 -07:00
|
|
|
import VueJsonPretty from 'vue-json-pretty';
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { IDataObject, INodeExecutionData } from 'n8n-workflow';
|
2022-10-06 06:03:55 -07:00
|
|
|
import Draggable from '@/components/Draggable.vue';
|
2023-02-21 02:27:15 -08:00
|
|
|
import { executionDataToJson, isString, shorten } from '@/utils';
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { INodeUi } from '@/Interface';
|
2022-12-14 01:04:10 -08:00
|
|
|
import { externalHooks } from '@/mixins/externalHooks';
|
|
|
|
import { mapStores } from 'pinia';
|
2023-05-05 01:41:54 -07:00
|
|
|
import { useNDVStore } from '@/stores/ndv.store';
|
2022-12-20 00:39:38 -08:00
|
|
|
import MappingPill from './MappingPill.vue';
|
2023-01-30 03:42:08 -08:00
|
|
|
import { getMappedExpression } from '@/utils/mappingUtils';
|
2023-05-05 01:41:54 -07:00
|
|
|
import { useWorkflowsStore } from '@/stores/workflows.store';
|
2023-05-02 00:39:09 -07:00
|
|
|
import { nonExistingJsonPath } from '@/components/RunDataJsonActions.vue';
|
2022-10-06 06:03:55 -07:00
|
|
|
|
2023-05-10 08:10:03 -07:00
|
|
|
const runDataJsonActions = async () => import('@/components/RunDataJsonActions.vue');
|
2022-10-06 06:03:55 -07:00
|
|
|
|
2023-05-16 02:43:46 -07:00
|
|
|
export default defineComponent({
|
2022-10-06 06:03:55 -07:00
|
|
|
name: 'run-data-json',
|
2023-05-16 02:43:46 -07:00
|
|
|
mixins: [externalHooks],
|
2022-10-06 06:03:55 -07:00
|
|
|
components: {
|
|
|
|
VueJsonPretty,
|
|
|
|
Draggable,
|
|
|
|
runDataJsonActions,
|
2022-12-20 00:39:38 -08:00
|
|
|
MappingPill,
|
2022-10-06 06:03:55 -07:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
editMode: {
|
2022-12-14 01:04:10 -08:00
|
|
|
type: Object as () => { enabled?: boolean; value?: string },
|
2022-10-06 06:03:55 -07:00
|
|
|
},
|
|
|
|
sessionId: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
paneType: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
node: {
|
|
|
|
type: Object as PropType<INodeUi>,
|
|
|
|
},
|
|
|
|
inputData: {
|
|
|
|
type: Array as PropType<INodeExecutionData[]>,
|
|
|
|
},
|
|
|
|
mappingEnabled: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
distanceFromActive: {
|
|
|
|
type: Number,
|
|
|
|
},
|
|
|
|
runIndex: {
|
|
|
|
type: Number,
|
|
|
|
},
|
|
|
|
totalRuns: {
|
|
|
|
type: Number,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2023-05-02 00:39:09 -07:00
|
|
|
selectedJsonPath: nonExistingJsonPath,
|
2022-10-06 06:03:55 -07:00
|
|
|
draggingPath: null as null | string,
|
|
|
|
displayMode: 'json',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2023-02-15 01:50:16 -08:00
|
|
|
...mapStores(useNDVStore, useWorkflowsStore),
|
2022-10-06 06:03:55 -07:00
|
|
|
jsonData(): IDataObject[] {
|
2022-11-07 03:27:02 -08:00
|
|
|
return executionDataToJson(this.inputData);
|
2022-10-06 06:03:55 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getShortKey(el: HTMLElement): string {
|
|
|
|
if (!el) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return shorten(el.dataset.name || '', 16, 2);
|
|
|
|
},
|
|
|
|
getJsonParameterPath(path: string): string {
|
2023-01-30 03:42:08 -08:00
|
|
|
const subPath = path.replace(/^(\["?\d"?])/, ''); // remove item position
|
|
|
|
|
|
|
|
return getMappedExpression({
|
|
|
|
nodeName: this.node.name,
|
|
|
|
distanceFromActive: this.distanceFromActive,
|
|
|
|
path: subPath,
|
|
|
|
});
|
2022-10-06 06:03:55 -07:00
|
|
|
},
|
|
|
|
onDragStart(el: HTMLElement) {
|
|
|
|
if (el && el.dataset.path) {
|
|
|
|
this.draggingPath = el.dataset.path;
|
|
|
|
}
|
|
|
|
|
2022-11-04 06:04:31 -07:00
|
|
|
this.ndvStore.resetMappingTelemetry();
|
2022-10-06 06:03:55 -07:00
|
|
|
},
|
|
|
|
onDragEnd(el: HTMLElement) {
|
|
|
|
this.draggingPath = null;
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2022-11-04 06:04:31 -07:00
|
|
|
const mappingTelemetry = this.ndvStore.mappingTelemetry;
|
2022-10-06 06:03:55 -07:00
|
|
|
const telemetryPayload = {
|
|
|
|
src_node_type: this.node.type,
|
|
|
|
src_field_name: el.dataset.name || '',
|
|
|
|
src_nodes_back: this.distanceFromActive,
|
|
|
|
src_run_index: this.runIndex,
|
|
|
|
src_runs_total: this.totalRuns,
|
|
|
|
src_field_nest_level: el.dataset.depth || 0,
|
|
|
|
src_view: 'json',
|
|
|
|
src_element: el,
|
|
|
|
success: false,
|
|
|
|
...mappingTelemetry,
|
|
|
|
};
|
|
|
|
|
2023-05-10 08:10:03 -07:00
|
|
|
void this.$externalHooks().run('runDataJson.onDragEnd', telemetryPayload);
|
2022-10-06 06:03:55 -07:00
|
|
|
|
|
|
|
this.$telemetry.track('User dragged data for mapping', telemetryPayload);
|
|
|
|
}, 1000); // ensure dest data gets set if drop
|
|
|
|
},
|
2022-11-07 03:27:02 -08:00
|
|
|
getContent(value: unknown): string {
|
2023-02-21 02:27:15 -08:00
|
|
|
return isString(value) ? `"${value}"` : JSON.stringify(value);
|
2022-10-06 06:03:55 -07:00
|
|
|
},
|
2022-12-01 00:33:34 -08:00
|
|
|
getListItemName(path: string): string {
|
|
|
|
return path.replace(/^(\["?\d"?]\.?)/g, '');
|
|
|
|
},
|
2022-10-06 06:03:55 -07:00
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.jsonDisplay {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
padding-left: var(--spacing-s);
|
|
|
|
right: 0;
|
|
|
|
overflow-y: auto;
|
|
|
|
line-height: 1.5;
|
|
|
|
word-break: normal;
|
|
|
|
height: 100%;
|
|
|
|
padding-bottom: var(--spacing-3xl);
|
|
|
|
background-color: var(--color-background-base);
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
/* Shows .actionsGroup element from <run-data-json-actions /> child component */
|
|
|
|
> div:first-child {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.mappable {
|
|
|
|
cursor: grab;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background-color: var(--color-json-highlight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.dragged {
|
|
|
|
&,
|
|
|
|
&:hover {
|
|
|
|
background-color: var(--color-primary-tint-2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.vjs-tree {
|
|
|
|
color: var(--color-json-default);
|
|
|
|
}
|
|
|
|
|
|
|
|
.vjs-tree-node {
|
|
|
|
&:hover {
|
|
|
|
background-color: transparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.is-highlight {
|
|
|
|
background-color: var(--color-json-highlight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-14 01:30:13 -07:00
|
|
|
.vjs-key,
|
|
|
|
.vjs-value {
|
2022-10-06 06:03:55 -07:00
|
|
|
> span {
|
|
|
|
color: var(--color-text-dark);
|
|
|
|
line-height: 1.7;
|
|
|
|
border-radius: var(--border-radius-base);
|
2022-10-14 01:30:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.vjs-value {
|
|
|
|
> span {
|
2022-10-06 06:03:55 -07:00
|
|
|
padding: 0 var(--spacing-5xs) 0 var(--spacing-5xs);
|
2022-10-14 01:30:13 -07:00
|
|
|
margin-left: var(--spacing-5xs);
|
2022-10-06 06:03:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.vjs-tree .vjs-value-null {
|
2022-12-14 01:04:10 -08:00
|
|
|
&,
|
|
|
|
span {
|
2022-10-06 06:03:55 -07:00
|
|
|
color: var(--color-json-null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.vjs-tree .vjs-value-boolean {
|
2022-12-14 01:04:10 -08:00
|
|
|
&,
|
|
|
|
span {
|
2022-10-06 06:03:55 -07:00
|
|
|
color: var(--color-json-boolean);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.vjs-tree .vjs-value-number {
|
2022-12-14 01:04:10 -08:00
|
|
|
&,
|
|
|
|
span {
|
2022-10-06 06:03:55 -07:00
|
|
|
color: var(--color-json-number);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.vjs-tree .vjs-value-string {
|
2022-12-14 01:04:10 -08:00
|
|
|
&,
|
|
|
|
span {
|
2022-10-06 06:03:55 -07:00
|
|
|
color: var(--color-json-string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.vjs-tree .vjs-key {
|
|
|
|
color: var(--color-json-key);
|
|
|
|
}
|
|
|
|
|
|
|
|
.vjs-tree .vjs-tree__brackets {
|
|
|
|
color: var(--color-json-brackets);
|
|
|
|
}
|
|
|
|
|
|
|
|
.vjs-tree .vjs-tree__brackets:hover {
|
|
|
|
color: var(--color-json-brackets-hover);
|
|
|
|
}
|
|
|
|
|
|
|
|
.vjs-tree .vjs-tree__content.has-line {
|
|
|
|
border-left: 1px dotted var(--color-json-line);
|
|
|
|
}
|
|
|
|
</style>
|