Force order in navigation panel for notes and tasks (#6557)

As title. Tasks and Notes order sometimes change
This commit is contained in:
Thomas Trompette 2024-08-06 18:24:33 +02:00 committed by GitHub
parent 018b8220dc
commit 1ed31d9d68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -18,6 +18,14 @@ import { View } from '@/views/types/View';
import { getObjectMetadataItemViews } from '@/views/utils/getObjectMetadataItemViews';
import { Theme, useTheme } from '@emotion/react';
const ORDERED_STANDARD_OBJECTS = [
'person',
'company',
'opportunity',
'task',
'note',
];
const navItemsAnimationVariants = (theme: Theme) => ({
hidden: {
height: 0,
@ -67,14 +75,15 @@ export const ObjectMetadataNavItems = ({ isRemote }: { isRemote: boolean }) => {
[
...filteredActiveObjectMetadataItems
.filter((item) =>
['person', 'company', 'opportunity'].includes(
item.nameSingular,
),
ORDERED_STANDARD_OBJECTS.includes(item.nameSingular),
)
.sort((objectMetadataItemA, objectMetadataItemB) => {
const order = ['person', 'company', 'opportunity'];
const indexA = order.indexOf(objectMetadataItemA.nameSingular);
const indexB = order.indexOf(objectMetadataItemB.nameSingular);
const indexA = ORDERED_STANDARD_OBJECTS.indexOf(
objectMetadataItemA.nameSingular,
);
const indexB = ORDERED_STANDARD_OBJECTS.indexOf(
objectMetadataItemB.nameSingular,
);
if (indexA === -1 || indexB === -1) {
return objectMetadataItemA.nameSingular.localeCompare(
objectMetadataItemB.nameSingular,
@ -84,10 +93,7 @@ export const ObjectMetadataNavItems = ({ isRemote }: { isRemote: boolean }) => {
}),
...filteredActiveObjectMetadataItems
.filter(
(item) =>
!['person', 'company', 'opportunity'].includes(
item.nameSingular,
),
(item) => !ORDERED_STANDARD_OBJECTS.includes(item.nameSingular),
)
.sort((objectMetadataItemA, objectMetadataItemB) => {
return new Date(objectMetadataItemA.createdAt) <