Skip to content

Commit

Permalink
Merge branch 'main' into feature/FilterModule_CustomFilters
Browse files Browse the repository at this point in the history
  • Loading branch information
Dias999 authored Sep 6, 2024
2 parents 2ceddc1 + a426e5b commit 5883e8d
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 257 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import React, { useState, PropsWithChildren, ReactNode } from 'react';

import type { RJSFSchema, UiSchema, CustomValidator } from '@rjsf/utils';
import type { IChangeEvent, FormProps } from '@rjsf/core';

import React, { useState } from 'react';
import type { IChangeEvent } from '@rjsf/core';
import {
Box,
Drawer,
Expand All @@ -11,59 +8,16 @@ import {
IconButton,
Typography,
} from '@mui/material';
import ChevronLeft from '@mui/icons-material/ChevronLeft';
import ChevronRight from '@mui/icons-material/ChevronRight';
import CloseIcon from '@mui/icons-material/Close';
import useDataProvider, { useQuery } from '@concepta/react-data-provider';
import validator from '@rjsf/validator-ajv6';

import { SchemaForm, SchemaFormProps } from '../../../components/SchemaForm';

import { SchemaForm } from '../../../components/SchemaForm';
import { CustomTextFieldWidget } from '../../../styles/CustomWidgets';
import { FormSubmoduleProps } from '../types/Form';
import TableRowControls from '../TableRowControls';

type Action = 'creation' | 'edit' | 'details' | null;

type DrawerFormSubmoduleProps = PropsWithChildren<
Omit<
SchemaFormProps,
| 'schema'
| 'uiSchema'
| 'validator'
| 'onSubmit'
| 'noHtml5Validate'
| 'showErrorList'
| 'formData'
| 'readonly'
| 'customValidate'
>
> & {
queryResource: string;
title?: string;
formSchema?: RJSFSchema;
viewMode?: Action | null;
formUiSchema?: UiSchema;
formData?: Record<string, unknown> | null;
submitButtonTitle?: string;
cancelButtonTitle?: string;
hideCancelButton?: boolean;
customFooterContent?: ReactNode;
onClose?: () => void;
customValidate?: CustomValidator;
widgets?: FormProps['widgets'];
onSuccess?: (data: unknown) => void;
onError?: (error: unknown) => void;
onDeleteSuccess?: (data: unknown) => void;
onDeleteError?: (error: unknown) => void;
onPrevious?: (data: unknown) => void;
onNext?: (data: unknown) => void;
isLoading?: boolean;
viewIndex?: number;
rowsPerPage?: number;
currentPage?: number;
pageCount?: number;
};

const DrawerFormSubmodule = (props: DrawerFormSubmoduleProps) => {
const DrawerFormSubmodule = (props: FormSubmoduleProps) => {
const {
queryResource,
viewMode,
Expand All @@ -87,11 +41,12 @@ const DrawerFormSubmodule = (props: DrawerFormSubmoduleProps) => {
rowsPerPage,
currentPage,
pageCount,
isVisible,
...otherProps
} = props;

const [fieldValues, setFieldValues] =
useState<DrawerFormSubmoduleProps['formData']>(null);
useState<FormSubmoduleProps['formData']>(null);

const { post, patch, del } = useDataProvider();

Expand Down Expand Up @@ -155,7 +110,7 @@ const DrawerFormSubmodule = (props: DrawerFormSubmoduleProps) => {
};

return (
<Drawer open={viewMode !== null} anchor="right">
<Drawer open={isVisible} anchor="right">
<Box
display="flex"
alignItems="center"
Expand Down Expand Up @@ -225,26 +180,20 @@ const DrawerFormSubmodule = (props: DrawerFormSubmoduleProps) => {
}
>
{viewMode !== 'creation' && (
<Box display="flex" alignItems="center" gap={2}>
<IconButton
onClick={() => onPrevious(formData)}
disabled={isLoading || (currentPage === 1 && viewIndex === 1)}
>
<ChevronLeft sx={{ color: '#333' }} />
</IconButton>
<Typography>
{isLoading ? '' : `Row ${viewIndex}/${rowsPerPage}`}
</Typography>
<IconButton
onClick={() => onNext(formData)}
disabled={
isLoading ||
(currentPage === pageCount && viewIndex === rowsPerPage)
}
>
<ChevronRight sx={{ color: '#333' }} />
</IconButton>
</Box>
<TableRowControls
isLoading={isLoading}
currentIndex={viewIndex}
rowsPerPage={rowsPerPage}
isPreviousDisabled={
isLoading || (currentPage === 1 && viewIndex === 1)
}
isNextDisabled={
isLoading ||
(currentPage === pageCount && viewIndex === rowsPerPage)
}
onPrevious={() => onPrevious(formData)}
onNext={() => onNext(formData)}
/>
)}
<Box display="flex" flexDirection="row" alignItems="center" gap={2}>
{props.customFooterContent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type FilterCallback = (filter: FilterValues) => void;
type Props = {
orderableListCacheKey?: string;
cacheApiPath?: string;
complementaryActions?: ReactNode;
};

const FilterSubmodule = (props: Props) => {
Expand Down
Loading

0 comments on commit 5883e8d

Please sign in to comment.