Skip to content

Commit 1c9face

Browse files
Mnickiigavinbarronmusalesebastienlevert
authored
feat: move completed items to bottom of the list in mgt-todo (#2215)
set completed tasks to always checked move completed items to the bottom of the list change to sorting completed tasks by last modified date change TaskStatus to string union type Co-authored-by: Gavin Barron <[email protected]> Co-authored-by: Musale Martin <[email protected]> Co-authored-by: Musale Martin <[email protected]> Co-authored-by: Sébastien Levert <[email protected]>
1 parent 4863995 commit 1c9face

File tree

3 files changed

+58
-30
lines changed

3 files changed

+58
-30
lines changed

packages/mgt-components/src/components/mgt-picker/mgt-picker.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ registerFluentComponents(fluentCombobox, fluentOption);
2727
*
2828
* @cssprop --picker-background-color - {Color} Picker component background color
2929
*/
30-
// @customElement('mgt-picker')
3130
@customElement('picker')
3231
export class MgtPicker extends MgtTemplatedComponent {
3332
protected get strings() {

packages/mgt-components/src/components/mgt-todo/graph.todo.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ export interface LinkedResource {
1717
externalId: string;
1818
}
1919

20-
export enum TaskStatus {
21-
notStarted,
22-
inProgress,
23-
completed,
24-
deferred,
25-
waitingOnOthers
26-
}
20+
export type TaskStatus = 'notStarted' | 'inProgress' | 'completed' | 'deferred' | 'waitingOnOthers';
2721

2822
export enum TaskImportance {
2923
low,
@@ -46,7 +40,7 @@ export interface TodoTask {
4640
status: TaskStatus;
4741
createdDateTime: Date;
4842
completedDateTime: DateTimeTimeZone;
49-
lastModifiedDate: Date;
43+
lastModifiedDateTime: Date;
5044
bodyLastModifiedDateTime: Date;
5145
dueDateTime: DateTimeTimeZone;
5246
isReminderOn: boolean;

packages/mgt-components/src/components/mgt-todo/mgt-todo.ts

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,26 @@ export class MgtTodo extends MgtTasksBase {
126126
if (tasks && this.taskFilter) {
127127
tasks = tasks.filter(task => this.taskFilter(task));
128128
}
129+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
130+
const completedTasks = tasks.filter(task => task.status === 'completed');
129131

130132
const taskTemplates = repeat(
131-
tasks,
133+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
134+
tasks.filter(task => task.status !== 'completed'),
132135
task => task.id,
133136
task => this.renderTask(task)
134137
);
138+
139+
const completedTaskTemplates = repeat(
140+
completedTasks.sort((a, b) => {
141+
return new Date(a.lastModifiedDateTime).getTime() - new Date(b.lastModifiedDateTime).getTime();
142+
}),
143+
task => task.id,
144+
task => this.renderCompletedTask(task)
145+
);
135146
return html`
136147
${taskTemplates}
148+
${completedTaskTemplates}
137149
`;
138150
}
139151

@@ -265,23 +277,20 @@ export class MgtTodo extends MgtTasksBase {
265277
};
266278

267279
/**
268-
* Render a task in the list.
280+
* Render task details.
269281
*
270282
* @protected
271283
* @param {TodoTask} task
272284
* @returns {TemplateResult}
273285
* @memberof MgtTodo
274286
*/
275-
protected renderTask = (task: TodoTask) => {
287+
protected renderTaskDetails = (task: TodoTask) => {
276288
const context = { task, list: this.currentList };
277289

278290
if (this.hasTemplate('task')) {
279291
return this.renderTemplate('task', context, task.id);
280292
}
281293

282-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
283-
const isCompleted = (TaskStatus as any)[task.status] === TaskStatus.completed;
284-
285294
let taskDetailsTemplate = null;
286295

287296
const taskDueTemplate = task.dueDateTime
@@ -307,27 +316,53 @@ export class MgtTodo extends MgtTasksBase {
307316
`;
308317
}
309318

319+
return html`${taskDetailsTemplate}`;
320+
};
321+
322+
/**
323+
* Render a task in the list.
324+
*
325+
* @protected
326+
* @param {TodoTask} task
327+
* @returns {TemplateResult}
328+
* @memberof MgtTodo
329+
*/
330+
protected renderTask = (task: TodoTask) => {
331+
const taskClasses = classMap({
332+
ReadOnly: this.readOnly,
333+
Task: true
334+
});
335+
336+
return html`
337+
<fluent-checkbox id=${task.id} class=${taskClasses} @click="${() => this.handleTaskCheckClick(task)}">
338+
${this.renderTaskDetails(task)}
339+
</fluent-checkbox>
340+
`;
341+
};
342+
343+
/**
344+
* Render a completed task in the list.
345+
*
346+
* @protected
347+
* @param {TodoTask} task
348+
* @returns {TemplateResult}
349+
* @memberof MgtTodo
350+
*/
351+
protected renderCompletedTask = (task: TodoTask) => {
310352
const taskClasses = classMap({
311-
Complete: isCompleted,
312-
Incomplete: !isCompleted,
353+
Complete: true,
313354
ReadOnly: this.readOnly,
314-
Task: true,
315-
checked: isCompleted
355+
Task: true
316356
});
317357

318-
const taskCheckContent = isCompleted
319-
? html`
320-
${getSvg(SvgIcon.CheckMark)}
321-
`
322-
: null;
358+
const taskCheckContent = html`${getSvg(SvgIcon.CheckMark)}`;
323359

324360
return html`
325-
<fluent-checkbox id=${task.id} class=${taskClasses} ?checked=${isCompleted} @click="${() =>
326-
this.handleTaskCheckClick(task)}">
361+
<fluent-checkbox id=${task.id} class=${taskClasses} checked @click="${() => this.handleTaskCheckClick(task)}">
327362
<div slot="checked-indicator">
328363
${taskCheckContent}
329364
</div>
330-
${taskDetailsTemplate}
365+
${this.renderTaskDetails(task)}
331366
</fluent-checkbox>
332367
`;
333368
};
@@ -447,10 +482,10 @@ export class MgtTodo extends MgtTasksBase {
447482
this.handleTaskClick(task);
448483
if (!this.readOnly) {
449484
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
450-
if ((TaskStatus as any)[task.status] === TaskStatus.completed) {
451-
void this.updateTaskStatus(task, TaskStatus.notStarted);
485+
if (task.status === 'completed') {
486+
void this.updateTaskStatus(task, 'notStarted');
452487
} else {
453-
void this.updateTaskStatus(task, TaskStatus.completed);
488+
void this.updateTaskStatus(task, 'completed');
454489
}
455490
}
456491
}

0 commit comments

Comments
 (0)