Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EDU-159: Remix Gen1 - Advanced child sub components #3750

Merged
merged 11 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -3,7 +3,7 @@ import { test, verifyTabContent } from '../helpers/index.js';

test.describe('Advanced child sub components', () => {
test('Display two buttons with label Tab 1 and Tab 2', async ({ page, packageName }) => {
test.skip(!['react', 'angular', 'angular-ssr'].includes(packageName));
test.skip(!['react', 'angular', 'angular-ssr', 'gen1-remix'].includes(packageName));

await page.goto('/advanced-child');

Expand Down
21 changes: 20 additions & 1 deletion packages/sdks-tests/src/snippet-tests/custom-child.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { test } from '../helpers/index.js';

test.describe('Div with Hero class, and text', () => {
test('should render the page without 404', async ({ page, packageName }) => {
test.skip(!['react', 'angular', 'angular-ssr'].includes(packageName));
test.skip(!['react', 'angular', 'angular-ssr', 'gen1-remix'].includes(packageName));

const response = await page.goto('/custom-child');
expect(response?.status()).toBeLessThan(400);
Expand Down Expand Up @@ -31,4 +31,23 @@ test.describe('Div with Hero class, and text', () => {
const builderText = await builderTextDiv.textContent();
expect(builderText?.trim()).toBe('This is Builder text');
});

test('should verify builder-block with specific text in gen1-remix', async ({
page,
packageName,
}) => {
test.skip(!['gen1-remix'].includes(packageName));

await page.goto('/custom-child');
await page.waitForLoadState('networkidle');

const builderBlock = page.locator('div.builder-block').first();
await expect(builderBlock).toBeVisible();

const column1Text = page.locator("text=This is your component's text");
await expect(column1Text).toBeVisible();

const column2Text = page.locator('text=This is Builder text');
await expect(column2Text).toBeVisible();
});
});
15 changes: 15 additions & 0 deletions packages/sdks-tests/src/snippet-tests/editable-regions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,19 @@ test.describe('Editable regions in custom components', () => {
const secondText = await columns.nth(1).textContent();
expect(secondText?.trim().toLowerCase()).toBe('column 2 text');
});

test.describe('Remix gen1 editable regions text validation', () => {
uttej-vsk marked this conversation as resolved.
Show resolved Hide resolved
test('should display column texts directly on the screen', async ({ page, packageName }) => {
test.skip(!['gen1-remix'].includes(packageName));

await page.goto('/editable-region');
await page.waitForLoadState('networkidle');

const column1Text = page.locator('text=column 1 text');
await expect(column1Text).toBeVisible();

const column2Text = page.locator('text=column 2 text');
await expect(column2Text).toBeVisible();
});
});
});
48 changes: 48 additions & 0 deletions packages/sdks/snippets/gen1-remix/app/routes/advanced-child.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// routes/advanced-child.tsx
import { Builder, BuilderComponent, builder } from '@builder.io/react';
import type { LoaderFunctionArgs } from '@remix-run/node';
import { useLoaderData } from '@remix-run/react';
import CustomTabs from './components/CustomTabs';

builder.init('ee9f13b4981e489a9a1209887695ef2b');

Builder.registerComponent(CustomTabs, {
name: 'TabFields',
inputs: [
{
name: 'tabList',
type: 'array',
defaultValue: [],
subFields: [
{
name: 'tabName',
type: 'string',
},
{
name: 'blocks',
type: 'uiBlocks',
hideFromUI: true,
samijaber marked this conversation as resolved.
Show resolved Hide resolved
defaultValue: [],
},
],
},
],
});

export const loader = async ({ request }: LoaderFunctionArgs) => {
const page = await builder
.get('advanced-child', {
userAttributes: {
urlPath: `/${request.url.split('/').pop()}`,
},
})
.toPromise();

return { page };
};

export default function AdvancedChildPage() {
const { page } = useLoaderData<typeof loader>();

return <BuilderComponent model="advanced-child" content={page} />;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { BuilderBlocks, BuilderElement } from '@builder.io/react';

interface CustomColumnsProps {
column1: { blocks: React.ReactNode };
column2: { blocks: React.ReactNode };
builderBlock: BuilderElement;
}

export const CustomColumns = (props: CustomColumnsProps) => {
return (
<>
<BuilderBlocks
parentElementId={props.builderBlock.id}
dataPath={`column1.blocks`}
uttej-vsk marked this conversation as resolved.
Show resolved Hide resolved
blocks={props.column1?.blocks}
/>

<BuilderBlocks
parentElementId={props.builderBlock.id}
dataPath={`column2.blocks`}
uttej-vsk marked this conversation as resolved.
Show resolved Hide resolved
blocks={props.column2?.blocks}
/>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ReactNode } from 'react';

interface CustomHeroProps {
children: ReactNode;
}

export const CustomHero = (props: CustomHeroProps) => {
uttej-vsk marked this conversation as resolved.
Show resolved Hide resolved
return (
<>
<div>This is your component&apos;s text</div>
uttej-vsk marked this conversation as resolved.
Show resolved Hide resolved
{props.children}
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { BuilderBlocks, BuilderElement } from '@builder.io/react';

import { useState } from 'react';

type TabProps = {
tabList: { tabName: string; blocks: React.ReactNode[] }[];
builderBlock: BuilderElement;
};

export default function CustomTabs({ tabList, builderBlock }: TabProps) {
const [activeTab, setActiveTab] = useState(0);

if (!tabList?.length) return null;

return (
<>
<div className="tab-buttons">
{tabList.map((tab, index) => (
<button
key={index}
className={`tab-button ${activeTab === index ? 'active' : ''}`}
onClick={() => setActiveTab(index)}
>
{tab.tabName}
</button>
))}
</div>

<BuilderBlocks
parentElementId={builderBlock?.id}
dataPath={`tabList.${activeTab}.blocks`}
blocks={tabList[activeTab].blocks}
/>
</>
);
}
42 changes: 42 additions & 0 deletions packages/sdks/snippets/gen1-remix/app/routes/custom-child.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Builder, builder, BuilderComponent } from '@builder.io/react';

import { LoaderFunctionArgs } from '@remix-run/node';
import { useLoaderData } from '@remix-run/react';
import { CustomHero } from './components/CustomHero';

builder.init('ee9f13b4981e489a9a1209887695ef2b');

Builder.registerComponent(CustomHero, {
name: 'CustomHero',
inputs: [],
uttej-vsk marked this conversation as resolved.
Show resolved Hide resolved
canHaveChildren: true,
defaultChildren: [
{
'@type': '@builder.io/sdk:Element',
component: {
name: 'Text',
options: {
text: 'This is Builder text',
},
},
},
],
});

export const loader = async ({ request }: LoaderFunctionArgs) => {
const page = await builder
.get('custom-child', {
userAttributes: {
urlPath: `/${request.url.split('/').pop()}`,
},
})
.toPromise();

return { page };
};

export default function CustomChildPage() {
const { page } = useLoaderData<typeof loader>();

return <BuilderComponent model="custom-child" content={page} />;
}
49 changes: 49 additions & 0 deletions packages/sdks/snippets/gen1-remix/app/routes/editable-region.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// routes/advanced-child.tsx
import { Builder, BuilderComponent, builder } from "@builder.io/react";
import type { LoaderFunctionArgs } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import { CustomColumns } from "./components/CustomColumns";

builder.init("ee9f13b4981e489a9a1209887695ef2b");

Builder.registerComponent(CustomColumns, {
name: "MyColumns",
inputs: [
{
name: "column1",
type: "uiBlocks",
broadcast: true,
hideFromUI: true,
uttej-vsk marked this conversation as resolved.
Show resolved Hide resolved
defaultValue: {
blocks: [],
},
uttej-vsk marked this conversation as resolved.
Show resolved Hide resolved
},
{
name: "column2",
type: "uiBlocks",
broadcast: true,
hideFromUI: true,
defaultValue: {
blocks: [],
},
},
],
});

export const loader = async ({ request }: LoaderFunctionArgs) => {
const page = await builder
.get("editable-regions", {
userAttributes: {
urlPath: `/${request.url.split("/").pop()}`,
uttej-vsk marked this conversation as resolved.
Show resolved Hide resolved
},
})
.toPromise();

return { page };
};

export default function EditableRegionsPage() {
const { page } = useLoaderData<typeof loader>();

return <BuilderComponent model="editable-regions" content={page} />;
}
Loading