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

Mutualize fetching functions #2099

Closed
wants to merge 18 commits into from
5 changes: 3 additions & 2 deletions src/components/app-top-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
OverflowableText,
TagRenderer,
TopBar,
fetchAppsMetadata,
} from '@gridsuite/commons-ui';
import GridStudyLogoLight from '../images/GridStudy_logo_light.svg?react';
import GridStudyLogoDark from '../images/GridStudy_logo_dark.svg?react';
Expand Down Expand Up @@ -62,7 +63,7 @@ import {
EQUIPMENT_INFOS_TYPES,
EQUIPMENT_TYPES,
} from './utils/equipment-types';
import { fetchAppsAndUrls, fetchVersion } from '../services/utils';
import { fetchVersion } from '../services/utils';
import { RunButtonContainer } from './run-button-container';
import { useComputationResultsCount } from '../hooks/use-computation-results-count';

Expand Down Expand Up @@ -242,7 +243,7 @@ const AppTopBar = ({ user, tabIndex, onChangeTab, userManager }) => {

useEffect(() => {
if (user !== null) {
fetchAppsAndUrls().then((res) => {
fetchAppsMetadata().then((res) => {
setAppsAndUrls(res);
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/dialogs/commons/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

export function getIdOrValue(value: { id: string; label: string } | string) {
export function getIdOrValue(value: any) {
return typeof value !== 'string' ? value?.id ?? null : value;
}

export function getLabelOrValue(value: { id: string; label: string } | string) {
export function getLabelOrValue(value: any) {
return typeof value !== 'string' ? value?.label ?? null : value;
}
5 changes: 0 additions & 5 deletions src/components/dialogs/contingency-list-selector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import { updateConfigParameter } from '../../services/config';
import { fetchContingencyAndFiltersLists } from '../../services/directory';
import { fetchContingencyCount } from '../../services/study';
import { DirectoryItemSelector } from '@gridsuite/commons-ui';
import { fetchDirectoryContent, fetchRootFolders } from 'services/directory';
import { fetchElementsMetadata } from 'services/explore';
import { isNodeBuilt } from 'components/graph/util/model-functions';

function makeButton(onClick, message, disabled) {
Expand Down Expand Up @@ -247,9 +245,6 @@ const ContingencyListSelector = (props) => {
onClose={addFavorites}
types={CONTINGENCY_TYPES}
title={intl.formatMessage({ id: 'ContingencyListsSelection' })}
fetchDirectoryContent={fetchDirectoryContent}
fetchRootFolders={fetchRootFolders}
fetchElementsInfos={fetchElementsMetadata}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ import {
fetchDynamicSimulationEvent,
saveDynamicSimulationEvent,
} from '../../../../services/dynamic-simulation';
import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui';
import { FetchStatus } from '../../../../services/utils';
import {
CustomFormProvider,
useSnackMessage,
FetchStatus,
} from '@gridsuite/commons-ui';

export type DynamicSimulationEventDialogProps = {
studyUuid: string;
Expand Down
5 changes: 0 additions & 5 deletions src/components/dialogs/import-modification-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import { CopyType } from '../graph/menus/network-modification-node-editor';
import { copyOrMoveModifications } from '../../services/study';
import { UUID } from 'crypto';
import { FunctionComponent } from 'react';
import { fetchDirectoryContent, fetchRootFolders } from 'services/directory';
import { fetchElementsMetadata } from 'services/explore';

/**
* Dialog to select some network modifications and append them in the current node
Expand Down Expand Up @@ -74,9 +72,6 @@ const ImportModificationDialog: FunctionComponent<
title={intl.formatMessage({
id: 'ModificationsSelection',
})}
fetchDirectoryContent={fetchDirectoryContent}
fetchRootFolders={fetchRootFolders}
fetchElementsInfos={fetchElementsMetadata}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import ModificationDialog from '../../../commons/modificationDialog';
import EquipmentSearchDialog from '../../../equipment-search-dialog';
import { useCallback, useEffect } from 'react';
import { useFormSearchCopy } from '../../../form-search-copy-hook';
import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui';
import {
CustomFormProvider,
useSnackMessage,
FetchStatus,
} from '@gridsuite/commons-ui';
import { yupResolver } from '@hookform/resolvers/yup';
import yup from 'components/utils/yup-config';
import {
Expand Down Expand Up @@ -60,7 +64,6 @@ import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modi
import { EQUIPMENT_TYPES } from '../../../../utils/equipment-types';
import PropTypes from 'prop-types';
import { createBattery } from '../../../../../services/study/network-modifications';
import { FetchStatus } from '../../../../../services/utils';
import {
copyEquipmentPropertiesForCreation,
creationPropertiesSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import { useForm } from 'react-hook-form';
import ModificationDialog from '../../../commons/modificationDialog';
import React, { useCallback, useEffect, useState } from 'react';
import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui';
import {
CustomFormProvider,
useSnackMessage,
FetchStatus,
} from '@gridsuite/commons-ui';
import { yupResolver } from '@hookform/resolvers/yup';
import yup from 'components/utils/yup-config';
import {
Expand Down Expand Up @@ -55,7 +59,6 @@ import {
} from '../../../set-points/set-points-utils';
import { modifyBattery } from '../../../../../services/study/network-modifications';
import { fetchNetworkElementInfos } from '../../../../../services/study/network';
import { FetchStatus } from '../../../../../services/utils';
import {
emptyProperties,
getConcatenatedProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ import {
SPECIFIC_METADATA,
TYPE,
} from '../../../utils/field-constants';
import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui';
import {
CustomFormProvider,
useSnackMessage,
FetchStatus,
} from '@gridsuite/commons-ui';
import { useForm } from 'react-hook-form';
import { FunctionComponent, useCallback, useEffect } from 'react';
import ModificationDialog from '../../commons/modificationDialog';
import { EQUIPMENT_TYPES } from 'components/utils/equipment-types';
import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modification-form';
import { FORM_LOADING_DELAY } from 'components/network/constants';
import { deleteEquipmentByFilter } from '../../../../services/study/network-modifications';
import { FetchStatus } from '../../../../services/utils';
import ByFilterDeletionForm from './by-filter-deletion-form';
import {
ByFilterDeletionDialogProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ import { EQUIPMENT_TYPES } from 'components/utils/equipment-types';

import { DirectoryItemsInput } from '@gridsuite/commons-ui';
import { getIdOrValue } from '../../commons/utils';
import {
fetchDirectoryContent,
fetchPath,
fetchRootFolders,
} from 'services/directory';
import { fetchElementsMetadata } from 'services/explore';

const ByFilterDeletionForm = () => {
const intl = useIntl();
Expand Down Expand Up @@ -69,10 +63,6 @@ const ByFilterDeletionForm = () => {
label={'filter'}
equipmentTypes={[equipmentTypeWatch]}
disable={!equipmentTypeWatch}
fetchDirectoryContent={fetchDirectoryContent}
fetchRootFolders={fetchRootFolders}
fetchElementsInfos={fetchElementsMetadata}
fetchDirectoryElementPath={fetchPath}
/>
);
}, [equipmentTypeWatch]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

import { yupResolver } from '@hookform/resolvers/yup';
import yup from 'components/utils/yup-config';
import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui';
import {
CustomFormProvider,
useSnackMessage,
FetchStatus,
} from '@gridsuite/commons-ui';
import { useCallback, useEffect } from 'react';
import { FetchStatus } from '../../../../services/utils';
import { useForm } from 'react-hook-form';
import ModificationDialog from '../../commons/modificationDialog';
import { useOpenShortWaitFetching } from '../../commons/handle-modification-form';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ import DragHandleIcon from '@mui/icons-material/DragHandle';
import { getIdOrValue, getLabelOrValue } from '../../../commons/utils';
import { useIntl } from 'react-intl';
import Grid from '@mui/material/Grid';
import {
fetchDirectoryContent,
fetchPath,
fetchRootFolders,
} from 'services/directory';
import { fetchElementsMetadata } from 'services/explore';

interface FormulaProps {
name: String;
Expand Down Expand Up @@ -60,10 +54,6 @@ const FormulaForm: FunctionComponent<FormulaProps> = ({ name, index }) => {
label={'filter'}
titleId={'FiltersListsSelection'}
disable={!equipmentTypeWatch}
fetchDirectoryContent={fetchDirectoryContent}
fetchRootFolders={fetchRootFolders}
fetchElementsInfos={fetchElementsMetadata}
fetchDirectoryElementPath={fetchPath}
/>
);

Expand All @@ -90,7 +80,9 @@ const FormulaForm: FunctionComponent<FormulaProps> = ({ name, index }) => {
/>
);

const inputTransform = (value: { id: string; label: string } | string) => {
const inputTransform = (
value: { id: string; label: string } | string | null
) => {
const newVal = value ?? null;
return (
OPERATOR_OPTIONS.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ const ReferenceAutocompleteInput: FunctionComponent<{
[intl]
);

const inputTransform = (value: { id: string; label: string } | string) =>
options.find((option) => option?.id === value) || value;
const inputTransform = (
value: { id: string; label: string } | string | null
) => options.find((option) => option?.id === value) || value;

const outputTransform = (value: any) => {
return value?.id ?? value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
VALUE,
} from 'components/utils/field-constants';
import { isBlankOrEmpty } from 'components/utils/validation-functions';
import { fetchStudyMetadata } from 'services/metadata';
import { fetchStudyMetadata } from '@gridsuite/commons-ui';

export type Property = {
[NAME]: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui';
import {
CustomFormProvider,
useSnackMessage,
FetchStatus,
} from '@gridsuite/commons-ui';
import { yupResolver } from '@hookform/resolvers/yup';
import { FORM_LOADING_DELAY } from 'components/network/constants';
import {
Expand All @@ -24,7 +28,6 @@ import ModificationDialog from '../../commons/modificationDialog';
import DeleteAttachingLineForm from './delete-attaching-line-form';
import { useOpenShortWaitFetching } from '../../commons/handle-modification-form';
import { deleteAttachingLine } from '../../../../services/study/network-modifications';
import { FetchStatus } from '../../../../services/utils';
import DeleteAttachingLineIllustration from './delete-attaching-line-illustration';

const emptyFormData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui';
import {
CustomFormProvider,
useSnackMessage,
FetchStatus,
} from '@gridsuite/commons-ui';
import { yupResolver } from '@hookform/resolvers/yup';
import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modification-form';
import { FORM_LOADING_DELAY } from 'components/network/constants';
Expand All @@ -23,7 +27,6 @@ import yup from 'components/utils/yup-config';
import ModificationDialog from '../../commons/modificationDialog';
import DeleteVoltageLevelOnLineForm from './delete-voltage-level-on-line-form';
import { deleteVoltageLevelOnLine } from '../../../../services/study/network-modifications';
import { FetchStatus } from '../../../../services/utils';
import DeleteVoltageLevelOnLineIllustration from './delete-voltage-level-on-line-illustration';

const emptyFormData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import {
EQUIPMENT_ID,
TYPE,
} from '../../../utils/field-constants';
import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui';
import {
CustomFormProvider,
useSnackMessage,
FetchStatus,
} from '@gridsuite/commons-ui';
import { useForm } from 'react-hook-form';
import React, { useCallback, useEffect } from 'react';
import ModificationDialog from '../../commons/modificationDialog';
Expand All @@ -22,7 +26,6 @@ import PropTypes from 'prop-types';
import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modification-form';
import { FORM_LOADING_DELAY } from 'components/network/constants';
import { deleteEquipment } from '../../../../services/study/network-modifications';
import { FetchStatus } from '../../../../services/utils';

const formSchema = yup
.object()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui';
import {
CustomFormProvider,
useSnackMessage,
FetchStatus,
} from '@gridsuite/commons-ui';
import { yupResolver } from '@hookform/resolvers/yup';
import { FORM_LOADING_DELAY } from 'components/network/constants';
import {
Expand All @@ -30,7 +34,6 @@ import ModificationDialog from '../../commons/modificationDialog';
import GenerationDispatchForm from './generation-dispatch-form';
import { addSelectedFieldToRows } from 'components/utils/dnd-table/dnd-table';
import { generationDispatch } from '../../../../services/study/network-modifications';
import { FetchStatus } from '../../../../services/utils';

const emptyFormData = {
[LOSS_COEFFICIENT]: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ import FrequencyReservePane from './frequency-reserve-pane';
import { FormattedMessage } from 'react-intl';
import { FieldLabel } from '@gridsuite/commons-ui';
import SubstationsGeneratorsOrderingPane from './substations-generators-ordering-pane';
import { fetchDirectoryContent, fetchRootFolders } from 'services/directory';
import { fetchElementsMetadata } from 'services/explore';
import { fetchPath } from '../../../../services/directory.js';

const GenerationDispatchForm = () => {
const handleCoefficientValueChange = (id, value) => {
Expand Down Expand Up @@ -57,10 +54,6 @@ const GenerationDispatchForm = () => {
equipmentTypes={[EQUIPMENT_TYPES.GENERATOR]}
elementType={ElementType.FILTER}
titleId={'FiltersListsSelection'}
fetchDirectoryContent={fetchDirectoryContent}
fetchRootFolders={fetchRootFolders}
fetchElementsInfos={fetchElementsMetadata}
fetchDirectoryElementPath={fetchPath}
/>
</Grid>
</Grid>
Expand Down Expand Up @@ -98,10 +91,6 @@ const GenerationDispatchForm = () => {
equipmentTypes={[EQUIPMENT_TYPES.GENERATOR]}
elementType={ElementType.FILTER}
titleId={'FiltersListsSelection'}
fetchDirectoryContent={fetchDirectoryContent}
fetchRootFolders={fetchRootFolders}
fetchElementsInfos={fetchElementsMetadata}
fetchDirectoryElementPath={fetchPath}
/>
</Grid>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import yup from 'components/utils/yup-config';
import ModificationDialog from '../../commons/modificationDialog';
import GeneratorScalingForm from './generator-scaling-form';
import { useCallback, useEffect } from 'react';
import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui';
import {
CustomFormProvider,
useSnackMessage,
FetchStatus,
} from '@gridsuite/commons-ui';
import { VARIATION_TYPE, VARIATIONS } from 'components/utils/field-constants';
import { getVariationsSchema } from './variation/variation-utils';
import {
Expand All @@ -20,7 +24,6 @@ import {
} from 'components/network/constants';
import { useOpenShortWaitFetching } from '../../commons/handle-modification-form';
import { generatorScaling } from '../../../../services/study/network-modifications';
import { FetchStatus } from '../../../../services/utils';

const emptyFormData = {
[VARIATION_TYPE]: VARIATION_TYPES.DELTA_P.id,
Expand Down
Loading
Loading