Skip to content

Commit

Permalink
Groups date attributes by friendly date translation key when friendly…
Browse files Browse the repository at this point in the history
… dates are enabled.

As before, when the user hasn't got friendly dates
enabled, todo objects will be grouped by the raw
value of date attributes, hopefully an ISO string
like `2024-07-10`.

But when the user enables friendly dates, todos
will instead be grouped by the friendly date
translation key, such as `drawer.attributes.today`.
  • Loading branch information
jcarstairs-scottlogic committed Jul 10, 2024
1 parent 7f02e97 commit 05b66ae
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/modules/DataRequest/SortAndGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { friendlyDateTranslationKeys } from 'renderer/Shared';
import { config } from '../../config';
import { getDateAttributes } from '../Attributes';

function sortAndGroupTodoObjects(todoObjects: TodoObject[], sorting: Sorting[]): TodoGroup {
const fileSorting: boolean = config.get('fileSorting');
Expand Down Expand Up @@ -31,13 +33,24 @@ function sortAndGroupTodoObjects(todoObjects: TodoObject[], sorting: Sorting[]):
return 0;
}

function getGroupKey(todoObject: TodoObject, attributeKey: string) {
const useFriendlyDates = config.get('useHumanFriendlyDates');
const isDateAttribute = Object.keys(getDateAttributes()).includes(attributeKey);

if (useFriendlyDates && isDateAttribute) {
return friendlyDateTranslationKeys(todoObject[attributeKey], attributeKey);
}

return todoObject[attributeKey];
}

function groupTodoObjectsByKey(todoObjects: TodoObject[], attributeKey: string) {
const grouped: TodoGroup = {};
for (const todoObject of todoObjects) {
const groupKey = todoObject[attributeKey] || null;
const groupKey = getGroupKey(todoObject, attributeKey);
if (!grouped[groupKey]) {
grouped[groupKey] = {
title: groupKey,
title: todoObject[attributeKey],
todoObjects: [],
visible: false
};
Expand Down

0 comments on commit 05b66ae

Please sign in to comment.