Skip to content

Commit

Permalink
[9382][FRONT]: Compute highlighted object view using raw name plural (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
prastoin and Paul Rastoin authored Jan 7, 2025
1 parent 04f648f commit 7b70f7d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useLastVisitedView = () => {
setLastVisitedViewPerObjectMetadataItem,
] = useRecoilState(lastVisitedViewPerObjectMetadataItemState);

const { findActiveObjectMetadataItemBySlug } =
const { findActiveObjectMetadataItemByNamePlural } =
useFilteredObjectMetadataItems();

const setFallbackForLastVisitedView = (objectMetadataItemId: string) => {
Expand All @@ -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
Expand All @@ -72,7 +72,7 @@ export const useLastVisitedView = () => {
objectNamePlural: string,
) => {
const objectMetadataItemId: string | undefined =
findActiveObjectMetadataItemBySlug(objectNamePlural)?.id;
findActiveObjectMetadataItemByNamePlural(objectNamePlural)?.id;
return objectMetadataItemId
? lastVisitedViewPerObjectMetadataItem?.[objectMetadataItemId]
: undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -53,6 +59,7 @@ export const useFilteredObjectMetadataItems = () => {
findActiveObjectMetadataItemBySlug,
findObjectMetadataItemById,
findObjectMetadataItemByNamePlural,
findActiveObjectMetadataItemByNamePlural,
inactiveObjectMetadataItems,
objectMetadataItems,
findObjectMetadataItemBySlug,
Expand Down

0 comments on commit 7b70f7d

Please sign in to comment.