feat(editor): Handle pin data edge cases and unify validation (no-changelog) (#6685)

Github issue / Community forum post (link here to close automatically):
This commit is contained in:
Alex Grozav
2023-11-02 10:43:02 +02:00
committed by GitHub
parent 27f37091c8
commit 721a36637c
15 changed files with 238 additions and 142 deletions

View File

@@ -538,9 +538,10 @@ import { externalHooks } from '@/mixins/externalHooks';
import { genericHelpers } from '@/mixins/genericHelpers';
import { nodeHelpers } from '@/mixins/nodeHelpers';
import { pinData } from '@/mixins/pinData';
import type { PinDataSource } from '@/mixins/pinData';
import CodeNodeEditor from '@/components/CodeNodeEditor/CodeNodeEditor.vue';
import { dataPinningEventBus } from '@/event-bus';
import { clearJsonKey, executionDataToJson, stringSizeInBytes, isEmpty } from '@/utils';
import { clearJsonKey, executionDataToJson, isEmpty } from '@/utils';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { useNDVStore } from '@/stores/ndv.store';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
@@ -646,9 +647,6 @@ export default defineComponent({
this.init();
if (!this.isPaneTypeInput) {
dataPinningEventBus.on('data-pinning-error', this.onDataPinningError);
dataPinningEventBus.on('data-unpinning', this.onDataUnpinning);
this.showPinDataDiscoveryTooltip(this.jsonData);
}
this.ndvStore.setNDVBranchIndex({
@@ -660,8 +658,6 @@ export default defineComponent({
},
beforeUnmount() {
this.hidePinDataDiscoveryTooltip();
dataPinningEventBus.off('data-pinning-error', this.onDataPinningError);
dataPinningEventBus.off('data-unpinning', this.onDataUnpinning);
},
computed: {
...mapStores(useNodeTypesStore, useNDVStore, useWorkflowsStore),
@@ -1028,27 +1024,22 @@ export default defineComponent({
this.onExitEditMode({ type: 'cancel' });
},
onClickSaveEdit() {
if (!this.node) {
return;
}
const { value } = this.editMode;
this.clearAllStickyNotifications();
if (!this.isValidPinDataSize(value)) {
this.onDataPinningError({ errorType: 'data-too-large', source: 'save-edit' });
return;
}
if (!this.isValidPinDataJSON(value)) {
this.onDataPinningError({ errorType: 'invalid-json', source: 'save-edit' });
try {
this.setPinData(this.node, clearJsonKey(value) as INodeExecutionData[], 'save-edit');
} catch (error) {
console.error(error);
return;
}
this.ndvStore.setOutputPanelEditModeEnabled(false);
this.workflowsStore.pinData({
node: this.node,
data: clearJsonKey(value) as INodeExecutionData[],
});
this.onDataPinningSuccess({ source: 'save-edit' });
this.onExitEditMode({ type: 'save' });
},
@@ -1061,53 +1052,11 @@ export default defineComponent({
type,
});
},
onDataUnpinning({
source,
}: {
source: 'banner-link' | 'pin-icon-click' | 'unpin-and-execute-modal';
}) {
this.$telemetry.track('User unpinned ndv data', {
node_type: this.activeNode?.type,
session_id: this.sessionId,
run_index: this.runIndex,
source,
data_size: stringSizeInBytes(this.pinData),
});
},
onDataPinningSuccess({ source }: { source: 'pin-icon-click' | 'save-edit' }) {
const telemetryPayload = {
pinning_source: source,
node_type: this.activeNode.type,
session_id: this.sessionId,
data_size: stringSizeInBytes(this.pinData),
view: this.displayMode,
run_index: this.runIndex,
};
void this.$externalHooks().run('runData.onDataPinningSuccess', telemetryPayload);
this.$telemetry.track('Ndv data pinning success', telemetryPayload);
},
onDataPinningError({
errorType,
source,
}: {
errorType: 'data-too-large' | 'invalid-json';
source: 'on-ndv-close-modal' | 'pin-icon-click' | 'save-edit';
}) {
this.$telemetry.track('Ndv data pinning failure', {
pinning_source: source,
node_type: this.activeNode.type,
session_id: this.sessionId,
data_size: stringSizeInBytes(this.pinData),
view: this.displayMode,
run_index: this.runIndex,
error_type: errorType,
});
},
async onTogglePinData({
source,
}: {
source: 'banner-link' | 'pin-icon-click' | 'unpin-and-execute-modal';
}) {
async onTogglePinData({ source }: { source: PinDataSource }) {
if (!this.node) {
return;
}
if (source === 'pin-icon-click') {
const telemetryPayload = {
node_type: this.activeNode.type,
@@ -1123,20 +1072,17 @@ export default defineComponent({
this.updateNodeParameterIssues(this.node);
if (this.hasPinData) {
this.onDataUnpinning({ source });
this.workflowsStore.unpinData({ node: this.node });
this.unsetPinData(this.node, source);
return;
}
if (!this.isValidPinDataSize(this.rawInputData)) {
this.onDataPinningError({ errorType: 'data-too-large', source: 'pin-icon-click' });
try {
this.setPinData(this.node, this.rawInputData, 'pin-icon-click');
} catch (error) {
console.error(error);
return;
}
this.onDataPinningSuccess({ source: 'pin-icon-click' });
this.workflowsStore.pinData({ node: this.node, data: this.rawInputData });
if (this.maxRunIndex > 0) {
this.showToast({
title: this.$locale.baseText('ndv.pinData.pin.multipleRuns.title', {