Skip to content

Commit

Permalink
Merge pull request #291 from contentstack/VE-3937
Browse files Browse the repository at this point in the history
fix remove highlight variant field classes
  • Loading branch information
srinad007 authored Nov 11, 2024
2 parents 94891b9 + 0b02a1d commit 5ffee44
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/visualBuilder/eventManager/useVariantsPostMessageEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ interface VariantFieldsEvent {
};
};
}
interface RemoveVariantFieldsEvent {
data: {
onlyHighlighted?: boolean;
};
}

interface AudienceEvent {
data: {
Expand Down Expand Up @@ -51,18 +56,29 @@ function addVariantFieldClass(
});
}

function removeVariantFieldClass(): void {
const variantAndBaseFieldElements = document.querySelectorAll(
".visual-builder__disabled-variant-field, .visual-builder__variant-field, .visual-builder__base-field"
);
variantAndBaseFieldElements.forEach((element) => {
element.classList.remove(
"visual-builder__disabled-variant-field",
"visual-builder__variant-field",
visualBuilderStyles()["visual-builder__variant-field"],
"visual-builder__base-field"
function removeVariantFieldClass(onlyHighlighted: boolean = false): void {
if (onlyHighlighted) {
const variantElements = document.querySelectorAll(
`.${visualBuilderStyles()["visual-builder__variant-field"]}`
);
});
variantElements.forEach((element) => {
element.classList.remove(
visualBuilderStyles()["visual-builder__variant-field"]
);
});
} else {
const variantAndBaseFieldElements = document.querySelectorAll(
".visual-builder__disabled-variant-field, .visual-builder__variant-field, .visual-builder__base-field"
);
variantAndBaseFieldElements.forEach((element) => {
element.classList.remove(
"visual-builder__disabled-variant-field",
"visual-builder__variant-field",
visualBuilderStyles()["visual-builder__variant-field"],
"visual-builder__base-field"
);
});
}
}

function setAudienceMode(mode: boolean): void {
Expand Down Expand Up @@ -106,8 +122,8 @@ export function useVariantFieldsPostMessageEvent(): void {
);
visualBuilderPostMessage?.on(
VisualBuilderPostMessageEvents.REMOVE_VARIANT_FIELDS,
() => {
removeVariantFieldClass();
(event: RemoveVariantFieldsEvent) => {
removeVariantFieldClass(event?.data?.onlyHighlighted);
}
);
}

0 comments on commit 5ffee44

Please sign in to comment.