Skip to content

Commit

Permalink
feat: apply temporary filter in the record details page
Browse files Browse the repository at this point in the history
  • Loading branch information
pacyL2K19 committed Sep 9, 2024
1 parent 23974d2 commit f45f3a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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 = ({
Expand All @@ -22,7 +23,7 @@ export const useQueryVariablesFromActiveFieldsOfViewOrDefaultView = ({
const { filter, orderBy } = getQueryVariablesFromView({
fieldMetadataItems: activeFieldMetadataItems,
objectMetadataItem,
view,
view: view as View,
});

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -10,7 +13,13 @@ export const useViewOrDefaultViewFromPrefetchedViews = ({
objectMetadataItemId: string;
viewId: string | null | undefined;
}) => {
const { objectNameSingular } = useParams();
const { records: views } = usePrefetchedData<View>(PrefetchKey.AllViews);
const { objectNamePlural } = useObjectNamePluralFromSingular({
objectNameSingular: objectNameSingular ?? '',
});
const { currentViewWithCombinedFiltersAndSorts } =
useGetCurrentView(objectNamePlural);

const view = useMemo(() => {
return views.find(
Expand All @@ -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 ?? []),
},
};
};

0 comments on commit f45f3a5

Please sign in to comment.