fix(ui): fix mapper from intelligent search (#1971)

* fix(ui): fix mapper from intelligent search

* fix typo
This commit is contained in:
Delirium 2024-03-18 13:17:34 +01:00 committed by GitHub
parent 325a10ea33
commit 94ce9fbc09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -94,24 +94,19 @@ export function isObject(item: any): boolean {
return item && typeof item === 'object' && !Array.isArray(item);
}
export function mergeDeep(target: Record<string, any>, ...sources: any[]): Record<string, any> {
if (!sources.length) return target;
const source = sources.shift();
const updateFilters = (defaultFilters: typeof defaultFetchFilter['filters'], backendFilters: Record<string, any>): typeof defaultFetchFilter['filters'] => {
const updatedFilters = [...defaultFilters]; // Clone the default filters
if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key])) {
if (!target[key]) Object.assign(target, { [key]: {} });
mergeDeep(target[key], source[key]);
} else {
Object.assign(target, { [key]: source[key] });
}
backendFilters.forEach(backendFilter => {
const index = updatedFilters.findIndex(f => f.type === backendFilter.key);
if (index > -1) {
updatedFilters[index] = { ...updatedFilters[index], ...backendFilter, type: updatedFilters[index].type };
}
}
});
return mergeDeep(target, ...sources);
}
return updatedFilters;
};
const mapFetch = (filter: Record<string, any>): Record<string, any> => {
return mergeDeep(filter, defaultFetchFilter);
return { ...defaultFetchFilter, filters: updateFilters(defaultFetchFilter.filters, filter.filters) }
};