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

Change default template #1601

Merged
merged 3 commits into from
Jan 28, 2023
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
4 changes: 2 additions & 2 deletions packages/toolpad-app/src/server/appTemplateDoms/doms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const getAppTemplateDomFromPath = (templatePath: string): Promise<appDom.AppDom>
readJsonFile(path.resolve(projectRoot, DOMS_DIR_PATH, templatePath));

const appTemplates: Record<AppTemplateId, () => Promise<appDom.AppDom | null>> = {
blank: async () => null,
default: async () => null,
images: async () =>
getAppTemplateDomFromPath(config.isDemo ? './images-demo.json' : './images.json'),
default: async () => {
hr: async () => {
const template = await getAppTemplateDomFromPath('./default.json');
(template.nodes['1313wn3' as NodeId] as appDom.QueryNode).attributes.query.value.url.value =
new URL('/static/employees.json', config.externalUrl).href;
Expand Down
10 changes: 5 additions & 5 deletions packages/toolpad-app/src/toolpad/Apps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ export const APP_TEMPLATE_OPTIONS: Map<
[
'default',
{
label: 'Default',
description: 'HR management tool',
label: 'Blank',
description: 'Start with an empty canvas',
},
],
[
'blank',
'hr',
{
label: 'Blank page',
description: 'Start with an empty canvas',
label: 'Data Grid',
description: 'HR management tool',
},
],
[
Expand Down
2 changes: 1 addition & 1 deletion packages/toolpad-app/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export interface AppTheme {

export type VersionOrPreview = 'preview' | number;

export type AppTemplateId = 'default' | 'blank' | 'images';
export type AppTemplateId = 'default' | 'hr' | 'images';

export type NodeHashes = Record<NodeId, number | undefined>;

Expand Down
14 changes: 14 additions & 0 deletions test/integration/appTemplates.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ test('can use default app template', async ({ page }) => {
const runtimeModel = new ToolpadRuntime(page);
await runtimeModel.gotoPage(app.id, 'page1');

const emptyCanvasLocator = page.getByText('Drop component here');
await expect(emptyCanvasLocator).not.toBeVisible();
});

test('can use hr template', async ({ page }) => {
const homeModel = new ToolpadHome(page);
await homeModel.goto();
const app = await homeModel.createApplication({ appTemplateId: 'hr' });

page.waitForNavigation();

const runtimeModel = new ToolpadRuntime(page);
await runtimeModel.gotoPage(app.id, 'page1');

const dataGridRowLocator = page.getByText('Todd Breitenberg');
await expect(dataGridRowLocator).toBeVisible();
});
Expand Down