Skip to content

fix(VE-6191): clear field schema map on variant change#432

Merged
faraazb merged 2 commits intodevelop_v3from
VE-6191-enable-disable-field-variant-switch
May 6, 2025
Merged

fix(VE-6191): clear field schema map on variant change#432
faraazb merged 2 commits intodevelop_v3from
VE-6191-enable-disable-field-variant-switch

Conversation

@faraazb
Copy link
Copy Markdown
Contributor

@faraazb faraazb commented Apr 23, 2025

Clear field schema map on variant change as it contains a field - isUnlinkedVariant which depends on the current selected variant for its value.
The "get-variant-id" message is received from "Visual Builder" whenever the variant is changed.

Clear field schema map on variant change as it contains
a field - isUnlinkedVariant which depends on the current
selected variant for its value
@faraazb faraazb requested a review from a team as a code owner April 23, 2025 11:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue by ensuring that the field schema map is fully cleared when the variant changes, preventing stale field state from affecting the UI.

  • Clears both fieldSchema and fieldSchemaPromise in FieldSchemaMap.
  • Updates the useVariantFieldsPostMessageEvent event handler to call FieldSchemaMap.clear().

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/visualBuilder/utils/fieldSchemaMap.ts Updates the clear() method to reset both fieldSchema and fieldSchemaPromise.
src/visualBuilder/eventManager/useVariantsPostMessageEvent.ts Adds a call to FieldSchemaMap.clear() upon variant change to clear cached fields.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 23, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 70.7% 8224 / 11631
🔵 Statements 70.7% 8224 / 11631
🔵 Functions 69.24% 286 / 413
🔵 Branches 84.75% 1006 / 1187
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/visualBuilder/eventManager/useVariantsPostMessageEvent.ts 100% 95.23% 100% 100%
src/visualBuilder/utils/fieldSchemaMap.ts 100% 90.9% 100% 100%
Generated in workflow #399 for commit 5d4a695 by the Vitest Coverage Report Action

Copy link
Copy Markdown
Contributor

@hiteshshetty-dev hiteshshetty-dev left a comment

Choose a reason for hiding this comment

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

LGTM!!

Copy link
Copy Markdown
Contributor

@hiteshshetty-dev hiteshshetty-dev left a comment

Choose a reason for hiding this comment

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

Let's add test cases

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where the field schema cache is not fully cleared when the variant changes, which can lead to incorrect field values.

  • Clear the field schema promise map in the FieldSchemaMap.clear() method.
  • Add a new test to verify that the promise map is cleared.
  • Export several functions and call FieldSchemaMap.clear() in the variant post message event handler.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/visualBuilder/utils/fieldSchemaMap.ts Updated clear method to reset both field schema and promise map
src/visualBuilder/utils/test/fieldSchemaMap.test.ts Added test to verify the clearing of the promise map
src/visualBuilder/eventManager/useVariantsPostMessageEvent.ts Exported several functions and added a call to clear the field schema cache on variant change

Comment thread src/visualBuilder/eventManager/useVariantsPostMessageEvent.ts
@faraazb faraazb changed the title fix: clear field schema map on variant change fix(VE-6191): clear field schema map on variant change May 5, 2025
Copy link
Copy Markdown
Contributor

@hiteshshetty-dev hiteshshetty-dev left a comment

Choose a reason for hiding this comment

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

LGTM!!

@faraazb faraazb merged commit be0e784 into develop_v3 May 6, 2025
8 checks passed
@faraazb faraazb deleted the VE-6191-enable-disable-field-variant-switch branch May 6, 2025 09:00
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.

4 participants