fix(editor): Allow pinning of AI root nodes (#9060)
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useToast } from '@/composables/useToast';
|
||||
import { useI18n } from '@/composables/useI18n';
|
||||
import type { INodeExecutionData, IPinData } from 'n8n-workflow';
|
||||
import { jsonParse, jsonStringify } from 'n8n-workflow';
|
||||
import { jsonParse, jsonStringify, NodeConnectionType, NodeHelpers } from 'n8n-workflow';
|
||||
import {
|
||||
MAX_EXPECTED_REQUEST_SIZE,
|
||||
MAX_PINNED_DATA_SIZE,
|
||||
@@ -18,6 +18,8 @@ import { computed, unref } from 'vue';
|
||||
import { useRootStore } from '@/stores/n8nRoot.store';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useNodeType } from '@/composables/useNodeType';
|
||||
import { useDataSchema } from './useDataSchema';
|
||||
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
||||
|
||||
export type PinDataSource =
|
||||
| 'pin-icon-click'
|
||||
@@ -47,6 +49,7 @@ export function usePinnedData(
|
||||
const i18n = useI18n();
|
||||
const telemetry = useTelemetry();
|
||||
const externalHooks = useExternalHooks();
|
||||
const { getInputDataWithPinned } = useDataSchema();
|
||||
|
||||
const { pushRef } = storeToRefs(rootStore);
|
||||
const { isSubNodeType, isMultipleOutputsNodeType } = useNodeType({
|
||||
@@ -73,6 +76,26 @@ export function usePinnedData(
|
||||
);
|
||||
});
|
||||
|
||||
function canPinNode(checkDataEmpty = false) {
|
||||
const targetNode = unref(node);
|
||||
if (targetNode === null) return false;
|
||||
|
||||
const nodeType = useNodeTypesStore().getNodeType(targetNode.type, targetNode.typeVersion);
|
||||
const dataToPin = getInputDataWithPinned(targetNode);
|
||||
|
||||
if (!nodeType || (checkDataEmpty && dataToPin.length === 0)) return false;
|
||||
|
||||
const workflow = workflowsStore.getCurrentWorkflow();
|
||||
const outputs = NodeHelpers.getNodeOutputs(workflow, targetNode, nodeType);
|
||||
const mainOutputs = outputs.filter((output) =>
|
||||
typeof output === 'string'
|
||||
? output === NodeConnectionType.Main
|
||||
: output.type === NodeConnectionType.Main,
|
||||
);
|
||||
|
||||
return mainOutputs.length === 1 && !PIN_DATA_NODE_TYPES_DENYLIST.includes(targetNode.type);
|
||||
}
|
||||
|
||||
function isValidJSON(data: string): boolean {
|
||||
try {
|
||||
JSON.parse(data);
|
||||
@@ -246,6 +269,7 @@ export function usePinnedData(
|
||||
data,
|
||||
hasData,
|
||||
isValidNodeType,
|
||||
canPinNode,
|
||||
setData,
|
||||
onSetDataSuccess,
|
||||
onSetDataError,
|
||||
|
||||
Reference in New Issue
Block a user