Skip to content

fix/regression view refetch#2914

Merged
adityathebe merged 3 commits intomainfrom
fix/regression-view-refetch
Mar 10, 2026
Merged

fix/regression view refetch#2914
adityathebe merged 3 commits intomainfrom
fix/regression-view-refetch

Conversation

@adityathebe
Copy link
Member

@adityathebe adityathebe commented Mar 10, 2026

resolves: #2913

Summary by CodeRabbit

  • Tests

    • Added comprehensive test coverage for template variable changes in view containers, verifying proper re-rendering behavior.
  • Bug Fixes

    • Fixed views failing to re-render when template variables are updated through URL parameters.
    • Template variable changes now correctly refresh view data and update the displayed content.

@vercel
Copy link

vercel bot commented Mar 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
aws-preview Ready Ready Preview Mar 10, 2026 5:49pm
flanksource-ui Ready Ready Preview Mar 10, 2026 5:49pm

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 10, 2026

Walkthrough

The changes introduce template variable handling via URL search parameters in the view data management system. A new test file validates ViewContainer's behavior when namespace template variables update through URL changes. The useViewData hook is enhanced to parse URL-prefixed view variables and incorporate them into the query key for proper cache invalidation when variables change.

Changes

Cohort / File(s) Summary
Template Variable URL Parsing
src/pages/views/hooks/useViewData.ts
Adds parsing of URL-prefixed view variables via usePrefixedSearchParams. Constructs standardModeVariables from prefixed search params, generates a standardModeVariablesKey from sorted/encoded pairs, and updates viewQueryKey for non-display-plugin mode to include this key, ensuring query cache invalidation when variables change.
ViewContainer Template Variable Tests
src/pages/views/components/__tests__/ViewContainer.templateVariables.unit.test.tsx
New test suite validating ViewContainer's re-render behavior when template variables update via URL search parameters. Tests initial render with default namespace and verifies fingerprint updates when the viewvar__namespace parameter changes.

Sequence Diagram

sequenceDiagram
    actor User
    participant URL as URL/SearchParams
    participant ViewContainer
    participant useViewData as useViewData Hook
    participant QuerySystem as React Query
    participant API
    
    User->>URL: Updates viewvar__namespace param
    URL->>ViewContainer: Search params change
    ViewContainer->>useViewData: Hook re-evaluates
    useViewData->>useViewData: Parse URL-prefixed variables<br/>(VIEW_VAR_PREFIX)
    useViewData->>useViewData: Build standardModeVariablesKey<br/>(sorted/encoded pairs)
    useViewData->>QuerySystem: viewQueryKey updated<br/>(includes variables)
    QuerySystem->>API: Fetch view data with new variables
    API-->>QuerySystem: Return updated fingerprint
    QuerySystem-->>ViewContainer: New data available
    ViewContainer->>ViewContainer: Re-render with updated state
Loading

Possibly related PRs

Suggested reviewers

  • moshloop
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix/regression view refetch' is vague and uses non-descriptive phrasing that doesn't clearly convey the specific change being made. Improve the title to be more specific and descriptive of the main change, such as 'Parse URL-prefixed view variables for template updates' or 'Fix view refetch when namespace template variable changes'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/regression-view-refetch

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/pages/views/hooks/useViewData.ts`:
- Around line 110-116: The aggregated fetch and computed variables are not
receiving updated standard-mode URL variables; when isDisplayPluginMode is
false, pass standardModeVariables into the aggregated variables path and into
useAggregatedViewVariables so sectionData and aggregatedCurrentVariables are
computed with the same template values as the primary getViewDataById refetch;
update the viewQueryKey branch for standard mode to include
standardModeVariables (or the actual variables object) instead of
standardModeVariablesKey and ensure the call site of useAggregatedViewVariables
uses that same variables value when isDisplayPluginMode === false (affecting the
code around viewQueryKey, variables, and the useAggregatedViewVariables
invocation, also mirror the same change at the other block mentioned).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 295fd69e-5f0f-4c54-9ee9-cc368ad48c23

📥 Commits

Reviewing files that changed from the base of the PR and between 0aec0bd and 59e4342.

📒 Files selected for processing (2)
  • src/pages/views/components/__tests__/ViewContainer.templateVariables.unit.test.tsx
  • src/pages/views/hooks/useViewData.ts

@adityathebe adityathebe merged commit d46f7a7 into main Mar 10, 2026
14 of 16 checks passed
@adityathebe adityathebe deleted the fix/regression-view-refetch branch March 10, 2026 18:05
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.

Regresion in view templating variables

1 participant