diff --git a/packages/twenty-front/src/modules/views/hooks/useQueryVariablesFromActiveFieldsOfViewOrDefaultView.ts b/packages/twenty-front/src/modules/views/hooks/useQueryVariablesFromActiveFieldsOfViewOrDefaultView.ts index f5431bc45a58..257f5e77d78c 100644 --- a/packages/twenty-front/src/modules/views/hooks/useQueryVariablesFromActiveFieldsOfViewOrDefaultView.ts +++ b/packages/twenty-front/src/modules/views/hooks/useQueryVariablesFromActiveFieldsOfViewOrDefaultView.ts @@ -1,6 +1,7 @@ import { useActiveFieldMetadataItems } from '@/object-metadata/hooks/useActiveFieldMetadataItems'; import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; import { useViewOrDefaultViewFromPrefetchedViews } from '@/views/hooks/useViewOrDefaultViewFromPrefetchedViews'; +import { View } from '@/views/types/View'; import { getQueryVariablesFromView } from '@/views/utils/getQueryVariablesFromView'; export const useQueryVariablesFromActiveFieldsOfViewOrDefaultView = ({ @@ -22,7 +23,7 @@ export const useQueryVariablesFromActiveFieldsOfViewOrDefaultView = ({ const { filter, orderBy } = getQueryVariablesFromView({ fieldMetadataItems: activeFieldMetadataItems, objectMetadataItem, - view, + view: view as View, }); return { diff --git a/packages/twenty-front/src/modules/views/hooks/useViewOrDefaultViewFromPrefetchedViews.ts b/packages/twenty-front/src/modules/views/hooks/useViewOrDefaultViewFromPrefetchedViews.ts index 40bd3d7a7393..19153cbdecb5 100644 --- a/packages/twenty-front/src/modules/views/hooks/useViewOrDefaultViewFromPrefetchedViews.ts +++ b/packages/twenty-front/src/modules/views/hooks/useViewOrDefaultViewFromPrefetchedViews.ts @@ -1,7 +1,10 @@ +import { useObjectNamePluralFromSingular } from '@/object-metadata/hooks/useObjectNamePluralFromSingular'; import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData'; import { PrefetchKey } from '@/prefetch/types/PrefetchKey'; +import { useGetCurrentView } from '@/views/hooks/useGetCurrentView'; import { View } from '@/views/types/View'; import { useMemo } from 'react'; +import { useParams } from 'react-router-dom'; export const useViewOrDefaultViewFromPrefetchedViews = ({ objectMetadataItemId, @@ -10,7 +13,13 @@ export const useViewOrDefaultViewFromPrefetchedViews = ({ objectMetadataItemId: string; viewId: string | null | undefined; }) => { + const { objectNameSingular } = useParams(); const { records: views } = usePrefetchedData(PrefetchKey.AllViews); + const { objectNamePlural } = useObjectNamePluralFromSingular({ + objectNameSingular: objectNameSingular ?? '', + }); + const { currentViewWithCombinedFiltersAndSorts } = + useGetCurrentView(objectNamePlural); const view = useMemo(() => { return views.find( @@ -20,5 +29,17 @@ export const useViewOrDefaultViewFromPrefetchedViews = ({ ); }, [viewId, views, objectMetadataItemId]); - return { view }; + return { + view: { + ...view, + viewFilters: + Number(view?.viewFilters?.length) > 0 + ? view?.viewFilters + : (currentViewWithCombinedFiltersAndSorts?.viewFilters ?? []), + viewSorts: + Number(view?.viewSorts?.length) > 0 + ? view?.viewSorts + : (currentViewWithCombinedFiltersAndSorts?.viewSorts ?? []), + }, + }; };