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

Admin Generator (Future): Use the correct component for field of type text depending on multiline #1709

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 5 additions & 17 deletions demo/admin/src/products/future/generated/ProductForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
FinalFormSubmitEvent,
Loading,
MainContent,
TextAreaField,
TextField,
Toolbar,
ToolbarActions,
ToolbarFillSpace,
Expand Down Expand Up @@ -159,28 +161,14 @@ export function ProductForm({ id }: FormProps): React.ReactElement {
</ToolbarActions>
</Toolbar>
<MainContent>
<Field
required
fullWidth
name="title"
component={FinalFormInput}
label={<FormattedMessage id="product.title" defaultMessage="Titel" />}
/>
<TextField required fullWidth name="title" label={<FormattedMessage id="product.title" defaultMessage="Titel" />} />

<Field
required
fullWidth
name="slug"
component={FinalFormInput}
label={<FormattedMessage id="product.slug" defaultMessage="Slug" />}
/>
<TextField required fullWidth name="slug" label={<FormattedMessage id="product.slug" defaultMessage="Slug" />} />

<Field
<TextAreaField
required
multiline
fullWidth
name="description"
component={FinalFormInput}
label={<FormattedMessage id="product.description" defaultMessage="Description" />}
/>
<Field fullWidth name="type" label={<FormattedMessage id="product.type" defaultMessage="Type" />}>
Expand Down
2 changes: 2 additions & 0 deletions packages/admin/cms-admin/src/generator/future/generateForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export function generateForm(
FinalFormSubmitEvent,
Loading,
MainContent,
TextAreaField,
TextField,
Toolbar,
ToolbarActions,
ToolbarFillSpace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ export function generateFormField(
const imports: Imports = [];
let code = "";
if (config.type == "text") {
const TextInputComponent = config.multiline ? "TextAreaField" : "TextField";
code = `
<Field
<${TextInputComponent}
${required ? "required" : ""}
${config.multiline ? "multiline" : ""}
fullWidth
name="${name}"
component={FinalFormInput}
label={<FormattedMessage id="${instanceGqlType}.${name}" defaultMessage="${label}" />}
/>`;
} else if (config.type == "number") {
Expand Down
Loading