mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
feat: style vendor form and list.
feat: items state selectors.
This commit is contained in:
@@ -43,35 +43,13 @@ export default createReducer(initialState, {
|
||||
|
||||
const viewId = customViewId || -1;
|
||||
const view = state.views[viewId] || {};
|
||||
const viewPages = getItemsViewPages(state.views, viewId);
|
||||
|
||||
items.forEach((item) => {
|
||||
const stateItem = state.items[item.id];
|
||||
const itemRelation = state.itemsRelation[stateItem.id];
|
||||
|
||||
if (typeof itemRelation === 'undefined') {
|
||||
state.itemsRelation[item.id] = [];
|
||||
}
|
||||
const filteredRelation = state.itemsRelation[item.id].filter(
|
||||
(relation) =>
|
||||
relation.viewId === viewId &&
|
||||
relation.pageNumber === paginationMeta.page,
|
||||
);
|
||||
|
||||
filteredRelation.push({
|
||||
viewId,
|
||||
pageNumber: paginationMeta.page,
|
||||
});
|
||||
state.itemsRelation[item.id] = filteredRelation;
|
||||
});
|
||||
|
||||
state.views[viewId] = {
|
||||
...view,
|
||||
pages: {
|
||||
...viewPages,
|
||||
...(state.views?.[viewId]?.pages || {}),
|
||||
[paginationMeta.page]: {
|
||||
ids: items.map((i) => i.id),
|
||||
meta: paginationMeta,
|
||||
ids: items.map((item) => item.id),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,7 +1,69 @@
|
||||
import { paginationLocationQuery } from "store/selectors";
|
||||
import { createSelector } from 'reselect';
|
||||
import {
|
||||
pickItemsFromIds,
|
||||
defaultPaginationMeta,
|
||||
} from 'store/selectors';
|
||||
|
||||
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;
|
||||
|
||||
export const getItemsViewPages = (itemsViews, viewId) => {
|
||||
return itemsViews[viewId] ?
|
||||
itemsViews[viewId].pages : {};
|
||||
};
|
||||
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 customersCurrentViewIdSelector = (state) => state.customers.currentViewId;
|
||||
|
||||
// Get items table query marged with location query.
|
||||
export const getItemsTableQueryFactory = () =>
|
||||
createSelector(
|
||||
paginationLocationQuery,
|
||||
itemsTableQuerySelector,
|
||||
(locationQuery, tableQuery) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableQuery,
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// 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(
|
||||
customersCurrentViewIdSelector,
|
||||
(currentViewId) => {
|
||||
return currentViewId;
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user