mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
WIP
This commit is contained in:
31
client/src/store/selectors.js
Normal file
31
client/src/store/selectors.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import {pick} from 'lodash';
|
||||
|
||||
export const pickItemsFromIds = (items, ids) => {
|
||||
return Object.values(pick(items, ids));
|
||||
}
|
||||
|
||||
export const getCurrentPageResults = (items, page, name) => {
|
||||
const currentPage = page.pages[page.currentPages[name]]
|
||||
return typeof currentPage == 'undefined' ? [] : Object.values(pick(items || [], currentPage.ids))
|
||||
}
|
||||
|
||||
export const getCurrentTotalResultsCount = (pagination, name) => {
|
||||
const currentPageUrl = pagination.currentPages[name]
|
||||
const currentPage = pagination.pages[currentPageUrl]
|
||||
return typeof currentPageUrl == 'undefined' ? 0 : pagination.params[currentPage.params]
|
||||
}
|
||||
|
||||
export const getAllResults = (items, pagination, name) => {
|
||||
const currentPage = pagination.pages[pagination.currentPages[name]]
|
||||
if (typeof currentPage == 'undefined') {
|
||||
return []
|
||||
}
|
||||
let allPagesKeys = Object.keys(pagination.pages)
|
||||
let allPagesIds = []
|
||||
for (let key of allPagesKeys) {
|
||||
if (pagination.pages[key].params == currentPage.params) {
|
||||
allPagesIds = allPagesIds.concat(pagination.pages[key].ids)
|
||||
}
|
||||
}
|
||||
return Object.values(pick(items || [], allPagesIds))
|
||||
}
|
||||
Reference in New Issue
Block a user