feat(editor): Workflow history [WIP] - Add cloned workflow link to success toast message (no-changelog) (#7405)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeMount, ref, watchEffect, computed } from 'vue';
|
||||
import { onBeforeMount, ref, watchEffect, computed, h } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import type { IWorkflowDb, UserAction } from '@/Interface';
|
||||
import { VIEWS, WORKFLOW_HISTORY_VERSION_RESTORE } from '@/constants';
|
||||
@@ -162,6 +162,58 @@ const openRestorationModal = async (
|
||||
});
|
||||
};
|
||||
|
||||
const cloneWorkflowVersion = async (
|
||||
id: WorkflowVersionId,
|
||||
data: { formattedCreatedAt: string },
|
||||
) => {
|
||||
const clonedWorkflow = await workflowHistoryStore.cloneIntoNewWorkflow(
|
||||
route.params.workflowId,
|
||||
id,
|
||||
data,
|
||||
);
|
||||
const { href } = router.resolve({
|
||||
name: VIEWS.WORKFLOW,
|
||||
params: {
|
||||
name: clonedWorkflow.id,
|
||||
},
|
||||
});
|
||||
|
||||
toast.showMessage({
|
||||
title: i18n.baseText('workflowHistory.action.clone.success.title'),
|
||||
message: h(
|
||||
'a',
|
||||
{ href, target: '_blank' },
|
||||
i18n.baseText('workflowHistory.action.clone.success.message'),
|
||||
),
|
||||
type: 'success',
|
||||
duration: 10000,
|
||||
});
|
||||
};
|
||||
|
||||
const restoreWorkflowVersion = async (
|
||||
id: WorkflowVersionId,
|
||||
data: { formattedCreatedAt: string },
|
||||
) => {
|
||||
const workflow = await workflowsStore.fetchWorkflow(route.params.workflowId);
|
||||
const modalAction = await openRestorationModal(workflow.active, data.formattedCreatedAt);
|
||||
if (modalAction === WorkflowHistoryVersionRestoreModalActions.cancel) {
|
||||
return;
|
||||
}
|
||||
await workflowHistoryStore.restoreWorkflow(
|
||||
route.params.workflowId,
|
||||
id,
|
||||
modalAction === WorkflowHistoryVersionRestoreModalActions.deactivateAndRestore,
|
||||
);
|
||||
const history = await workflowHistoryStore.getWorkflowHistory(route.params.workflowId, {
|
||||
take: 1,
|
||||
});
|
||||
workflowHistory.value = history.concat(workflowHistory.value);
|
||||
toast.showMessage({
|
||||
title: i18n.baseText('workflowHistory.action.restore.success.title'),
|
||||
type: 'success',
|
||||
});
|
||||
};
|
||||
|
||||
const onAction = async ({
|
||||
action,
|
||||
id,
|
||||
@@ -180,31 +232,10 @@ const onAction = async ({
|
||||
await workflowHistoryStore.downloadVersion(route.params.workflowId, id, data);
|
||||
break;
|
||||
case WORKFLOW_HISTORY_ACTIONS.CLONE:
|
||||
await workflowHistoryStore.cloneIntoNewWorkflow(route.params.workflowId, id, data);
|
||||
toast.showMessage({
|
||||
title: i18n.baseText('workflowHistory.action.clone.success.title'),
|
||||
type: 'success',
|
||||
});
|
||||
await cloneWorkflowVersion(id, data);
|
||||
break;
|
||||
case WORKFLOW_HISTORY_ACTIONS.RESTORE:
|
||||
const workflow = await workflowsStore.fetchWorkflow(route.params.workflowId);
|
||||
const modalAction = await openRestorationModal(workflow.active, data.formattedCreatedAt);
|
||||
if (modalAction === WorkflowHistoryVersionRestoreModalActions.cancel) {
|
||||
break;
|
||||
}
|
||||
await workflowHistoryStore.restoreWorkflow(
|
||||
route.params.workflowId,
|
||||
id,
|
||||
modalAction === WorkflowHistoryVersionRestoreModalActions.deactivateAndRestore,
|
||||
);
|
||||
const history = await workflowHistoryStore.getWorkflowHistory(route.params.workflowId, {
|
||||
take: 1,
|
||||
});
|
||||
workflowHistory.value = history.concat(workflowHistory.value);
|
||||
toast.showMessage({
|
||||
title: i18n.baseText('workflowHistory.action.restore.success.title'),
|
||||
type: 'success',
|
||||
});
|
||||
await restoreWorkflowVersion(id, data);
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { SpyInstance } from 'vitest';
|
||||
import { createTestingPinia } from '@pinia/testing';
|
||||
import { waitFor } from '@testing-library/vue';
|
||||
import { waitFor, within } from '@testing-library/vue';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { defineComponent } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
@@ -54,8 +54,10 @@ const renderComponent = createComponentRenderer(WorkflowHistoryPage, {
|
||||
default: versionId,
|
||||
},
|
||||
},
|
||||
template:
|
||||
'<div><button data-test-id="stub-preview-button" @click="event => $emit(`preview`, {id, event})">Preview</button>button></div>',
|
||||
template: `<div>
|
||||
<button data-test-id="stub-preview-button" @click="event => $emit('preview', {id, event})" />
|
||||
<button data-test-id="stub-clone-button" @click="() => $emit('action', { action: 'clone', id })" />
|
||||
</div>`,
|
||||
}),
|
||||
},
|
||||
},
|
||||
@@ -147,4 +149,24 @@ describe('WorkflowHistory', () => {
|
||||
);
|
||||
expect(windowOpenSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should clone workflow from version data', async () => {
|
||||
route.params.workflowId = workflowId;
|
||||
const newWorkflowId = faker.string.nanoid();
|
||||
vi.spyOn(workflowHistoryStore, 'cloneIntoNewWorkflow').mockResolvedValue({
|
||||
id: newWorkflowId,
|
||||
} as IWorkflowDb);
|
||||
|
||||
const { getByTestId, getByRole } = renderComponent({ pinia });
|
||||
await userEvent.click(getByTestId('stub-clone-button'));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(router.resolve).toHaveBeenCalledWith({
|
||||
name: VIEWS.WORKFLOW,
|
||||
params: { name: newWorkflowId },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(within(getByRole('alert')).getByRole('link')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user