feat(editor): Cleanup unused keymap functions and add additional onSave events in new canvas (no-changelog) (#10106)

This commit is contained in:
Alex Grozav 2024-07-19 14:40:00 +03:00 committed by GitHub
parent a388cc33d6
commit 4559e3ae18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 47 additions and 20 deletions

View file

@ -116,7 +116,7 @@ const isNewWorkflow = computed(() => {
}); });
const isWorkflowSaving = computed(() => { const isWorkflowSaving = computed(() => {
return uiStore.isActionActive['workflowSaving']; return uiStore.isActionActive.workflowSaving;
}); });
const onWorkflowPage = computed(() => { const onWorkflowPage = computed(() => {
@ -710,6 +710,7 @@ function showCreateWorkflowSuccessToast(id?: string) {
type="primary" type="primary"
:saved="!uiStore.stateIsDirty && !isNewWorkflow" :saved="!uiStore.stateIsDirty && !isNewWorkflow"
:disabled="isWorkflowSaving || readOnly" :disabled="isWorkflowSaving || readOnly"
:is-saving="isWorkflowSaving"
with-shortcut with-shortcut
:shortcut-tooltip="$locale.baseText('saveWorkflowButton.hint')" :shortcut-tooltip="$locale.baseText('saveWorkflowButton.hint')"
data-test-id="workflow-save-button" data-test-id="workflow-save-button"

View file

@ -3,7 +3,7 @@ import { computed, useCssModule } from 'vue';
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
position: 'top' | 'right' | 'bottom' | 'left'; position?: 'top' | 'right' | 'bottom' | 'left';
}>(), }>(),
{ {
position: 'right', position: 'right',

View file

@ -7,6 +7,10 @@ import { NodeResizer } from '@vue-flow/node-resizer';
import type { OnResize } from '@vue-flow/node-resizer/dist/types'; import type { OnResize } from '@vue-flow/node-resizer/dist/types';
import type { XYPosition } from '@vue-flow/core'; import type { XYPosition } from '@vue-flow/core';
defineOptions({
inheritAttrs: false,
});
const emit = defineEmits<{ const emit = defineEmits<{
update: [parameters: Record<string, unknown>]; update: [parameters: Record<string, unknown>];
move: [position: XYPosition]; move: [position: XYPosition];
@ -62,6 +66,7 @@ function onDoubleClick(event: MouseEvent) {
@resize="onResize" @resize="onResize"
/> />
<N8nSticky <N8nSticky
v-bind="$attrs"
:id="id" :id="id"
data-test-id="canvas-sticky-note-node" data-test-id="canvas-sticky-note-node"
:height="renderOptions.height" :height="renderOptions.height"

View file

@ -496,7 +496,30 @@ function onPinNodes(ids: string[], source: PinDataSource) {
} }
async function onSaveWorkflow() { async function onSaveWorkflow() {
await workflowHelpers.saveCurrentWorkflow(); const saved = await workflowHelpers.saveCurrentWorkflow();
if (saved) {
canvasEventBus.emit('saved:workflow');
}
}
function addWorkflowSavedEventBindings() {
canvasEventBus.on('saved:workflow', npsSurveyStore.fetchPromptsData);
canvasEventBus.on('saved:workflow', onSaveFromWithinNDV);
}
function removeWorkflowSavedEventBindings() {
canvasEventBus.off('saved:workflow', npsSurveyStore.fetchPromptsData);
canvasEventBus.off('saved:workflow', onSaveFromWithinNDV);
canvasEventBus.off('saved:workflow', onSaveFromWithinExecutionDebug);
}
async function onSaveFromWithinNDV() {
if (ndvStore.activeNodeName) {
toast.showMessage({
title: i18n.baseText('generic.workflowSaved'),
type: 'success',
});
}
} }
async function onCreateWorkflow() { async function onCreateWorkflow() {
@ -874,20 +897,6 @@ const chatTriggerNodePinnedData = computed(() => {
return workflowsStore.pinDataByNodeName(chatTriggerNode.value.name); return workflowsStore.pinDataByNodeName(chatTriggerNode.value.name);
}); });
/**
* Keyboard
*/
function addKeyboardEventBindings() {
// document.addEventListener('keydown', this.keyDown);
// document.addEventListener('keyup', this.keyUp);
}
function removeKeyboardEventBindings() {
// document.removeEventListener('keydown', this.keyDown);
// document.removeEventListener('keyup', this.keyUp);
}
/** /**
* History events * History events
*/ */
@ -1074,13 +1083,25 @@ function checkIfRouteIsAllowed() {
async function initializeDebugMode() { async function initializeDebugMode() {
if (route.name === VIEWS.EXECUTION_DEBUG) { if (route.name === VIEWS.EXECUTION_DEBUG) {
titleSet(workflowsStore.workflowName, 'DEBUG'); titleSet(workflowsStore.workflowName, 'DEBUG');
if (!workflowsStore.isInDebugMode) { if (!workflowsStore.isInDebugMode) {
await applyExecutionData(route.params.executionId as string); await applyExecutionData(route.params.executionId as string);
workflowsStore.isInDebugMode = true; workflowsStore.isInDebugMode = true;
} }
canvasEventBus.on('saved:workflow', onSaveFromWithinExecutionDebug);
} }
} }
async function onSaveFromWithinExecutionDebug() {
if (route.name !== VIEWS.EXECUTION_DEBUG) return;
await router.replace({
name: VIEWS.WORKFLOW,
params: { name: workflowId.value },
});
}
/** /**
* Canvas * Canvas
*/ */
@ -1223,9 +1244,9 @@ onMounted(async () => {
addUndoRedoEventBindings(); addUndoRedoEventBindings();
addPostMessageEventBindings(); addPostMessageEventBindings();
addKeyboardEventBindings();
addSourceControlEventBindings(); addSourceControlEventBindings();
addImportEventBindings(); addImportEventBindings();
addWorkflowSavedEventBindings();
registerCustomActions(); registerCustomActions();
@ -1239,9 +1260,9 @@ onMounted(async () => {
onBeforeUnmount(() => { onBeforeUnmount(() => {
removeUndoRedoEventBindings(); removeUndoRedoEventBindings();
removePostMessageEventBindings(); removePostMessageEventBindings();
removeKeyboardEventBindings();
removeSourceControlEventBindings(); removeSourceControlEventBindings();
removeImportEventBindings(); removeImportEventBindings();
removeWorkflowSavedEventBindings();
}); });
</script> </script>
@ -1320,10 +1341,10 @@ onBeforeUnmount(() => {
@stop-execution="onStopExecution" @stop-execution="onStopExecution"
@switch-selected-node="onSwitchActiveNode" @switch-selected-node="onSwitchActiveNode"
@open-connection-node-creator="onOpenSelectiveNodeCreator" @open-connection-node-creator="onOpenSelectiveNodeCreator"
@save-keyboard-shortcut="onSaveWorkflow"
/> />
<!-- <!--
:renaming="renamingActive" :renaming="renamingActive"
@save-keyboard-shortcut="onSaveKeyboardShortcut"
--> -->
</Suspense> </Suspense>
</WorkflowCanvas> </WorkflowCanvas>