feat: fix items list datatable.

This commit is contained in:
a.bouhuolia
2021-02-08 13:17:11 +02:00
parent adac2386bb
commit 304f0c9ae5
43 changed files with 777 additions and 835 deletions

View File

@@ -1,28 +1,11 @@
import { paginationLocationQuery } from 'store/selectors';
import { createSelector } from 'reselect';
import { pickItemsFromIds, defaultPaginationMeta } from 'store/selectors';
import { createDeepEqualSelector } from 'utils';
const itemsTableQuerySelector = (state) => state.items.tableQuery;
const itemsCurrentPageSelector = (state, props) => {
const currentViewId = state.items.currentViewId;
const currentView = state.items.views?.[currentViewId];
const currentPageId = currentView?.paginationMeta?.page;
return currentView?.pages?.[currentPageId];
};
const itemsDataSelector = (state) => state.items.items;
const itemsPaginationSelector = (state, props) => {
const viewId = state.items.currentViewId;
return state.items.views?.[viewId]?.paginationMeta;
};
const itemsCurrentViewIdSelector = (state) => {
return state.items.currentViewId;
};
// Get items table query marged with location query.
export const getItemsTableQueryFactory = () =>
createSelector(
createDeepEqualSelector(
paginationLocationQuery,
itemsTableQuerySelector,
(locationQuery, tableQuery) => {
@@ -32,30 +15,3 @@ export const getItemsTableQueryFactory = () =>
};
},
);
// Retrieve items current page and view.
export const getItemsCurrentPageFactory = () =>
createSelector(
itemsDataSelector,
itemsCurrentPageSelector,
(items, itemsIdsCurrentPage) => {
return typeof itemsIdsCurrentPage === 'object'
? pickItemsFromIds(items, itemsIdsCurrentPage.ids) || []
: [];
},
);
// Retrieve items pagination meta.
export const getItemsPaginationMetaFactory = () =>
createSelector(itemsPaginationSelector, (itemsPagination) => {
return {
...defaultPaginationMeta(),
...itemsPagination,
};
});
// Retrieve items current view id.
export const getItemsCurrentViewIdFactory = () =>
createSelector(itemsCurrentViewIdSelector, (currentViewId) => {
return currentViewId;
});