Skip to content

Fix #4124: Boards: Hide tasks from hidden projects #4186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/app/core-ui/side-nav/side-nav.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import {
selectUnarchivedHiddenProjectIds,
selectUnarchivedVisibleProjects,
} from '../../features/project/store/project.selectors';
import { updateProject } from '../../features/project/store/project.actions';
import { SideNavItemComponent } from './side-nav-item/side-nav-item.component';
import { RouterLink, RouterLinkActive } from '@angular/router';
import { MatIcon } from '@angular/material/icon';
Expand Down Expand Up @@ -277,14 +276,7 @@ export class SideNavComponent implements OnDestroy {
}

toggleProjectVisibility(project: Project): void {
this._store.dispatch(
updateProject({
project: {
id: project.id,
changes: { isHiddenFromMenu: !project.isHiddenFromMenu },
},
}),
);
this.projectService.projectHideFromMenu(project);
}

async dropOnProjectList(
Expand Down
4 changes: 2 additions & 2 deletions src/app/features/boards/board-panel/board-panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '../boards.model';
import { select, Store } from '@ngrx/store';
import {
selectAllTasks,
selectAllAvailableTasksWithSubTasks,
selectTaskById,
selectTaskByIdWithSubTaskData,
} from '../../tasks/store/task.selectors';
Expand Down Expand Up @@ -75,7 +75,7 @@ export class BoardPanelComponent {
plannerService = inject(PlannerService);
_matDialog = inject(MatDialog);

allTasks$ = this.store.select(selectAllTasks);
allTasks$ = this.store.select(selectAllAvailableTasksWithSubTasks);
allTasks = toSignal(this.allTasks$, {
initialValue: [],
});
Expand Down
28 changes: 28 additions & 0 deletions src/app/features/project/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
updateProject,
updateProjectOrder,
upsertProject,
toggleHideFromMenu,
} from './store/project.actions';
import { DEFAULT_PROJECT } from './project.const';
import {
Expand Down Expand Up @@ -177,4 +178,31 @@ export class ProjectService {
updateOrder(ids: string[]): void {
this._store$.dispatch(updateProjectOrder({ ids }));
}

async projectHideFromMenu(project: Project): Promise<void> {
const taskState = await this._store$
.select(selectTaskFeatureState)
.pipe(take(1))
.toPromise();
const subTaskIdsForProject: string[] = [];
project.taskIds.forEach((id) => {
const task = getTaskById(id, taskState);
if (task.projectId && task.subTaskIds.length > 0) {
subTaskIdsForProject.push(...task.subTaskIds);
}
});
const allTaskIds = [
...project.taskIds,
...project.backlogTaskIds,
...subTaskIdsForProject,
];
const newVisibilityState = !project.isHiddenFromMenu;
this._store$.dispatch(
toggleHideFromMenu({
projectId: project.id,
allTaskIds,
isHiddenFromMenu: newVisibilityState,
}),
);
}
}
6 changes: 5 additions & 1 deletion src/app/features/project/store/project.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ export const unarchiveProject = createAction(

export const toggleHideFromMenu = createAction(
'[Project] Toggle hide from menu',
props<{ id: string }>(),
props<{
projectId: string;
allTaskIds: string[];
isHiddenFromMenu: boolean;
}>(),
);

// MOVE TASK ACTIONS
Expand Down
6 changes: 3 additions & 3 deletions src/app/features/project/store/project.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ export const projectReducer = createReducer<ProjectState>(
// on(deleteProjects, (state, { ids }) => projectAdapter.removeMany(ids, state)),
on(loadProjects, (state, { projects }) => projectAdapter.setAll(projects, state)),

on(toggleHideFromMenu, (state, { id }) =>
on(toggleHideFromMenu, (state, { projectId, isHiddenFromMenu }) =>
projectAdapter.updateOne(
{
id,
id: projectId,
changes: {
isHiddenFromMenu: !state.entities[id]?.isHiddenFromMenu,
isHiddenFromMenu: isHiddenFromMenu,
},
},
state,
Expand Down
1 change: 1 addition & 0 deletions src/app/features/tasks/short-syntax.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const TASK: TaskCopy = {
issueLastUpdated: undefined,
issueWasUpdated: undefined,
issueTimeTracked: undefined,
unavailable: false,
};
const ALL_TAGS: Tag[] = [
{ ...DEFAULT_TAG, id: 'blu_id', title: 'blu' },
Expand Down
20 changes: 19 additions & 1 deletion src/app/features/tasks/store/task.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import { MODEL_VERSION } from '../../../core/model-version';
import { PlannerActions } from '../../planner/store/planner.actions';
import { TODAY_TAG } from '../../tag/tag.const';
import { getWorklogStr } from '../../../util/get-work-log-str';
import { deleteProject } from '../../project/store/project.actions';
import { deleteProject, toggleHideFromMenu } from '../../project/store/project.actions';

export const TASK_FEATURE_NAME = 'tasks';

Expand Down Expand Up @@ -113,6 +113,24 @@ export const taskReducer = createReducer<TaskState>(
});
}),

on(toggleHideFromMenu, (state, { projectId, allTaskIds, isHiddenFromMenu }) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather avoid updating the task model itself for this, since it might complicate things further down the road, adds additional data size and logically the hidden state belongs more to the project model, than the task model.

const updatedTasks = allTaskIds
.map((taskId) => {
const task = state.entities[taskId];
if (task && task.projectId === projectId) {
return {
id: task.id,
changes: {
unavailable: isHiddenFromMenu,
},
};
}
return null;
})
.filter((task) => task !== null);
return taskAdapter.updateMany(updatedTasks, state);
}),

// TODO check if working
on(setCurrentTask, (state, { id }) => {
if (id) {
Expand Down
25 changes: 25 additions & 0 deletions src/app/features/tasks/store/task.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,28 @@ export const selectAllTaskIssueIdsForIssueProvider = (issueProvider: IssueProvid
.map((t) => t.issueId as string);
});
};

export const selectAllAvailableTasks = createSelector(selectAllTasks, (tasks: Task[]) =>
tasks.filter((task) => !task.unavailable),
);

export const selectAllAvailableTasksWithSubTasks = createSelector(
selectAllTasks,
(tasks: Task[]) => {
const availableTasks = tasks.filter((task) => !task.unavailable);
return availableTasks
.filter((task) => !task.parentId)
.map((task) => {
if (task.subTaskIds && task.subTaskIds.length > 0) {
return {
...task,
subTasks: task.subTaskIds
.map((subTaskId) => tasks.find((t) => t.id === subTaskId && !t.unavailable))
.filter((subTask) => !!subTask),
};
} else {
return task;
}
});
},
);
2 changes: 2 additions & 0 deletions src/app/features/tasks/task.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface TaskCopy extends IssueFieldsForTask {
id: string;
projectId?: string;
title: string;
unavailable: boolean;

subTaskIds: string[];
timeSpentOnDay: TimeSpentOnDay;
Expand Down Expand Up @@ -148,6 +149,7 @@ export const DEFAULT_TASK: Task = {
notes: '',
tagIds: [],
created: Date.now(),
unavailable: false,

_showSubTasksMode: ShowSubTasksMode.Show,

Expand Down