feat: introduce CustomAutocomplete with variables

This commit is contained in:
Ali BARIN
2023-05-25 13:40:27 +00:00
parent 42842e7aec
commit f2dc2f5530
47 changed files with 1441 additions and 468 deletions

View File

@@ -0,0 +1,53 @@
import get from 'lodash/get';
import set from 'lodash/set';
import forIn from 'lodash/forIn';
import isPlainObject from 'lodash/isPlainObject';
export default function filterObject(
data: any,
searchTerm: string,
result = {},
prefix: string[] = [],
withinArray = false
) {
if (withinArray) {
const containerValue = get(result, prefix, []);
result = filterObject(
data,
searchTerm,
result,
prefix.concat(containerValue.length.toString())
);
return result;
}
if (isPlainObject(data)) {
forIn(data, (value, key) => {
const fullKey = [...prefix, key];
if (key.toLowerCase().includes(searchTerm)) {
set(result, fullKey, value);
return;
}
result = filterObject(value, searchTerm, result, fullKey);
});
}
if (Array.isArray(data)) {
forIn(data, (value) => {
result = filterObject(value, searchTerm, result, prefix, true);
});
}
if (
['string', 'number'].includes(typeof data) &&
String(data).toLowerCase().includes(searchTerm)
) {
set(result, prefix, data);
}
return result;
};

View File

@@ -0,0 +1,16 @@
import lodashIsEmpty from 'lodash/isEmpty';
export default function isEmpty(value: any) {
if (value === undefined && value === null) return true;
if (Array.isArray(value) || typeof value === 'string') {
return value.length === 0;
}
if (!Number.isNaN(value)) {
return false;
}
// covers objects and anything else possibly
return lodashIsEmpty(value);
};