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

change commons-ui version #572

Merged
merged 4 commits into from
Nov 28, 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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@gridsuite/commons-ui": "0.72.0",
"@gridsuite/commons-ui": "0.72.2",
"@hookform/resolvers": "^3.3.4",
"@mui/icons-material": "^5.15.14",
"@mui/lab": "5.0.0-alpha.169",
Expand Down
22 changes: 3 additions & 19 deletions src/components/dialogs/contingency-list/contingency-list-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { v4 as uuid4 } from 'uuid';
import {
CONTINGENCY_LIST_EQUIPMENTS,
type CriteriaBasedData,
EquipmentType,
FieldConstants,
getCriteriaBasedFormData,
Expand All @@ -27,23 +28,6 @@ export interface IdentifierList {
identifierList: Identifier[];
}

export interface RangeInputData {
[FieldConstants.OPERATION_TYPE]: string;
[FieldConstants.VALUE_1]: number | null;
[FieldConstants.VALUE_2]: number | null;
}

export interface CriteriaBasedData {
[FieldConstants.COUNTRIES]?: string[];
[FieldConstants.COUNTRIES_1]?: string[];
[FieldConstants.COUNTRIES_2]?: string[];
[FieldConstants.NOMINAL_VOLTAGE]?: RangeInputData | null;
[FieldConstants.NOMINAL_VOLTAGE_1]?: RangeInputData | null;
[FieldConstants.NOMINAL_VOLTAGE_2]?: RangeInputData | null;
[FieldConstants.NOMINAL_VOLTAGE_3]?: RangeInputData | null;
[key: string]: any;
}

export type ContingencyListFormData = {
[FieldConstants.NAME]: string;
[FieldConstants.DESCRIPTION]?: string;
Expand Down Expand Up @@ -77,14 +61,14 @@ export const getContingencyListEmptyFormData = (name = '') => ({
[FieldConstants.CONTINGENCY_LIST_TYPE]: ContingencyListType.CRITERIA_BASED.id,
[FieldConstants.SCRIPT]: '',
[FieldConstants.EQUIPMENT_TYPE]: null,
...getCriteriaBasedFormData({}, {}),
...getCriteriaBasedFormData(),
});

export const getCriteriaBasedFormDataFromFetchedElement = (response: any, name: string) => ({
[FieldConstants.NAME]: name,
[FieldConstants.CONTINGENCY_LIST_TYPE]: ContingencyListType.CRITERIA_BASED.id,
[FieldConstants.EQUIPMENT_TYPE]: response.equipmentType,
...getCriteriaBasedFormData(response, {}),
...getCriteriaBasedFormData(response),
});

export const getExplicitNamingFormDataFromFetchedElement = (response: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const schema = yup.object().shape({
otherwise: (schemaOtherwise) => schemaOtherwise.nullable(),
}),
...getExplicitNamingSchema(),
...getCriteriaBasedSchema({}),
...getCriteriaBasedSchema(),
});

const emptyFormData = getContingencyListEmptyFormData();
Expand Down Expand Up @@ -104,6 +104,7 @@ export default function ContingencyListCreationDialog({
onClose={closeAndClear}
onSave={onSubmit}
formSchema={schema}
// @ts-expect-error TODO: formSchema is of type ContingencyListFormDataWithRequiredCriteria but formMethods of type ContingencyListFormData
formMethods={methods}
titleId={titleId}
removeOptional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function ContingencyListCreationForm() {
/>
);

const emptyValues = getCriteriaBasedFormData({}, {});
const emptyValues = getCriteriaBasedFormData();
return (
<>
<Box sx={unscrollableDialogStyles.unscrollableHeader}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ import { PARAM_LANGUAGE } from '../../../../../utils/config-params';
const schema = yup.object().shape({
[FieldConstants.NAME]: yup.string().trim().required('nameEmpty'),
[FieldConstants.EQUIPMENT_TYPE]: yup.string().required(),
...getCriteriaBasedSchema(null),
...getCriteriaBasedSchema(),
});

const emptyFormData = (name?: string) => getContingencyListEmptyFormData(name);

export interface CriteriaBasedEditionDialogProps {
contingencyListId: string;
contingencyListType: string;
Expand All @@ -62,7 +60,7 @@ export default function CriteriaBasedEditionDialog({
const selectionForCopy = useSelector((state: AppState) => state.selectionForCopy);
const dispatch = useDispatch();
const methods = useForm<CriteriaBasedEditionFormData>({
defaultValues: emptyFormData(name),
defaultValues: getContingencyListEmptyFormData(name),
resolver: yupResolver<CriteriaBasedEditionFormData>(schema),
});

Expand Down Expand Up @@ -93,7 +91,7 @@ export default function CriteriaBasedEditionDialog({
}, [contingencyListId, contingencyListType, name, reset, snackError]);

const closeAndClear = () => {
reset(emptyFormData());
reset(getContingencyListEmptyFormData());
onClose();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { AppState } from '../../../../../redux/types';
import { SUPPORTED_CONTINGENCY_LIST_EQUIPMENTS } from '../../contingency-list-utils';

export default function CriteriaBasedEditionForm() {
const emptyValues = getCriteriaBasedFormData({}, {});
const emptyValues = getCriteriaBasedFormData();
const activeDirectory = useSelector((state: AppState) => state.activeDirectory);
return (
<>
Expand Down
6 changes: 3 additions & 3 deletions src/utils/rest-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import ReconnectingWebSocket from 'reconnecting-websocket';
import {
backendFetch,
backendFetchJson,
type CriteriaBasedData,
ElementType,
fetchEnv,
FieldConstants,
getRequestParamFromList,
GsLang,
GsTheme,
type GsLang,
type GsTheme,
} from '@gridsuite/commons-ui';
import { LiteralUnion } from 'type-fest';
import { IncomingHttpHeaders } from 'node:http';
Expand All @@ -25,7 +26,6 @@ import { store } from '../redux/store';
import { ContingencyListType } from './elementType';
import { CONTINGENCY_ENDPOINTS } from './constants-endpoints';
import { AppState } from '../redux/types';
import { CriteriaBasedData } from '../components/dialogs/contingency-list/contingency-list-utils';
import { PrepareContingencyListForBackend } from '../components/dialogs/contingency-list-helper';
import { UsersIdentities } from './user-identities.type';

Expand Down
Loading