Skip to content

Commit

Permalink
feat: crudModule - form title customization
Browse files Browse the repository at this point in the history
  • Loading branch information
Dias999 committed Sep 10, 2024
1 parent def342a commit 1cde439
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ const DrawerFormSubmodule = (props: FormSubmoduleProps) => {
...widgets,
};

const title = () => {
if (formSchema?.title) {
return formSchema.title;
}
if (viewMode === 'creation') {
return 'Add Data';
}
if (viewMode === 'edit') {
return 'Edit Data';
}
return 'View Data';
};

return (
<Drawer open={isVisible} anchor="right">
<Box
Expand All @@ -120,11 +133,7 @@ const DrawerFormSubmodule = (props: FormSubmoduleProps) => {
ml={1}
>
<Typography variant="h5" sx={{ marginLeft: 3, fontSize: '20px' }}>
{viewMode === 'creation'
? 'Add Data'
: viewMode === 'edit'
? 'Edit Data'
: 'View Data'}
{title()}
</Typography>
<IconButton
aria-label="close"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,22 @@ const ModalFormSubmodule = (props: FormSubmoduleProps) => {
...widgets,
};

const title = () => {
if (formSchema?.title) {
return formSchema.title;
}
if (viewMode === 'creation') {
return 'Add Data';
}
if (viewMode === 'edit') {
return 'Edit Data';
}
return 'View Data';
};

return (
<Dialog open={isVisible} maxWidth="md" fullWidth onClose={onClose}>
<DialogTitle>
{viewMode === 'creation'
? 'Add Data'
: viewMode === 'edit'
? 'Edit Data'
: 'View Data'}
</DialogTitle>
<DialogTitle>{title()}</DialogTitle>
<IconButton
aria-label="close"
onClick={onClose}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export type FormSubmoduleProps = PropsWithChildren<
> & {
isVisible: boolean;
queryResource: string;
title?: string;
formSchema?: RJSFSchema;
viewMode?: Action | null;
formUiSchema?: UiSchema;
Expand Down
1 change: 0 additions & 1 deletion packages/react-material-ui/src/modules/crud/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ const CrudModule = (props: ModuleProps) => {
{enhancedFormProps && (
<FormComponent
isVisible={isFormVisible}
title={titleName}
queryResource={props.resource}
viewMode={drawerViewMode}
formData={selectedRow}
Expand Down

0 comments on commit 1cde439

Please sign in to comment.