Skip to content

feat: adding post messages to link unlinked ct to variant group#514

Merged
karancs06 merged 15 commits intodevelop_v4from
VB-530-support-to-link-unlinked-ct-to-variant-group
Nov 13, 2025
Merged

feat: adding post messages to link unlinked ct to variant group#514
karancs06 merged 15 commits intodevelop_v4from
VB-530-support-to-link-unlinked-ct-to-variant-group

Conversation

@karancs06
Copy link
Copy Markdown
Contributor

@karancs06 karancs06 commented Oct 10, 2025

Screen.Recording.2025-10-14.at.3.36.48.PM.mov

@karancs06 karancs06 requested a review from a team as a code owner October 10, 2025 09:46
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Oct 10, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 72.6% 9531 / 13127
🔵 Statements 72.6% 9531 / 13127
🔵 Functions 71.51% 339 / 474
🔵 Branches 84.05% 1207 / 1436
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/visualBuilder/index.ts 56.87% 66.66% 42.85% 56.87% 98-105, 108-112, 115-127, 130-203, 209-241, 249-271, 322-325, 328-329, 379-385
src/visualBuilder/visualBuilder.style.ts 100% 100% 100% 100%
src/visualBuilder/components/fieldLabelWrapper.tsx 70.15% 57.44% 72.72% 70.15% 48-50, 58-60, 142-153, 156-160, 179-208, 221-252, 277-278, 282-287, 291, 356-358, 364-382, 387-399
src/visualBuilder/eventManager/useRevalidateFieldDataPostMessageEvent.ts 100% 91.3% 80% 100%
src/visualBuilder/utils/constants.ts 100% 100% 100% 100%
src/visualBuilder/utils/fieldSchemaMap.ts 94.73% 100% 87.5% 94.73% 98-100
src/visualBuilder/utils/isFieldDisabled.ts 98.44% 96.07% 100% 98.44% 129-130
src/visualBuilder/utils/types/index.types.ts 100% 100% 100% 100%
src/visualBuilder/utils/types/postMessage.types.ts 100% 100% 100% 100%
Generated in workflow #614 for commit 388370e by the Vitest Coverage Report Action

Copy link
Copy Markdown
Contributor

@csAyushDubey csAyushDubey left a comment

Choose a reason for hiding this comment

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

Left a few comments

Comment thread src/visualBuilder/components/fieldLabelWrapper.tsx Outdated
Comment thread src/visualBuilder/eventManager/useRevalidateFieldDataPostMessageEvent.ts Outdated
Comment thread src/visualBuilder/utils/isFieldDisabled.ts Outdated
Comment thread src/visualBuilder/utils/isFieldDisabled.ts Outdated
Base automatically changed from develop_v4 to stage_v4 October 14, 2025 10:07
@karancs06 karancs06 changed the base branch from stage_v4 to develop_v4 October 15, 2025 04:40
Copy link
Copy Markdown
Contributor

@csAyushDubey csAyushDubey left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread src/visualBuilder/index.ts
Comment thread src/visualBuilder/visualBuilder.style.ts Outdated
Comment thread src/visualBuilder/components/fieldLabelWrapper.tsx Outdated
{(() => {
const [before, after] = reason.split(
/here/i
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We might not need regex here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@karancs06 - I missed this in my earlier review but why do we need regex here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we have changed that while changing to constants

Comment thread src/visualBuilder/eventManager/useRevalidateFieldDataPostMessageEvent.ts Outdated
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!!


const handleLinkVariant = async () => {
if (fieldSchema.field_metadata?.canLinkVariant) {
try {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The check can be done inside the try block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

if (fieldSchema.field_metadata?.canLinkVariant) {
try {
const result = await visualBuilderPostMessage?.send<{
type: "success" | "error";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Create constants for both success & error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

}

// If linking was successful and requires revalidation, revalidate
if (result.type === "success") {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

reuse the success constant here instead of creating a new string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

);

// If the modal was closed or linking failed, do nothing
if (!result || result.type === "error") {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

reuse the error constant here instead of creating a new string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

if (result.type === "success") {
await handleRevalidateFieldData();
}
} catch (message) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
} catch (message) {
} catch (error) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

let overlayWrapper: HTMLDivElement;
let focusedToolbar: HTMLDivElement;

beforeEach(() => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we need this before every test case?
Can the test cases be refactored to avoid doing this before every test and instead do it once for the class?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

focusedElement?.getAttribute("data-cslp-unique-id") || null;
const shouldRefocus = !!focusedElement;

try {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Having multiple nested try catch blocks is a bad practice and creates code readability issues.
Please refactor this code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

expect(result.isDisabled).toBe(true);
expect(result.reason).toBe(
"This field is not editable as it is not linked to the selected variant"
"This field is not editable as it is not linked to the selected variant. Contact your stack admin or owner to link it."
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would expect all these messages to come from constants. I have already mentioned the benefits of doing so in the above comments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

if (flags.updateRestrictDueToUnlinkVariant) {
let reason = DisableReason.UnlinkedVariant;
if (flags.canLinkVariant) {
reason += ` ${DisableReason.CanLinkVaraint}`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

NIT: Typo

Suggested change
reason += ` ${DisableReason.CanLinkVaraint}`;
reason += ` ${DisableReason.CanLinkVariant}`;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

return DisableReason.UnlinkedVariant;
if (flags.updateRestrictDueToUnlinkVariant) {
let reason = DisableReason.UnlinkedVariant;
if (flags.canLinkVariant) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

String concatenation logic can be improved & made cleaner:

return flags.canLinkVariant
  ? `${DisableReason.UnlinkedVariant} ${DisableReason.CanLinkVariant}`
  : `${DisableReason.UnlinkedVariant} ${DisableReason.CannotLinkVariant}`;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

{(() => {
const [before, after] = reason.split(
/here/i
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@karancs06 - I missed this in my earlier review but why do we need regex here?

expect(result.reason).toBe(
"You do not have Edit access to this entry on the 'Review Stage' workflow stage"
DisableReason.WorkflowStagePermission({
stageName: "Review Stage",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

stageNames can be come from an ENUM or constant file.

expect(result.reason).toBe(
"Editing is restricted for your role or by the rules for the 'Final Review' stage. Contact your admin for edit access."
DisableReason.EntryUpdateRestrictedRoleAndWorkflowStage({
stageName: "Final Review",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same as above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

);
expect(result.isDisabled).toBe(false);
expect(result.reason).toBe("");
expect(result.reason).toBe(DisableReason.None);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we really need a constant for a blank string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

expect(result.isDisabled).toBe(true);
expect(result.reason).toBe(
"You do not have Edit access to this entry on the 'Unknown' workflow stage"
DisableReason.WorkflowStagePermission({ stageName: "Unknown" })
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

const REVIEW_STAGES = Object.freeze({
  UNKNOWN: 'Unknown',
  FINAL_REVIEW: 'Final Review',
  IN_REVIEW: 'In Review',
// add other values as needed.
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread src/visualBuilder/utils/constants.ts Outdated

export const DATA_CSLP_ATTR_SELECTOR = "data-cslp";

export const RESULT_TYPES = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

export const RESULT_TYPES = Object.freeze({
  SUCCESS: 'success',
  ERROR: 'error',
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

import { WorkflowStageDetails } from "./getWorkflowStageDetails";

const DisableReason = {
export const DisableReason = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Constants should be named in UPPER CASE.

Suggested change
export const DisableReason = {
export const REASON_FOR_DISABLING = {


const DisableReason = {
export const DisableReason = {
ReadOnly: "You have only read access to this field",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

READ_ONLY

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cannot change this constant as it would change a lot in the code base and also edit files are not intended to be editted in this pr

const DisableReason = {
export const DisableReason = {
ReadOnly: "You have only read access to this field",
LocalizedEntry: "Editing this field is restricted in localized entries",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All constants to be written in UPPERCASE.

Suggested change
LocalizedEntry: "Editing this field is restricted in localized entries",
LOCALIZED_ENTRY: "Editing this field is restricted in localized entries",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cannot change this constant as it would change a lot in the code base and also edit files are not intended to be editted in this pr

"This field is not editable as it is not linked to the selected variant.",
CanLinkVaraint: "Click here to link a variant",
CanLinkVariant: "Click here to link a variant",
SplitOn: "here",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rename this to something more meaningful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@karancs06 karancs06 merged commit 4c9d670 into develop_v4 Nov 13, 2025
10 checks passed
@karancs06 karancs06 deleted the VB-530-support-to-link-unlinked-ct-to-variant-group branch November 13, 2025 07:46
@hiteshshetty-dev hiteshshetty-dev restored the VB-530-support-to-link-unlinked-ct-to-variant-group branch December 5, 2025 08:14
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