Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/remove_fetch_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-WorkGH committed Aug 12, 2024
2 parents 0140385 + ebe2657 commit 8896372
Show file tree
Hide file tree
Showing 24 changed files with 394 additions and 620 deletions.
55 changes: 22 additions & 33 deletions src/components/app-top-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
* 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 { useCallback, useEffect, useRef, useState } from 'react';
import { useCallback, useEffect, useRef } from 'react';
import { LIGHT_THEME, logout, PARAM_LANGUAGE, PARAM_THEME, TopBar, UserManagerState } from '@gridsuite/commons-ui';
import ParametersDialog, { useParameterState } from './dialogs/parameters-dialog';
import { APP_NAME } from '../utils/config-params';
import { useDispatch, useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import { useNavigate } from 'react-router-dom';
import GridExploreLogoLight from '../images/GridExplore_logo_light.svg?react';
import GridExploreLogoDark from '../images/GridExplore_logo_dark.svg?react';
Expand All @@ -19,12 +17,13 @@ import { SearchBar } from './search/search-bar';
import { AppState } from '../redux/reducer';
import { AppDispatch } from '../redux/store';
import { appsMetadataSrv } from '../services';
import { useParameterState } from './dialogs/use-parameters-dialog';

type AppTopBarProps = {
userManagerInstance: UserManagerState['instance'];
};

export default function AppTopBar({ userManagerInstance }: AppTopBarProps) {
export default function AppTopBar({ userManagerInstance }: Readonly<AppTopBarProps>) {
const navigate = useNavigate();

const onLogoClick = useCallback(() => navigate('/', { replace: true }), [navigate]);
Expand All @@ -43,8 +42,6 @@ export default function AppTopBar({ userManagerInstance }: AppTopBarProps) {

const [languageLocal, handleChangeLanguage] = useParameterState(PARAM_LANGUAGE);

const [showParameters, setShowParameters] = useState(false);

const searchInputRef = useRef<any | null>(null);

useEffect(() => {
Expand Down Expand Up @@ -74,32 +71,24 @@ export default function AppTopBar({ userManagerInstance }: AppTopBarProps) {
);

return (
<>
<TopBar
appName={APP_NAME}
appColor="#3DABE2"
appLogo={theme === LIGHT_THEME ? <GridExploreLogoLight /> : <GridExploreLogoDark />}
appVersion={AppPackage.version}
appLicense={AppPackage.license}
onLogoutClick={onLogoutClick}
onLogoClick={onLogoClick}
user={user}
appsAndUrls={appsAndUrls}
onThemeClick={handleChangeTheme}
theme={themeLocal}
onLanguageClick={handleChangeLanguage}
language={languageLocal}
globalVersionPromise={globalVersionFetcher}
additionalModulesPromise={'explore'}
>
{user && <SearchBar inputRef={searchInputRef} />}
</TopBar>
<ParametersDialog showParameters={showParameters} hideParameters={() => setShowParameters(false)} />
</>
<TopBar
appName={APP_NAME}
appColor="#3DABE2"
appLogo={theme === LIGHT_THEME ? <GridExploreLogoLight /> : <GridExploreLogoDark />}
appVersion={AppPackage.version}
appLicense={AppPackage.license}
onLogoutClick={onLogoutClick}
onLogoClick={onLogoClick}
user={user}
appsAndUrls={appsAndUrls}
onThemeClick={handleChangeTheme}
theme={themeLocal}
onLanguageClick={handleChangeLanguage}
language={languageLocal}
globalVersionPromise={globalVersionFetcher}
additionalModulesPromise={'explore'}
>
{user && <SearchBar inputRef={searchInputRef} />}
</TopBar>
);
}

AppTopBar.propTypes = {
user: PropTypes.object,
userManager: PropTypes.object,
};
3 changes: 2 additions & 1 deletion src/components/dialogs/commons/upload-new-case.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import { FormattedMessage, useIntl } from 'react-intl';
import { Button, CircularProgress, Grid, Input } from '@mui/material';
import { useController, useFormContext } from 'react-hook-form';
import { FieldConstants } from '@gridsuite/commons-ui';
import { UUID } from 'crypto';
import { caseSrv } from '../../../services';

interface UploadNewCaseProps {
isNewStudyCreation?: boolean;
getCurrentCaseImportParams?: (uuid: string) => void;
getCurrentCaseImportParams?: (uuid: UUID) => void;
handleApiCallError?: ErrorCallback;
}

Expand Down
35 changes: 0 additions & 35 deletions src/components/dialogs/contingency-list-helper.js

This file was deleted.

68 changes: 68 additions & 0 deletions src/components/dialogs/contingency-list-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* 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 { FieldConstants } from '@gridsuite/commons-ui';

interface ContingencyList {
[FieldConstants.NAME]: string;
[FieldConstants.EQUIPMENT_TABLE]: Array<{
[FieldConstants.CONTINGENCY_NAME]: string;
[FieldConstants.EQUIPMENT_IDS]: string[];
}>;
}

interface Identifier {
type: 'ID_BASED';
identifier: string;
}

interface IdentifierList {
type: 'LIST';
contingencyId: string;
identifierList: Identifier[];
}

interface PrepareContingencyListForBackend {
id: string;
identifierContingencyList: {
type: 'identifier';
version: string;
name: string;
identifiers: IdentifierList[];
};
type: 'IDENTIFIERS';
}

export const prepareContingencyListForBackend = (
id: string,
contingencyList: ContingencyList
): PrepareContingencyListForBackend => {
const identifiersList: IdentifierList[] = contingencyList[FieldConstants.EQUIPMENT_TABLE].map((contingency) => {
const identifierList: Identifier[] = contingency[FieldConstants.EQUIPMENT_IDS].map((identifier) => {
return {
type: 'ID_BASED',
identifier: identifier,
};
});

return {
type: 'LIST',
contingencyId: contingency[FieldConstants.CONTINGENCY_NAME],
identifierList: identifierList,
};
});

return {
id: id,
identifierContingencyList: {
type: 'identifier',
version: '1.2',
name: contingencyList[FieldConstants.NAME],
identifiers: identifiersList,
},
type: 'IDENTIFIERS',
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ContingencyListCreationForm from './contingency-list-creation-form';
import { getContingencyListEmptyFormData, getFormContent } from '../contingency-list-utils';
import { getExplicitNamingSchema } from '../explicit-naming/explicit-naming-form';
import { ContingencyListType } from '../../../../utils/elementType';
import { useParameterState } from '../../parameters-dialog';
import { useParameterState } from '../../use-parameters-dialog';
import { exploreSrv } from '../../../../services';

const schema = yup.object().shape({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import CriteriaBasedEditionForm from './criteria-based-edition-form';
import { useDispatch, useSelector } from 'react-redux';
import { noSelectionForCopy } from 'utils/constants';
import { setSelectionForCopy } from '../../../../../redux/actions';
import { useParameterState } from '../../../parameters-dialog';
import { useParameterState } from '../../../use-parameters-dialog';
import { actionsSrv, exploreSrv } from '../../../../../services';

const schema = yup.object().shape({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* 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 Dialog from '@mui/material/Dialog';
import DialogTitle from '@mui/material/DialogTitle';
import { FunctionComponent } from 'react';
import { Alert, Button, Dialog, DialogActions, DialogContent, DialogTitle } from '@mui/material';
import { FormattedMessage } from 'react-intl';
import DialogContent from '@mui/material/DialogContent';
import DialogActions from '@mui/material/DialogActions';
import Button from '@mui/material/Button';
import PropTypes from 'prop-types';
import React from 'react';
import Alert from '@mui/material/Alert';
import { ElementType } from '@gridsuite/commons-ui';
import { CancelButton, ElementType } from '@gridsuite/commons-ui';
import { UUID } from 'crypto';
import { useNameField } from './field-hook';
import { CancelButton } from '@gridsuite/commons-ui';

interface CreateDirectoryDialogProps {
open: boolean;
onClose: () => void;
onClick: (newName: string) => void;
title: string;
parentDirectory: UUID;
error: string;
}

/**
* Dialog to create a directory
Expand All @@ -26,7 +29,14 @@ import { CancelButton } from '@gridsuite/commons-ui';
* @param {String} title Title of the dialog
* @param {String} message Message of the dialog
*/
export const CreateDirectoryDialog = ({ open, onClose, onClick, title, parentDirectory, error }) => {
export const CreateDirectoryDialog: FunctionComponent<CreateDirectoryDialogProps> = ({
open,
onClose,
onClick,
title,
parentDirectory,
error,
}) => {
const [name, nameField, nameError, nameOk] = useNameField({
label: 'nameProperty',
autoFocus: true,
Expand Down Expand Up @@ -68,13 +78,4 @@ export const CreateDirectoryDialog = ({ open, onClose, onClick, title, parentDir
</Dialog>
);
};

CreateDirectoryDialog.propTypes = {
open: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
onClick: PropTypes.func.isRequired,
title: PropTypes.string.isRequired,
error: PropTypes.string.isRequired,
};

export default CreateDirectoryDialog;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* 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 { ElementAttributes, FieldConstants, Parameter, yup } from '@gridsuite/commons-ui';
import { UUID } from 'crypto';

export const getCreateStudyDialogFormDefaultValues = ({
directory = '',
studyName = '',
caseFile,
caseUuid,
}: {
directory?: string;
studyName?: string;
caseFile?: ElementAttributes | null;
caseUuid?: UUID;
}): CreateStudyDialogFormValues => {
return {
[FieldConstants.STUDY_NAME]: studyName,
[FieldConstants.DESCRIPTION]: '',
[FieldConstants.CASE_FILE]: caseFile ?? null,
[FieldConstants.CASE_UUID]: caseUuid ?? null,
[FieldConstants.FORMATTED_CASE_PARAMETERS]: [],
[FieldConstants.CURRENT_PARAMETERS]: {},
[FieldConstants.DIRECTORY]: directory,
[FieldConstants.CASE_FORMAT]: '',
[FieldConstants.CASE_NAME]: '',
};
};

export const createStudyDialogFormValidationSchema = yup.object().shape({
[FieldConstants.STUDY_NAME]: yup.string().trim().required('nameEmpty'),
[FieldConstants.FORMATTED_CASE_PARAMETERS]: yup.mixed<Parameter[]>().required(),
[FieldConstants.DESCRIPTION]: yup.string().max(500, 'descriptionLimitError'),
[FieldConstants.CURRENT_PARAMETERS]: yup.mixed<Record<string, string>>().required(),
[FieldConstants.CASE_UUID]: yup.string<UUID>().nullable().required(),
[FieldConstants.CASE_FILE]: yup.mixed<ElementAttributes>().nullable().required(),
[FieldConstants.DIRECTORY]: yup.string().required(),
[FieldConstants.CASE_FORMAT]: yup.string().optional(),
[FieldConstants.CASE_NAME]: yup.string().optional(),
});

export interface CreateStudyDialogFormValues {
[FieldConstants.STUDY_NAME]: string;
[FieldConstants.DESCRIPTION]?: string;
[FieldConstants.CASE_FILE]: ElementAttributes | null;
[FieldConstants.CASE_UUID]: UUID | null;
[FieldConstants.FORMATTED_CASE_PARAMETERS]: Parameter[];
[FieldConstants.CURRENT_PARAMETERS]: Record<string, string>;
[FieldConstants.DIRECTORY]: string;
[FieldConstants.CASE_FORMAT]?: string;
[FieldConstants.CASE_NAME]?: string;
}
Loading

0 comments on commit 8896372

Please sign in to comment.