Skip to content

fix(catalog): reflect the newly selected kind immediately on switch#690

Merged
kaviththiranga merged 1 commit into
openchoreo:mainfrom
kaviththiranga:fix-cache-loader
Jul 17, 2026
Merged

fix(catalog): reflect the newly selected kind immediately on switch#690
kaviththiranga merged 1 commit into
openchoreo:mainfrom
kaviththiranga:fix-cache-loader

Conversation

@kaviththiranga

@kaviththiranga kaviththiranga commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Switching the Kind filter now updates the title, columns and rows to the picked kind at once instead of lingering on the previous kind while it loads. A cached kind paints instantly from the seed; an uncached kind clears the old rows and shows the full-page loader under the new kind's title.

The picker publishes its selection to a shared SelectedKindContext synchronously, since useEntityList's filters.kind and the URL only settle after the fetch resolves. CatalogCardList reads that context so a kind switch is detected right away, and prefers a kind-matched cache seed over the held previous-kind rows.

Before:

Screen.Recording.2026-07-16.at.14.51.22.mov

After:

Screen.Recording.2026-07-16.at.14.20.55.mov

Summary by CodeRabbit

  • New Features

    • Catalog pages now display cached results immediately and refresh in the background.
    • Returning to catalog pages reduces loading delays and skeleton flashes.
    • Breadcrumb entity lists reopen quickly using cached data while checking for updates.
  • Bug Fixes

    • Catalog changes now appear immediately after write operations.
    • Switching catalog kinds updates titles and cached results instantly.
    • Uncached kinds show a clear loading state without displaying rows from the previous kind.
    • Background refresh activity is now represented with an inline spinner.

Switching the Kind filter now updates the title, columns and rows to the picked
kind at once instead of lingering on the previous kind while it loads. A cached
kind paints instantly from the seed; an uncached kind clears the old rows and
shows the full-page loader under the new kind's title.

The picker publishes its selection to a shared SelectedKindContext synchronously,
since useEntityList's filters.kind and the URL only settle after the fetch
resolves. CatalogCardList reads that context so a kind switch is detected right
away, and prefers a kind-matched cache seed over the held previous-kind rows.

Signed-off-by: Kavith Lokuhewage <kaviththiranga@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Catalog kind selection is synchronized through shared context. Catalog rendering now prioritizes the selected kind, excludes held entities from other kinds, and distinguishes cached from uncached switches through selected-kind-scoped load state.

Changes

Catalog kind switching

Layer / File(s) Summary
Selected kind context wiring
packages/app/src/components/catalog/SelectedKindContext.tsx, packages/app/src/components/catalog/CustomCatalogPage.tsx, packages/app/src/components/catalog/ChoreoEntityKindPicker.tsx, packages/app/src/components/catalog/SelectedKindContext.test.tsx
Adds normalized selected-kind context state, wraps the catalog page with its provider, publishes picker changes, and tests provider and fallback behavior.
Kind-specific rendering and load state
packages/app/src/components/catalog/CatalogCardList.tsx, packages/app/src/components/catalog/catalogLoadState.ts, packages/app/src/components/catalog/catalogLoadState.test.ts, .changeset/cache-catalog-always-revalidate.md
Catalog rendering prioritizes the shared selected kind, filters held entities by kind, uses cached rows when available, and treats empty selected-kind display data as a first load. Tests cover cached and uncached switches.tempo

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: sameerajayasoma, mirage20, stefinie123

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change, but it omits most required template sections such as Purpose, Goals, Release note, tests, and security checks. Populate the template sections with Purpose, Goals, Approach, User stories, Release note, Documentation, tests, Security checks, and other applicable fields.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main catalog kind-switch behavior change.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 42.42424% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ges/app/src/components/catalog/CatalogCardList.tsx 13.33% 13 Missing ⚠️
.../src/components/catalog/ChoreoEntityKindPicker.tsx 0.00% 3 Missing and 1 partial ⚠️
...s/app/src/components/catalog/CustomCatalogPage.tsx 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/app/src/components/catalog/SelectedKindContext.tsx (1)

43-50: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Stabilize context references to prevent excessive effect executions.

Defining the fallback object inline within useSelectedKind causes it to return a new object reference on every render when used outside a provider. Downstream components (like ChoreoEntityKindPicker) that place setSelectedKind in a useEffect dependency array will unnecessarily re-execute that effect on every render.

Similarly, defining the setter inline within the provider's useMemo means the function identity changes every time selectedKind changes.

Extracting the fallback object and wrapping the setter in useCallback will stabilize these references.

♻️ Proposed refactor
+const defaultSelectedKindContextValue: SelectedKindContextValue = {
+  selectedKind: undefined,
+  setSelectedKind: () => {},
+};
+
 /**
  * Holds the synchronously-selected catalog kind. Mount inside the
  * `EntityListProvider` so it wraps the picker(s) and the list.
  */
 export const SelectedKindProvider = ({ children }: PropsWithChildren<{}>) => {
   const [selectedKind, setSelectedKindState] = useState<string | undefined>(
     undefined,
   );
 
+  const setSelectedKind = useCallback((kind: string) => {
+    setSelectedKindState(kind.toLowerCase());
+  }, []);
+
   const value = useMemo<SelectedKindContextValue>(
     () => ({
       selectedKind,
-      setSelectedKind: (kind: string) =>
-        setSelectedKindState(kind.toLowerCase()),
+      setSelectedKind,
     }),
-    [selectedKind],
+    [selectedKind, setSelectedKind],
   );
 
   return (
// ... further down ...
 export function useSelectedKind(): SelectedKindContextValue {
   return (
-    useContext(SelectedKindContext) ?? {
-      selectedKind: undefined,
-      setSelectedKind: () => {},
-    }
+    useContext(SelectedKindContext) ?? defaultSelectedKindContextValue
   );
 }

Also applies to: 64-71

🤖 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 `@packages/app/src/components/catalog/SelectedKindContext.tsx` around lines 43
- 50, Stabilize both context usage paths: extract the fallback value returned by
useSelectedKind into a module-level stable object, and define the provider’s
setSelectedKind callback with useCallback so its identity does not change when
selectedKind updates. Update the useMemo dependencies to reuse that stable
callback while preserving lowercase normalization.
🤖 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 `@packages/app/src/components/catalog/SelectedKindContext.tsx`:
- Around line 43-50: Stabilize both context usage paths: extract the fallback
value returned by useSelectedKind into a module-level stable object, and define
the provider’s setSelectedKind callback with useCallback so its identity does
not change when selectedKind updates. Update the useMemo dependencies to reuse
that stable callback while preserving lowercase normalization.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a2784856-d5ca-42d2-8b0a-2b8557679694

📥 Commits

Reviewing files that changed from the base of the PR and between 9cbc6f9 and b59b691.

📒 Files selected for processing (8)
  • .changeset/cache-catalog-always-revalidate.md
  • packages/app/src/components/catalog/CatalogCardList.tsx
  • packages/app/src/components/catalog/ChoreoEntityKindPicker.tsx
  • packages/app/src/components/catalog/CustomCatalogPage.tsx
  • packages/app/src/components/catalog/SelectedKindContext.test.tsx
  • packages/app/src/components/catalog/SelectedKindContext.tsx
  • packages/app/src/components/catalog/catalogLoadState.test.ts
  • packages/app/src/components/catalog/catalogLoadState.ts

@kaviththiranga
kaviththiranga merged commit 9994b59 into openchoreo:main Jul 17, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants