Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ const CustomCodeSectionWrapper = ({
/**
* The CustomCodeSection component allows you to add custom HTML, CSS, and JavaScript to your page.
* It is useful for integrating third-party widgets or custom scripts that are not supported by the visual editor natively.
* Only available with additional feature flag enabled.
*/
export const CustomCodeSection: ComponentConfig<{
props: CustomCodeSectionProps;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/visual-editor/src/docs/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ If 'true', the component is visible on the live page; if 'false', it's hidden.

## CustomCodeSection

The CustomCodeSection component allows you to add custom HTML, CSS, and JavaScript to your page. It is useful for integrating third-party widgets or custom scripts that are not supported by the visual editor natively. Only available with additional feature flag enabled.
The CustomCodeSection component allows you to add custom HTML, CSS, and JavaScript to your page. It is useful for integrating third-party widgets or custom scripts that are not supported by the visual editor natively.

![Preview of the CustomCodeSection component](../components/testing/screenshots/CustomCodeSection/%5Bdesktop%5D%20default%20props%20with%20empty%20document.png)

Expand Down
36 changes: 2 additions & 34 deletions packages/visual-editor/src/utils/filterComponents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,6 @@ describe("filterComponentsFromConfig", () => {
it("filters gated components and categories when no feature flags are enabled", () => {
const config = filterComponentsFromConfig(mainConfig);

// Test component registry
expect(Object.keys(config.components)).toContain("BannerSection");
expect(Object.keys(config.components)).toContain("ExpandedHeader");
expect(Object.keys(config.components)).not.toContain("Grid");
expect(Object.keys(config.components)).not.toContain("BodyText");
expect(Object.keys(config.components)).not.toContain("CustomCodeSection");

// Test list of categories
expect(Object.keys(config.categories ?? {})).toContain("pageSections");
expect(Object.keys(config.categories ?? {})).toContain("other");
expect(Object.keys(config.categories ?? {})).toContain(
"deprecatedComponents"
);
expect(Object.keys(config.categories ?? {})).not.toContain(
"coreInformation"
);

// Test component visibility within categories
expect(config.categories?.other?.components).toContain("ExpandedHeader");
expect(config.categories?.coreInformation?.components).toBeUndefined();
expect(config.categories?.other?.components).not.toContain(
"CustomCodeSection"
);
});

it("filters components and categories correctly when the custom code feature flag is enabled", () => {
const config = filterComponentsFromConfig(mainConfig, [
"CustomCodeSection",
]);

// Test component registry
expect(Object.keys(config.components)).toContain("BannerSection");
expect(Object.keys(config.components)).toContain("ExpandedHeader");
Expand Down Expand Up @@ -71,7 +41,7 @@ describe("filterComponentsFromConfig", () => {
expect(Object.keys(config.components)).toContain("ExpandedHeader");
expect(Object.keys(config.components)).toContain("Grid");
expect(Object.keys(config.components)).toContain("BodyText");
expect(Object.keys(config.components)).not.toContain("CustomCodeSection");
expect(Object.keys(config.components)).toContain("CustomCodeSection");

// Test list of categories
expect(Object.keys(config.categories ?? {})).toContain("pageSections");
Expand All @@ -84,8 +54,6 @@ describe("filterComponentsFromConfig", () => {
// Test component visibility within categories
expect(config.categories?.other?.components).toContain("ExpandedHeader");
expect(config.categories?.coreInformation?.components).toContain("Grid");
expect(config.categories?.other?.components).not.toContain(
"CustomCodeSection"
);
expect(config.categories?.other?.components).toContain("CustomCodeSection");
});
});
6 changes: 4 additions & 2 deletions packages/visual-editor/src/utils/filterComponents.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Config } from "@measured/puck";

// The components that are disallowed by default.
const gatedLayoutComponents: string[] = ["CustomCodeSection"];
const gatedLayoutComponents: string[] = [];

// The categories that are disallowed by default.
const gatedLayoutCategories: string[] = ["coreInformation"];
Expand Down Expand Up @@ -38,7 +38,9 @@ export const filterComponentsFromConfig = <C extends Config>(
);

// Step 2: Determine the allowed components
// A component is allowed if ((it is not gated or is explicitly allowed) AND belongs to an allowed category).
// A component is allowed if it belongs to an allowed category and one of the following is true:
// 1) it is explicitly allowed via payload from storm
// 2) it is not in the gatedLayoutComponents list
const finalComponents = Object.fromEntries(
Object.entries(config.components).filter(([componentKey]) => {
const isGated = gatedLayoutComponents.includes(componentKey);
Expand Down