Skip to content

Commit

Permalink
Merge branch 'main' into BI/dt-2496-bug-aauser-i-see-a-bug-when-renam…
Browse files Browse the repository at this point in the history
  • Loading branch information
BohdanOne committed Dec 19, 2024
2 parents 675284f + 1dc83cf commit d6d300a
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 13 deletions.
9 changes: 8 additions & 1 deletion packages/manager/src/managers/telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const SegmentEventType = {
sharedOnboarding_step_opened: "shared-onboarding:step-opened",
sharedOnboarding_step_completed: "shared-onboarding:step-completed",
sharedOnboarding_completed: "shared-onboarding:completed",
sharedOnboarding_tutorial: "shared-onboarding:follow-tutorial",
} as const;
type SegmentEventTypes =
(typeof SegmentEventType)[keyof typeof SegmentEventType];
Expand Down Expand Up @@ -107,6 +108,8 @@ export const HumanSegmentEventType = {
"Prismic Onboarding Guide Step Open",
[SegmentEventType.sharedOnboarding_completed]:
"Prismic Onboarding Guide Completed",
[SegmentEventType.sharedOnboarding_tutorial]:
"Prismic Onboarding Guide Follow Tutorial",
} as const;

export type HumanSegmentEventTypes =
Expand Down Expand Up @@ -387,7 +390,10 @@ type SliceMachineSharedOnboardingCompleted = SegmentEvent<
typeof SegmentEventType.sharedOnboarding_completed,
SharedOnboardingProperties
>;

type SliceMachineSharedOnboardingTutorial = SegmentEvent<
typeof SegmentEventType.sharedOnboarding_tutorial,
SharedOnboardingProperties
>;
type SliceMachinePostPushEmptyStateCtaClicked = SegmentEvent<
typeof SegmentEventType.postPush_emptyStateCtaClicked
>;
Expand Down Expand Up @@ -441,6 +447,7 @@ export type SegmentEvents =
| SliceMachineSharedOnboardingStepOpened
| SliceMachineSharedOnboardingStepCompleted
| SliceMachineSharedOnboardingCompleted
| SliceMachineSharedOnboardingTutorial
| SliceMachinePostPushEmptyStateCtaClicked
| SliceMachinePostPushToastCtaClicked
| SliceMachineExperimentExposure;
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,18 @@ export const CreateCustomTypeModal: React.FC<CreateCustomTypeModalProps> = ({
})} name is already taken.`;
}

if (["update", "insert"].includes(label.toLowerCase())) {
errors.label = `Name "${label}" is reserved for Slice Machine use.`;
}

if (!id || !id.length) {
errors.id = "ID cannot be empty.";
}

if (["update", "insert"].includes(id.toLowerCase())) {
errors.id = `Id "${id}" is reserved for Slice Machine use.`;
}

// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (!errors.id && id && !API_ID_REGEX.exec(id)) {
errors.id = "Invalid id: No special characters allowed.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export const RenameCustomTypeModal: React.FC<RenameCustomTypeModalProps> = ({
})} name is already taken.`;
}

if (["update", "insert"].includes(newName.toLowerCase())) {
errors.customTypeName = `Name "${newName}" is reserved for Slice Machine use.`;
}

return Object.keys(errors).length > 0 ? errors : undefined;
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ export function validateSliceModalValues(
if (!sliceName) {
return { sliceName: "Cannot be empty" };
}
if (RESERVED_SLICE_NAME.includes(sliceName.toLowerCase())) {
return {
sliceName: `Name "${sliceName}" is reserved for Slice Machine use.`,
};
}
if (!API_ID_REGEX.exec(sliceName)) {
return { sliceName: "No special characters allowed" };
return { sliceName: "No special characters allowed." };
}
const cased = startCase(camelCase(sliceName)).replace(/\s/gm, "");
if (cased !== sliceName.trim()) {
return { sliceName: "Value has to be PascalCased" };
return { sliceName: "Value has to be PascalCased." };
}
// See: #599
if (sliceName.match(/^\d/)) {
return { sliceName: "Value cannot start with a number" };
}
if (RESERVED_SLICE_NAME.includes(sliceName)) {
return {
sliceName: `${sliceName} is reserved for Slice Machine use`,
};
return { sliceName: "Value cannot start with a number." };
}

const localNames = localLibs.flatMap((lib) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/slice-machine/src/legacy/lib/consts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// A list of slice names that are reserved for internal uses.
export const RESERVED_SLICE_NAME = ["components"];
export const RESERVED_SLICE_NAME = ["components", "update", "insert"];

export const acceptedImagesTypes = ["png", "jpg", "jpeg"];

Expand Down
17 changes: 17 additions & 0 deletions playwright/tests/customTypes/customTypesTable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ test("I cannot create a custom type with a name or id already used", async ({
).toBeDisabled();
});

test("I cannot create a custom type with a name update or insert", async ({
customTypesTablePage,
}) => {
await customTypesTablePage.goto();
await customTypesTablePage.openCreateDialog();

await expect(customTypesTablePage.createTypeDialog.title).toBeVisible();
await customTypesTablePage.createTypeDialog.nameInput.fill("update");
await expect(
customTypesTablePage.createTypeDialog.submitButton,
).toBeDisabled();
await customTypesTablePage.createTypeDialog.nameInput.fill("insert");
await expect(
customTypesTablePage.createTypeDialog.submitButton,
).toBeDisabled();
});

test("I can rename a custom type", async ({
reusableCustomType,
customTypesTablePage,
Expand Down
13 changes: 13 additions & 0 deletions playwright/tests/pageTypes/pageTypesTable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ test("I cannot create a page type with a name or id already used", async ({
await expect(pageTypesTablePage.createTypeDialog.submitButton).toBeDisabled();
});

test("I cannot create a page type with a name update or insert", async ({
pageTypesTablePage,
}) => {
await pageTypesTablePage.goto();
await pageTypesTablePage.openCreateDialog();

await expect(pageTypesTablePage.createTypeDialog.title).toBeVisible();
await pageTypesTablePage.createTypeDialog.nameInput.fill("update");
await expect(pageTypesTablePage.createTypeDialog.submitButton).toBeDisabled();
await pageTypesTablePage.createTypeDialog.nameInput.fill("insert");
await expect(pageTypesTablePage.createTypeDialog.submitButton).toBeDisabled();
});

test("I can rename a page type", async ({
pageTypesTablePage,
reusablePageType,
Expand Down
16 changes: 16 additions & 0 deletions playwright/tests/slices/slicesList.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ test("I cannot rename a slice with a name starting with a number", async ({
await expect(slicesListPage.renameSliceDialog.submitButton).toBeDisabled();
});

test("I cannot create a slice with a restricted name ", async ({
slicesListPage,
}) => {
await slicesListPage.goto();
await slicesListPage.openCreateDialog();

const { nameInput, submitButton } = slicesListPage.createSliceDialog;

await nameInput.fill("components");
await expect(submitButton).toBeDisabled();
await nameInput.fill("update");
await expect(submitButton).toBeDisabled();
await nameInput.fill("insert");
await expect(submitButton).toBeDisabled();
});

test("I cannot create two slices with the same name", async ({
sliceBuilderPage,
slicesListPage,
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,12 @@ __metadata:
linkType: hard

"@aws-sdk/types@npm:^3.222.0":
version: 3.714.0
resolution: "@aws-sdk/types@npm:3.714.0"
version: 3.713.0
resolution: "@aws-sdk/types@npm:3.713.0"
dependencies:
"@smithy/types": ^3.7.2
tslib: ^2.6.2
checksum: 2cc6ea0ec3331a24b5cc6dfba0963ff5a673c7149eadbaf9f9ab8bfdfaa56a7a02a7df80f6921108aca3ef022047f931fd8f36b34bfe6c963e8606f72e068143
checksum: 4e2d211838da5f64bb04693b0a0ab198e28fa1e1d1e394d96b91c87e07af525211bd88f2b91e9619158b595c23d688f2dc2de44fe2d01e8c21ef9a1d7ba0cece
languageName: node
linkType: hard

Expand Down

0 comments on commit d6d300a

Please sign in to comment.