Something changed, which affected the Favorite folder picker checkbox styles -- fixed it! Cleaned up code in `CurrentWorkspaceMemberFavoritesFolders` - removed redundant filtering since favorites are already filtered in `usePrefetchedFavoritesData`. Regarding issue #8569 - I am not sure what to do in this case. Since Folders data is gated by a feature flag, we can't use it in `CurrentWorkspaceMemberFavoritesFolders` to ensure the favorite section renders with empty folders. Currently, the section only appears when at least one favorite exists - may be leave this section open at all times or fix this bug after removal of the feature flag? --------- Co-authored-by: Nitin Koche <nitinkoche@Nitins-MacBook-Pro.local> Co-authored-by: Charles Bochet <charles@twenty.com>
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { useWorkspaceFavorites } from '@/favorites/hooks/useWorkspaceFavorites';
|
|
import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems';
|
|
import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData';
|
|
import { PrefetchKey } from '@/prefetch/types/PrefetchKey';
|
|
import { View } from '@/views/types/View';
|
|
|
|
export const useFilteredObjectMetadataItemsForWorkspaceFavorites = () => {
|
|
const { records: views } = usePrefetchedData<View>(PrefetchKey.AllViews);
|
|
|
|
const { sortedWorkspaceFavorites: workspaceFavorites } =
|
|
useWorkspaceFavorites();
|
|
|
|
const workspaceFavoriteIds = new Set(
|
|
workspaceFavorites.map((favorite) => favorite.recordId),
|
|
);
|
|
|
|
const favoriteViewObjectMetadataIds = new Set(
|
|
views.reduce<string[]>((acc, view) => {
|
|
if (workspaceFavoriteIds.has(view.id)) {
|
|
acc.push(view.objectMetadataId);
|
|
}
|
|
return acc;
|
|
}, []),
|
|
);
|
|
|
|
const { activeObjectMetadataItems } = useFilteredObjectMetadataItems();
|
|
|
|
const activeObjectMetadataItemsInWorkspaceFavorites =
|
|
activeObjectMetadataItems.filter((item) =>
|
|
favoriteViewObjectMetadataIds.has(item.id),
|
|
);
|
|
|
|
return {
|
|
activeObjectMetadataItems: activeObjectMetadataItemsInWorkspaceFavorites,
|
|
};
|
|
};
|