Skip to content

Commit c6080a5

Browse files
committed
Enhance task sorting by adding priority consideration
Updated the task sorting logic to account for both due dates and priority levels, ensuring tasks with higher priority are sorted first. Added a `priority` function in task configs to define a priority level and label for each task. Adjusted the reducer to use the updated sorting logic.
1 parent 067b146 commit c6080a5

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

config/default/app_settings.json

Lines changed: 5 additions & 3 deletions
Large diffs are not rendered by default.

config/default/tasks.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,15 @@ module.exports = [
280280
const endTime = addDays(dueDate, event.end).getTime();
281281
return isFormArraySubmittedInWindow(contact.reports, ['pnc_danger_sign_follow_up_baby'], startTime, endTime);
282282
},
283+
priority: function(contact, report, event, dueDate) {
284+
console.warn(contact);
285+
console.warn(event);
286+
console.warn(dueDate);
287+
return {
288+
level: 10,
289+
label: 'High',
290+
};
291+
},
283292
actions: [
284293
{
285294
type: 'report',
@@ -318,6 +327,15 @@ module.exports = [
318327
const endTime = addDays(dueDate, event.end + 1).getTime();
319328
return isFormArraySubmittedInWindow(contact.reports, ['pnc_danger_sign_follow_up_baby'], startTime, endTime);
320329
},
330+
priority: function(contact, report, event, dueDate) {
331+
console.warn(contact);
332+
console.warn(event);
333+
console.warn(dueDate);
334+
return {
335+
level: 10,
336+
label: 'High',
337+
};
338+
},
321339
actions: [
322340
{
323341
type: 'report',

webapp/src/ts/reducers/tasks.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,21 @@ const initialState = {
1414
},
1515
};
1616

17-
const orderByDueDate = (t1, t2) => {
17+
const orderByDueDateAndPriority = (t1, t2) => {
1818
const lhs = t1?.dueDate;
1919
const rhs = t2?.dueDate;
20+
21+
const lhsPriority = t1?.priority;
22+
const rhsPriority = t2?.priority;
23+
24+
if ((lhsPriority && !rhsPriority) || lhsPriority > rhsPriority) {
25+
return -1;
26+
}
27+
28+
if ((!lhsPriority && rhsPriority) || lhsPriority < rhsPriority) {
29+
return 1;
30+
}
31+
2032
if (!lhs && !rhs) {
2133
return 0;
2234
}
@@ -37,7 +49,7 @@ const _tasksReducer = createReducer(
3749
on(Actions.setTasksList, (state, { payload: { tasks } }) => {
3850
return {
3951
...state,
40-
tasksList: [...tasks].sort(orderByDueDate),
52+
tasksList: [...tasks].sort(orderByDueDateAndPriority),
4153
};
4254
}),
4355

0 commit comments

Comments
 (0)