Skip to content

Commit

Permalink
Revert "Merge branch 'jcarstairs-scottlogic-group-elements-use-friend…
Browse files Browse the repository at this point in the history
…ly-dates'"

This reverts commit f975507, reversing
changes made to 6252fad.
  • Loading branch information
ransome1 committed Aug 5, 2024
1 parent 46bb8f3 commit 018090a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 39 deletions.
1 change: 0 additions & 1 deletion src/renderer/Grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ const GridComponent: React.FC<GridComponentProps> = memo(({
return (
<React.Fragment key={group.title}>
<Group
settings={settings}
title={group.title}
todotxtAttribute={settings.sorting[0].value}
filters={filters}
Expand Down
41 changes: 5 additions & 36 deletions src/renderer/Grid/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,25 @@ import React, { memo } from 'react';
import ListItem from '@mui/material/ListItem';
import Button from '@mui/material/Button';
import Divider from '@mui/material/Divider';
import dayjs from 'dayjs';
import updateLocale from 'dayjs/plugin/updateLocale';
import { friendlyDate } from 'renderer/Shared';
import { i18n } from 'renderer/Settings/LanguageSelector';
import { WithTranslation, withTranslation } from 'react-i18next';
dayjs.extend(updateLocale);

interface FormatGroupElementProps {
groupElement: string;
settings: Settings;
t: typeof i18n.t;
todotxtAttribute: string;
}

function formatGroupElement({ groupElement, settings, t, todotxtAttribute }: FormatGroupElementProps) {
// If group element is a date, then format according to user preferences
if (
['due', 't'].includes(todotxtAttribute)
&& dayjs(groupElement).isValid()
&& settings.useHumanFriendlyDates
) {
return friendlyDate(groupElement, todotxtAttribute, settings, t).pop();
}

// No transformation required: display as-is
return groupElement;
}

interface GroupProps extends WithTranslation {
settings: Settings;
interface GroupProps {
title: string | string[];
todotxtAttribute: string;
filters: Filters | null;
onClick: Function;
t: typeof i18n.t;
}

const Group: React.FC<GroupProps> = memo(({ settings, t, title, todotxtAttribute, filters, onClick }) => {
const Group: React.FC<GroupProps> = memo(({ title, todotxtAttribute, filters, onClick }) => {

if (!title || title.length === 0) {
return <ListItem className="row group"><Divider /></ListItem>;
}

const groupElements = (typeof title === 'string') ? [title] : title
const formattedGroupElements = groupElements.map(
(groupElement) => formatGroupElement({ groupElement, settings, t, todotxtAttribute })
);

return (
<ListItem className="row group">
{formattedGroupElements.map((groupElement, index) => {
{groupElements.map((groupElement, index) => {
const selected: boolean = filters && (filters[todotxtAttribute as keyof Filters] || []).some(
(filter: Filter) => filter && filter.name === groupElement.trim()
);
Expand All @@ -72,4 +41,4 @@ const Group: React.FC<GroupProps> = memo(({ settings, t, title, todotxtAttribute
);
});

export default withTranslation()(Group);
export default Group;
3 changes: 1 addition & 2 deletions src/renderer/Shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import duration from 'dayjs/plugin/duration';
import calendar from 'dayjs/plugin/calendar';
import weekday from 'dayjs/plugin/weekday';
import updateLocale from 'dayjs/plugin/updateLocale';
import { i18n } from './Settings/LanguageSelector';
dayjs.extend(relativeTime);
dayjs.extend(duration);
dayjs.extend(calendar);
Expand Down Expand Up @@ -113,4 +112,4 @@ export const friendlyDate = (value: string, attributeKey: string, settings: Sett
}

return results;
};
};

0 comments on commit 018090a

Please sign in to comment.