feat: Add a priority + created at sort for conversations (#13658)
- Add a new conversation sort option "Priority: Highest first, Created: Oldest first" that sorts by priority descending (urgent > high > medium > low > none) with created_at ascending as the tiebreaker
This commit is contained in:
@@ -11,6 +11,7 @@ class ConversationFinder
|
|||||||
'priority_desc' => %w[sort_on_priority desc],
|
'priority_desc' => %w[sort_on_priority desc],
|
||||||
'waiting_since_asc' => %w[sort_on_waiting_since asc],
|
'waiting_since_asc' => %w[sort_on_waiting_since asc],
|
||||||
'waiting_since_desc' => %w[sort_on_waiting_since desc],
|
'waiting_since_desc' => %w[sort_on_waiting_since desc],
|
||||||
|
'priority_desc_created_at_asc' => %w[sort_on_priority_created_at desc],
|
||||||
|
|
||||||
# To be removed in v3.5.0
|
# To be removed in v3.5.0
|
||||||
'latest' => %w[sort_on_last_activity_at desc],
|
'latest' => %w[sort_on_last_activity_at desc],
|
||||||
|
|||||||
@@ -86,6 +86,10 @@ const chatSortOptions = computed(() => [
|
|||||||
label: t('CHAT_LIST.SORT_ORDER_ITEMS.priority_asc.TEXT'),
|
label: t('CHAT_LIST.SORT_ORDER_ITEMS.priority_asc.TEXT'),
|
||||||
value: 'priority_asc',
|
value: 'priority_asc',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: t('CHAT_LIST.SORT_ORDER_ITEMS.priority_desc_created_at_asc.TEXT'),
|
||||||
|
value: 'priority_desc_created_at_asc',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: t('CHAT_LIST.SORT_ORDER_ITEMS.waiting_since_asc.TEXT'),
|
label: t('CHAT_LIST.SORT_ORDER_ITEMS.waiting_since_asc.TEXT'),
|
||||||
value: 'waiting_since_asc',
|
value: 'waiting_since_asc',
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export default {
|
|||||||
PRIORITY_DESC: 'priority_desc',
|
PRIORITY_DESC: 'priority_desc',
|
||||||
WAITING_SINCE_ASC: 'waiting_since_asc',
|
WAITING_SINCE_ASC: 'waiting_since_asc',
|
||||||
WAITING_SINCE_DESC: 'waiting_since_desc',
|
WAITING_SINCE_DESC: 'waiting_since_desc',
|
||||||
|
PRIORITY_DESC_CREATED_AT_ASC: 'priority_desc_created_at_asc',
|
||||||
},
|
},
|
||||||
ARTICLE_STATUS_TYPES: {
|
ARTICLE_STATUS_TYPES: {
|
||||||
DRAFT: 0,
|
DRAFT: 0,
|
||||||
|
|||||||
@@ -76,6 +76,9 @@
|
|||||||
},
|
},
|
||||||
"waiting_since_desc": {
|
"waiting_since_desc": {
|
||||||
"TEXT": "Pending Response: Shortest first"
|
"TEXT": "Pending Response: Shortest first"
|
||||||
|
},
|
||||||
|
"priority_desc_created_at_asc": {
|
||||||
|
"TEXT": "Priority: Highest first, Created: Oldest first"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ATTACHMENTS": {
|
"ATTACHMENTS": {
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ const SORT_OPTIONS = {
|
|||||||
priority_desc: ['sortOnPriority', 'desc'],
|
priority_desc: ['sortOnPriority', 'desc'],
|
||||||
waiting_since_asc: ['sortOnWaitingSince', 'asc'],
|
waiting_since_asc: ['sortOnWaitingSince', 'asc'],
|
||||||
waiting_since_desc: ['sortOnWaitingSince', 'desc'],
|
waiting_since_desc: ['sortOnWaitingSince', 'desc'],
|
||||||
|
priority_desc_created_at_asc: ['sortOnPriorityCreatedAt', 'desc'],
|
||||||
};
|
};
|
||||||
const sortAscending = (valueA, valueB) => valueA - valueB;
|
const sortAscending = (valueA, valueB) => valueA - valueB;
|
||||||
const sortDescending = (valueA, valueB) => valueB - valueA;
|
const sortDescending = (valueA, valueB) => valueB - valueA;
|
||||||
@@ -139,6 +140,14 @@ const sortConfig = {
|
|||||||
return getSortOrderFunction(sortDirection)(p1, p2);
|
return getSortOrderFunction(sortDirection)(p1, p2);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sortOnPriorityCreatedAt: (a, b) => {
|
||||||
|
const DEFAULT_FOR_NULL = 0;
|
||||||
|
const p1 = CONVERSATION_PRIORITY_ORDER[a.priority] || DEFAULT_FOR_NULL;
|
||||||
|
const p2 = CONVERSATION_PRIORITY_ORDER[b.priority] || DEFAULT_FOR_NULL;
|
||||||
|
if (p1 !== p2) return p2 - p1;
|
||||||
|
return a.created_at - b.created_at;
|
||||||
|
},
|
||||||
|
|
||||||
sortOnWaitingSince: (a, b, sortDirection) => {
|
sortOnWaitingSince: (a, b, sortDirection) => {
|
||||||
const sortFunc = getSortOrderFunction(sortDirection);
|
const sortFunc = getSortOrderFunction(sortDirection);
|
||||||
if (!a.waiting_since || !b.waiting_since) {
|
if (!a.waiting_since || !b.waiting_since) {
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ module SortHandler
|
|||||||
order(generate_sql_query("priority #{sort_direction.to_s.upcase} NULLS LAST, last_activity_at DESC"))
|
order(generate_sql_query("priority #{sort_direction.to_s.upcase} NULLS LAST, last_activity_at DESC"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sort_on_priority_created_at(sort_direction = :desc)
|
||||||
|
order(generate_sql_query("priority #{sort_direction.to_s.upcase} NULLS LAST, created_at ASC"))
|
||||||
|
end
|
||||||
|
|
||||||
def sort_on_waiting_since(sort_direction = :asc)
|
def sort_on_waiting_since(sort_direction = :asc)
|
||||||
order(generate_sql_query("waiting_since #{sort_direction.to_s.upcase} NULLS LAST, created_at ASC"))
|
order(generate_sql_query("waiting_since #{sort_direction.to_s.upcase} NULLS LAST, created_at ASC"))
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user