2022-07-20 04:32:51 -07:00
|
|
|
<template>
|
2022-10-06 06:03:55 -07:00
|
|
|
<div :class="$style.dataDisplay">
|
2022-07-20 04:32:51 -07:00
|
|
|
<table :class="$style.table" v-if="tableData.columns && tableData.columns.length === 0">
|
|
|
|
<tr>
|
|
|
|
<th :class="$style.emptyCell"></th>
|
2022-08-24 05:47:42 -07:00
|
|
|
<th :class="$style.tableRightMargin"></th>
|
2022-07-20 04:32:51 -07:00
|
|
|
</tr>
|
2022-12-14 01:04:10 -08:00
|
|
|
<tr
|
|
|
|
v-for="(row, index1) in tableData.data"
|
|
|
|
:key="index1"
|
|
|
|
:class="{ [$style.hoveringRow]: isHoveringRow(index1) }"
|
|
|
|
>
|
2022-10-12 05:06:28 -07:00
|
|
|
<td
|
|
|
|
:data-row="index1"
|
|
|
|
:data-col="0"
|
|
|
|
@mouseenter="onMouseEnterCell"
|
|
|
|
@mouseleave="onMouseLeaveCell"
|
|
|
|
>
|
2022-12-13 05:00:20 -08:00
|
|
|
<n8n-info-tip>{{ $locale.baseText('runData.emptyItemHint') }}</n8n-info-tip>
|
2022-07-20 04:32:51 -07:00
|
|
|
</td>
|
2022-08-24 05:47:42 -07:00
|
|
|
<td :class="$style.tableRightMargin"></td>
|
2022-07-20 04:32:51 -07:00
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<table :class="$style.table" v-else>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th v-for="(column, i) in tableData.columns || []" :key="column">
|
2022-12-14 01:04:10 -08:00
|
|
|
<n8n-tooltip placement="bottom-start" :disabled="!mappingEnabled" :open-delay="1000">
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #content>
|
|
|
|
<div>
|
2022-12-14 01:04:10 -08:00
|
|
|
<img src="/static/data-mapping-gif.gif" />
|
2022-11-18 05:59:31 -08:00
|
|
|
{{ $locale.baseText('dataMapping.dragColumnToFieldHint') }}
|
|
|
|
</div>
|
|
|
|
</template>
|
2022-10-06 06:03:55 -07:00
|
|
|
<draggable
|
2022-08-24 05:47:42 -07:00
|
|
|
type="mapping"
|
|
|
|
:data="getExpression(column)"
|
|
|
|
:disabled="!mappingEnabled"
|
|
|
|
@dragstart="onDragStart"
|
|
|
|
@dragend="(column) => onDragEnd(column, 'column')"
|
|
|
|
>
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #preview="{ canDrop }">
|
2022-12-23 04:37:32 -08:00
|
|
|
<MappingPill :html="shorten(column, 16, 2)" :can-drop="canDrop" />
|
2022-07-20 04:32:51 -07:00
|
|
|
</template>
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #default="{ isDragging }">
|
2022-07-20 04:32:51 -07:00
|
|
|
<div
|
|
|
|
:class="{
|
|
|
|
[$style.header]: true,
|
|
|
|
[$style.draggableHeader]: mappingEnabled,
|
2022-12-14 01:04:10 -08:00
|
|
|
[$style.activeHeader]:
|
|
|
|
(i === activeColumn || forceShowGrip) && mappingEnabled,
|
2022-07-20 04:32:51 -07:00
|
|
|
[$style.draggingHeader]: isDragging,
|
|
|
|
}"
|
|
|
|
>
|
2022-09-05 07:36:22 -07:00
|
|
|
<span>{{ column || ' ' }}</span>
|
2022-10-06 06:03:55 -07:00
|
|
|
<div :class="$style.dragButton">
|
|
|
|
<font-awesome-icon icon="grip-vertical" />
|
|
|
|
</div>
|
2022-07-20 04:32:51 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
2022-10-06 06:03:55 -07:00
|
|
|
</draggable>
|
2022-07-20 04:32:51 -07:00
|
|
|
</n8n-tooltip>
|
|
|
|
</th>
|
2022-11-02 01:23:09 -07:00
|
|
|
<th v-if="columnLimitExceeded" :class="$style.header">
|
|
|
|
<n8n-tooltip placement="bottom-end">
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #content>
|
|
|
|
<div>
|
|
|
|
<i18n path="dataMapping.tableView.tableColumnsExceeded.tooltip">
|
2022-11-21 04:00:21 -08:00
|
|
|
<template #columnLimit>{{ columnLimit }}</template>
|
|
|
|
<template #link>
|
2022-12-14 01:04:10 -08:00
|
|
|
<a @click="switchToJsonView">{{
|
|
|
|
$locale.baseText('dataMapping.tableView.tableColumnsExceeded.tooltip.link')
|
|
|
|
}}</a>
|
2022-11-21 04:00:21 -08:00
|
|
|
</template>
|
2022-11-18 05:59:31 -08:00
|
|
|
</i18n>
|
|
|
|
</div>
|
|
|
|
</template>
|
2022-11-02 01:23:09 -07:00
|
|
|
<span>
|
2022-12-14 01:04:10 -08:00
|
|
|
<font-awesome-icon
|
|
|
|
:class="$style['warningTooltip']"
|
|
|
|
icon="exclamation-triangle"
|
|
|
|
></font-awesome-icon>
|
2022-11-02 01:23:09 -07:00
|
|
|
{{ $locale.baseText('dataMapping.tableView.tableColumnsExceeded') }}
|
|
|
|
</span>
|
|
|
|
</n8n-tooltip>
|
|
|
|
</th>
|
2022-08-24 05:47:42 -07:00
|
|
|
<th :class="$style.tableRightMargin"></th>
|
2022-07-20 04:32:51 -07:00
|
|
|
</tr>
|
|
|
|
</thead>
|
2022-10-06 06:03:55 -07:00
|
|
|
<draggable
|
2022-08-24 05:47:42 -07:00
|
|
|
tag="tbody"
|
|
|
|
type="mapping"
|
|
|
|
targetDataKey="mappable"
|
|
|
|
:disabled="!mappingEnabled"
|
|
|
|
@dragstart="onCellDragStart"
|
|
|
|
@dragend="onCellDragEnd"
|
|
|
|
ref="draggable"
|
|
|
|
>
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #preview="{ canDrop, el }">
|
2022-12-23 04:37:32 -08:00
|
|
|
<MappingPill
|
|
|
|
:html="shorten(getPathNameFromTarget(el) || '', 16, 2)"
|
|
|
|
:can-drop="canDrop"
|
|
|
|
/>
|
2022-08-24 05:47:42 -07:00
|
|
|
</template>
|
|
|
|
<template>
|
2022-12-14 01:04:10 -08:00
|
|
|
<tr
|
|
|
|
v-for="(row, index1) in tableData.data"
|
|
|
|
:key="index1"
|
|
|
|
:class="{ [$style.hoveringRow]: isHoveringRow(index1) }"
|
2023-04-21 05:08:51 -07:00
|
|
|
:data-test-id="isHoveringRow(index1) ? 'hovering-item' : undefined"
|
2022-12-14 01:04:10 -08:00
|
|
|
>
|
2022-08-24 05:47:42 -07:00
|
|
|
<td
|
|
|
|
v-for="(data, index2) in row"
|
|
|
|
:key="index2"
|
2022-10-12 05:06:28 -07:00
|
|
|
:data-row="index1"
|
2022-08-24 05:47:42 -07:00
|
|
|
:data-col="index2"
|
|
|
|
@mouseenter="onMouseEnterCell"
|
|
|
|
@mouseleave="onMouseLeaveCell"
|
|
|
|
:class="hasJsonInColumn(index2) ? $style.minColWidth : $style.limitColWidth"
|
|
|
|
>
|
2022-12-14 01:04:10 -08:00
|
|
|
<span
|
|
|
|
v-if="isSimple(data)"
|
|
|
|
:class="{ [$style.value]: true, [$style.empty]: isEmpty(data) }"
|
2023-03-23 03:20:11 -07:00
|
|
|
class="ph-no-capture"
|
2022-12-14 01:04:10 -08:00
|
|
|
>{{ getValueToRender(data) }}</span
|
|
|
|
>
|
2022-08-24 05:47:42 -07:00
|
|
|
<n8n-tree :nodeClass="$style.nodeClass" v-else :value="data">
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #label="{ label, path }">
|
2022-08-24 05:47:42 -07:00
|
|
|
<span
|
|
|
|
@mouseenter="() => onMouseEnterKey(path, index2)"
|
|
|
|
@mouseleave="onMouseLeaveKey"
|
|
|
|
:class="{
|
|
|
|
[$style.hoveringKey]: mappingEnabled && isHovering(path, index2),
|
|
|
|
[$style.draggingKey]: isDraggingKey(path, index2),
|
|
|
|
[$style.dataKey]: true,
|
|
|
|
[$style.mappable]: mappingEnabled,
|
|
|
|
}"
|
|
|
|
data-target="mappable"
|
|
|
|
:data-name="getCellPathName(path, index2)"
|
|
|
|
:data-value="getCellExpression(path, index2)"
|
|
|
|
:data-depth="path.length"
|
|
|
|
>{{ label || $locale.baseText('runData.unnamedField') }}</span
|
|
|
|
>
|
|
|
|
</template>
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #value="{ value }">
|
2023-03-23 03:20:11 -07:00
|
|
|
<span
|
|
|
|
:class="{ [$style.nestedValue]: true, [$style.empty]: isEmpty(value) }"
|
|
|
|
class="ph-no-capture"
|
|
|
|
>{{ getValueToRender(value) }}</span
|
|
|
|
>
|
2022-08-24 05:47:42 -07:00
|
|
|
</template>
|
|
|
|
</n8n-tree>
|
|
|
|
</td>
|
2022-11-02 01:23:09 -07:00
|
|
|
<td v-if="columnLimitExceeded"></td>
|
2022-08-24 05:47:42 -07:00
|
|
|
<td :class="$style.tableRightMargin"></td>
|
|
|
|
</tr>
|
|
|
|
</template>
|
2022-10-06 06:03:55 -07:00
|
|
|
</draggable>
|
2022-07-20 04:32:51 -07:00
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-11-04 06:04:31 -07:00
|
|
|
/* eslint-disable prefer-spread */
|
|
|
|
import { INodeUi, ITableData, NDVState } from '@/Interface';
|
2023-02-21 02:27:15 -08:00
|
|
|
import { getPairedItemId } from '@/utils';
|
2022-10-06 06:03:55 -07:00
|
|
|
import Vue, { PropType } from 'vue';
|
|
|
|
import mixins from 'vue-typed-mixins';
|
2022-08-24 05:47:42 -07:00
|
|
|
import { GenericValue, IDataObject, INodeExecutionData } from 'n8n-workflow';
|
2022-11-04 06:04:31 -07:00
|
|
|
import Draggable from './Draggable.vue';
|
2022-11-23 04:41:53 -08:00
|
|
|
import { shorten } from '@/utils';
|
|
|
|
import { externalHooks } from '@/mixins/externalHooks';
|
2022-11-04 06:04:31 -07:00
|
|
|
import { mapStores } from 'pinia';
|
|
|
|
import { useWorkflowsStore } from '@/stores/workflows';
|
|
|
|
import { useNDVStore } from '@/stores/ndv';
|
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';
|
2022-11-02 01:23:09 -07:00
|
|
|
|
|
|
|
const MAX_COLUMNS_LIMIT = 40;
|
2022-07-20 04:32:51 -07:00
|
|
|
|
2023-04-21 06:59:04 -07:00
|
|
|
type DraggableRef = InstanceType<typeof Draggable>;
|
|
|
|
|
2022-08-19 06:35:39 -07:00
|
|
|
export default mixins(externalHooks).extend({
|
2022-10-06 06:03:55 -07:00
|
|
|
name: 'run-data-table',
|
2022-12-20 00:39:38 -08:00
|
|
|
components: { Draggable, MappingPill },
|
2022-07-20 04:32:51 -07:00
|
|
|
props: {
|
|
|
|
node: {
|
2022-10-06 06:03:55 -07:00
|
|
|
type: Object as PropType<INodeUi>,
|
2022-07-20 04:32:51 -07:00
|
|
|
},
|
2022-08-24 05:47:42 -07:00
|
|
|
inputData: {
|
2022-10-06 06:03:55 -07:00
|
|
|
type: Array as PropType<INodeExecutionData[]>,
|
2022-07-20 04:32:51 -07:00
|
|
|
},
|
|
|
|
mappingEnabled: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
distanceFromActive: {
|
|
|
|
type: Number,
|
|
|
|
},
|
|
|
|
runIndex: {
|
|
|
|
type: Number,
|
|
|
|
},
|
2022-10-12 05:06:28 -07:00
|
|
|
outputIndex: {
|
|
|
|
type: Number,
|
|
|
|
},
|
2022-07-20 04:32:51 -07:00
|
|
|
totalRuns: {
|
|
|
|
type: Number,
|
|
|
|
},
|
2022-10-12 05:06:28 -07:00
|
|
|
pageOffset: {
|
|
|
|
type: Number,
|
|
|
|
},
|
|
|
|
hasDefaultHoverState: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
2022-07-20 04:32:51 -07:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
activeColumn: -1,
|
2022-11-17 04:57:29 -08:00
|
|
|
forceShowGrip: false,
|
2022-07-20 04:32:51 -07:00
|
|
|
draggedColumn: false,
|
2022-08-24 05:47:42 -07:00
|
|
|
draggingPath: null as null | string,
|
|
|
|
hoveringPath: null as null | string,
|
2022-08-31 01:51:26 -07:00
|
|
|
mappingHintVisible: false,
|
2022-10-12 05:06:28 -07:00
|
|
|
activeRow: null as number | null,
|
2022-11-21 04:00:21 -08:00
|
|
|
columnLimit: MAX_COLUMNS_LIMIT,
|
2022-11-02 01:23:09 -07:00
|
|
|
columnLimitExceeded: false,
|
2022-07-20 04:32:51 -07:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
2022-08-24 05:47:42 -07:00
|
|
|
if (this.tableData && this.tableData.columns && this.$refs.draggable) {
|
2023-04-21 06:59:04 -07:00
|
|
|
const tbody = (this.$refs.draggable as DraggableRef).$refs.wrapper;
|
2022-08-24 05:47:42 -07:00
|
|
|
if (tbody) {
|
|
|
|
this.$emit('mounted', {
|
|
|
|
avgRowHeight: tbody.offsetHeight / this.tableData.data.length,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-07-20 04:32:51 -07:00
|
|
|
},
|
|
|
|
computed: {
|
2022-12-14 01:04:10 -08:00
|
|
|
...mapStores(useNDVStore, useWorkflowsStore),
|
2022-11-02 01:23:09 -07:00
|
|
|
hoveringItem(): NDVState['hoveringItem'] {
|
2022-11-04 06:04:31 -07:00
|
|
|
return this.ndvStore.hoveringItem;
|
2022-10-12 05:06:28 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
pairedItemMappings(): { [itemId: string]: Set<string> } {
|
2022-11-04 06:04:31 -07:00
|
|
|
return this.workflowsStore.workflowExecutionPairedItemMappings;
|
2022-10-12 05:06:28 -07:00
|
|
|
},
|
2022-08-24 05:47:42 -07:00
|
|
|
tableData(): ITableData {
|
|
|
|
return this.convertToTable(this.inputData);
|
|
|
|
},
|
2022-11-17 04:57:29 -08:00
|
|
|
focusedMappableInput(): string {
|
|
|
|
return this.ndvStore.focusedMappableInput;
|
|
|
|
},
|
2022-07-20 04:32:51 -07:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
shorten,
|
2022-10-12 05:06:28 -07:00
|
|
|
isHoveringRow(row: number): boolean {
|
|
|
|
if (row === this.activeRow) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const itemIndex = this.pageOffset + row;
|
2022-12-14 01:04:10 -08:00
|
|
|
if (
|
|
|
|
itemIndex === 0 &&
|
|
|
|
!this.hoveringItem &&
|
|
|
|
this.hasDefaultHoverState &&
|
|
|
|
this.distanceFromActive === 1
|
|
|
|
) {
|
2022-10-12 05:06:28 -07:00
|
|
|
return true;
|
|
|
|
}
|
2022-12-14 01:04:10 -08:00
|
|
|
const itemNodeId = getPairedItemId(
|
|
|
|
this.node.name,
|
|
|
|
this.runIndex || 0,
|
|
|
|
this.outputIndex || 0,
|
|
|
|
itemIndex,
|
|
|
|
);
|
2022-10-12 05:06:28 -07:00
|
|
|
if (!this.hoveringItem || !this.pairedItemMappings[itemNodeId]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
const hoveringItemId = getPairedItemId(
|
|
|
|
this.hoveringItem.nodeName,
|
|
|
|
this.hoveringItem.runIndex,
|
|
|
|
this.hoveringItem.outputIndex,
|
|
|
|
this.hoveringItem.itemIndex,
|
|
|
|
);
|
2022-10-12 05:06:28 -07:00
|
|
|
return this.pairedItemMappings[itemNodeId].has(hoveringItemId);
|
|
|
|
},
|
2022-07-20 04:32:51 -07:00
|
|
|
onMouseEnterCell(e: MouseEvent) {
|
|
|
|
const target = e.target;
|
|
|
|
if (target && this.mappingEnabled) {
|
|
|
|
const col = (target as HTMLElement).dataset.col;
|
|
|
|
if (col && !isNaN(parseInt(col, 10))) {
|
|
|
|
this.activeColumn = parseInt(col, 10);
|
|
|
|
}
|
|
|
|
}
|
2022-10-12 05:06:28 -07:00
|
|
|
|
|
|
|
if (target) {
|
|
|
|
const row = (target as HTMLElement).dataset.row;
|
|
|
|
if (row && !isNaN(parseInt(row, 10))) {
|
|
|
|
this.activeRow = parseInt(row, 10);
|
|
|
|
this.$emit('activeRowChanged', this.pageOffset + this.activeRow);
|
|
|
|
}
|
|
|
|
}
|
2022-07-20 04:32:51 -07:00
|
|
|
},
|
|
|
|
onMouseLeaveCell() {
|
|
|
|
this.activeColumn = -1;
|
2022-10-12 05:06:28 -07:00
|
|
|
this.activeRow = null;
|
|
|
|
this.$emit('activeRowChanged', null);
|
2022-07-20 04:32:51 -07:00
|
|
|
},
|
2022-08-24 05:47:42 -07:00
|
|
|
onMouseEnterKey(path: string[], colIndex: number) {
|
|
|
|
this.hoveringPath = this.getCellExpression(path, colIndex);
|
|
|
|
},
|
|
|
|
onMouseLeaveKey() {
|
|
|
|
this.hoveringPath = null;
|
|
|
|
},
|
|
|
|
isHovering(path: string[], colIndex: number) {
|
|
|
|
const expr = this.getCellExpression(path, colIndex);
|
|
|
|
|
|
|
|
return this.hoveringPath === expr;
|
|
|
|
},
|
2022-07-20 04:32:51 -07:00
|
|
|
getExpression(column: string) {
|
|
|
|
if (!this.node) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2023-01-30 03:42:08 -08:00
|
|
|
return getMappedExpression({
|
|
|
|
nodeName: this.node.name,
|
|
|
|
distanceFromActive: this.distanceFromActive,
|
|
|
|
path: [column],
|
|
|
|
});
|
2022-07-20 04:32:51 -07:00
|
|
|
},
|
2022-08-24 05:47:42 -07:00
|
|
|
getPathNameFromTarget(el: HTMLElement) {
|
|
|
|
if (!el) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return el.dataset.name;
|
|
|
|
},
|
|
|
|
getCellPathName(path: Array<string | number>, colIndex: number) {
|
|
|
|
const lastKey = path[path.length - 1];
|
|
|
|
if (typeof lastKey === 'string') {
|
|
|
|
return lastKey;
|
|
|
|
}
|
|
|
|
if (path.length > 1) {
|
|
|
|
const prevKey = path[path.length - 2];
|
|
|
|
return `${prevKey}[${lastKey}]`;
|
|
|
|
}
|
|
|
|
const column = this.tableData.columns[colIndex];
|
|
|
|
return `${column}[${lastKey}]`;
|
|
|
|
},
|
|
|
|
getCellExpression(path: Array<string | number>, colIndex: number) {
|
|
|
|
if (!this.node) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
const column = this.tableData.columns[colIndex];
|
2023-01-30 03:42:08 -08:00
|
|
|
return getMappedExpression({
|
|
|
|
nodeName: this.node.name,
|
|
|
|
distanceFromActive: this.distanceFromActive,
|
|
|
|
path: [column, ...path],
|
|
|
|
});
|
2022-08-24 05:47:42 -07:00
|
|
|
},
|
2022-10-18 06:22:33 -07:00
|
|
|
isEmpty(value: unknown): boolean {
|
2022-08-24 05:47:42 -07:00
|
|
|
return (
|
|
|
|
value === '' ||
|
|
|
|
(Array.isArray(value) && value.length === 0) ||
|
2022-10-18 06:22:33 -07:00
|
|
|
(typeof value === 'object' && value !== null && Object.keys(value).length === 0) ||
|
2022-12-14 01:04:10 -08:00
|
|
|
value === null ||
|
|
|
|
value === undefined
|
2022-08-24 05:47:42 -07:00
|
|
|
);
|
|
|
|
},
|
|
|
|
getValueToRender(value: unknown) {
|
|
|
|
if (value === '') {
|
|
|
|
return this.$locale.baseText('runData.emptyString');
|
|
|
|
}
|
|
|
|
if (typeof value === 'string') {
|
|
|
|
return value.replaceAll('\n', '\\n');
|
|
|
|
}
|
|
|
|
if (Array.isArray(value) && value.length === 0) {
|
|
|
|
return this.$locale.baseText('runData.emptyArray');
|
|
|
|
}
|
|
|
|
if (typeof value === 'object' && value !== null && Object.keys(value).length === 0) {
|
|
|
|
return this.$locale.baseText('runData.emptyObject');
|
|
|
|
}
|
2022-10-18 06:22:33 -07:00
|
|
|
if (value === null || value === undefined) {
|
|
|
|
return `[${value}]`;
|
|
|
|
}
|
2022-08-24 05:47:42 -07:00
|
|
|
return value;
|
|
|
|
},
|
2022-07-20 04:32:51 -07:00
|
|
|
onDragStart() {
|
|
|
|
this.draggedColumn = true;
|
2022-11-04 06:04:31 -07:00
|
|
|
this.ndvStore.resetMappingTelemetry();
|
2022-07-20 04:32:51 -07:00
|
|
|
},
|
2022-08-24 05:47:42 -07:00
|
|
|
onCellDragStart(el: HTMLElement) {
|
|
|
|
if (el && el.dataset.value) {
|
|
|
|
this.draggingPath = el.dataset.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.onDragStart();
|
|
|
|
},
|
|
|
|
onCellDragEnd(el: HTMLElement) {
|
|
|
|
this.draggingPath = null;
|
|
|
|
|
|
|
|
this.onDragEnd(el.dataset.name || '', 'tree', el.dataset.depth || '0');
|
|
|
|
},
|
|
|
|
isDraggingKey(path: Array<string | number>, colIndex: number) {
|
|
|
|
if (!this.draggingPath) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.draggingPath === this.getCellExpression(path, colIndex);
|
|
|
|
},
|
|
|
|
onDragEnd(column: string, src: string, depth = '0') {
|
2022-07-20 04:32:51 -07:00
|
|
|
setTimeout(() => {
|
2022-11-04 06:04:31 -07:00
|
|
|
const mappingTelemetry = this.ndvStore.mappingTelemetry;
|
2022-08-19 06:35:39 -07:00
|
|
|
const telemetryPayload = {
|
2022-07-20 04:32:51 -07:00
|
|
|
src_node_type: this.node.type,
|
|
|
|
src_field_name: column,
|
|
|
|
src_nodes_back: this.distanceFromActive,
|
|
|
|
src_run_index: this.runIndex,
|
|
|
|
src_runs_total: this.totalRuns,
|
2022-08-24 05:47:42 -07:00
|
|
|
src_field_nest_level: parseInt(depth, 10),
|
2022-07-20 04:32:51 -07:00
|
|
|
src_view: 'table',
|
2022-08-24 05:47:42 -07:00
|
|
|
src_element: src,
|
2022-07-20 04:32:51 -07:00
|
|
|
success: false,
|
|
|
|
...mappingTelemetry,
|
2022-08-19 06:35:39 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
this.$externalHooks().run('runDataTable.onDragEnd', telemetryPayload);
|
|
|
|
|
|
|
|
this.$telemetry.track('User dragged data for mapping', telemetryPayload);
|
2022-07-20 04:32:51 -07:00
|
|
|
}, 1000); // ensure dest data gets set if drop
|
|
|
|
},
|
2022-08-24 05:47:42 -07:00
|
|
|
isSimple(data: unknown): boolean {
|
2022-12-14 01:04:10 -08:00
|
|
|
return (
|
|
|
|
typeof data !== 'object' ||
|
|
|
|
data === null ||
|
2022-10-18 06:22:33 -07:00
|
|
|
(Array.isArray(data) && data.length === 0) ||
|
2022-12-14 01:04:10 -08:00
|
|
|
(typeof data === 'object' && Object.keys(data).length === 0)
|
|
|
|
);
|
2022-08-24 05:47:42 -07:00
|
|
|
},
|
|
|
|
hasJsonInColumn(colIndex: number): boolean {
|
|
|
|
return this.tableData.hasJson[this.tableData.columns[colIndex]];
|
|
|
|
},
|
|
|
|
convertToTable(inputData: INodeExecutionData[]): ITableData {
|
|
|
|
const tableData: GenericValue[][] = [];
|
|
|
|
const tableColumns: string[] = [];
|
|
|
|
let leftEntryColumns: string[], entryRows: GenericValue[];
|
|
|
|
// Go over all entries
|
|
|
|
let entry: IDataObject;
|
|
|
|
const hasJson: { [key: string]: boolean } = {};
|
|
|
|
inputData.forEach((data) => {
|
|
|
|
if (!data.hasOwnProperty('json')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
entry = data.json;
|
|
|
|
|
|
|
|
// Go over all keys of entry
|
|
|
|
entryRows = [];
|
2022-11-02 01:23:09 -07:00
|
|
|
const entryColumns = Object.keys(entry || {});
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
if (entryColumns.length > MAX_COLUMNS_LIMIT) {
|
2022-11-02 01:23:09 -07:00
|
|
|
this.columnLimitExceeded = true;
|
|
|
|
leftEntryColumns = entryColumns.slice(0, MAX_COLUMNS_LIMIT);
|
|
|
|
} else {
|
|
|
|
leftEntryColumns = entryColumns;
|
|
|
|
}
|
2022-08-24 05:47:42 -07:00
|
|
|
|
|
|
|
// Go over all the already existing column-keys
|
|
|
|
tableColumns.forEach((key) => {
|
|
|
|
if (entry.hasOwnProperty(key)) {
|
|
|
|
// Entry does have key so add its value
|
|
|
|
entryRows.push(entry[key]);
|
|
|
|
// Remove key so that we know that it got added
|
|
|
|
leftEntryColumns.splice(leftEntryColumns.indexOf(key), 1);
|
|
|
|
|
2022-08-31 01:51:26 -07:00
|
|
|
hasJson[key] =
|
|
|
|
hasJson[key] ||
|
|
|
|
(typeof entry[key] === 'object' && Object.keys(entry[key] || {}).length > 0) ||
|
|
|
|
false;
|
2022-08-24 05:47:42 -07:00
|
|
|
} else {
|
2022-12-27 08:22:48 -08:00
|
|
|
// Entry does not have key so add undefined
|
|
|
|
entryRows.push(undefined);
|
2022-08-24 05:47:42 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Go over all the columns the entry has but did not exist yet
|
|
|
|
leftEntryColumns.forEach((key) => {
|
|
|
|
// Add the key for all runs in the future
|
|
|
|
tableColumns.push(key);
|
|
|
|
// Add the value
|
|
|
|
entryRows.push(entry[key]);
|
2022-08-31 01:51:26 -07:00
|
|
|
hasJson[key] =
|
|
|
|
hasJson[key] ||
|
|
|
|
(typeof entry[key] === 'object' && Object.keys(entry[key] || {}).length > 0) ||
|
|
|
|
false;
|
2022-08-24 05:47:42 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
// Add the data of the entry
|
|
|
|
tableData.push(entryRows);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Make sure that all entry-rows have the same length
|
|
|
|
tableData.forEach((entryRows) => {
|
|
|
|
if (tableColumns.length > entryRows.length) {
|
2022-11-02 01:23:09 -07:00
|
|
|
// Has fewer entries so add the missing ones
|
|
|
|
entryRows.push(...new Array(tableColumns.length - entryRows.length));
|
2022-08-24 05:47:42 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
hasJson,
|
|
|
|
columns: tableColumns,
|
|
|
|
data: tableData,
|
|
|
|
};
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
switchToJsonView() {
|
2022-11-02 01:23:09 -07:00
|
|
|
this.$emit('displayModeChange', 'json');
|
|
|
|
},
|
2022-07-20 04:32:51 -07:00
|
|
|
},
|
2022-11-17 04:57:29 -08:00
|
|
|
watch: {
|
|
|
|
focusedMappableInput(curr: boolean) {
|
|
|
|
setTimeout(
|
|
|
|
() => {
|
|
|
|
this.forceShowGrip = !!this.focusedMappableInput;
|
|
|
|
},
|
|
|
|
curr ? 300 : 150,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2022-07-20 04:32:51 -07:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
2022-10-06 06:03:55 -07:00
|
|
|
.dataDisplay {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-07-20 04:32:51 -07:00
|
|
|
.table {
|
|
|
|
border-collapse: separate;
|
|
|
|
text-align: left;
|
2022-08-24 05:47:42 -07:00
|
|
|
width: calc(100%);
|
2022-07-20 04:32:51 -07:00
|
|
|
font-size: var(--font-size-s);
|
|
|
|
|
|
|
|
th {
|
|
|
|
background-color: var(--color-background-base);
|
|
|
|
border-top: var(--border-base);
|
|
|
|
border-bottom: var(--border-base);
|
|
|
|
border-left: var(--border-base);
|
|
|
|
position: sticky;
|
|
|
|
top: 0;
|
2022-08-24 05:47:42 -07:00
|
|
|
color: var(--color-text-dark);
|
2022-10-12 05:06:28 -07:00
|
|
|
z-index: 1;
|
2022-07-20 04:32:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
td {
|
2022-08-24 05:47:42 -07:00
|
|
|
vertical-align: top;
|
|
|
|
padding: var(--spacing-2xs) var(--spacing-2xs) var(--spacing-2xs) var(--spacing-3xs);
|
2022-07-20 04:32:51 -07:00
|
|
|
border-bottom: var(--border-base);
|
|
|
|
border-left: var(--border-base);
|
|
|
|
overflow-wrap: break-word;
|
|
|
|
white-space: pre-wrap;
|
|
|
|
}
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
td:first-child,
|
|
|
|
td:nth-last-child(2) {
|
2022-10-12 05:06:28 -07:00
|
|
|
position: relative;
|
|
|
|
z-index: 0;
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
&:after {
|
|
|
|
// add border without shifting content
|
2022-10-12 05:06:28 -07:00
|
|
|
content: '';
|
|
|
|
position: absolute;
|
|
|
|
height: 100%;
|
|
|
|
width: 2px;
|
|
|
|
top: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
td:nth-last-child(2):after {
|
|
|
|
right: -1px;
|
|
|
|
}
|
|
|
|
|
|
|
|
td:first-child:after {
|
|
|
|
left: -1px;
|
|
|
|
}
|
|
|
|
|
2022-07-20 04:32:51 -07:00
|
|
|
th:last-child,
|
|
|
|
td:last-child {
|
|
|
|
border-right: var(--border-base);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-24 05:47:42 -07:00
|
|
|
.nodeClass {
|
|
|
|
margin-bottom: var(--spacing-5xs);
|
|
|
|
}
|
|
|
|
|
2022-07-20 04:32:51 -07:00
|
|
|
.emptyCell {
|
|
|
|
height: 32px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.header {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
padding: var(--spacing-2xs);
|
|
|
|
|
|
|
|
span {
|
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
|
|
|
flex-grow: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.draggableHeader {
|
|
|
|
&:hover {
|
|
|
|
cursor: grab;
|
|
|
|
background-color: var(--color-foreground-base);
|
|
|
|
|
|
|
|
.dragButton {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.draggingHeader {
|
|
|
|
background-color: var(--color-primary-tint-2);
|
|
|
|
}
|
|
|
|
|
|
|
|
.activeHeader {
|
|
|
|
.dragButton {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.dragButton {
|
|
|
|
opacity: 0;
|
|
|
|
margin-left: var(--spacing-2xs);
|
|
|
|
}
|
|
|
|
|
2022-08-24 05:47:42 -07:00
|
|
|
.dataKey {
|
|
|
|
color: var(--color-text-dark);
|
|
|
|
line-height: 1.7;
|
|
|
|
font-weight: var(--font-weight-bold);
|
|
|
|
border-radius: var(--border-radius-base);
|
|
|
|
padding: 0 var(--spacing-5xs) 0 var(--spacing-5xs);
|
|
|
|
margin-right: var(--spacing-5xs);
|
|
|
|
}
|
|
|
|
|
|
|
|
.value {
|
|
|
|
line-height: var(--font-line-height-regular);
|
|
|
|
}
|
|
|
|
|
|
|
|
.nestedValue {
|
|
|
|
composes: value;
|
|
|
|
margin-left: var(--spacing-4xs);
|
|
|
|
}
|
|
|
|
|
|
|
|
.mappable {
|
|
|
|
cursor: grab;
|
|
|
|
}
|
|
|
|
|
|
|
|
.empty {
|
|
|
|
color: var(--color-danger);
|
|
|
|
}
|
|
|
|
|
|
|
|
.limitColWidth {
|
|
|
|
max-width: 300px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.minColWidth {
|
|
|
|
min-width: 240px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.hoveringKey {
|
|
|
|
background-color: var(--color-foreground-base);
|
|
|
|
}
|
|
|
|
|
|
|
|
.draggingKey {
|
|
|
|
background-color: var(--color-primary-tint-2);
|
|
|
|
}
|
|
|
|
|
|
|
|
.tableRightMargin {
|
|
|
|
// becomes necessary with large tables
|
2022-10-12 05:06:28 -07:00
|
|
|
background-color: var(--color-background-base) !important;
|
2022-08-24 05:47:42 -07:00
|
|
|
width: var(--spacing-s);
|
|
|
|
border-right: none !important;
|
|
|
|
border-top: none !important;
|
|
|
|
border-bottom: none !important;
|
|
|
|
}
|
2022-10-12 05:06:28 -07:00
|
|
|
|
|
|
|
.hoveringRow {
|
2022-12-14 01:04:10 -08:00
|
|
|
td:first-child:after,
|
|
|
|
td:nth-last-child(2):after {
|
2022-10-12 05:06:28 -07:00
|
|
|
background-color: var(--color-secondary);
|
|
|
|
}
|
|
|
|
}
|
2022-11-02 01:23:09 -07:00
|
|
|
|
|
|
|
.warningTooltip {
|
|
|
|
color: var(--color-warning);
|
|
|
|
}
|
2022-07-20 04:32:51 -07:00
|
|
|
</style>
|