Fix filters and sorts on views (#2258)
This commit is contained in:
@ -28,8 +28,7 @@ export const HooksCompanyBoardEffect = () => {
|
|||||||
setCurrentViewId,
|
setCurrentViewId,
|
||||||
} = useView();
|
} = useView();
|
||||||
|
|
||||||
const { currentViewFilters, currentViewSortsOrderBy } =
|
const { currentViewFilters } = useViewInternalStates();
|
||||||
useViewInternalStates();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setAvailableFilters(opportunitiesBoardOptions.filters);
|
setAvailableFilters(opportunitiesBoardOptions.filters);
|
||||||
@ -72,7 +71,6 @@ export const HooksCompanyBoardEffect = () => {
|
|||||||
useGetPipelineProgressQuery({
|
useGetPipelineProgressQuery({
|
||||||
variables: {
|
variables: {
|
||||||
where: whereFilters,
|
where: whereFilters,
|
||||||
orderBy: currentViewSortsOrderBy,
|
|
||||||
},
|
},
|
||||||
onCompleted: (data) => {
|
onCompleted: (data) => {
|
||||||
const pipelineProgresses = data?.findManyPipelineProgress || [];
|
const pipelineProgresses = data?.findManyPipelineProgress || [];
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import { companiesAvailableFieldDefinitions } from '@/companies/constants/compan
|
|||||||
import { availableTableColumnsScopedState } from '@/ui/data/data-table/states/availableTableColumnsScopedState';
|
import { availableTableColumnsScopedState } from '@/ui/data/data-table/states/availableTableColumnsScopedState';
|
||||||
import { TableRecoilScopeContext } from '@/ui/data/data-table/states/recoil-scope-contexts/TableRecoilScopeContext';
|
import { TableRecoilScopeContext } from '@/ui/data/data-table/states/recoil-scope-contexts/TableRecoilScopeContext';
|
||||||
import { tableColumnsScopedState } from '@/ui/data/data-table/states/tableColumnsScopedState';
|
import { tableColumnsScopedState } from '@/ui/data/data-table/states/tableColumnsScopedState';
|
||||||
|
import { tableFiltersScopedState } from '@/ui/data/data-table/states/tableFiltersScopedState';
|
||||||
|
import { tableSortsScopedState } from '@/ui/data/data-table/states/tableSortsScopedState';
|
||||||
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
||||||
import { useView } from '@/views/hooks/useView';
|
import { useView } from '@/views/hooks/useView';
|
||||||
import { useViewInternalStates } from '@/views/hooks/useViewInternalStates';
|
import { useViewInternalStates } from '@/views/hooks/useViewInternalStates';
|
||||||
@ -19,13 +21,24 @@ const CompanyTableEffect = () => {
|
|||||||
setViewType,
|
setViewType,
|
||||||
setViewObjectId,
|
setViewObjectId,
|
||||||
} = useView();
|
} = useView();
|
||||||
const { currentViewFields } = useViewInternalStates();
|
const { currentViewFields, currentViewSorts, currentViewFilters } =
|
||||||
|
useViewInternalStates();
|
||||||
|
|
||||||
const [, setTableColumns] = useRecoilScopedState(
|
const [, setTableColumns] = useRecoilScopedState(
|
||||||
tableColumnsScopedState,
|
tableColumnsScopedState,
|
||||||
TableRecoilScopeContext,
|
TableRecoilScopeContext,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [, setTableSorts] = useRecoilScopedState(
|
||||||
|
tableSortsScopedState,
|
||||||
|
TableRecoilScopeContext,
|
||||||
|
);
|
||||||
|
|
||||||
|
const [, setTableFilters] = useRecoilScopedState(
|
||||||
|
tableFiltersScopedState,
|
||||||
|
TableRecoilScopeContext,
|
||||||
|
);
|
||||||
|
|
||||||
const [, setAvailableTableColumns] = useRecoilScopedState(
|
const [, setAvailableTableColumns] = useRecoilScopedState(
|
||||||
availableTableColumnsScopedState,
|
availableTableColumnsScopedState,
|
||||||
TableRecoilScopeContext,
|
TableRecoilScopeContext,
|
||||||
@ -54,6 +67,24 @@ const CompanyTableEffect = () => {
|
|||||||
}
|
}
|
||||||
}, [currentViewFields, setTableColumns]);
|
}, [currentViewFields, setTableColumns]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentViewSorts) {
|
||||||
|
setTableSorts(currentViewSorts);
|
||||||
|
}
|
||||||
|
}, [currentViewFields, currentViewSorts, setTableColumns, setTableSorts]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentViewFilters) {
|
||||||
|
setTableFilters(currentViewFilters);
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
currentViewFields,
|
||||||
|
currentViewFilters,
|
||||||
|
setTableColumns,
|
||||||
|
setTableFilters,
|
||||||
|
setTableSorts,
|
||||||
|
]);
|
||||||
|
|
||||||
return <></>;
|
return <></>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -7,17 +7,17 @@ import { OptimisticEffectDefinition } from '@/apollo/optimistic-effect/types/Opt
|
|||||||
import { FilterDefinition } from '@/ui/data/filter/types/FilterDefinition';
|
import { FilterDefinition } from '@/ui/data/filter/types/FilterDefinition';
|
||||||
import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue';
|
import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue';
|
||||||
import { useView } from '@/views/hooks/useView';
|
import { useView } from '@/views/hooks/useView';
|
||||||
import { useViewInternalStates } from '@/views/hooks/useViewInternalStates';
|
|
||||||
import {
|
import {
|
||||||
SortOrder,
|
SortOrder,
|
||||||
useGetCompaniesQuery,
|
useGetCompaniesQuery,
|
||||||
useGetPeopleQuery,
|
useGetPeopleQuery,
|
||||||
} from '~/generated/graphql';
|
} from '~/generated/graphql';
|
||||||
|
|
||||||
import { filtersWhereScopedSelector } from '../../filter/states/selectors/filtersWhereScopedSelector';
|
|
||||||
import { SortDefinition } from '../../sort/types/SortDefinition';
|
import { SortDefinition } from '../../sort/types/SortDefinition';
|
||||||
import { useSetDataTableData } from '../hooks/useSetDataTableData';
|
import { useSetDataTableData } from '../hooks/useSetDataTableData';
|
||||||
import { TableRecoilScopeContext } from '../states/recoil-scope-contexts/TableRecoilScopeContext';
|
import { TableRecoilScopeContext } from '../states/recoil-scope-contexts/TableRecoilScopeContext';
|
||||||
|
import { tablefiltersWhereScopedSelector } from '../states/selectors/tablefiltersWhereScopedSelector';
|
||||||
|
import { tableSortsOrderByScopedSelector } from '../states/selectors/tableSortsOrderByScopedSelector';
|
||||||
|
|
||||||
export const DataTableEffect = ({
|
export const DataTableEffect = ({
|
||||||
useGetRequest,
|
useGetRequest,
|
||||||
@ -41,27 +41,30 @@ export const DataTableEffect = ({
|
|||||||
const setDataTableData = useSetDataTableData();
|
const setDataTableData = useSetDataTableData();
|
||||||
const { registerOptimisticEffect } = useOptimisticEffect();
|
const { registerOptimisticEffect } = useOptimisticEffect();
|
||||||
const { setCurrentViewId } = useView();
|
const { setCurrentViewId } = useView();
|
||||||
const { currentViewSortsOrderBy } = useViewInternalStates();
|
|
||||||
|
|
||||||
const sortsOrderBy = defaults(currentViewSortsOrderBy, [
|
const tableSortsOrderBy = useRecoilScopedValue(
|
||||||
|
tableSortsOrderByScopedSelector,
|
||||||
|
TableRecoilScopeContext,
|
||||||
|
);
|
||||||
|
const sortsOrderBy = defaults(tableSortsOrderBy, [
|
||||||
{
|
{
|
||||||
createdAt: SortOrder.Desc,
|
createdAt: SortOrder.Desc,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
const filtersWhere = useRecoilScopedValue(
|
const tablefiltersWhere = useRecoilScopedValue(
|
||||||
filtersWhereScopedSelector,
|
tablefiltersWhereScopedSelector,
|
||||||
TableRecoilScopeContext,
|
TableRecoilScopeContext,
|
||||||
);
|
);
|
||||||
|
|
||||||
useGetRequest({
|
useGetRequest({
|
||||||
variables: { orderBy: sortsOrderBy, where: filtersWhere },
|
variables: { orderBy: sortsOrderBy, where: tablefiltersWhere },
|
||||||
onCompleted: (data: any) => {
|
onCompleted: (data: any) => {
|
||||||
const entities = data[getRequestResultKey] ?? [];
|
const entities = data[getRequestResultKey] ?? [];
|
||||||
|
|
||||||
setDataTableData(entities, filterDefinitionArray, sortDefinitionArray);
|
setDataTableData(entities, filterDefinitionArray, sortDefinitionArray);
|
||||||
|
|
||||||
registerOptimisticEffect({
|
registerOptimisticEffect({
|
||||||
variables: { orderBy: sortsOrderBy, where: filtersWhere },
|
variables: { orderBy: sortsOrderBy, where: tablefiltersWhere },
|
||||||
definition: getRequestOptimisticEffectDefinition,
|
definition: getRequestOptimisticEffectDefinition,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@ -0,0 +1,16 @@
|
|||||||
|
import { selectorFamily } from 'recoil';
|
||||||
|
|
||||||
|
import { reduceSortsToOrderBy } from '@/ui/data/sort/utils/helpers';
|
||||||
|
import { SortOrder } from '~/generated/graphql';
|
||||||
|
|
||||||
|
import { tableSortsScopedState } from '../tableSortsScopedState';
|
||||||
|
|
||||||
|
export const tableSortsOrderByScopedSelector = selectorFamily({
|
||||||
|
key: 'tableSortsOrderByScopedSelector',
|
||||||
|
get:
|
||||||
|
(scopeId: string) =>
|
||||||
|
({ get }) => {
|
||||||
|
const orderBy = reduceSortsToOrderBy(get(tableSortsScopedState(scopeId)));
|
||||||
|
return orderBy.length ? orderBy : [{ createdAt: SortOrder.Desc }];
|
||||||
|
},
|
||||||
|
});
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
import { selectorFamily } from 'recoil';
|
||||||
|
|
||||||
|
import { turnFilterIntoWhereClause } from '../../../filter/utils/turnFilterIntoWhereClause';
|
||||||
|
import { tableFiltersScopedState } from '../tableFiltersScopedState';
|
||||||
|
|
||||||
|
export const tablefiltersWhereScopedSelector = selectorFamily({
|
||||||
|
key: 'tablefiltersWhereScopedSelector',
|
||||||
|
get:
|
||||||
|
(scopeId: string) =>
|
||||||
|
({ get }) => ({
|
||||||
|
AND: get(tableFiltersScopedState(scopeId)).map(turnFilterIntoWhereClause),
|
||||||
|
}),
|
||||||
|
});
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
import { atomFamily } from 'recoil';
|
||||||
|
|
||||||
|
import { Filter } from '../../filter/types/Filter';
|
||||||
|
|
||||||
|
export const tableFiltersScopedState = atomFamily<Filter[], string>({
|
||||||
|
key: 'tableFiltersScopedState',
|
||||||
|
default: [],
|
||||||
|
});
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
import { atomFamily } from 'recoil';
|
||||||
|
|
||||||
|
import { Sort } from '../../sort/types/Sort';
|
||||||
|
|
||||||
|
export const tableSortsScopedState = atomFamily<Sort[], string>({
|
||||||
|
key: 'tableSortsScopedState',
|
||||||
|
default: [],
|
||||||
|
});
|
||||||
@ -1,15 +0,0 @@
|
|||||||
import { selectorFamily } from 'recoil';
|
|
||||||
|
|
||||||
import { turnFilterIntoWhereClause } from '../../utils/turnFilterIntoWhereClause';
|
|
||||||
import { selectedFiltersScopedState } from '../selectedFiltersScopedState';
|
|
||||||
|
|
||||||
export const filtersWhereScopedSelector = selectorFamily({
|
|
||||||
key: 'filtersWhereScopedSelector',
|
|
||||||
get:
|
|
||||||
(scopeId: string) =>
|
|
||||||
({ get }) => ({
|
|
||||||
AND: get(selectedFiltersScopedState({ scopeId })).map(
|
|
||||||
turnFilterIntoWhereClause,
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
@ -4,6 +4,7 @@ import { useRecoilCallback } from 'recoil';
|
|||||||
|
|
||||||
import { ColumnDefinition } from '@/ui/data/data-table/types/ColumnDefinition';
|
import { ColumnDefinition } from '@/ui/data/data-table/types/ColumnDefinition';
|
||||||
import { FieldMetadata } from '@/ui/data/field/types/FieldMetadata';
|
import { FieldMetadata } from '@/ui/data/field/types/FieldMetadata';
|
||||||
|
import { GET_VIEW_FIELDS } from '@/views/graphql/queries/getViewFields';
|
||||||
import { GET_VIEWS } from '@/views/graphql/queries/getViews';
|
import { GET_VIEWS } from '@/views/graphql/queries/getViews';
|
||||||
import { currentViewIdScopedState } from '@/views/states/currentViewIdScopedState';
|
import { currentViewIdScopedState } from '@/views/states/currentViewIdScopedState';
|
||||||
import { savedViewFieldByKeyScopedFamilySelector } from '@/views/states/selectors/savedViewFieldByKeyScopedFamilySelector';
|
import { savedViewFieldByKeyScopedFamilySelector } from '@/views/states/selectors/savedViewFieldByKeyScopedFamilySelector';
|
||||||
@ -13,8 +14,6 @@ import {
|
|||||||
useUpdateViewFieldMutation,
|
useUpdateViewFieldMutation,
|
||||||
} from '~/generated/graphql';
|
} from '~/generated/graphql';
|
||||||
|
|
||||||
import { GET_VIEW_FIELDS } from '../../graphql/queries/getViewFields';
|
|
||||||
|
|
||||||
export const toViewFieldInput = (
|
export const toViewFieldInput = (
|
||||||
objectId: string,
|
objectId: string,
|
||||||
fieldDefinition: ColumnDefinition<FieldMetadata>,
|
fieldDefinition: ColumnDefinition<FieldMetadata>,
|
||||||
|
|||||||
@ -23,7 +23,6 @@ import { savedViewSortsScopedFamilyState } from '../states/savedViewSortsScopedF
|
|||||||
import { canPersistViewFiltersScopedFamilySelector } from '../states/selectors/canPersistViewFiltersScopedFamilySelector';
|
import { canPersistViewFiltersScopedFamilySelector } from '../states/selectors/canPersistViewFiltersScopedFamilySelector';
|
||||||
import { canPersistViewSortsScopedFamilySelector } from '../states/selectors/canPersistViewSortsScopedFamilySelector';
|
import { canPersistViewSortsScopedFamilySelector } from '../states/selectors/canPersistViewSortsScopedFamilySelector';
|
||||||
import { currentViewScopedSelector } from '../states/selectors/currentViewScopedSelector';
|
import { currentViewScopedSelector } from '../states/selectors/currentViewScopedSelector';
|
||||||
import { currentViewSortsOrderByScopedFamilySelector } from '../states/selectors/currentViewSortsOrderByScopedFamilySelector';
|
|
||||||
import { savedViewFieldByKeyScopedFamilySelector } from '../states/selectors/savedViewFieldByKeyScopedFamilySelector';
|
import { savedViewFieldByKeyScopedFamilySelector } from '../states/selectors/savedViewFieldByKeyScopedFamilySelector';
|
||||||
import { savedViewFiltersByKeyScopedFamilySelector } from '../states/selectors/savedViewFiltersByKeyScopedFamilySelector';
|
import { savedViewFiltersByKeyScopedFamilySelector } from '../states/selectors/savedViewFiltersByKeyScopedFamilySelector';
|
||||||
import { savedViewSortsByKeyScopedFamilySelector } from '../states/selectors/savedViewSortsByKeyScopedFamilySelector';
|
import { savedViewSortsByKeyScopedFamilySelector } from '../states/selectors/savedViewSortsByKeyScopedFamilySelector';
|
||||||
@ -108,13 +107,6 @@ export const useViewInternalStates = (
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const currentViewSortsOrderBy = useRecoilValue(
|
|
||||||
currentViewSortsOrderByScopedFamilySelector({
|
|
||||||
viewScopeId: scopeId,
|
|
||||||
viewId: familyItemId,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
// ViewFilters
|
// ViewFilters
|
||||||
const [currentViewFilters, setCurrentViewFilters] =
|
const [currentViewFilters, setCurrentViewFilters] =
|
||||||
useRecoilScopedFamilyState(
|
useRecoilScopedFamilyState(
|
||||||
@ -215,7 +207,6 @@ export const useViewInternalStates = (
|
|||||||
savedViewSortsByKey,
|
savedViewSortsByKey,
|
||||||
setSavedViewSorts,
|
setSavedViewSorts,
|
||||||
canPersistSorts,
|
canPersistSorts,
|
||||||
currentViewSortsOrderBy,
|
|
||||||
|
|
||||||
availableFilters,
|
availableFilters,
|
||||||
setAvailableFilters,
|
setAvailableFilters,
|
||||||
|
|||||||
@ -1,26 +0,0 @@
|
|||||||
import { selectorFamily } from 'recoil';
|
|
||||||
|
|
||||||
import { reduceSortsToOrderBy } from '@/ui/data/sort/utils/helpers';
|
|
||||||
import { SortOrder } from '~/generated/graphql';
|
|
||||||
|
|
||||||
import { currentViewSortsScopedFamilyState } from '../currentViewSortsScopedFamilyState';
|
|
||||||
|
|
||||||
export const currentViewSortsOrderByScopedFamilySelector = selectorFamily({
|
|
||||||
key: 'currentViewSortsOrderByScopedFamilySelector',
|
|
||||||
get:
|
|
||||||
({ viewScopeId, viewId }: { viewScopeId: string; viewId?: string }) =>
|
|
||||||
({ get }) => {
|
|
||||||
if (!viewId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const orderBy = reduceSortsToOrderBy(
|
|
||||||
get(
|
|
||||||
currentViewSortsScopedFamilyState({
|
|
||||||
scopeId: viewScopeId,
|
|
||||||
familyKey: viewId,
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return orderBy.length ? orderBy : [{ createdAt: SortOrder.Desc }];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user