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