diff --git a/front/src/modules/companies/components/HooksCompanyBoardEffect.tsx b/front/src/modules/companies/components/HooksCompanyBoardEffect.tsx index c1a1ad743..d4aec39dc 100644 --- a/front/src/modules/companies/components/HooksCompanyBoardEffect.tsx +++ b/front/src/modules/companies/components/HooksCompanyBoardEffect.tsx @@ -28,8 +28,7 @@ export const HooksCompanyBoardEffect = () => { setCurrentViewId, } = useView(); - const { currentViewFilters, currentViewSortsOrderBy } = - useViewInternalStates(); + const { currentViewFilters } = useViewInternalStates(); useEffect(() => { setAvailableFilters(opportunitiesBoardOptions.filters); @@ -72,7 +71,6 @@ export const HooksCompanyBoardEffect = () => { useGetPipelineProgressQuery({ variables: { where: whereFilters, - orderBy: currentViewSortsOrderBy, }, onCompleted: (data) => { const pipelineProgresses = data?.findManyPipelineProgress || []; diff --git a/front/src/modules/companies/table/components/CompanyTableEffect.tsx b/front/src/modules/companies/table/components/CompanyTableEffect.tsx index 90a272988..3dde94af5 100644 --- a/front/src/modules/companies/table/components/CompanyTableEffect.tsx +++ b/front/src/modules/companies/table/components/CompanyTableEffect.tsx @@ -4,6 +4,8 @@ import { companiesAvailableFieldDefinitions } from '@/companies/constants/compan import { availableTableColumnsScopedState } from '@/ui/data/data-table/states/availableTableColumnsScopedState'; import { TableRecoilScopeContext } from '@/ui/data/data-table/states/recoil-scope-contexts/TableRecoilScopeContext'; 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 { useView } from '@/views/hooks/useView'; import { useViewInternalStates } from '@/views/hooks/useViewInternalStates'; @@ -19,13 +21,24 @@ const CompanyTableEffect = () => { setViewType, setViewObjectId, } = useView(); - const { currentViewFields } = useViewInternalStates(); + const { currentViewFields, currentViewSorts, currentViewFilters } = + useViewInternalStates(); const [, setTableColumns] = useRecoilScopedState( tableColumnsScopedState, TableRecoilScopeContext, ); + const [, setTableSorts] = useRecoilScopedState( + tableSortsScopedState, + TableRecoilScopeContext, + ); + + const [, setTableFilters] = useRecoilScopedState( + tableFiltersScopedState, + TableRecoilScopeContext, + ); + const [, setAvailableTableColumns] = useRecoilScopedState( availableTableColumnsScopedState, TableRecoilScopeContext, @@ -54,6 +67,24 @@ const CompanyTableEffect = () => { } }, [currentViewFields, setTableColumns]); + useEffect(() => { + if (currentViewSorts) { + setTableSorts(currentViewSorts); + } + }, [currentViewFields, currentViewSorts, setTableColumns, setTableSorts]); + + useEffect(() => { + if (currentViewFilters) { + setTableFilters(currentViewFilters); + } + }, [ + currentViewFields, + currentViewFilters, + setTableColumns, + setTableFilters, + setTableSorts, + ]); + return <>; }; diff --git a/front/src/modules/ui/data/data-table/components/DataTableEffect.tsx b/front/src/modules/ui/data/data-table/components/DataTableEffect.tsx index 39fb2aa0f..91c24c9ab 100644 --- a/front/src/modules/ui/data/data-table/components/DataTableEffect.tsx +++ b/front/src/modules/ui/data/data-table/components/DataTableEffect.tsx @@ -7,17 +7,17 @@ import { OptimisticEffectDefinition } from '@/apollo/optimistic-effect/types/Opt import { FilterDefinition } from '@/ui/data/filter/types/FilterDefinition'; import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue'; import { useView } from '@/views/hooks/useView'; -import { useViewInternalStates } from '@/views/hooks/useViewInternalStates'; import { SortOrder, useGetCompaniesQuery, useGetPeopleQuery, } from '~/generated/graphql'; -import { filtersWhereScopedSelector } from '../../filter/states/selectors/filtersWhereScopedSelector'; import { SortDefinition } from '../../sort/types/SortDefinition'; import { useSetDataTableData } from '../hooks/useSetDataTableData'; import { TableRecoilScopeContext } from '../states/recoil-scope-contexts/TableRecoilScopeContext'; +import { tablefiltersWhereScopedSelector } from '../states/selectors/tablefiltersWhereScopedSelector'; +import { tableSortsOrderByScopedSelector } from '../states/selectors/tableSortsOrderByScopedSelector'; export const DataTableEffect = ({ useGetRequest, @@ -41,27 +41,30 @@ export const DataTableEffect = ({ const setDataTableData = useSetDataTableData(); const { registerOptimisticEffect } = useOptimisticEffect(); const { setCurrentViewId } = useView(); - const { currentViewSortsOrderBy } = useViewInternalStates(); - const sortsOrderBy = defaults(currentViewSortsOrderBy, [ + const tableSortsOrderBy = useRecoilScopedValue( + tableSortsOrderByScopedSelector, + TableRecoilScopeContext, + ); + const sortsOrderBy = defaults(tableSortsOrderBy, [ { createdAt: SortOrder.Desc, }, ]); - const filtersWhere = useRecoilScopedValue( - filtersWhereScopedSelector, + const tablefiltersWhere = useRecoilScopedValue( + tablefiltersWhereScopedSelector, TableRecoilScopeContext, ); useGetRequest({ - variables: { orderBy: sortsOrderBy, where: filtersWhere }, + variables: { orderBy: sortsOrderBy, where: tablefiltersWhere }, onCompleted: (data: any) => { const entities = data[getRequestResultKey] ?? []; setDataTableData(entities, filterDefinitionArray, sortDefinitionArray); registerOptimisticEffect({ - variables: { orderBy: sortsOrderBy, where: filtersWhere }, + variables: { orderBy: sortsOrderBy, where: tablefiltersWhere }, definition: getRequestOptimisticEffectDefinition, }); }, diff --git a/front/src/modules/ui/data/data-table/states/selectors/tableSortsOrderByScopedSelector.ts b/front/src/modules/ui/data/data-table/states/selectors/tableSortsOrderByScopedSelector.ts new file mode 100644 index 000000000..2590e8af8 --- /dev/null +++ b/front/src/modules/ui/data/data-table/states/selectors/tableSortsOrderByScopedSelector.ts @@ -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 }]; + }, +}); diff --git a/front/src/modules/ui/data/data-table/states/selectors/tablefiltersWhereScopedSelector.ts b/front/src/modules/ui/data/data-table/states/selectors/tablefiltersWhereScopedSelector.ts new file mode 100644 index 000000000..00c7b3038 --- /dev/null +++ b/front/src/modules/ui/data/data-table/states/selectors/tablefiltersWhereScopedSelector.ts @@ -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), + }), +}); diff --git a/front/src/modules/ui/data/data-table/states/tableFiltersScopedState.ts b/front/src/modules/ui/data/data-table/states/tableFiltersScopedState.ts new file mode 100644 index 000000000..ef6de5348 --- /dev/null +++ b/front/src/modules/ui/data/data-table/states/tableFiltersScopedState.ts @@ -0,0 +1,8 @@ +import { atomFamily } from 'recoil'; + +import { Filter } from '../../filter/types/Filter'; + +export const tableFiltersScopedState = atomFamily({ + key: 'tableFiltersScopedState', + default: [], +}); diff --git a/front/src/modules/ui/data/data-table/states/tableSortsScopedState.ts b/front/src/modules/ui/data/data-table/states/tableSortsScopedState.ts new file mode 100644 index 000000000..611998da3 --- /dev/null +++ b/front/src/modules/ui/data/data-table/states/tableSortsScopedState.ts @@ -0,0 +1,8 @@ +import { atomFamily } from 'recoil'; + +import { Sort } from '../../sort/types/Sort'; + +export const tableSortsScopedState = atomFamily({ + key: 'tableSortsScopedState', + default: [], +}); diff --git a/front/src/modules/ui/data/filter/states/selectors/filtersWhereScopedSelector.ts b/front/src/modules/ui/data/filter/states/selectors/filtersWhereScopedSelector.ts deleted file mode 100644 index a52dc4c14..000000000 --- a/front/src/modules/ui/data/filter/states/selectors/filtersWhereScopedSelector.ts +++ /dev/null @@ -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, - ), - }), -}); diff --git a/front/src/modules/views/hooks/internal/useViewFields.ts b/front/src/modules/views/hooks/internal/useViewFields.ts index 754b19375..9d8ac5abf 100644 --- a/front/src/modules/views/hooks/internal/useViewFields.ts +++ b/front/src/modules/views/hooks/internal/useViewFields.ts @@ -4,6 +4,7 @@ import { useRecoilCallback } from 'recoil'; import { ColumnDefinition } from '@/ui/data/data-table/types/ColumnDefinition'; 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 { currentViewIdScopedState } from '@/views/states/currentViewIdScopedState'; import { savedViewFieldByKeyScopedFamilySelector } from '@/views/states/selectors/savedViewFieldByKeyScopedFamilySelector'; @@ -13,8 +14,6 @@ import { useUpdateViewFieldMutation, } from '~/generated/graphql'; -import { GET_VIEW_FIELDS } from '../../graphql/queries/getViewFields'; - export const toViewFieldInput = ( objectId: string, fieldDefinition: ColumnDefinition, diff --git a/front/src/modules/views/hooks/useViewInternalStates.ts b/front/src/modules/views/hooks/useViewInternalStates.ts index 69875d38b..068322434 100644 --- a/front/src/modules/views/hooks/useViewInternalStates.ts +++ b/front/src/modules/views/hooks/useViewInternalStates.ts @@ -23,7 +23,6 @@ import { savedViewSortsScopedFamilyState } from '../states/savedViewSortsScopedF import { canPersistViewFiltersScopedFamilySelector } from '../states/selectors/canPersistViewFiltersScopedFamilySelector'; import { canPersistViewSortsScopedFamilySelector } from '../states/selectors/canPersistViewSortsScopedFamilySelector'; import { currentViewScopedSelector } from '../states/selectors/currentViewScopedSelector'; -import { currentViewSortsOrderByScopedFamilySelector } from '../states/selectors/currentViewSortsOrderByScopedFamilySelector'; import { savedViewFieldByKeyScopedFamilySelector } from '../states/selectors/savedViewFieldByKeyScopedFamilySelector'; import { savedViewFiltersByKeyScopedFamilySelector } from '../states/selectors/savedViewFiltersByKeyScopedFamilySelector'; import { savedViewSortsByKeyScopedFamilySelector } from '../states/selectors/savedViewSortsByKeyScopedFamilySelector'; @@ -108,13 +107,6 @@ export const useViewInternalStates = ( }), ); - const currentViewSortsOrderBy = useRecoilValue( - currentViewSortsOrderByScopedFamilySelector({ - viewScopeId: scopeId, - viewId: familyItemId, - }), - ); - // ViewFilters const [currentViewFilters, setCurrentViewFilters] = useRecoilScopedFamilyState( @@ -215,7 +207,6 @@ export const useViewInternalStates = ( savedViewSortsByKey, setSavedViewSorts, canPersistSorts, - currentViewSortsOrderBy, availableFilters, setAvailableFilters, diff --git a/front/src/modules/views/states/selectors/currentViewSortsOrderByScopedFamilySelector.ts b/front/src/modules/views/states/selectors/currentViewSortsOrderByScopedFamilySelector.ts deleted file mode 100644 index 02d3c90d1..000000000 --- a/front/src/modules/views/states/selectors/currentViewSortsOrderByScopedFamilySelector.ts +++ /dev/null @@ -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 }]; - }, -});