Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
basseche committed Jan 8, 2025
1 parent e656e10 commit 59aa874
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { FieldConstants } from '../../../utils/constants/fieldConstants';
import { useSnackMessage } from '../../../hooks/useSnackMessage';
import { CustomMuiDialog } from '../customMuiDialog/CustomMuiDialog';
import { ExpandingTextField } from '../../inputs/reactHookForm/text/ExpandingTextField';
import { MAX_CHAR_DESCRIPTION } from '../../../utils/constants/UIconstants';
import { MAX_CHAR_DESCRIPTION } from '../../../utils/constants/uiConstants';

export interface DescriptionModificationDialogProps {
elementUuid: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/filter/FilterCreationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { FilterForm } from './FilterForm';
import { EXPERT_FILTER_QUERY, expertFilterSchema, getExpertFilterEmptyFormData } from './expert/ExpertFilterForm';
import { FilterType } from './constants/FilterConstants';
import { ElementExistsType } from '../../utils/types/elementType';
import { MAX_CHAR_DESCRIPTION } from '../../utils/constants/UIconstants';
import { MAX_CHAR_DESCRIPTION } from '../../utils/constants/uiConstants';

const emptyFormData = {
[FieldConstants.NAME]: '',
Expand Down
9 changes: 0 additions & 9 deletions src/components/filter/FilterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ import { ExplicitNamingFilterForm } from './explicitNaming/ExplicitNamingFilterF
import { ExpertFilterForm } from './expert/ExpertFilterForm';
import { FilterType } from './constants/FilterConstants';
import { unscrollableDialogStyles } from '../dialogs';
import yup from '../../utils/yupConfig';
import { MAX_CHAR_DESCRIPTION } from '../../utils/constants/UIconstants';

export const FilterSchema = {
[FieldConstants.NAME]: yup.string().trim().required('nameEmpty'),
[FieldConstants.FILTER_TYPE]: yup.string().required(),
[FieldConstants.EQUIPMENT_TYPE]: yup.string().required(),
[FieldConstants.DESCRIPTION]: yup.string().max(MAX_CHAR_DESCRIPTION, 'descriptionLimitError'),
};

export function FilterForm({
sourceFilterForExplicitNamingConversion,
Expand Down
11 changes: 10 additions & 1 deletion src/components/filter/HeaderFilterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { UniqueNameInput } from '../inputs/reactHookForm/text/UniqueNameInput';
import { ElementExistsType, ElementType } from '../../utils/types/elementType';
import { DescriptionField } from '../inputs/reactHookForm/text/DescriptionField';
import { RadioInput } from '../inputs/reactHookForm/booleans/RadioInput';
import yup from '../../utils/yupConfig';
import { MAX_CHAR_DESCRIPTION } from '../../utils/constants/uiConstants';

export interface FilterFormProps {
creation?: boolean;
Expand All @@ -25,6 +27,13 @@ export interface FilterFormProps {
handleFilterTypeChange?: (event: React.ChangeEvent<HTMLInputElement>, value: string) => void;
}

export const HeaderFilterSchema = {
[FieldConstants.NAME]: yup.string().trim().required('nameEmpty'),
[FieldConstants.FILTER_TYPE]: yup.string().required(),
[FieldConstants.EQUIPMENT_TYPE]: yup.string().required(),
[FieldConstants.DESCRIPTION]: yup.string().max(MAX_CHAR_DESCRIPTION, 'descriptionLimitError'),
};

export function HeaderFilterForm({
sourceFilterForExplicitNamingConversion,
creation,
Expand All @@ -48,7 +57,7 @@ export function HeaderFilterForm({
</Grid>
<>
<Grid item xs={12}>
<DescriptionField showDescription />
<DescriptionField />
</Grid>
{creation && !sourceFilterForExplicitNamingConversion && (
<Grid item>
Expand Down
9 changes: 5 additions & 4 deletions src/components/filter/expert/ExpertFilterEditionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import { FieldConstants } from '../../../utils/constants/fieldConstants';
import yup from '../../../utils/yupConfig';
import { CustomMuiDialog } from '../../dialogs/customMuiDialog/CustomMuiDialog';
import { FilterType, NO_ITEM_SELECTION_FOR_COPY } from '../constants/FilterConstants';
import { FilterProps } from '../filter.type';
import { FilterForm, FilterSchema } from '../FilterForm';
import { FilterEditionProps } from '../filter.type';
import { FilterForm } from '../FilterForm';
import { saveExpertFilter } from '../utils/filterApi';
import { EXPERT_FILTER_QUERY, expertFilterSchema } from './ExpertFilterForm';
import { importExpertRules } from './expertFilterUtils';
import { HeaderFilterSchema } from '../HeaderFilterForm';

const formSchema = yup
.object()
.shape({
...FilterSchema,
...HeaderFilterSchema,
...expertFilterSchema,
})
.required();
Expand All @@ -42,7 +43,7 @@ export function ExpertFilterEditionDialog({
elementExists,
language,
description,
}: Readonly<FilterProps>) {
}: Readonly<FilterEditionProps>) {
const { snackError } = useSnackMessage();
const [dataFetchStatus, setDataFetchStatus] = useState(FetchStatus.IDLE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import { saveExplicitNamingFilter } from '../utils/filterApi';
import { explicitNamingFilterSchema, FILTER_EQUIPMENTS_ATTRIBUTES } from './ExplicitNamingFilterForm';

import { FetchStatus } from '../../../utils/constants/fetchStatus';
import { FilterForm, FilterSchema } from '../FilterForm';
import { FilterForm } from '../FilterForm';
import { FilterType, NO_ITEM_SELECTION_FOR_COPY } from '../constants/FilterConstants';
import { FilterProps } from '../filter.type';
import { FilterEditionProps } from '../filter.type';
import { HeaderFilterSchema } from '../HeaderFilterForm';

const formSchema = yup
.object()
.shape({
...FilterSchema,
...HeaderFilterSchema,
...explicitNamingFilterSchema,
})
.required();
Expand All @@ -46,7 +47,7 @@ export function ExplicitNamingFilterEditionDialog({
elementExists,
language,
description,
}: Readonly<FilterProps>) {
}: Readonly<FilterEditionProps>) {
const { snackError } = useSnackMessage();
const [dataFetchStatus, setDataFetchStatus] = useState(FetchStatus.IDLE);

Expand Down
2 changes: 1 addition & 1 deletion src/components/filter/filter.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type ItemSelectionForCopy = {
specificTypeItem: string | null;
};

export interface FilterProps {
export interface FilterEditionProps {
id: string;
name: string;
titleId: string;
Expand Down
10 changes: 2 additions & 8 deletions src/components/inputs/reactHookForm/text/DescriptionField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@ import { useFormContext } from 'react-hook-form'; // Import useFormContext
import { FieldConstants } from '../../../../utils/constants/fieldConstants';
import { ExpandingTextField } from './ExpandingTextField';

interface DescriptionProps {
showDescription?: boolean;
description?: string;
}
export function DescriptionField({ showDescription }: Readonly<DescriptionProps>) {
export function DescriptionField() {
const { setValue, getValues } = useFormContext();
const description = getValues(FieldConstants.DESCRIPTION);
const [isDescriptionFieldVisible, setIsDescriptionFieldVisible] = useState(
showDescription && description && description !== ''
);
const [isDescriptionFieldVisible, setIsDescriptionFieldVisible] = useState(!!description);

const handleOpenDescription = () => {
setIsDescriptionFieldVisible(true);
Expand Down
File renamed without changes.

0 comments on commit 59aa874

Please sign in to comment.