Skip to content

Commit

Permalink
feat(workflow): Move story to other workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaviju committed Oct 4, 2023
1 parent ef66930 commit 6ab62ea
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import { createFeature, createSelector, on } from '@ngrx/store';
import { Status, Story, Workflow } from '@taiga/data';
import { DropCandidate } from '@taiga/ui/drag/drag.model';
import {
projectEventActions,
projectApiActions,
projectEventActions,
} from '~/app/modules/project/data-access/+state/actions/project.actions';
import {
KanbanStory,
KanbanStoryA11y,
PartialStory,
} from '~/app/modules/project/feature-kanban/kanban.model';
import { StoryDetailActions } from '~/app/modules/project/story-detail/data-access/+state/actions/story-detail.actions';
import { StoryDetailActions, StoryDetailApiActions } from '~/app/modules/project/story-detail/data-access/+state/actions/story-detail.actions';
import { moveItemArray } from '~/app/shared/utils/move-item-array';
import { pick } from '~/app/shared/utils/pick';
import { createImmerReducer } from '~/app/shared/utils/store';
Expand Down Expand Up @@ -627,6 +627,11 @@ export const reducer = createImmerReducer(
return state;
}
),
on(StoryDetailApiActions.updateStoryWorkflowSuccess, (state, { story }): KanbanState => {
state = removeStory(state, (it) => it.ref === story.ref);

return state
}),

Check failure on line 634 in javascript/apps/taiga/src/app/modules/project/feature-kanban/data-access/+state/reducers/kanban.reducer.ts

View workflow job for this annotation

GitHub Actions / linters

Missing semicolon
on(
KanbanActions.deleteStory,
StoryDetailActions.deleteStory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Copyright (c) 2023-present Kaleidos INC
}

.workflow-name {
@mixin ellipsis;

&:hover {
color: var(--color-secondary80);
background: var(--color-gray20);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
<hr class="separator" />
<tui-opt-group>
<button
*ngFor="let workflow of workflows; trackBy: trackByWorkflowId"
*ngFor="
let workflow of filteredWorkflows;
trackBy: trackByWorkflowId
"
class="workflow-btn"
tuiOption
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
OnInit,
Output,
ViewChild,
} from '@angular/core';

Expand Down Expand Up @@ -41,7 +44,7 @@ import { BreadcrumbComponent } from '@taiga/ui/breadcrumb/breadcrumb.component';
TuiSvgModule,
],
})
export class StoryDetailWorkflowComponent {
export class StoryDetailWorkflowComponent implements OnInit {
@Input({ required: true })
public story!: StoryDetail;

Expand All @@ -51,7 +54,17 @@ export class StoryDetailWorkflowComponent {
@ViewChild(TuiHostedDropdownComponent)

Check failure on line 54 in javascript/apps/taiga/src/app/modules/project/story-detail/components/story-detail-workflow/story-detail-workflow.component.ts

View workflow job for this annotation

GitHub Actions / linters

Missing accessibility modifier on class property component
component?: TuiHostedDropdownComponent;

@Output()
public toWorkflow = new EventEmitter<Workflow>();

public openWorkflowList = false;
public filteredWorkflows: Workflow[] = [];

public ngOnInit(): void {
this.filteredWorkflows = this.workflows.filter(
(workflow) => workflow.slug !== this.story.workflow.slug
);
}

public trackByWorkflowId(_index: number, workflow: Workflow) {
return workflow.id;
Expand All @@ -60,6 +73,6 @@ export class StoryDetailWorkflowComponent {
public moveToWorkflow(workflow: Workflow) {
this.openWorkflowList = false;
this.component?.nativeFocusableElement?.focus();
console.log('move to workflow', workflow);
this.toWorkflow.emit(workflow);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export const StoryDetailActions = createActionGroup({
story: StoryUpdate;
projectId: Project['id'];
}>(),
'Update story workflow': props<{
story: StoryUpdate;
projectId: Project['id'];
}>(),
'Delete story': props<{
ref: Story['ref'];
project: Project;
Expand Down Expand Up @@ -104,6 +108,7 @@ export const StoryDetailApiActions = createActionGroup({
'Fetch Story Success': props<{ story: StoryDetail }>(),
'Fetch Workflow Success': props<{ workflow: Workflow }>(),
'Update Story Success': props<{ story: StoryDetail }>(),
'Update Story Workflow Success': props<{ story: StoryDetail }>(),
'Delete Story Success': props<{
project: Project;
ref: Story['ref'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export class StoryDetailEffects {

public loadWorkflow$ = createEffect(() => {
return this.actions$.pipe(
ofType(StoryDetailApiActions.fetchStorySuccess),
ofType(
StoryDetailApiActions.fetchStorySuccess,
StoryDetailApiActions.updateStoryWorkflowSuccess
),
concatLatestFrom(() => [
this.store.select(selectWorkflow),
this.store.select(selectCurrentProject).pipe(filterNil()),
Expand Down Expand Up @@ -152,6 +155,35 @@ export class StoryDetailEffects {
);
});

public updateStoryWorkflow$ = createEffect(() => {
return this.actions$.pipe(
ofType(StoryDetailActions.updateStoryWorkflow),
pessimisticUpdate({
run: (action) => {
return this.projectApiService
.updateStory(action.projectId, action.story)
.pipe(
map((story) =>
StoryDetailApiActions.updateStoryWorkflowSuccess({ story })
)
);
},
onError: (action, httpResponse: HttpErrorResponse) => {
this.appService.errorManagement(httpResponse, {
any: {
type: 'toast',
options: {
label: 'errors.save_changes',
message: 'errors.please_refresh',
status: TuiNotification.Error,
},
},
});
},
})
);
});

public deleteStory$ = createEffect(() => {
return this.actions$.pipe(
ofType(StoryDetailActions.deleteStory),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,14 @@ export const reducer = createImmerReducer(
),
on(
StoryDetailApiActions.updateStorySuccess,
StoryDetailApiActions.updateStoryWorkflowSuccess,
(state, { story }): StoryDetailState => {
state.story = story;

return state;
}
),

on(StoryDetailActions.updateStory, (state, { story }): StoryDetailState => {
if (state.story) {
if (story.title) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@
<tg-story-detail-workflow
*ngIf="vm.story"
[story]="vm.story"
[workflows]="
vm.project.workflows
"></tg-story-detail-workflow>
[workflows]="vm.project.workflows"
(toWorkflow)="moveStoryToWorkflow($event)">
</tg-story-detail-workflow>
</ng-container>

<tg-story-detail-status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,18 @@ export class StoryDetailComponent {
);
}

public moveStoryToWorkflow(workflow: Workflow) {
const story = this.getStoryUpdate();
story.workflow = workflow.slug;

this.store.dispatch(
StoryDetailActions.updateStoryWorkflow({
projectId: this.state.get('project').id,
story,
})
);
}

public fieldFocus(focus: boolean) {
this.state.set({ fieldFocus: focus });
}
Expand Down
1 change: 1 addition & 0 deletions javascript/libs/data/src/lib/story.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface StoryUpdate {
status?: Story['status']['id'];
title?: Story['title'];
description?: Story['description'];
workflow?: Workflow['slug'];
}

export interface createdBy {
Expand Down

0 comments on commit 6ab62ea

Please sign in to comment.