refactor(store): dedupe node-type maps, cover resolveParentEntityType#78
Open
bburda wants to merge 1 commit into
Open
refactor(store): dedupe node-type maps, cover resolveParentEntityType#78bburda wants to merge 1 commit into
bburda wants to merge 1 commit into
Conversation
Follow-up polish on the parent entity-type resolution used by the topic
data fallback.
- Export resolveParentEntityType and add unit tests covering the
runtime_only function/app hierarchy (the scenario behind the topic
data 400), operations/configurations/faults segments, and the
not-in-tree and unknown-type fallbacks.
- Hoist NODE_TYPE_TO_RESOURCE and resolveParentEntityType next to
findNode so the "Fallback: fetch entity details" comment documents
fetchEntityFromApi again.
- Replace the duplicate type maps in handleTopicSelection and
refreshSelectedEntity with the shared NODE_TYPE_TO_RESOURCE, dropping
the invalid `${type}s` cast for sub-area/sub-component node types.
- Fix a JSDoc typo and a split comment fragment.
Closes #77
There was a problem hiding this comment.
Pull request overview
Refactors and hardens the “parent entity-type resolution” logic in the Zustand store to avoid duplicated node-type → API-resource mappings, and adds unit tests to prevent regressions in runtime_only (function/app) hierarchy scenarios tied to #77.
Changes:
- Hoisted/deduplicated the node-type → API resource mapping into a single
NODE_TYPE_TO_RESOURCEconstant and reused it in topic selection + refresh logic. - Exported
resolveParentEntityTypeand added focused unit tests coveringruntime_onlydepth pitfalls, supported resource segments, and safe fallbacks. - Minor comment/JSDoc cleanup so the fallback documentation again applies to
fetchEntityFromApi.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/lib/store.ts | Centralizes node-type→resource mapping, exports resolveParentEntityType, and replaces ad-hoc casts/maps in topic selection and refresh logic. |
| src/lib/store-helpers.test.ts | Adds unit coverage for resolveParentEntityType (runtime_only hierarchy, resource segments, unknown/missing parent fallbacks). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Summary
Follow-up polish on the parent entity-type resolution used by the topic data fallback (#77). No user-facing behavior change beyond dropping a latent invalid type cast.
resolveParentEntityTypeand add unit tests covering theruntime_onlyfunction/app hierarchy (the scenario behind the topic data 400),operations/configurations/faultsresource segments, and the not-in-tree and unknown-type fallbacks.NODE_TYPE_TO_RESOURCEandresolveParentEntityTypenext tofindNodeso the/** Fallback: fetch entity details ... */comment documentsfetchEntityFromApiagain.handleTopicSelectionandrefreshSelectedEntitywith the sharedNODE_TYPE_TO_RESOURCE, dropping the invalid${type}scast for sub-area/sub-component node types.Issue
Link the related issue (required):
Type
Testing
npx vitest run- 412 tests pass (16 files), including 9 newresolveParentEntityTypecases instore-helpers.test.ts.npm run typecheck,npm run lint,npm run format:check- clean.npm run build- succeeds.Checklist
npm run lint)npm run build)