fix(editor): Take user back to correct project after archive/delete (#21940)

This commit is contained in:
Nikhil Kuriakose 2025-11-17 16:49:38 +01:00 committed by GitHub
parent 15ea8b76c6
commit 9ddedb03df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 155 additions and 2 deletions

View File

@ -391,6 +391,72 @@ describe('WorkflowDetails', () => {
});
});
it("should navigate to team project workflows page on 'Archive' for team project workflow", async () => {
const teamProjectId = 'team-project-123';
const teamWorkflow = {
...workflow,
homeProject: {
id: teamProjectId,
name: 'Team Project',
type: 'team',
},
};
workflowsStore.getWorkflowById = vi.fn().mockReturnValue(teamWorkflow);
workflowsStore.archiveWorkflow.mockResolvedValue(undefined);
const { getByTestId } = renderComponent({
props: {
...teamWorkflow,
active: false,
readOnly: false,
isArchived: false,
scopes: ['workflow:delete'],
},
});
await userEvent.click(getByTestId('workflow-menu'));
await userEvent.click(getByTestId('workflow-menu-item-archive'));
expect(workflowsStore.archiveWorkflow).toHaveBeenCalledWith(teamWorkflow.id);
expect(router.push).toHaveBeenCalledWith({
name: VIEWS.PROJECTS_WORKFLOWS,
params: { projectId: teamProjectId },
});
});
it("should navigate to personal workflows page on 'Archive' for personal project workflow", async () => {
const personalWorkflow = {
...workflow,
homeProject: {
id: 'personal-project-123',
name: 'Personal Project',
type: 'personal',
},
};
workflowsStore.getWorkflowById = vi.fn().mockReturnValue(personalWorkflow);
workflowsStore.archiveWorkflow.mockResolvedValue(undefined);
const { getByTestId } = renderComponent({
props: {
...personalWorkflow,
active: false,
readOnly: false,
isArchived: false,
scopes: ['workflow:delete'],
},
});
await userEvent.click(getByTestId('workflow-menu'));
await userEvent.click(getByTestId('workflow-menu-item-archive'));
expect(workflowsStore.archiveWorkflow).toHaveBeenCalledWith(personalWorkflow.id);
expect(router.push).toHaveBeenCalledWith({
name: VIEWS.WORKFLOWS,
});
});
it("should confirm onWorkflowMenuSelect on 'Archive' option click on active workflow", async () => {
const { getByTestId } = renderComponent({
props: {
@ -461,6 +527,72 @@ describe('WorkflowDetails', () => {
});
});
it("should navigate to team project workflows page on 'Delete' for team project workflow", async () => {
const teamProjectId = 'team-project-456';
const teamWorkflow = {
...workflow,
isArchived: true,
homeProject: {
id: teamProjectId,
name: 'Team Project',
type: 'team',
},
};
workflowsStore.getWorkflowById = vi.fn().mockReturnValue(teamWorkflow);
workflowsStore.deleteWorkflow.mockResolvedValue(undefined);
const { getByTestId } = renderComponent({
props: {
...teamWorkflow,
readOnly: false,
isArchived: true,
scopes: ['workflow:delete'],
},
});
await userEvent.click(getByTestId('workflow-menu'));
await userEvent.click(getByTestId('workflow-menu-item-delete'));
expect(workflowsStore.deleteWorkflow).toHaveBeenCalledWith(teamWorkflow.id);
expect(router.push).toHaveBeenCalledWith({
name: VIEWS.PROJECTS_WORKFLOWS,
params: { projectId: teamProjectId },
});
});
it("should navigate to personal workflows page on 'Delete' for personal project workflow", async () => {
const personalWorkflow = {
...workflow,
isArchived: true,
homeProject: {
id: 'personal-project-456',
name: 'Personal Project',
type: 'personal',
},
};
workflowsStore.getWorkflowById = vi.fn().mockReturnValue(personalWorkflow);
workflowsStore.deleteWorkflow.mockResolvedValue(undefined);
const { getByTestId } = renderComponent({
props: {
...personalWorkflow,
readOnly: false,
isArchived: true,
scopes: ['workflow:delete'],
},
});
await userEvent.click(getByTestId('workflow-menu'));
await userEvent.click(getByTestId('workflow-menu-item-delete'));
expect(workflowsStore.deleteWorkflow).toHaveBeenCalledWith(personalWorkflow.id);
expect(router.push).toHaveBeenCalledWith({
name: VIEWS.WORKFLOWS,
});
});
it("should call onWorkflowMenuSelect on 'Change owner' option click", async () => {
const openModalSpy = vi.spyOn(uiStore, 'openModalWithData');

View File

@ -487,7 +487,16 @@ async function handleArchiveWorkflow() {
type: 'success',
});
await router.push({ name: VIEWS.WORKFLOWS });
// Navigate to the appropriate project's workflow list
const workflow = workflowsStore.getWorkflowById(props.id);
if (workflow?.homeProject?.type === ProjectTypes.Team) {
await router.push({
name: VIEWS.PROJECTS_WORKFLOWS,
params: { projectId: workflow.homeProject.id },
});
} else {
await router.push({ name: VIEWS.WORKFLOWS });
}
}
async function handleUnarchiveWorkflow() {
@ -521,6 +530,10 @@ async function handleDeleteWorkflow() {
return;
}
// Get workflow before deletion to know which project to navigate to
const workflow = workflowsStore.getWorkflowById(props.id);
const isTeamProject = workflow?.homeProject?.type === ProjectTypes.Team;
try {
await workflowsStore.deleteWorkflow(props.id);
} catch (error) {
@ -537,7 +550,15 @@ async function handleDeleteWorkflow() {
type: 'success',
});
await router.push({ name: VIEWS.WORKFLOWS });
// Navigate to the appropriate project's workflow list
if (isTeamProject && workflow?.homeProject) {
await router.push({
name: VIEWS.PROJECTS_WORKFLOWS,
params: { projectId: workflow.homeProject.id },
});
} else {
await router.push({ name: VIEWS.WORKFLOWS });
}
}
async function onWorkflowMenuSelect(action: WORKFLOW_MENU_ACTIONS): Promise<void> {