mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
60 lines
1.7 KiB
JavaScript
60 lines
1.7 KiB
JavaScript
import { createSelector } from '@reduxjs/toolkit';
|
|
import {
|
|
pickItemsFromIds,
|
|
paginationLocationQuery,
|
|
defaultPaginationMeta,
|
|
} from 'store/selectors';
|
|
|
|
const inventoryAdjustmentTableQuery = (state) =>
|
|
state.inventoryAdjustments.tableQuery;
|
|
|
|
const inventoryAdjustmentsPaginationSelector = (state, props) => {
|
|
const viewId = state.inventoryAdjustments.currentViewId;
|
|
return state.inventoryAdjustments.views?.[viewId];
|
|
};
|
|
|
|
const inventoryAdjustmentItemsSelector = (state) =>
|
|
state.inventoryAdjustments.items;
|
|
|
|
const inventoryAdjustmentCurrentPageSelector = (state, props) => {
|
|
const currentViewId = state.inventoryAdjustments.currentViewId;
|
|
const currentView = state.inventoryAdjustments.views?.[currentViewId];
|
|
const currentPageId = currentView?.paginationMeta?.page;
|
|
|
|
return currentView?.pages?.[currentPageId];
|
|
};
|
|
|
|
const getinventoryAdjustmentCurrentViewIdSelector = (state) =>
|
|
state.inventoryAdjustments.currentViewId;
|
|
|
|
export const getInvoiceTableQueryFactory = () =>
|
|
createSelector(
|
|
paginationLocationQuery,
|
|
inventoryAdjustmentTableQuery,
|
|
(locationQuery, tableQuery) => {
|
|
return {
|
|
...locationQuery,
|
|
...tableQuery,
|
|
};
|
|
},
|
|
);
|
|
|
|
export const getInventoryAdjustmentCurrentPageFactory = () =>
|
|
createSelector(
|
|
inventoryAdjustmentCurrentPageSelector,
|
|
inventoryAdjustmentItemsSelector,
|
|
(currentPage, items) => {
|
|
return typeof currentPage === 'object'
|
|
? pickItemsFromIds(items, currentPage.ids) || []
|
|
: [];
|
|
},
|
|
);
|
|
|
|
export const getInventoryAdjustmentPaginationMetaFactory = () =>
|
|
createSelector(inventoryAdjustmentsPaginationSelector, (Page) => {
|
|
return {
|
|
...defaultPaginationMeta(),
|
|
...(Page?.paginationMeta || {}),
|
|
};
|
|
});
|