Change API for object property listing to work better with the ui.
This commit is contained in:
parent
36151f35bd
commit
c36c9ac46a
@ -225,16 +225,23 @@ function nestGroups(groups, props, filter, idx = 0) {
|
|||||||
// Build a map of key -> groups for this property
|
// Build a map of key -> groups for this property
|
||||||
const keyToGroups = {};
|
const keyToGroups = {};
|
||||||
for (const group of groups) {
|
for (const group of groups) {
|
||||||
const { key } = getKeyAndFilterVals(group._id[prop]);
|
const val = group._id[prop];
|
||||||
if (!keyToGroups[key]) keyToGroups[key] = [];
|
const { key } = getKeyAndFilterVals(val);
|
||||||
keyToGroups[key].push(group);
|
if (!keyToGroups[key]) {
|
||||||
|
keyToGroups[key] = {
|
||||||
|
groups: [],
|
||||||
|
value: val,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
keyToGroups[key].groups.push(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
let map = {};
|
let result = [];
|
||||||
|
|
||||||
if (filterPresent) {
|
if (filterPresent) {
|
||||||
const filterValue = filter[prop]?.toString?.() ?? filter[prop];
|
const filterValue = filter[prop]?.toString?.() ?? filter[prop];
|
||||||
for (const [key, groupList] of Object.entries(keyToGroups)) {
|
for (const [key, data] of Object.entries(keyToGroups)) {
|
||||||
|
const { groups: groupList, value } = data;
|
||||||
// Check if any group in this key matches the filter (by _id or name)
|
// Check if any group in this key matches the filter (by _id or name)
|
||||||
const matches = groupList.filter((group) => {
|
const matches = groupList.filter((group) => {
|
||||||
const { filterVals } = getKeyAndFilterVals(group._id[prop]);
|
const { filterVals } = getKeyAndFilterVals(group._id[prop]);
|
||||||
@ -242,28 +249,36 @@ function nestGroups(groups, props, filter, idx = 0) {
|
|||||||
console.log('filterValue', filterValue);
|
console.log('filterValue', filterValue);
|
||||||
return filterVals.some((val) => val?.toString() === filterValue);
|
return filterVals.some((val) => val?.toString() === filterValue);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let children = [];
|
||||||
if (matches.length > 0) {
|
if (matches.length > 0) {
|
||||||
if (idx === props.length - 1) {
|
if (idx === props.length - 1) {
|
||||||
// Last property in filter, return items
|
// Last property in filter, return items
|
||||||
let items = [];
|
|
||||||
for (const group of matches) {
|
for (const group of matches) {
|
||||||
items = items.concat(group.objects.map(expandObjectIds));
|
children = children.concat(group.objects.map(expandObjectIds));
|
||||||
}
|
|
||||||
map[key] = items;
|
|
||||||
} else {
|
|
||||||
map[key] = nestGroups(matches, props, filter, idx + 1);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
map[key] = {};
|
children = nestGroups(matches, props, filter, idx + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.push({
|
||||||
|
property: prop,
|
||||||
|
value: expandObjectIds(value),
|
||||||
|
children: children,
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// No filter for this property, just show all keys at this level with empty objects
|
// No filter for this property, just show all keys at this level with empty objects
|
||||||
for (const key of Object.keys(keyToGroups)) {
|
for (const [key, data] of Object.entries(keyToGroups)) {
|
||||||
map[key] = {};
|
result.push({
|
||||||
|
property: prop,
|
||||||
|
value: expandObjectIds(data.value),
|
||||||
|
children: [],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return map;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group objects by multiple properties and return nested groupings
|
// Group objects by multiple properties and return nested groupings
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user