1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-24 06:28:42 +01:00

feat: adds a side panel for complex logs that enables reordering and enabling fields (#3237)

This commit is contained in:
Amir Raminfar
2024-08-28 17:37:04 -07:00
committed by GitHub
parent 62a2ef9eb4
commit 85271a595a
31 changed files with 345 additions and 174 deletions

View File

@@ -16,16 +16,28 @@ export function isObject(value: any): value is Record<string, any> {
}
export function flattenJSON(obj: Record<string, any>, path: string[] = []) {
const result: Record<string, any> = {};
Object.keys(obj).forEach((key) => {
const map = flattenJSONToMap(obj);
const result = {} as Record<string, any>;
for (const [key, value] of map) {
result[key.join(".")] = value;
}
return result;
}
export function flattenJSONToMap(obj: Record<string, any>, path: string[] = []): Map<string[], any> {
const result = new Map<string[], any>();
for (const key of Object.keys(obj)) {
const value = obj[key];
const newPath = path.concat(key);
if (isObject(value)) {
Object.assign(result, flattenJSON(value, newPath));
for (const [k, v] of flattenJSONToMap(value, newPath)) {
result.set(k, v);
}
} else {
result[newPath.join(".")] = value;
result.set(newPath, value);
}
});
}
return result;
}