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): Add FinalFormRangeInput to form generator #2612

Merged
merged 4 commits into from
Oct 10, 2024
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
1 change: 1 addition & 0 deletions demo/admin/src/products/future/ProductForm.cometGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const ProductForm: FormConfig<GQLProduct> = {
values: [{ value: "Cap", label: "great Cap" }, "Shirt", "Tie"],
},
{ type: "asyncSelect", name: "category", rootQuery: "productCategories" },
{ type: "numberRange", name: "priceRange", minValue: 25, maxValue: 500, disableSlider: true, startAdornment: "€" },
{
type: "optionalNestedFields",
name: "dimensions",
Expand Down
4 changes: 4 additions & 0 deletions demo/admin/src/products/future/generated/ProductForm.gql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const productFormFragment = gql`
id
title
}
priceRange {
min
max
}
dimensions {
width
height
Expand Down
13 changes: 13 additions & 0 deletions demo/admin/src/products/future/generated/ProductForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
FinalForm,
FinalFormCheckbox,
FinalFormInput,
FinalFormRangeInput,
FinalFormSubmitEvent,
FinalFormSwitch,
Loading,
Expand Down Expand Up @@ -285,6 +286,18 @@ export function ProductForm({ id }: FormProps): React.ReactElement {
}}
getOptionLabel={(option) => option.title}
/>

<Field
variant="horizontal"
fullWidth
name="priceRange"
component={FinalFormRangeInput}
label={<FormattedMessage id="product.priceRange" defaultMessage="Price Range" />}
min={25}
max={500}
disableSlider
startAdornment={<InputAdornment position="start">€</InputAdornment>}
/>
<Field
fullWidth
name="dimensionsEnabled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export function generateForm(
FinalForm,
FinalFormCheckbox,
FinalFormInput,
FinalFormRangeInput,
FinalFormSelect,
FinalFormSubmitEvent,
Loading,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,32 @@ export function generateFormField({
},
},
];
} else if (config.type === "numberRange") {
code = `
<Field
${required ? "required" : ""}
${config.readOnly ? readOnlyPropsWithLock : ""}
variant="horizontal"
fullWidth
name="${nameWithPrefix}"
component={FinalFormRangeInput}
label={${fieldLabel}}
min={${config.minValue}}
max={${config.maxValue}}
${config.disableSlider ? "disableSlider" : ""}
${config.startAdornment ? `startAdornment={<InputAdornment position="start">${config.startAdornment}</InputAdornment>}` : ""}
${config.endAdornment ? `endAdornment={<InputAdornment position="end">${config.endAdornment}</InputAdornment>}` : ""}
${
config.helperText
? `helperText={<FormattedMessage id=` +
`"${formattedMessageRootId}.${name}.helperText" ` +
`defaultMessage="${config.helperText}" />}`
: ""
}
${validateCode}
/>`;

formFragmentField = `${name} { min max }`;
} else if (config.type == "boolean") {
code = `<Field name="${nameWithPrefix}" label="" type="checkbox" variant="horizontal" fullWidth ${validateCode}>
{(props) => (
Expand Down
8 changes: 8 additions & 0 deletions packages/admin/cms-admin/src/generator/future/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ type MultiFileFormFieldConfig = { type: "fileUpload"; multiple: true; maxFiles?:
export type FormFieldConfig<T> = (
| { type: "text"; multiline?: boolean }
| { type: "number" }
| {
type: "numberRange";
minValue: number;
maxValue: number;
disableSlider?: boolean;
startAdornment?: string;
endAdornment?: string;
}
| { type: "boolean" }
| { type: "date" }
// TODO | { type: "dateTime" }
Expand Down
Loading