Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | 27x 27x 7x 7x 7x 1x 6x 1x 7x 7x 7x 27x | import PropTypes from 'prop-types';
import useParallelBatchFetch from './useParallelBatchFetch';
export const CUSTPROPS_QUERY_KEY_BASE = [
'stripes-kint-components',
'useCustProps',
'custprops'
];
const useCustProps = ({
endpoint,
ctx,
nsValues = {
sort: 'id'
},
options = {},
queryParams = {},
batchLimit = Infinity,
batchSize = 100,
concurrentRequests = 5,
}) => {
const custPropOptions = {
searchKey: 'label,name,description',
filterKeys: {
ContextKey: 'ctx'
},
sort: [
{ path: 'weight' },
{ path: 'label' }
],
filters: [],
...options
};
Iif (Array.isArray(ctx)) {
custPropOptions.filters.push({
values: ctx.map(c => (c === 'isNull' ? 'ctx isNull' : `ctx==${c}`))
});
} else if (ctx === 'isNull') {
custPropOptions.filters.push({
value: 'ctx isNull'
});
} else if (ctx) {
custPropOptions.filters.push({
path: 'ctx',
value: ctx
});
}
const {
items: custprops = [],
isLoading = true,
total = 0
} = useParallelBatchFetch({
endpoint,
BATCH_LIMIT: batchLimit,
BATCH_SIZE: batchSize,
CONCURRENT_REQUESTS: concurrentRequests,
batchParams: custPropOptions,
nsValues,
generateQueryKey: ({
endpoint: queryEndpoint,
offset,
paramsArray
}) => [
...CUSTPROPS_QUERY_KEY_BASE,
ctx,
queryEndpoint,
offset,
paramsArray
],
queryOptions: queryParams
});
return {
custprops,
isLoading,
total
};
};
useCustProps.propTypes = {
endpoint: PropTypes.string,
ctx: PropTypes.oneOfType([
PropTypes.string,
PropTypes.arrayOf(PropTypes.string)
]),
nsValues: PropTypes.object,
options: PropTypes.object,
queryParams: PropTypes.object,
batchLimit: PropTypes.number,
batchSize: PropTypes.number,
concurrentRequests: PropTypes.number,
};
export default useCustProps;
|