feat(logExplorer): add configurable flatten depth setting - #2297
Conversation
Add a "flatten depth" option to LogsViewer for clickHouse/doris ExplorerNG. flattenDepth=0 skips parsing/flattening (raw strings); N>=1 expands nested JSON up to N levels. Refactor flatten() to take explicit maxDepth with depth threaded via recursion, and merge defaultOptions when reading localstorage so existing users get the new default.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🟡 Changes recommended
LocalStorage parsing and flattenDepth handling need defensive validation/clamping to avoid corrupted values producing unexpected options merges or excessively deep recursion.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds a configurable “flatten depth” option for ExplorerNG log viewing so users can control how aggressively nested JSON fields are expanded (including an option to skip parsing/flattening entirely), while keeping existing localStorage-stored options compatible via default-merging.
Changes:
- Introduces
flattenDepth(default1) and a new settings modal entry inLogsViewer(“Flatten depth”) with i18n strings. - Refactors
flatten()to accept an explicitmaxDepththreaded through recursion, and adds unit tests for depth behavior. - Threads
flattenDepththrough clickHouse/doris ExplorerNG Query flows (including view restore via hidden form field) and merges new defaults when reading localStorage.
File summaries
| File | Description |
|---|---|
| src/plugins/doris/ExplorerNG/utils/optionsLocalstorage.ts | Merge stored options with defaults to backfill newly added fields like flattenDepth. |
| src/plugins/doris/ExplorerNG/Main/SQL/Table.tsx | Stops applying flatten() to SQL table rows (passes raw item fields through). |
| src/plugins/doris/ExplorerNG/Main/Query/index.tsx | Applies flattenDepth in doris query results, supports flattenDepth=0 raw mode, and exposes settings toggle. |
| src/plugins/doris/ExplorerNG/index.tsx | Registers hidden query.flattenDepth field so view restore persists it. |
| src/plugins/clickHouse/ExplorerNG/utils/optionsLocalstorage.ts | Same default-merging behavior for clickHouse ExplorerNG options. |
| src/plugins/clickHouse/ExplorerNG/Main/SQL/Table.tsx | Stops applying flatten() to SQL table rows (passes raw item fields through). |
| src/plugins/clickHouse/ExplorerNG/Main/Query/index.tsx | Applies flattenDepth in clickHouse query results, supports flattenDepth=0 raw mode, and exposes settings toggle. |
| src/plugins/clickHouse/ExplorerNG/index.tsx | Registers hidden query.flattenDepth field so view restore persists it. |
| src/pages/logExplorer/locale/zh_CN.ts | Adds zh-CN strings for flatten depth settings UI. |
| src/pages/logExplorer/locale/en_US.ts | Adds en-US strings for flatten depth settings UI. |
| src/pages/logExplorer/constants.ts | Adds DEFAULT_FLATTEN_DEPTH and includes flattenDepth in DEFAULT_OPTIONS. |
| src/pages/logExplorer/components/LogsViewer/utils/flatten.ts | Refactors flatten recursion to honor explicit maxDepth via a threaded depth param. |
| src/pages/logExplorer/components/LogsViewer/utils/flatten.test.ts | Adds test coverage validating maxDepth semantics and sibling expansion. |
| src/pages/logExplorer/components/LogsViewer/types.ts | Extends OptionsType with flattenDepth. |
| src/pages/logExplorer/components/LogsViewer/index.tsx | Adds showFlattenSettings prop plumbing into settings. |
| src/pages/logExplorer/components/LogsViewer/components/OriginSettings.tsx | Adds a modal UI to configure flattenDepth (0–10) and persists via updateOptions. |
Review details
- Files reviewed: 16/16 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // 优先 form(视图恢复时 form 即时最新),其次 options,最后默认值 | ||
| const flattenDepth = typeof queryValues?.flattenDepth === 'number' ? queryValues.flattenDepth : options.flattenDepth ?? DEFAULT_FLATTEN_DEPTH; |
| if (optionsLocalStorage) { | ||
| try { | ||
| return JSON.parse(optionsLocalStorage); | ||
| return { ...defaultOptions, ...JSON.parse(optionsLocalStorage) }; |
| // 优先 form(视图恢复时 form 即时最新),其次 options,最后默认值 | ||
| const flattenDepth = typeof queryValues?.flattenDepth === 'number' ? queryValues.flattenDepth : options.flattenDepth ?? DEFAULT_FLATTEN_DEPTH; |
| if (optionsLocalStorage) { | ||
| try { | ||
| return JSON.parse(optionsLocalStorage); | ||
| return { ...defaultOptions, ...JSON.parse(optionsLocalStorage) }; |
Add a "flatten depth" option to LogsViewer for clickHouse/doris ExplorerNG. flattenDepth=0 skips parsing/flattening (raw strings); N>=1 expands nested JSON up to N levels. Refactor flatten() to take explicit maxDepth with depth threaded via recursion, and merge defaultOptions when reading localstorage so existing users get the new default.