[9382][FRONT]: Compute highlighted object view using raw name plural (#9394)

# Introduction
Please find related ticket here #9382
To fix the issue the solution seems to be to stop searching for last
viewed `objectMetadata` using their slugged version `namePlural`

## Upcoming cleanup
After discussing with @charlesBochet it seems like a bad practice to
slug the `objectMetadata`, in this way in a following PR we will suggest
a cleanup of the remaining method that does within the
`useFilteredObjectMetadataItems.ts`

## Conclusion
As always any suggestions are welcomed !
Please let me know

closes #9382

---------

Co-authored-by: Paul Rastoin <paulrastoin@Pauls-MacBook-Pro.local>
This commit is contained in:
Paul Rastoin
2025-01-07 15:20:54 +01:00
committed by GitHub
parent 04f648f7f3
commit 7b70f7d93b
2 changed files with 10 additions and 3 deletions

View File

@ -29,7 +29,7 @@ export const useLastVisitedView = () => {
setLastVisitedViewPerObjectMetadataItem,
] = useRecoilState(lastVisitedViewPerObjectMetadataItemState);
const { findActiveObjectMetadataItemBySlug } =
const { findActiveObjectMetadataItemByNamePlural } =
useFilteredObjectMetadataItems();
const setFallbackForLastVisitedView = (objectMetadataItemId: string) => {
@ -49,7 +49,7 @@ export const useLastVisitedView = () => {
viewId: string;
}) => {
const fallbackObjectMetadataItem =
findActiveObjectMetadataItemBySlug(objectNamePlural);
findActiveObjectMetadataItemByNamePlural(objectNamePlural);
if (isDefined(fallbackObjectMetadataItem)) {
/* when both are equal meaning there was change in view else
@ -72,7 +72,7 @@ export const useLastVisitedView = () => {
objectNamePlural: string,
) => {
const objectMetadataItemId: string | undefined =
findActiveObjectMetadataItemBySlug(objectNamePlural)?.id;
findActiveObjectMetadataItemByNamePlural(objectNamePlural)?.id;
return objectMetadataItemId
? lastVisitedViewPerObjectMetadataItem?.[objectMetadataItemId]
: undefined;

View File

@ -38,6 +38,12 @@ export const useFilteredObjectMetadataItems = () => {
getObjectSlug(activeObjectMetadataItem) === slug,
);
const findActiveObjectMetadataItemByNamePlural = (namePlural: string) =>
activeObjectMetadataItems.find(
(activeObjectMetadataItem) =>
activeObjectMetadataItem.namePlural === namePlural,
);
const findObjectMetadataItemById = (id: string) =>
objectMetadataItems.find(
(objectMetadataItem) => objectMetadataItem.id === id,
@ -53,6 +59,7 @@ export const useFilteredObjectMetadataItems = () => {
findActiveObjectMetadataItemBySlug,
findObjectMetadataItemById,
findObjectMetadataItemByNamePlural,
findActiveObjectMetadataItemByNamePlural,
inactiveObjectMetadataItems,
objectMetadataItems,
findObjectMetadataItemBySlug,