FE: types, global store, and data hooks for categorical metadata - #1746
Conversation
Adds weather (skewed string), reviewed (boolean), camera_id (25 values, exercises the "Other" bucket), and split (~20% missing, exercises the "Missing" bucket) alongside the existing numeric fields. location now uses weighted sampling instead of uniform. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds categorical metadata types, session-backed selection state, categorical ChangesCategorical metadata
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant MetadataView
participant useCategoricalMetadataDistribution
participant getMetadataValueCounts
MetadataView->>useCategoricalMetadataDistribution: provide collectionId and filter
useCategoricalMetadataDistribution->>getMetadataValueCounts: request value counts
getMetadataValueCounts-->>useCategoricalMetadataDistribution: return value_counts
useCategoricalMetadataDistribution-->>MetadataView: return typed value, missing, and other buckets
Possibly related PRs
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 |
❌ Fast Track: checks did not pass
To run the guardrails locally, from Reflects |
…ta-bar-chart-filter-ui-8-sp.p0
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d54a61f998
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds an 'in' operator that accepts a list of string/boolean/null values and builds an OR predicate, using a LEFT OUTER JOIN when null is present to match samples with no metadata entry. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Introduces the CategoricalMetadataValue/CategoricalMetadataValues types and a session-storage-backed store for selected categorical filter values, alongside an export for the upcoming useCategoricalMetadataDistribution hook. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
createMetadataFilters now accepts an optional categoricalMetadataValues map and appends one 'in' filter per non-empty key; also clears the categorical store when the collection changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fetches value-counts for all categorical metadata fields and shapes the response into typed CategoricalMetadataBucket arrays, disambiguating literal 'Missing'/'Other' values from the sentinel missing/other buckets. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
55ec580 to
cf40cb2
Compare
d54a61f to
8d4e752
Compare
|
/review |
|
/review |
The hook used .svelte.ts but doesn't use Svelte reactivity primitives directly; .ts matches the convention of useNumericMetadataDistribution. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
TanStack Query v6 hooks must live in .svelte.ts files per frontend guidelines. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Split the combined test into focused cases for string values vs booleans, use keyword arguments for clarity, and tighten resolver call assertions with assert_called_once_with. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When a function and its module file share the same name, mypy resolves the attribute as the module (not callable). Add a __init__.pyi stub for metadata_resolver to declare the four exported functions explicitly, and use explicit re-exports (as) in both __init__.py files to signal intent. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…t-filter-ui-8-sp.p1.p2' into kondrat-lig-9585-frontend-categorical-metadata-bar-chart-filter-ui-8-sp.p2
…ta-bar-chart-filter-ui-8-sp.p1.p2
…t-filter-ui-8-sp.p1.p2' into kondrat-lig-9585-frontend-categorical-metadata-bar-chart-filter-ui-8-sp.p2
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…t-filter-ui-8-sp.p1.p2' into kondrat-lig-9585-frontend-categorical-metadata-bar-chart-filter-ui-8-sp.p2
…t-filter-ui-8-sp.p2' into kondrat-lig-9585-frontend-categorical-metadata-bar-chart-filter-ui-8-sp.p4
…ta-bar-chart-filter-ui-8-sp.p4
…t-filter-ui-8-sp.p4' into kondrat-lig-9585-frontend-categorical-metadata-bar-chart-filter-ui-8-sp.p5
…ta-bar-chart-filter-ui-8-sp.p5
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@lightly_studio_view/src/lib/services/types.ts`:
- Around line 90-91: The categorical metadata contract currently represents
missing selections as null instead of "__missing__". In
lightly_studio_view/src/lib/services/types.ts lines 90-91, remove null from
CategoricalMetadataValue and expose the missing sentinel; in
lightly_studio_view/src/lib/hooks/useMetadataFilters/useMetadataFilters.ts lines
52-55, type and translate categorical selections using that sentinel per the API
contract; in
lightly_studio_view/src/lib/hooks/useMetadataFilters/useMetadataFilters.test.ts
lines 86-96, update coverage so the expected in predicate includes
"__missing__".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a635c7ec-3c84-485d-8772-f802f2f2fec0
📒 Files selected for processing (7)
lightly_studio_view/src/lib/hooks/index.tslightly_studio_view/src/lib/hooks/useCategoricalMetadataDistribution/useCategoricalMetadataDistribution.svelte.tslightly_studio_view/src/lib/hooks/useCategoricalMetadataDistribution/useCategoricalMetadataDistribution.test.tslightly_studio_view/src/lib/hooks/useGlobalStorage.tslightly_studio_view/src/lib/hooks/useMetadataFilters/useMetadataFilters.test.tslightly_studio_view/src/lib/hooks/useMetadataFilters/useMetadataFilters.tslightly_studio_view/src/lib/services/types.ts
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lightly_studio_view/src/lib/hooks/useCategoricalMetadataDistribution/useCategoricalMetadataDistribution.test.ts (1)
9-42: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAdd coverage for sentinel buckets.
These tests cover literal
"Missing"and emptyvalue_counts, but nomissing_count/other_countinput. Add assertions proving literal values remain normalvaluebuckets while sentinel buckets are emitted separately; otherwise the selector regression is not detected.🤖 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 `@lightly_studio_view/src/lib/hooks/useCategoricalMetadataDistribution/useCategoricalMetadataDistribution.test.ts` around lines 9 - 42, Add test coverage for missing_count and other_count handling in selectCategoricalDistributions. Verify literal "Missing" entries remain normal kind "value" buckets, while missing_count and other_count inputs produce separate sentinel buckets with their expected kinds, labels, counts, and IDs.
🤖 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.
Inline comments:
In
`@lightly_studio_view/src/lib/hooks/useCategoricalMetadataDistribution/useCategoricalMetadataDistribution.svelte.ts`:
- Around line 6-32: Restore separate sentinel bucket types in
selectCategoricalDistributions: map missing_count and other_count to distinct
buckets with stable IDs, while preserving literal value buckets including string
values "Missing" and "Other". In
lightly_studio_view/src/lib/hooks/useCategoricalMetadataDistribution/useCategoricalMetadataDistribution.svelte.ts#L6-L32,
update the bucket type definitions and selector mapping; in
lightly_studio_view/src/lib/hooks/useCategoricalMetadataDistribution/useCategoricalMetadataDistribution.test.ts#L9-L42,
add fixtures and assertions covering both sentinel buckets and literal
"Missing"/"Other" values.
---
Outside diff comments:
In
`@lightly_studio_view/src/lib/hooks/useCategoricalMetadataDistribution/useCategoricalMetadataDistribution.test.ts`:
- Around line 9-42: Add test coverage for missing_count and other_count handling
in selectCategoricalDistributions. Verify literal "Missing" entries remain
normal kind "value" buckets, while missing_count and other_count inputs produce
separate sentinel buckets with their expected kinds, labels, counts, and IDs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ce45d3ad-69cd-45aa-9342-8b7b089494e7
📒 Files selected for processing (2)
lightly_studio_view/src/lib/hooks/useCategoricalMetadataDistribution/useCategoricalMetadataDistribution.svelte.tslightly_studio_view/src/lib/hooks/useCategoricalMetadataDistribution/useCategoricalMetadataDistribution.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In
`@lightly_studio_view/src/lib/hooks/useCategoricalMetadataDistribution/useCategoricalMetadataDistribution.svelte.ts`:
- Around line 7-10: Update the categorical metadata bucket mapper to emit
"__missing__" as the value for buckets recognized as missing instead of null,
and align CategoricalMetadataBucket’s missing variant with that sentinel so
bucket.value remains a valid CategoricalMetadataValue for filtering.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2313f6b7-e5d8-4730-8792-916c0402af1e
📒 Files selected for processing (3)
lightly_studio_view/src/lib/hooks/useCategoricalMetadataDistribution/useCategoricalMetadataDistribution.svelte.tslightly_studio_view/src/lib/hooks/useCategoricalMetadataDistribution/useCategoricalMetadataDistribution.test.tslightly_studio_view/src/lib/services/types.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- lightly_studio_view/src/lib/hooks/useCategoricalMetadataDistribution/useCategoricalMetadataDistribution.test.ts
Summary
Stacked on p4. Pure data layer — no UI changes.
CategoricalMetadataValue/CategoricalMetadataValuestypes (services/types.ts): map field name → set of selected values; the sentinel string"__missing__"represents samples with no value for the fieldcategoricalMetadataValuessession-storage slot (useGlobalStorage.ts): persists categorical selections across page navigation, cleared when the collection changescreateMetadataFiltersextended: converts the selected values map into oneinfilter per non-empty field (calls the BE operator added in p4)useCategoricalMetadataDistributionhook: callsGET /metadata/value_counts, disambiguates literal"Missing"/"Other"strings from the sentinel buckets, and returns typedCategoricalMetadataBucket[]arrays per fieldTest plan
make static-checks(frontend) passesnpm run test:unitpasses (new tests inuseCategoricalMetadataDistribution,useMetadataFilters)Part of LIG-9585.
Summary by CodeRabbit