2023-03-01 03:02:34 -08:00
|
|
|
import { LOCAL_STORAGE_MAPPING_IS_ONBOARDED, STORES } from '@/constants';
|
2022-12-14 01:04:10 -08:00
|
|
|
import { INodeUi, IRunDataDisplayMode, NDVState, NodePanelType, XYPosition } from '@/Interface';
|
|
|
|
import { IRunData } from 'n8n-workflow';
|
|
|
|
import { defineStore } from 'pinia';
|
|
|
|
import Vue from 'vue';
|
|
|
|
import { useWorkflowsStore } from './workflows';
|
2022-11-04 06:04:31 -07:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
export const useNDVStore = defineStore(STORES.NDV, {
|
2022-11-04 06:04:31 -07:00
|
|
|
state: (): NDVState => ({
|
|
|
|
activeNodeName: null,
|
|
|
|
mainPanelDimensions: {},
|
|
|
|
sessionId: '',
|
|
|
|
input: {
|
2023-01-31 06:20:33 -08:00
|
|
|
displayMode: 'schema',
|
2022-11-04 06:04:31 -07:00
|
|
|
nodeName: undefined,
|
|
|
|
run: undefined,
|
|
|
|
branch: undefined,
|
|
|
|
data: {
|
|
|
|
isEmpty: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
displayMode: 'table',
|
|
|
|
branch: undefined,
|
|
|
|
data: {
|
|
|
|
isEmpty: true,
|
|
|
|
},
|
|
|
|
editMode: {
|
|
|
|
enabled: false,
|
|
|
|
value: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
focusedMappableInput: '',
|
|
|
|
mappingTelemetry: {},
|
|
|
|
hoveringItem: null,
|
|
|
|
draggable: {
|
|
|
|
isDragging: false,
|
|
|
|
type: '',
|
|
|
|
data: '',
|
|
|
|
canDrop: false,
|
|
|
|
stickyPosition: null,
|
|
|
|
},
|
2023-03-01 03:02:34 -08:00
|
|
|
isMappingOnboarded: window.localStorage.getItem(LOCAL_STORAGE_MAPPING_IS_ONBOARDED) === 'true',
|
2022-11-04 06:04:31 -07:00
|
|
|
}),
|
|
|
|
getters: {
|
|
|
|
activeNode(): INodeUi | null {
|
|
|
|
const workflowsStore = useWorkflowsStore();
|
|
|
|
return workflowsStore.getNodeByName(this.activeNodeName || '');
|
|
|
|
},
|
|
|
|
ndvInputData(): IRunData[] {
|
|
|
|
const workflowsStore = useWorkflowsStore();
|
|
|
|
const executionData = workflowsStore.getWorkflowExecution;
|
|
|
|
const inputNodeName: string | undefined = this.input.nodeName;
|
|
|
|
const inputRunIndex: number = this.input.run ?? 0;
|
2022-12-14 01:04:10 -08:00
|
|
|
const inputBranchIndex: number = this.input.branch ?? 0;
|
2022-11-04 06:04:31 -07:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
if (
|
|
|
|
!executionData ||
|
|
|
|
!inputNodeName ||
|
|
|
|
inputRunIndex === undefined ||
|
|
|
|
inputBranchIndex === undefined
|
|
|
|
) {
|
2022-11-04 06:04:31 -07:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
return executionData.data?.resultData?.runData?.[inputNodeName]?.[inputRunIndex]?.data
|
|
|
|
?.main?.[inputBranchIndex];
|
2022-11-04 06:04:31 -07:00
|
|
|
},
|
|
|
|
getPanelDisplayMode() {
|
2022-12-06 03:50:06 -08:00
|
|
|
return (panel: NodePanelType) => this[panel].displayMode;
|
2022-11-04 06:04:31 -07:00
|
|
|
},
|
|
|
|
inputPanelDisplayMode(): IRunDataDisplayMode {
|
|
|
|
return this.input.displayMode;
|
|
|
|
},
|
|
|
|
outputPanelDisplayMode(): IRunDataDisplayMode {
|
|
|
|
return this.output.displayMode;
|
|
|
|
},
|
|
|
|
isDraggableDragging(): boolean {
|
|
|
|
return this.draggable.isDragging;
|
|
|
|
},
|
|
|
|
draggableType(): string {
|
|
|
|
return this.draggable.type;
|
|
|
|
},
|
|
|
|
draggableData(): string {
|
|
|
|
return this.draggable.data;
|
|
|
|
},
|
|
|
|
canDraggableDrop(): boolean {
|
|
|
|
return this.draggable.canDrop;
|
|
|
|
},
|
|
|
|
outputPanelEditMode(): NDVState['output']['editMode'] {
|
|
|
|
return this.output.editMode;
|
|
|
|
},
|
|
|
|
getMainPanelDimensions() {
|
|
|
|
return (panelType: string) => {
|
|
|
|
const defaults = { relativeRight: 1, relativeLeft: 1, relativeWidth: 1 };
|
2022-12-14 01:04:10 -08:00
|
|
|
return { ...defaults, ...this.mainPanelDimensions[panelType] };
|
2022-11-04 06:04:31 -07:00
|
|
|
};
|
|
|
|
},
|
|
|
|
draggableStickyPos(): XYPosition | null {
|
|
|
|
return this.draggable.stickyPosition;
|
|
|
|
},
|
|
|
|
ndvInputNodeName(): string | undefined {
|
|
|
|
return this.input.nodeName;
|
|
|
|
},
|
|
|
|
ndvInputRunIndex(): number | undefined {
|
|
|
|
return this.input.run;
|
|
|
|
},
|
|
|
|
ndvInputBranchIndex(): number | undefined {
|
|
|
|
return this.input.branch;
|
|
|
|
},
|
|
|
|
isDNVDataEmpty() {
|
|
|
|
return (panel: 'input' | 'output'): boolean => this[panel].data.isEmpty;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
setInputNodeName(name: string | undefined): void {
|
|
|
|
Vue.set(this.input, 'nodeName', name);
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
setInputRunIndex(run?: string): void {
|
2022-11-04 06:04:31 -07:00
|
|
|
Vue.set(this.input, 'run', run);
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
setMainPanelDimensions(params: {
|
|
|
|
panelType: string;
|
|
|
|
dimensions: { relativeLeft?: number; relativeRight?: number; relativeWidth?: number };
|
|
|
|
}): void {
|
|
|
|
Vue.set(this.mainPanelDimensions, params.panelType, {
|
|
|
|
...this.mainPanelDimensions[params.panelType],
|
|
|
|
...params.dimensions,
|
|
|
|
});
|
2022-11-04 06:04:31 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
setNDVSessionId(): void {
|
2022-11-04 06:04:31 -07:00
|
|
|
Vue.set(this, 'sessionId', `ndv-${Math.random().toString(36).slice(-8)}`);
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
resetNDVSessionId(): void {
|
2022-11-04 06:04:31 -07:00
|
|
|
Vue.set(this, 'sessionId', '');
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
setPanelDisplayMode(params: { pane: NodePanelType; mode: IRunDataDisplayMode }): void {
|
2022-11-04 06:04:31 -07:00
|
|
|
Vue.set(this[params.pane], 'displayMode', params.mode);
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
setOutputPanelEditModeEnabled(isEnabled: boolean): void {
|
2022-11-04 06:04:31 -07:00
|
|
|
Vue.set(this.output.editMode, 'enabled', isEnabled);
|
|
|
|
},
|
|
|
|
setOutputPanelEditModeValue(payload: string): void {
|
|
|
|
Vue.set(this.output.editMode, 'value', payload);
|
|
|
|
},
|
|
|
|
setMappableNDVInputFocus(paramName: string): void {
|
|
|
|
Vue.set(this, 'focusedMappableInput', paramName);
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
draggableStartDragging({ type, data }: { type: string; data: string }): void {
|
2022-11-04 06:04:31 -07:00
|
|
|
this.draggable = {
|
|
|
|
isDragging: true,
|
|
|
|
type,
|
|
|
|
data,
|
|
|
|
canDrop: false,
|
|
|
|
stickyPosition: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
draggableStopDragging(): void {
|
|
|
|
this.draggable = {
|
|
|
|
isDragging: false,
|
|
|
|
type: '',
|
|
|
|
data: '',
|
|
|
|
canDrop: false,
|
|
|
|
stickyPosition: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
setDraggableStickyPos(position: XYPosition | null): void {
|
|
|
|
Vue.set(this.draggable, 'stickyPosition', position);
|
|
|
|
},
|
|
|
|
setDraggableCanDrop(canDrop: boolean): void {
|
|
|
|
Vue.set(this.draggable, 'canDrop', canDrop);
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
setMappingTelemetry(telemetry: { [key: string]: string | number | boolean }): void {
|
|
|
|
this.mappingTelemetry = { ...this.mappingTelemetry, ...telemetry };
|
2022-11-04 06:04:31 -07:00
|
|
|
},
|
|
|
|
resetMappingTelemetry(): void {
|
|
|
|
this.mappingTelemetry = {};
|
|
|
|
},
|
|
|
|
setHoveringItem(item: null | NDVState['hoveringItem']): void {
|
|
|
|
Vue.set(this, 'hoveringItem', item);
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
setNDVBranchIndex(e: { pane: 'input' | 'output'; branchIndex: number }): void {
|
2022-11-04 06:04:31 -07:00
|
|
|
Vue.set(this[e.pane], 'branch', e.branchIndex);
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
setNDVPanelDataIsEmpty(payload: { panel: 'input' | 'output'; isEmpty: boolean }): void {
|
2022-11-04 06:04:31 -07:00
|
|
|
Vue.set(this[payload.panel].data, 'isEmpty', payload.isEmpty);
|
|
|
|
},
|
2023-03-02 04:02:29 -08:00
|
|
|
disableMappingHint(store = true) {
|
2023-03-01 03:02:34 -08:00
|
|
|
this.isMappingOnboarded = true;
|
2023-03-02 04:02:29 -08:00
|
|
|
if (store) {
|
|
|
|
window.localStorage.setItem(LOCAL_STORAGE_MAPPING_IS_ONBOARDED, 'true');
|
|
|
|
}
|
2023-03-01 03:02:34 -08:00
|
|
|
},
|
2022-11-04 06:04:31 -07:00
|
|
|
},
|
|
|
|
});
|