2022-12-06 03:50:06 -08:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, ref } from 'vue';
|
2023-04-11 04:05:43 -07:00
|
|
|
import { merge } from 'lodash-es';
|
2022-12-14 01:04:10 -08:00
|
|
|
import { INodeUi, Schema } from '@/Interface';
|
|
|
|
import RunDataSchemaItem from '@/components/RunDataSchemaItem.vue';
|
2022-12-06 03:50:06 -08:00
|
|
|
import Draggable from '@/components/Draggable.vue';
|
2022-12-14 01:04:10 -08:00
|
|
|
import { useNDVStore } from '@/stores/ndv';
|
|
|
|
import { useWebhooksStore } from '@/stores/webhooks';
|
|
|
|
import { runExternalHook } from '@/mixins/externalHooks';
|
|
|
|
import { telemetry } from '@/plugins/telemetry';
|
|
|
|
import { IDataObject } from 'n8n-workflow';
|
2023-04-11 04:05:43 -07:00
|
|
|
import { getSchema, isEmpty } from '@/utils';
|
2022-12-13 05:00:20 -08:00
|
|
|
import { i18n } from '@/plugins/i18n';
|
2022-12-20 00:39:38 -08:00
|
|
|
import MappingPill from './MappingPill.vue';
|
2022-12-06 03:50:06 -08:00
|
|
|
|
|
|
|
type Props = {
|
2022-12-14 01:04:10 -08:00
|
|
|
data: IDataObject[];
|
|
|
|
mappingEnabled: boolean;
|
|
|
|
distanceFromActive: number;
|
|
|
|
runIndex: number;
|
|
|
|
totalRuns: number;
|
2023-03-16 02:19:12 -07:00
|
|
|
paneType: 'input' | 'output';
|
2022-12-14 01:04:10 -08:00
|
|
|
node: INodeUi | null;
|
|
|
|
};
|
2022-12-06 03:50:06 -08:00
|
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
|
distanceFromActive: 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
const draggingPath = ref<string>('');
|
|
|
|
const ndvStore = useNDVStore();
|
|
|
|
const webhooksStore = useWebhooksStore();
|
|
|
|
|
|
|
|
const schema = computed<Schema>(() => {
|
|
|
|
const [head, ...tail] = props.data;
|
2023-04-11 04:05:43 -07:00
|
|
|
return getSchema(merge({}, head, ...tail, head));
|
2022-12-06 03:50:06 -08:00
|
|
|
});
|
|
|
|
|
2022-12-12 01:08:29 -08:00
|
|
|
const isDataEmpty = computed(() => {
|
|
|
|
return isEmpty(props.data);
|
|
|
|
});
|
|
|
|
|
2022-12-06 03:50:06 -08:00
|
|
|
const onDragStart = (el: HTMLElement) => {
|
|
|
|
if (el && el.dataset?.path) {
|
|
|
|
draggingPath.value = el.dataset.path;
|
|
|
|
}
|
|
|
|
|
|
|
|
ndvStore.resetMappingTelemetry();
|
|
|
|
};
|
|
|
|
const onDragEnd = (el: HTMLElement) => {
|
|
|
|
draggingPath.value = '';
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
const mappingTelemetry = ndvStore.mappingTelemetry;
|
|
|
|
const telemetryPayload = {
|
|
|
|
src_node_type: props.node?.type,
|
|
|
|
src_field_name: el.dataset.name || '',
|
|
|
|
src_nodes_back: props.distanceFromActive,
|
|
|
|
src_run_index: props.runIndex,
|
|
|
|
src_runs_total: props.totalRuns,
|
|
|
|
src_field_nest_level: el.dataset.depth || 0,
|
|
|
|
src_view: 'schema',
|
|
|
|
src_element: el,
|
|
|
|
success: false,
|
|
|
|
...mappingTelemetry,
|
|
|
|
};
|
|
|
|
|
|
|
|
runExternalHook('runDataJson.onDragEnd', webhooksStore, telemetryPayload);
|
|
|
|
|
|
|
|
telemetry.track('User dragged data for mapping', telemetryPayload);
|
|
|
|
}, 1000); // ensure dest data gets set if drop
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div :class="$style.schemaWrapper">
|
2022-12-14 01:04:10 -08:00
|
|
|
<n8n-info-tip v-if="isDataEmpty">{{
|
|
|
|
i18n.baseText('dataMapping.schemaView.emptyData')
|
|
|
|
}}</n8n-info-tip>
|
2022-12-06 03:50:06 -08:00
|
|
|
<draggable
|
2022-12-12 01:08:29 -08:00
|
|
|
v-else
|
2022-12-06 03:50:06 -08:00
|
|
|
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="el.outerHTML" :can-drop="canDrop" />
|
2022-12-06 03:50:06 -08:00
|
|
|
</template>
|
|
|
|
<template>
|
|
|
|
<div :class="$style.schema">
|
|
|
|
<run-data-schema-item
|
|
|
|
:schema="schema"
|
|
|
|
:level="0"
|
|
|
|
:parent="null"
|
2023-03-16 02:19:12 -07:00
|
|
|
:paneType="paneType"
|
2022-12-06 03:50:06 -08:00
|
|
|
:subKey="`${schema.type}-0-0`"
|
|
|
|
:mappingEnabled="mappingEnabled"
|
|
|
|
:draggingPath="draggingPath"
|
|
|
|
:distanceFromActive="distanceFromActive"
|
|
|
|
:node="node"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</draggable>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.schemaWrapper {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
bottom: 0;
|
|
|
|
right: 0;
|
|
|
|
overflow: auto;
|
|
|
|
line-height: 1.5;
|
|
|
|
word-break: normal;
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
background-color: var(--color-background-base);
|
2022-12-13 05:00:20 -08:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
> div[class*='info'] {
|
2022-12-13 05:00:20 -08:00
|
|
|
padding: 0 var(--spacing-s);
|
|
|
|
}
|
2022-12-06 03:50:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
.schema {
|
|
|
|
display: inline-block;
|
|
|
|
padding: 0 var(--spacing-s) var(--spacing-s);
|
|
|
|
}
|
|
|
|
</style>
|