Merge pull request '#8028: Modified arrayData to fix inject warning' (!1747) from 8028-WarningInject into dev
gitea/salix-front/pipeline/head This commit looks good
Details
gitea/salix-front/pipeline/head This commit looks good
Details
Reviewed-on: #1747 Reviewed-by: Jorge Penadés <jorgep@verdnatura.es>
This commit is contained in:
commit
6273aea7ff
|
@ -146,14 +146,14 @@ const addFilter = async (filter, params) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
async function fetch(params) {
|
async function fetch(params) {
|
||||||
useArrayData(props.dataKey, params);
|
arrayData.setOptions(params);
|
||||||
arrayData.resetPagination();
|
arrayData.resetPagination();
|
||||||
await arrayData.fetch({ append: false });
|
await arrayData.fetch({ append: false });
|
||||||
return emitStoreData();
|
return emitStoreData();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function update(params) {
|
async function update(params) {
|
||||||
useArrayData(props.dataKey, params);
|
arrayData.setOptions(params);
|
||||||
const { limit, skip } = store;
|
const { limit, skip } = store;
|
||||||
store.limit = limit + skip;
|
store.limit = limit + skip;
|
||||||
store.skip = 0;
|
store.skip = 0;
|
||||||
|
|
|
@ -41,7 +41,7 @@ export function useArrayData(key, userOptions) {
|
||||||
|
|
||||||
if (key && userOptions) setOptions();
|
if (key && userOptions) setOptions();
|
||||||
|
|
||||||
function setOptions() {
|
function setOptions(params = userOptions) {
|
||||||
const allowedOptions = [
|
const allowedOptions = [
|
||||||
'url',
|
'url',
|
||||||
'filter',
|
'filter',
|
||||||
|
@ -57,14 +57,14 @@ export function useArrayData(key, userOptions) {
|
||||||
'mapKey',
|
'mapKey',
|
||||||
'oneRecord',
|
'oneRecord',
|
||||||
];
|
];
|
||||||
if (typeof userOptions === 'object') {
|
if (typeof params === 'object') {
|
||||||
for (const option in userOptions) {
|
for (const option in params) {
|
||||||
const isEmpty = userOptions[option] == null || userOptions[option] === '';
|
const isEmpty = params[option] == null || params[option] === '';
|
||||||
if (isEmpty || !allowedOptions.includes(option)) continue;
|
if (isEmpty || !allowedOptions.includes(option)) continue;
|
||||||
|
|
||||||
if (Object.hasOwn(store, option)) {
|
if (Object.hasOwn(store, option)) {
|
||||||
const defaultOpts = userOptions[option];
|
const defaultOpts = params[option];
|
||||||
store[option] = userOptions.keepOpts?.includes(option)
|
store[option] = params.keepOpts?.includes(option)
|
||||||
? Object.assign(defaultOpts, store[option])
|
? Object.assign(defaultOpts, store[option])
|
||||||
: defaultOpts;
|
: defaultOpts;
|
||||||
if (option === 'userParams') store.defaultParams = store[option];
|
if (option === 'userParams') store.defaultParams = store[option];
|
||||||
|
@ -367,5 +367,6 @@ export function useArrayData(key, userOptions) {
|
||||||
deleteOption,
|
deleteOption,
|
||||||
reset,
|
reset,
|
||||||
resetPagination,
|
resetPagination,
|
||||||
|
setOptions,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue