feat: adding post messages to link unlinked ct to variant group#514
Conversation
csAyushDubey
left a comment
There was a problem hiding this comment.
Left a few comments
| {(() => { | ||
| const [before, after] = reason.split( | ||
| /here/i | ||
| ); |
There was a problem hiding this comment.
We might not need regex here.
There was a problem hiding this comment.
@karancs06 - I missed this in my earlier review but why do we need regex here?
There was a problem hiding this comment.
we have changed that while changing to constants
|
|
||
| const handleLinkVariant = async () => { | ||
| if (fieldSchema.field_metadata?.canLinkVariant) { | ||
| try { |
There was a problem hiding this comment.
The check can be done inside the try block.
| if (fieldSchema.field_metadata?.canLinkVariant) { | ||
| try { | ||
| const result = await visualBuilderPostMessage?.send<{ | ||
| type: "success" | "error"; |
There was a problem hiding this comment.
Create constants for both success & error.
| } | ||
|
|
||
| // If linking was successful and requires revalidation, revalidate | ||
| if (result.type === "success") { |
There was a problem hiding this comment.
reuse the success constant here instead of creating a new string.
| ); | ||
|
|
||
| // If the modal was closed or linking failed, do nothing | ||
| if (!result || result.type === "error") { |
There was a problem hiding this comment.
reuse the error constant here instead of creating a new string.
| if (result.type === "success") { | ||
| await handleRevalidateFieldData(); | ||
| } | ||
| } catch (message) { |
There was a problem hiding this comment.
| } catch (message) { | |
| } catch (error) { |
| let overlayWrapper: HTMLDivElement; | ||
| let focusedToolbar: HTMLDivElement; | ||
|
|
||
| beforeEach(() => { |
There was a problem hiding this comment.
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?
| focusedElement?.getAttribute("data-cslp-unique-id") || null; | ||
| const shouldRefocus = !!focusedElement; | ||
|
|
||
| try { |
There was a problem hiding this comment.
Having multiple nested try catch blocks is a bad practice and creates code readability issues.
Please refactor this code.
| 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." |
There was a problem hiding this comment.
I would expect all these messages to come from constants. I have already mentioned the benefits of doing so in the above comments.
| if (flags.updateRestrictDueToUnlinkVariant) { | ||
| let reason = DisableReason.UnlinkedVariant; | ||
| if (flags.canLinkVariant) { | ||
| reason += ` ${DisableReason.CanLinkVaraint}`; |
There was a problem hiding this comment.
NIT: Typo
| reason += ` ${DisableReason.CanLinkVaraint}`; | |
| reason += ` ${DisableReason.CanLinkVariant}`; |
| return DisableReason.UnlinkedVariant; | ||
| if (flags.updateRestrictDueToUnlinkVariant) { | ||
| let reason = DisableReason.UnlinkedVariant; | ||
| if (flags.canLinkVariant) { |
There was a problem hiding this comment.
String concatenation logic can be improved & made cleaner:
return flags.canLinkVariant
? `${DisableReason.UnlinkedVariant} ${DisableReason.CanLinkVariant}`
: `${DisableReason.UnlinkedVariant} ${DisableReason.CannotLinkVariant}`;
| {(() => { | ||
| const [before, after] = reason.split( | ||
| /here/i | ||
| ); |
There was a problem hiding this comment.
@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", |
There was a problem hiding this comment.
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", |
| ); | ||
| expect(result.isDisabled).toBe(false); | ||
| expect(result.reason).toBe(""); | ||
| expect(result.reason).toBe(DisableReason.None); |
There was a problem hiding this comment.
Do we really need a constant for a blank string.
| 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" }) |
There was a problem hiding this comment.
const REVIEW_STAGES = Object.freeze({
UNKNOWN: 'Unknown',
FINAL_REVIEW: 'Final Review',
IN_REVIEW: 'In Review',
// add other values as needed.
});
|
|
||
| export const DATA_CSLP_ATTR_SELECTOR = "data-cslp"; | ||
|
|
||
| export const RESULT_TYPES = { |
There was a problem hiding this comment.
export const RESULT_TYPES = Object.freeze({
SUCCESS: 'success',
ERROR: 'error',
});
| import { WorkflowStageDetails } from "./getWorkflowStageDetails"; | ||
|
|
||
| const DisableReason = { | ||
| export const DisableReason = { |
There was a problem hiding this comment.
Constants should be named in UPPER CASE.
| export const DisableReason = { | |
| export const REASON_FOR_DISABLING = { |
|
|
||
| const DisableReason = { | ||
| export const DisableReason = { | ||
| ReadOnly: "You have only read access to this field", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
All constants to be written in UPPERCASE.
| LocalizedEntry: "Editing this field is restricted in localized entries", | |
| LOCALIZED_ENTRY: "Editing this field is restricted in localized entries", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Rename this to something more meaningful.
Screen.Recording.2025-10-14.at.3.36.48.PM.mov