From 0aa80ef5822607e21fc61e926d0a08d1528e74fc Mon Sep 17 00:00:00 2001 From: Csaba Tuncsik Date: Fri, 8 Nov 2024 15:48:23 +0100 Subject: [PATCH] fix(editor): Fix default workflow settings (#11632) --- packages/editor-ui/src/Interface.ts | 1 - packages/editor-ui/src/__tests__/defaults.ts | 4 +- .../src/components/WorkflowSettings.test.ts | 46 ++++++++++++++ .../src/components/WorkflowSettings.vue | 63 +++++++++---------- 4 files changed, 79 insertions(+), 35 deletions(-) diff --git a/packages/editor-ui/src/Interface.ts b/packages/editor-ui/src/Interface.ts index 11c30c67c38b2b..2a140eb76cef78 100644 --- a/packages/editor-ui/src/Interface.ts +++ b/packages/editor-ui/src/Interface.ts @@ -626,7 +626,6 @@ export type WorkflowCallerPolicyDefaultOption = 'any' | 'none' | 'workflowsFromA export interface IWorkflowSettings extends IWorkflowSettingsWorkflow { errorWorkflow?: string; - saveManualExecutions?: boolean; timezone?: string; executionTimeout?: number; maxExecutionTimeout?: number; diff --git a/packages/editor-ui/src/__tests__/defaults.ts b/packages/editor-ui/src/__tests__/defaults.ts index d16678b17ccf19..d2181db151a698 100644 --- a/packages/editor-ui/src/__tests__/defaults.ts +++ b/packages/editor-ui/src/__tests__/defaults.ts @@ -63,8 +63,8 @@ export const defaultSettings: FrontendSettings = { }, publicApi: { enabled: false, latestVersion: 0, path: '', swaggerUi: { enabled: false } }, pushBackend: 'websocket', - saveDataErrorExecution: 'DEFAULT', - saveDataSuccessExecution: 'DEFAULT', + saveDataErrorExecution: 'all', + saveDataSuccessExecution: 'all', saveManualExecutions: false, saveExecutionProgress: false, sso: { diff --git a/packages/editor-ui/src/components/WorkflowSettings.test.ts b/packages/editor-ui/src/components/WorkflowSettings.test.ts index 2c1a5e2c9c95bc..fdca2d5f339f19 100644 --- a/packages/editor-ui/src/components/WorkflowSettings.test.ts +++ b/packages/editor-ui/src/components/WorkflowSettings.test.ts @@ -145,4 +145,50 @@ describe('WorkflowSettingsVue', () => { expect(getByTestId('workflow-caller-policy-workflow-ids')).toHaveValue(cleanedUpWorkflowList); }); + + test.each([ + ['workflow-settings-save-failed-executions', 'Default - Save', () => {}], + [ + 'workflow-settings-save-failed-executions', + 'Default - Do not save', + () => { + settingsStore.saveDataErrorExecution = 'none'; + }, + ], + ['workflow-settings-save-success-executions', 'Default - Save', () => {}], + [ + 'workflow-settings-save-success-executions', + 'Default - Do not save', + () => { + settingsStore.saveDataSuccessExecution = 'none'; + }, + ], + [ + 'workflow-settings-save-manual-executions', + 'Default - Save', + () => { + settingsStore.saveManualExecutions = true; + }, + ], + ['workflow-settings-save-manual-executions', 'Default - Do not save', () => {}], + [ + 'workflow-settings-save-execution-progress', + 'Default - Save', + () => { + settingsStore.saveDataProgressExecution = true; + }, + ], + ['workflow-settings-save-execution-progress', 'Default - Do not save', () => {}], + ])( + 'should show %s dropdown correct default value as %s', + async (testId, optionText, storeSetter) => { + storeSetter(); + const { getByTestId } = createComponent({ pinia }); + await nextTick(); + + const dropdownItems = await getDropdownItems(getByTestId(testId)); + + expect(dropdownItems[0]).toHaveTextContent(optionText); + }, + ); }); diff --git a/packages/editor-ui/src/components/WorkflowSettings.vue b/packages/editor-ui/src/components/WorkflowSettings.vue index 3146e9a7e64166..d6d306eacd40e0 100644 --- a/packages/editor-ui/src/components/WorkflowSettings.vue +++ b/packages/editor-ui/src/components/WorkflowSettings.vue @@ -70,14 +70,14 @@ const helpTexts = computed(() => ({ workflowCallerPolicy: i18n.baseText('workflowSettings.helpTexts.workflowCallerPolicy'), workflowCallerIds: i18n.baseText('workflowSettings.helpTexts.workflowCallerIds'), })); -const defaultValues = computed(() => ({ +const defaultValues = ref({ timezone: 'America/New_York', saveDataErrorExecution: 'all', saveDataSuccessExecution: 'all', saveExecutionProgress: false, saveManualExecutions: false, workflowCallerPolicy: 'workflowsFromSameOwner', -})); +}); const readOnlyEnv = computed(() => sourceControlStore.preferences.branchReadOnly); const workflowName = computed(() => workflowsStore.workflowName); const workflowId = computed(() => workflowsStore.workflowId); @@ -145,8 +145,7 @@ const loadWorkflowCallerPolicyOptions = async () => { }; const loadSaveDataErrorExecutionOptions = async () => { - saveDataErrorExecutionOptions.value.length = 0; - saveDataErrorExecutionOptions.value.push.apply(saveDataErrorExecutionOptions.value, [ + saveDataErrorExecutionOptions.value = [ { key: 'DEFAULT', value: i18n.baseText('workflowSettings.saveDataErrorExecutionOptions.defaultSave', { @@ -166,12 +165,11 @@ const loadSaveDataErrorExecutionOptions = async () => { key: 'none', value: i18n.baseText('workflowSettings.saveDataErrorExecutionOptions.doNotSave'), }, - ]); + ]; }; const loadSaveDataSuccessExecutionOptions = async () => { - saveDataSuccessExecutionOptions.value.length = 0; - saveDataSuccessExecutionOptions.value.push.apply(saveDataSuccessExecutionOptions.value, [ + saveDataSuccessExecutionOptions.value = [ { key: 'DEFAULT', value: i18n.baseText('workflowSettings.saveDataSuccessExecutionOptions.defaultSave', { @@ -191,12 +189,11 @@ const loadSaveDataSuccessExecutionOptions = async () => { key: 'none', value: i18n.baseText('workflowSettings.saveDataSuccessExecutionOptions.doNotSave'), }, - ]); + ]; }; const loadSaveExecutionProgressOptions = async () => { - saveExecutionProgressOptions.value.length = 0; - saveExecutionProgressOptions.value.push.apply(saveExecutionProgressOptions.value, [ + saveExecutionProgressOptions.value = [ { key: 'DEFAULT', value: i18n.baseText('workflowSettings.saveExecutionProgressOptions.defaultSave', { @@ -215,29 +212,30 @@ const loadSaveExecutionProgressOptions = async () => { key: false, value: i18n.baseText('workflowSettings.saveExecutionProgressOptions.doNotSave'), }, - ]); + ]; }; const loadSaveManualOptions = async () => { - saveManualOptions.value.length = 0; - saveManualOptions.value.push({ - key: 'DEFAULT', - value: i18n.baseText('workflowSettings.saveManualOptions.defaultSave', { - interpolate: { - defaultValue: defaultValues.value.saveManualExecutions - ? i18n.baseText('workflowSettings.saveManualOptions.save') - : i18n.baseText('workflowSettings.saveManualOptions.doNotSave'), - }, - }), - }); - saveManualOptions.value.push({ - key: true, - value: i18n.baseText('workflowSettings.saveManualOptions.save'), - }); - saveManualOptions.value.push({ - key: false, - value: i18n.baseText('workflowSettings.saveManualOptions.doNotSave'), - }); + saveManualOptions.value = [ + { + key: 'DEFAULT', + value: i18n.baseText('workflowSettings.saveManualOptions.defaultSave', { + interpolate: { + defaultValue: defaultValues.value.saveManualExecutions + ? i18n.baseText('workflowSettings.saveManualOptions.save') + : i18n.baseText('workflowSettings.saveManualOptions.doNotSave'), + }, + }), + }, + { + key: true, + value: i18n.baseText('workflowSettings.saveManualOptions.save'), + }, + { + key: false, + value: i18n.baseText('workflowSettings.saveManualOptions.doNotSave'), + }, + ]; }; const loadTimezones = async () => { @@ -400,6 +398,7 @@ onMounted(async () => { defaultValues.value.saveDataErrorExecution = settingsStore.saveDataErrorExecution; defaultValues.value.saveDataSuccessExecution = settingsStore.saveDataSuccessExecution; defaultValues.value.saveManualExecutions = settingsStore.saveManualExecutions; + defaultValues.value.saveExecutionProgress = settingsStore.saveDataProgressExecution; defaultValues.value.timezone = rootStore.timezone; defaultValues.value.workflowCallerPolicy = settingsStore.workflowCallerPolicyDefaultOption; @@ -423,7 +422,7 @@ onMounted(async () => { ); } - const workflowSettingsData = deepCopy(workflowsStore.workflowSettings) as IWorkflowSettings; + const workflowSettingsData = deepCopy(workflowsStore.workflowSettings); if (workflowSettingsData.timezone === undefined) { workflowSettingsData.timezone = 'DEFAULT'; @@ -438,7 +437,7 @@ onMounted(async () => { workflowSettingsData.saveExecutionProgress = 'DEFAULT'; } if (workflowSettingsData.saveManualExecutions === undefined) { - workflowSettingsData.saveManualExecutions = defaultValues.value.saveManualExecutions; + workflowSettingsData.saveManualExecutions = 'DEFAULT'; } if (workflowSettingsData.callerPolicy === undefined) { workflowSettingsData.callerPolicy = defaultValues.value