mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat(editor): Migrate pinData mixin to usePinnedData composable (no-changelog) (#8207)
## Summary Required as part of NodeView refactoring: - Migrates `pinData` mixin to `usePinnedData` composable. - Adds `useActiveNode` and `useNodeType` composables ## Related tickets and issues https://linear.app/n8n/issue/N8N-6355/pindata ## Review / Merge checklist - [x] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [x] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [x] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. > A feature is not complete without tests.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
<template>
|
||||
<div :class="['run-data', $style.container]" @mouseover="activatePane">
|
||||
<n8n-callout
|
||||
v-if="canPinData && hasPinData && !editMode.enabled && !isProductionExecutionPreview"
|
||||
v-if="
|
||||
canPinData && pinnedData.hasData.value && !editMode.enabled && !isProductionExecutionPreview
|
||||
"
|
||||
theme="secondary"
|
||||
icon="thumbtack"
|
||||
:class="$style.pinnedDataCallout"
|
||||
@@ -98,11 +100,11 @@
|
||||
<n8n-icon-button
|
||||
:class="['ml-2xs', $style.pinDataButton]"
|
||||
type="tertiary"
|
||||
:active="hasPinData"
|
||||
:active="pinnedData.hasData.value"
|
||||
icon="thumbtack"
|
||||
:disabled="
|
||||
editMode.enabled ||
|
||||
(rawInputData.length === 0 && !hasPinData) ||
|
||||
(rawInputData.length === 0 && !pinnedData.hasData.value) ||
|
||||
isReadOnlyRoute ||
|
||||
readOnlyEnv
|
||||
"
|
||||
@@ -562,7 +564,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineAsyncComponent, defineComponent } from 'vue';
|
||||
import { defineAsyncComponent, defineComponent, toRef } from 'vue';
|
||||
import type { PropType } from 'vue';
|
||||
import { mapStores } from 'pinia';
|
||||
import { useStorage } from '@/composables/useStorage';
|
||||
@@ -606,8 +608,8 @@ import NodeErrorView from '@/components/Error/NodeErrorView.vue';
|
||||
import JsonEditor from '@/components/JsonEditor/JsonEditor.vue';
|
||||
|
||||
import { genericHelpers } from '@/mixins/genericHelpers';
|
||||
import { pinData } from '@/mixins/pinData';
|
||||
import type { PinDataSource } from '@/mixins/pinData';
|
||||
import type { PinDataSource } from '@/composables/usePinnedData';
|
||||
import { usePinnedData } from '@/composables/usePinnedData';
|
||||
import { dataPinningEventBus } from '@/event-bus';
|
||||
import { clearJsonKey, isEmpty } from '@/utils/typesUtils';
|
||||
import { executionDataToJson } from '@/utils/nodeTypesUtils';
|
||||
@@ -642,10 +644,11 @@ export default defineComponent({
|
||||
RunDataHtml,
|
||||
RunDataSearch,
|
||||
},
|
||||
mixins: [genericHelpers, pinData],
|
||||
mixins: [genericHelpers],
|
||||
props: {
|
||||
nodeUi: {
|
||||
node: {
|
||||
type: Object as PropType<INodeUi>,
|
||||
default: null,
|
||||
},
|
||||
runIndex: {
|
||||
type: Number,
|
||||
@@ -674,6 +677,7 @@ export default defineComponent({
|
||||
},
|
||||
paneType: {
|
||||
type: String as PropType<NodePanelType>,
|
||||
required: true,
|
||||
},
|
||||
overrideOutputs: {
|
||||
type: Array as PropType<number[]>,
|
||||
@@ -697,14 +701,21 @@ export default defineComponent({
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
setup() {
|
||||
setup(props) {
|
||||
const ndvStore = useNDVStore();
|
||||
const nodeHelpers = useNodeHelpers();
|
||||
const externalHooks = useExternalHooks();
|
||||
const node = toRef(props, 'node');
|
||||
const pinnedData = usePinnedData(node, {
|
||||
runIndex: props.runIndex,
|
||||
displayMode: ndvStore.getPanelDisplayMode(props.paneType),
|
||||
});
|
||||
|
||||
return {
|
||||
...useToast(),
|
||||
externalHooks,
|
||||
nodeHelpers,
|
||||
pinnedData,
|
||||
};
|
||||
},
|
||||
data() {
|
||||
@@ -761,9 +772,6 @@ export default defineComponent({
|
||||
displayMode(): IRunDataDisplayMode {
|
||||
return this.ndvStore.getPanelDisplayMode(this.paneType);
|
||||
},
|
||||
node(): INodeUi | null {
|
||||
return (this.nodeUi as INodeUi | null) || null;
|
||||
},
|
||||
nodeType(): INodeTypeDescription | null {
|
||||
if (this.node) {
|
||||
return this.nodeTypesStore.getNodeType(this.node.type, this.node.typeVersion);
|
||||
@@ -796,7 +804,7 @@ export default defineComponent({
|
||||
return (
|
||||
!nonMainInputs &&
|
||||
!this.isPaneTypeInput &&
|
||||
this.isPinDataNodeType &&
|
||||
this.pinnedData.isValidNodeType.value &&
|
||||
!(this.binaryData && this.binaryData.length > 0)
|
||||
);
|
||||
},
|
||||
@@ -832,7 +840,7 @@ export default defineComponent({
|
||||
!this.isExecuting &&
|
||||
this.node &&
|
||||
((this.workflowRunData && this.workflowRunData.hasOwnProperty(this.node.name)) ||
|
||||
this.hasPinData),
|
||||
this.pinnedData.hasData.value),
|
||||
);
|
||||
},
|
||||
isArtificialRecoveredEventItem(): boolean {
|
||||
@@ -864,7 +872,9 @@ export default defineComponent({
|
||||
return this.getDataCount(this.runIndex, this.currentOutputIndex);
|
||||
},
|
||||
unfilteredDataCount(): number {
|
||||
return this.pinData ? this.pinData.length : this.rawInputData.length;
|
||||
return this.pinnedData.data.value
|
||||
? this.pinnedData.data.value.length
|
||||
: this.rawInputData.length;
|
||||
},
|
||||
dataSizeInMB(): string {
|
||||
return (this.dataSize / 1024 / 1000).toLocaleString();
|
||||
@@ -1072,8 +1082,8 @@ export default defineComponent({
|
||||
useStorage(LOCAL_STORAGE_PIN_DATA_DISCOVERY_CANVAS_FLAG).value = 'true';
|
||||
},
|
||||
enterEditMode({ origin }: EnterEditModeArgs) {
|
||||
const inputData = this.pinData
|
||||
? clearJsonKey(this.pinData)
|
||||
const inputData = this.pinnedData.data.value
|
||||
? clearJsonKey(this.pinnedData.data.value)
|
||||
: executionDataToJson(this.rawInputData);
|
||||
|
||||
const data = inputData.length > 0 ? inputData : TEST_PIN_DATA;
|
||||
@@ -1086,9 +1096,9 @@ export default defineComponent({
|
||||
click_type: origin === 'editIconButton' ? 'button' : 'link',
|
||||
session_id: this.sessionId,
|
||||
run_index: this.runIndex,
|
||||
is_output_present: this.hasNodeRun || this.hasPinData,
|
||||
view: !this.hasNodeRun && !this.hasPinData ? 'undefined' : this.displayMode,
|
||||
is_data_pinned: this.hasPinData,
|
||||
is_output_present: this.hasNodeRun || this.pinnedData.hasData.value,
|
||||
view: !this.hasNodeRun && !this.pinnedData.hasData.value ? 'undefined' : this.displayMode,
|
||||
is_data_pinned: this.pinnedData.hasData.value,
|
||||
});
|
||||
},
|
||||
onClickCancelEdit() {
|
||||
@@ -1106,7 +1116,7 @@ export default defineComponent({
|
||||
this.clearAllStickyNotifications();
|
||||
|
||||
try {
|
||||
this.setPinData(this.node, clearJsonKey(value) as INodeExecutionData[], 'save-edit');
|
||||
this.pinnedData.setData(clearJsonKey(value) as INodeExecutionData[], 'save-edit');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return;
|
||||
@@ -1135,7 +1145,7 @@ export default defineComponent({
|
||||
node_type: this.activeNode.type,
|
||||
session_id: this.sessionId,
|
||||
run_index: this.runIndex,
|
||||
view: !this.hasNodeRun && !this.hasPinData ? 'none' : this.displayMode,
|
||||
view: !this.hasNodeRun && !this.pinnedData.hasData.value ? 'none' : this.displayMode,
|
||||
};
|
||||
|
||||
void this.externalHooks.run('runData.onTogglePinData', telemetryPayload);
|
||||
@@ -1144,13 +1154,13 @@ export default defineComponent({
|
||||
|
||||
this.nodeHelpers.updateNodeParameterIssues(this.node);
|
||||
|
||||
if (this.hasPinData) {
|
||||
this.unsetPinData(this.node, source);
|
||||
if (this.pinnedData.hasData.value) {
|
||||
this.pinnedData.unsetData(source);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.setPinData(this.node, this.rawInputData, 'pin-icon-click');
|
||||
this.pinnedData.setData(this.rawInputData, 'pin-icon-click');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return;
|
||||
@@ -1299,14 +1309,14 @@ export default defineComponent({
|
||||
return inputData;
|
||||
},
|
||||
getPinDataOrLiveData(inputData: INodeExecutionData[]): INodeExecutionData[] {
|
||||
if (this.pinData && !this.isProductionExecutionPreview) {
|
||||
return Array.isArray(this.pinData)
|
||||
? this.pinData.map((value) => ({
|
||||
if (this.pinnedData.data.value && !this.isProductionExecutionPreview) {
|
||||
return Array.isArray(this.pinnedData.data.value)
|
||||
? this.pinnedData.data.value.map((value) => ({
|
||||
json: value,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
json: this.pinData,
|
||||
json: this.pinnedData.data.value,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user