From d2d4ba436085c31eec54f42bda938bcfb6b63371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Zaninotto?= Date: Sat, 27 Jul 2024 10:33:16 +0200 Subject: [PATCH] Fix override code for page components Closes #573 --- src/create/CreateGuesser.tsx | 23 ++++++++++++++++------- src/edit/EditGuesser.tsx | 23 ++++++++++++++++------- src/list/ListGuesser.tsx | 23 ++++++++++++++++------- src/show/ShowGuesser.tsx | 23 ++++++++++++++++------- 4 files changed, 64 insertions(+), 28 deletions(-) diff --git a/src/create/CreateGuesser.tsx b/src/create/CreateGuesser.tsx index 1515b03e..7d17fbef 100644 --- a/src/create/CreateGuesser.tsx +++ b/src/create/CreateGuesser.tsx @@ -18,20 +18,29 @@ import type { } from '../types.js'; const getOverrideCode = (schema: Resource, fields: Field[]) => { - let code = - 'If you want to override at least one input, paste this content in the component of your resource:\n\n'; - - code += `const ${schema.title}Create = () => (\n`; + let code = `If you want to override at least one input, create a ${schema.title}Create component with this content:\n`; + code += `\n`; + code += `import { CreateGuesser, InputGuesser } from "@api-platform/admin";\n`; + code += `\n`; + code += `export const ${schema.title}Create = () => (\n`; code += ` \n`; - fields.forEach((field) => { code += ` \n`; }); code += ` \n`; code += `);\n`; code += `\n`; - code += `And don't forget update your component:\n`; - code += ``; + code += `Then, update your main admin component:\n`; + code += `\n`; + code += `import { HydraAdmin, ResourceGuesser } from "@api-platform/admin";\n`; + code += `import { ${schema.title}Create } from './${schema.title}Create';\n`; + code += `\n`; + code += `const App = () => (\n`; + code += ` \n`; + code += ` \n`; + code += ` {/* ... */}\n`; + code += ` \n`; + code += `);\n`; return code; }; diff --git a/src/edit/EditGuesser.tsx b/src/edit/EditGuesser.tsx index 6602a207..cfa5bb81 100644 --- a/src/edit/EditGuesser.tsx +++ b/src/edit/EditGuesser.tsx @@ -20,20 +20,29 @@ import type { } from '../types.js'; const getOverrideCode = (schema: Resource, fields: Field[]) => { - let code = - 'If you want to override at least one input, paste this content in the component of your resource:\n\n'; - - code += `const ${schema.title}Edit = () => (\n`; + let code = `If you want to override at least one input, create a ${schema.title}Edit component with this content:\n`; + code += `\n`; + code += `import { EditGuesser, InputGuesser } from "@api-platform/admin";\n`; + code += `\n`; + code += `export const ${schema.title}Edit = () => (\n`; code += ` \n`; - fields.forEach((field) => { code += ` \n`; }); code += ` \n`; code += `);\n`; code += `\n`; - code += `And don't forget update your component:\n`; - code += ``; + code += `Then, update your main admin component:\n`; + code += `\n`; + code += `import { HydraAdmin, ResourceGuesser } from "@api-platform/admin";\n`; + code += `import { ${schema.title}Edit } from './${schema.title}Edit';\n`; + code += `\n`; + code += `const App = () => (\n`; + code += ` \n`; + code += ` \n`; + code += ` {/* ... */}\n`; + code += ` \n`; + code += `);\n`; return code; }; diff --git a/src/list/ListGuesser.tsx b/src/list/ListGuesser.tsx index 49a95244..64a67602 100644 --- a/src/list/ListGuesser.tsx +++ b/src/list/ListGuesser.tsx @@ -23,20 +23,29 @@ import type { } from '../types.js'; const getOverrideCode = (schema: Resource, fields: Field[]) => { - let code = - 'If you want to override at least one field, paste this content in the component of your resource:\n\n'; - - code += `const ${schema.title}List = () => (\n`; + let code = `If you want to override at least one field, create a ${schema.title}List component with this content:\n`; + code += `\n`; + code += `import { ListGuesser, FieldGuesser } from "@api-platform/admin";\n`; + code += `\n`; + code += `export const ${schema.title}List = () => (\n`; code += ` \n`; - fields.forEach((field) => { code += ` \n`; }); code += ` \n`; code += `);\n`; code += `\n`; - code += `And don't forget update your component:\n`; - code += ``; + code += `Then, update your main admin component:\n`; + code += `\n`; + code += `import { HydraAdmin, ResourceGuesser } from "@api-platform/admin";\n`; + code += `import { ${schema.title}List } from './${schema.title}List';\n`; + code += `\n`; + code += `const App = () => (\n`; + code += ` \n`; + code += ` \n`; + code += ` {/* ... */}\n`; + code += ` \n`; + code += `);\n`; return code; }; diff --git a/src/show/ShowGuesser.tsx b/src/show/ShowGuesser.tsx index 0e7abc21..45eced66 100644 --- a/src/show/ShowGuesser.tsx +++ b/src/show/ShowGuesser.tsx @@ -19,20 +19,29 @@ import type { } from '../types.js'; const getOverrideCode = (schema: Resource, fields: Field[]) => { - let code = - 'If you want to override at least one field, paste this content in the component of your resource:\n\n'; - - code += `const ${schema.title}Show = () => (\n`; + let code = `If you want to override at least one field, create a ${schema.title}Show component with this content:\n`; + code += `\n`; + code += `import { ShowGuesser, FieldGuesser } from "@api-platform/admin";\n`; + code += `\n`; + code += `export const ${schema.title}Show = () => (\n`; code += ` \n`; - fields.forEach((field) => { code += ` \n`; }); code += ` \n`; code += `);\n`; code += `\n`; - code += `And don't forget update your component:\n`; - code += ``; + code += `Then, update your main admin component:\n`; + code += `\n`; + code += `import { HydraAdmin, ResourceGuesser } from "@api-platform/admin";\n`; + code += `import { ${schema.title}Show } from './${schema.title}Show';\n`; + code += `\n`; + code += `const App = () => (\n`; + code += ` \n`; + code += ` \n`; + code += ` {/* ... */}\n`; + code += ` \n`; + code += `);\n`; return code; };