Skip to content

Commit

Permalink
Merge branch 'main' into update_cancel_button
Browse files Browse the repository at this point in the history
  • Loading branch information
EstherDarkish authored Jan 24, 2024
2 parents f4f0ffc + ff2be1d commit b4e9b9f
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export const getCreateCaseDialogFormValidationDefaultValues = () => ({

export const createCaseDialogFormValidationSchema = yup.object().shape({
[CASE_NAME]: yup.string().trim().required('nameEmpty'),
[DESCRIPTION]: yup.string(),
[DESCRIPTION]: yup.string().max(500, 'descriptionLimitError'),
[CASE_FILE]: yup.mixed().nullable().required(),
});
11 changes: 3 additions & 8 deletions src/components/dialogs/create-case-dialog/create-case-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ElementType } from '../../../utils/elementType';
import { useSnackMessage } from '@gridsuite/commons-ui';
import { useForm } from 'react-hook-form';
import { CASE_FILE, CASE_NAME, DESCRIPTION } from '../../utils/field-constants';
import { ErrorInput, TextInput, FieldErrorAlert } from '@gridsuite/commons-ui';
import { ErrorInput, FieldErrorAlert } from '@gridsuite/commons-ui';
import { yupResolver } from '@hookform/resolvers/yup/dist/yup';
import CustomMuiDialog from '../commons/custom-mui-dialog/custom-mui-dialog';
import {
Expand All @@ -29,6 +29,7 @@ import {
} from './create-case-dialog-utils';
import { ReduxState } from '../../../redux/reducer.type';
import PrefilledNameInput from '../commons/prefilled-name-input';
import DescriptionInput from '../description-modification/description-input';

interface IFormData {
[CASE_NAME]: string;
Expand Down Expand Up @@ -126,13 +127,7 @@ const CreateCaseDialog: React.FunctionComponent<CreateCaseDialogProps> = ({
/>
</Grid>
<Grid item>
<TextInput
name={DESCRIPTION}
label={'descriptionProperty'}
formProps={{
size: 'medium',
}}
/>
<DescriptionInput rows={5} />
</Grid>
</Grid>
<ErrorInput name={CASE_FILE} InputField={FieldErrorAlert} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const getCreateStudyDialogFormDefaultValues = ({
export const createStudyDialogFormValidationSchema = yup.object().shape({
[STUDY_NAME]: yup.string().trim().required('nameEmpty'),
[FORMATTED_CASE_PARAMETERS]: yup.mixed().required(),
[DESCRIPTION]: yup.string(),
[DESCRIPTION]: yup.string().max(500, 'descriptionLimitError'),
[CURRENT_PARAMETERS]: yup.mixed().required(),
[CASE_UUID]: yup.string().required(),
[CASE_FILE]: yup.mixed().nullable().required(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ import {
CASE_NAME,
CASE_UUID,
CURRENT_PARAMETERS,
DESCRIPTION,
FORMATTED_CASE_PARAMETERS,
STUDY_NAME,
} from '../../utils/field-constants';
import { yupResolver } from '@hookform/resolvers/yup/dist/yup';
import CustomMuiDialog from '../commons/custom-mui-dialog/custom-mui-dialog';
import { ErrorInput, FieldErrorAlert, TextInput } from '@gridsuite/commons-ui';
import { ErrorInput, FieldErrorAlert } from '@gridsuite/commons-ui';
import PrefilledNameInput from '../commons/prefilled-name-input';
import DescriptionInput from '../description-modification/description-input';

const STRING_LIST = 'STRING_LIST';

Expand Down Expand Up @@ -259,13 +259,7 @@ const CreateStudyDialog = ({ open, onClose, providedExistingCase }) => {
/>
</Grid>
<Grid item>
<TextInput
name={DESCRIPTION}
label={'descriptionProperty'}
formProps={{
size: 'medium',
}}
/>
<DescriptionInput rows={5} />
</Grid>
</Grid>
{providedExistingCase ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { FunctionComponent } from 'react';
import { DESCRIPTION } from '../../utils/field-constants';
import { InputAdornment, SxProps } from '@mui/material';
import { TextInput } from '@gridsuite/commons-ui';
import React, { useMemo } from 'react';
import { useFormContext, useWatch } from 'react-hook-form';

interface IDescriptionInput {
maxCharactersNumber?: number;
rows?: number;
minRows?: number;
maxRows?: number;
sx?: SxProps;
}

const DescriptionInput: FunctionComponent<IDescriptionInput> = ({
maxCharactersNumber,
rows,
minRows,
maxRows,
sx,
}) => {
const { control } = useFormContext();
const descriptionWatch = useWatch({
name: `${DESCRIPTION}`,
control,
});

const maxCounter = maxCharactersNumber ?? 500;
const isOverTheLimit = descriptionWatch?.length > maxCounter;
const descriptionCounter = useMemo(() => {
const descriptionLength = descriptionWatch?.length ?? 0;
return descriptionLength + '/' + maxCounter;
}, [descriptionWatch, maxCounter]);

const formProps = {
size: 'medium',
multiline: true,
InputProps: {
endAdornment: (
<InputAdornment
color={'red'}
position="end"
sx={{
position: 'absolute',
bottom: 10,
right: 8,
}}
>
<div
style={{
color: isOverTheLimit ? 'red' : 'inherit',
}}
>
{descriptionCounter}
</div>
</InputAdornment>
),
},
...(minRows && { minRows: minRows }),
...(rows && { rows: rows }),
...(maxRows && { maxRows: maxRows }),
...(sx && { sx: sx }),
};
return (
<TextInput
name={DESCRIPTION}
label={'descriptionProperty'}
formProps={formProps}
/>
);
};

export default DescriptionInput;
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { DESCRIPTION } from '../../utils/field-constants';
import { useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
import { updateElement } from '../../../utils/rest-api';
import { TextInput, useSnackMessage } from '@gridsuite/commons-ui';
import { useSnackMessage } from '@gridsuite/commons-ui';
import CustomMuiDialog from '../commons/custom-mui-dialog/custom-mui-dialog';
import React from 'react';
import DescriptionInput from './description-input';

interface IDescriptionModificationDialogue {
elementUuid: string;
Expand All @@ -23,7 +24,7 @@ interface IDescriptionModificationDialogue {
}

const schema = yup.object().shape({
[DESCRIPTION]: yup.string().nullable(),
[DESCRIPTION]: yup.string().max(500, 'descriptionLimitError'),
});

const DescriptionModificationDialogue: FunctionComponent<
Expand Down Expand Up @@ -70,14 +71,10 @@ const DescriptionModificationDialogue: FunctionComponent<
onSave={onSubmit}
formSchema={schema}
formMethods={methods}
titleId={'descriptionModificationDialog'}
titleId={'description'}
removeOptional={true}
>
<TextInput
name={DESCRIPTION}
formProps={{
multiline: true,
}}
/>
<DescriptionInput minRows={3} sx={{ marginTop: '10px' }} />
</CustomMuiDialog>
);
};
Expand Down
41 changes: 41 additions & 0 deletions src/components/dialogs/filter/expert/expert-filter-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,41 @@ export const FIELDS_OPTIONS = {
dataType: DataType.NUMBER,
inputType: 'number',
},
CONNECTED: {
name: FieldType.CONNECTED,
label: 'connected',
dataType: DataType.BOOLEAN,
valueEditorType: 'switch',
},
RATED_S: {
name: FieldType.RATED_S,
label: 'ratedS',
dataType: DataType.NUMBER,
inputType: 'number',
},
MARGINAL_COST: {
name: FieldType.MARGINAL_COST,
label: 'marginalCost',
dataType: DataType.NUMBER,
inputType: 'number',
},
PLANNED_OUTAGE_RATE: {
name: FieldType.PLANNED_OUTAGE_RATE,
label: 'plannedOutageRate',
dataType: DataType.NUMBER,
inputType: 'number',
},
FORCED_OUTAGE_RATE: {
name: FieldType.FORCED_OUTAGE_RATE,
label: 'forcedOutageRate',
dataType: DataType.NUMBER,
inputType: 'number',
},
VOLTAGE_LEVEL_ID: {
name: FieldType.VOLTAGE_LEVEL_ID,
label: 'vlId',
dataType: DataType.STRING,
},
};

export const fields: Record<string, Field[]> = {
Expand All @@ -184,6 +219,12 @@ export const fields: Record<string, Field[]> = {
FIELDS_OPTIONS.COUNTRY,
FIELDS_OPTIONS.VOLTAGE_REGULATOR_ON,
FIELDS_OPTIONS.PLANNED_ACTIVE_POWER_SET_POINT,
FIELDS_OPTIONS.CONNECTED,
FIELDS_OPTIONS.RATED_S,
FIELDS_OPTIONS.MARGINAL_COST,
FIELDS_OPTIONS.PLANNED_OUTAGE_RATE,
FIELDS_OPTIONS.FORCED_OUTAGE_RATE,
FIELDS_OPTIONS.VOLTAGE_LEVEL_ID,
],
LOAD: [FIELDS_OPTIONS.ID],
};
6 changes: 6 additions & 0 deletions src/components/dialogs/filter/expert/expert-filter.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export enum FieldType {
COUNTRY = 'COUNTRY',
VOLTAGE_REGULATOR_ON = 'VOLTAGE_REGULATOR_ON',
PLANNED_ACTIVE_POWER_SET_POINT = 'PLANNED_ACTIVE_POWER_SET_POINT',
CONNECTED = 'CONNECTED',
RATED_S = 'RATED_S',
MARGINAL_COST = 'MARGINAL_COST',
PLANNED_OUTAGE_RATE = 'PLANNED_OUTAGE_RATE',
FORCED_OUTAGE_RATE = 'FORCED_OUTAGE_RATE',
VOLTAGE_LEVEL_ID = 'VOLTAGE_LEVEL_ID',
}

export enum DataType {
Expand Down
Loading

0 comments on commit b4e9b9f

Please sign in to comment.