fix(ui): normalize single embedded dataset#257
Conversation
Embedded HTML injects one DataSet object, but getDataSets assumed an array and crashed with ".map is not a function". Route all load paths through classifyPayload (renamed from classifyRemotePayload) and drop the unused normalizeDataSets mirror test.
Align UI naming with Go's Dataset type and standard English casing.
📝 WalkthroughWalkthroughThe PR renames dataset types and APIs to ChangesDataset contract migration
Estimated code review effort: 3 (Moderate) | ~30 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks 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.
🧹 Nitpick comments (2)
ui/src/composables/useDataPoint.ts (1)
108-114: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove the ref mutation inside the
datasetsProcessedcomputed getter.Mutating
datasets.valuefrom within the getter that reads it is a Vue anti-pattern (computed getters are expected to be side-effect free). It's also now vestigial:classifyPayload(line 22/28/33) already normalizes every load path into{ mode: 'full', datasets: [...] }/{ mode: 'catalog', entries: [...] }, anddatasetsis typedshallowRef<Dataset[]>, so every writer (payload.entries.map(...)/payload.datasets.map(...)) always assigns an array. The!Array.isArraybranch is unreachable given the current contract, yet it still triggers an extra reactive write on every evaluation path that would hit it.♻️ Proposed fix: make the getter pure
const datasetsProcessed = computed<Dataset[]>(() => { - if (!Array.isArray(datasets.value)) { - datasets.value = [datasets.value] - } - - return datasets.value + return Array.isArray(datasets.value) ? datasets.value : [datasets.value] })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ui/src/composables/useDataPoint.ts` around lines 108 - 114, Remove the !Array.isArray branch and its assignment from the datasetsProcessed computed getter. Return datasets.value directly, keeping the getter pure and relying on the existing array normalization performed by classifyPayload and the typed writers.ui/src/views/Dashboard.vue (1)
1-1: 📐 Maintainability & Code Quality | 🔵 TrivialRun
task build:uibefore building the CLI or running Go tests.As per coding guidelines, please ensure you run
task build:uiafter thisui/change before running Go tests or CLI builds.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ui/src/views/Dashboard.vue` at line 1, Run task build:ui after the Dashboard.vue change and before building the CLI or running Go tests; no source changes are required.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@ui/src/composables/useDataPoint.ts`:
- Around line 108-114: Remove the !Array.isArray branch and its assignment from
the datasetsProcessed computed getter. Return datasets.value directly, keeping
the getter pure and relying on the existing array normalization performed by
classifyPayload and the typed writers.
In `@ui/src/views/Dashboard.vue`:
- Line 1: Run task build:ui after the Dashboard.vue change and before building
the CLI or running Go tests; no source changes are required.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e026274e-1b4e-483d-8c54-0e30bce368c4
📒 Files selected for processing (21)
ui/src/components/ChartCard.vueui/src/components/DatasetHeader.vueui/src/components/Selector.vueui/src/components/SettingsPanel.vueui/src/components/settings/SwapControl.vueui/src/composables/useActiveChartShape.test.tsui/src/composables/useActiveChartShape.tsui/src/composables/useDashboardInit.tsui/src/composables/useDataPoint.normalize.test.tsui/src/composables/useDataPoint.tsui/src/composables/useSettingsStore.test.tsui/src/composables/useSettingsStore.tsui/src/composables/useUrlRouter.test.tsui/src/composables/useUrlRouter.tsui/src/global.d.tsui/src/lib/filterDatasetSettings.test.tsui/src/lib/filterDatasetSettings.tsui/src/lib/remoteData.test.tsui/src/lib/remoteData.tsui/src/types/index.tsui/src/views/Dashboard.vue
💤 Files with no reviewable changes (1)
- ui/src/composables/useDataPoint.normalize.test.ts
Summary
window.VIZB_DATA = {...}) instead of an array: load paths now always go throughclassifyPayload, so.mapis never called on a plain object.classifyRemotePayload→classifyPayload/RemotePayload→DataPayloadbecause classification is shared by remote, embedded, and dev fixtures.useDataPoint.normalize.test.tsmirror (real coverage lives inremoteData.test.ts).DataSettoDatasetto match Go and standard English (DatasetHeader,filterDatasetSettings,activeDataset, etc.).Test plan
pnpm exec vue-tsc -b(UI typecheck)pnpm exec vitest run(UI unit tests).map is not a function--data-urlcatalog + detail fetch still worksSummary by CodeRabbit