-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskSort.js
More file actions
52 lines (43 loc) · 1.57 KB
/
taskSort.js
File metadata and controls
52 lines (43 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
export const sortTaskUtil = (data, field, order) => {
let sortedTask = data
switch (field) {
case 'name':
if (order == "asc") {
sortedTask.sort((a, b) => a.title.localeCompare(b.title))
} else {
sortedTask.sort((a, b) => b.title.localeCompare(a.title))
}
break;
case 'status':
if (order == "asc") {
sortedTask.sort((a, b) => a.status.text.localeCompare(b.status.text));
} else {
sortedTask.sort((a, b) => b.status.text.localeCompare(a.status.text));
}
break;
case 'priority':
if (order == "asc") {
sortedTask.sort((a, b) => a.priority.text.localeCompare(b.priority.text));
} else {
sortedTask.sort((a, b) => b.priority.text.localeCompare(a.priority.text));
}
break;
case 'owner':
if (order == "asc") {
sortedTask.sort((a, b) => a.user.firstName.localeCompare(b.user.firstName));
} else {
sortedTask.sort((a, b) => b.user.firstName.localeCompare(a.user.firstName));
}
break;
case 'dueDate':
if (order == "asc") {
sortedTask.sort((a, b) => new Date(a.dueDate) - new Date(b.dueDate));
} else {
sortedTask.sort((a, b) => new Date(b.dueDate) - new Date(a.dueDate));
}
break;
default:
return sortedTask;
}
return sortedTask
}