Skip to content

Commit

Permalink
fix: update workflow menu
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfran committed Nov 21, 2023
1 parent 6fb3d5b commit 40d942d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const projectApiActions = createActionGroup({
}>(),
'Delete Workflow Success': props<{
workflow: Workflow;
renamedWorkflow?: Workflow;
}>(),
'Fetch workflow': props<{
workflow: Workflow['slug'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,10 @@ describe('ProjectEffects', () => {
undefined
);
const expected = cold('--a', {
a: projectApiActions.deleteWorkflowSuccess({ workflow }),
a: projectApiActions.deleteWorkflowSuccess({
workflow,
renamedWorkflow: workflowRenameResult,
}),
});

expect(effects.deleteWorkflow$).toBeObservable(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
} from '../selectors/project.selectors';
import { MovedWorkflowService } from '~/app/modules/project/feature-kanban/services/moved-workflow.service';
import { selectCurrentWorkflowSlug } from '~/app/modules/project/feature-kanban/data-access/+state/selectors/kanban.selectors';
import { Workflow } from '@taiga/data';

@Injectable()
export class ProjectEffects {
Expand Down Expand Up @@ -279,6 +280,7 @@ export class ProjectEffects {
);

let workflowRename$ = of(action.moveTo ?? 'main');
let renamedWorkflow: Workflow;

if (
afterDeleteWorkflows.length === 1 &&
Expand All @@ -287,8 +289,11 @@ export class ProjectEffects {
workflowRename$ = this.projectApiService
.updateWorkflow('Main', afterDeleteWorkflows[0].slug, project.id)
.pipe(
map((result) => {
return result.slug;
tap((response) => {
renamedWorkflow = response;
}),
map((response) => {
return response.slug;
})
);
}
Expand Down Expand Up @@ -321,6 +326,7 @@ export class ProjectEffects {

return ProjectActions.projectApiActions.deleteWorkflowSuccess({
workflow: action.workflow,
renamedWorkflow,
});
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,26 @@ export const reducer = createImmerReducer(
return state;
}
),
on(
ProjectActions.projectApiActions.deleteWorkflowSuccess,
(state, { renamedWorkflow }): ProjectState => {
if (state.currentProjectId) {
const workflows = state.projects[state.currentProjectId].workflows.map(
(w) => {
if (w.id === renamedWorkflow?.id) {
return renamedWorkflow;
}

return w;
}
);

state.projects[state.currentProjectId].workflows = workflows;
}

return state;
}
),
on(
ProjectActions.permissionsUpdateSuccess,
(state, { project }): ProjectState => {
Expand Down

0 comments on commit 40d942d

Please sign in to comment.