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
7 changes: 4 additions & 3 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions 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.59.0",
"@gridsuite/commons-ui": "file:../commons-ui/gridsuite-commons-ui-0.59.0.tgz",
"@hookform/resolvers": "^3.3.4",
"@mui/icons-material": "^5.15.14",
"@mui/lab": "5.0.0-alpha.169",
Expand Down Expand Up @@ -106,8 +106,8 @@
"jest-environment-jsdom": "^29.7.0",
"license-checker": "^25.0.1",
"prettier": "^2.8.8",
"typescript": "5.1.6",
"ts-node": "^10.9.2",
"typescript": "5.1.6",
"vite": "^5.2.7",
"vite-plugin-eslint": "^1.8.1",
"vite-plugin-svgr": "^4.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/components/app-top-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
logout,
OverflowableText,
TopBar,
fetchAppsMetadata,
fetchVersion,
} from '@gridsuite/commons-ui';
import GridStudyLogoLight from '../images/GridStudy_logo_light.svg?react';
import GridStudyLogoDark from '../images/GridStudy_logo_dark.svg?react';
Expand All @@ -31,12 +33,10 @@ import { isNodeBuilt, isNodeReadOnly } from './graph/util/model-functions';
import { useParameterState } from './dialogs/parameters/parameters';
import { getServersInfos } from '../services/study';
import { EQUIPMENT_TYPES } from './utils/equipment-types';
import { fetchVersion } from '../services/utils';
import { RunButtonContainer } from './run-button-container';
import { useComputationResultsCount } from '../hooks/use-computation-results-count';

import { TopBarEquipmentSearchDialog } from './top-bar-equipment-seach-dialog/top-bar-equipment-search-dialog';
import { fetchAppsMetadata } from '@gridsuite/commons-ui';

const styles = {
currentNodeBox: {
Expand Down
8 changes: 3 additions & 5 deletions src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import {
getPreLoginPath,
initializeAuthenticationProd,
useSnackMessage,
fetchAuthorizationCodeFlowFeatureFlag,
fetchDefaultParametersValues,
fetchIdpSettings,
} from '@gridsuite/commons-ui';

import PageNotFound from './page-not-found';
Expand Down Expand Up @@ -72,11 +75,6 @@ import {
fetchConfigParameter,
fetchConfigParameters,
} from '../services/config';
import {
fetchAuthorizationCodeFlowFeatureFlag,
fetchDefaultParametersValues,
fetchIdpSettings,
} from '../services/utils';
import { getOptionalServices } from '../services/study';
import {
changeDisplayedColumns,
Expand Down
3 changes: 1 addition & 2 deletions src/components/dialogs/commons/unique-name-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import React, {
useCallback,
useEffect,
} from 'react';
import { useDebounce } from '@gridsuite/commons-ui';
import { elementExists } from 'services/explore';
import { elementExists, useDebounce } from '@gridsuite/commons-ui';
import { FormattedMessage } from 'react-intl';
import { InputAdornment, TextFieldProps } from '@mui/material';
import CheckIcon from '@mui/icons-material/Check';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { DirectoryItemsInput } from '@gridsuite/commons-ui';
import { DirectoryItemsInput, fetchElementsInfos } from '@gridsuite/commons-ui';
import {
FILTERS,
ID,
Expand All @@ -24,7 +24,6 @@ import { FloatInput } from '@gridsuite/commons-ui';
import { ActivePowerAdornment, gridItem } from '../../../dialogUtils';
import { ElementType, useSnackMessage } from '@gridsuite/commons-ui';
import { IDENTIFIER_LIST } from './variation-utils';
import { fetchElementsInfos } from '@gridsuite/commons-ui';

const GENERATORS = [EQUIPMENT_TYPES.GENERATOR];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from 'components/utils/field-constants';
import ModificationDialog from 'components/dialogs/commons/modificationDialog';
import { createTabularCreation } from 'services/study/network-modifications';
import { FetchStatus } from 'services/utils';
import { FetchStatus } from '../../../../services/utils';
import TabularCreationForm from './tabular-creation-form';
import {
convertCreationFieldFromBackToFront,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { FORM_LOADING_DELAY } from 'components/network/constants';
import { MODIFICATIONS_TABLE, TYPE } from 'components/utils/field-constants';
import ModificationDialog from 'components/dialogs/commons/modificationDialog';
import { createTabulareModification } from 'services/study/network-modifications';
import { FetchStatus } from 'services/utils';
import { FetchStatus } from '../../../../services/utils';
import TabularModificationForm from './tabular-modification-form';
import {
convertValueFromBackToFront,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import {
CustomFormProvider,
DirectoryItemSelector,
ElementType,
fetchDirectoryElementPath,
TreeViewFinderNodeProps,
} from '@gridsuite/commons-ui';
import ModificationDialog from 'components/dialogs/commons/modificationDialog';
import { createParameter } from 'services/explore';
import { UniqueNameInput } from 'components/dialogs/commons/unique-name-input';
import { ReduxState } from 'redux/reducer.type';
import { UUID } from 'crypto';
import { fetchDirectoryElementPath } from '@gridsuite/commons-ui';

interface FormData {
[NAME]: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/dialogs/parameters/network-parameters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { LabelledButton, useParameterState, styles } from './parameters';
import { LineSeparator } from '../dialogUtils';
import Alert from '@mui/material/Alert';
import { fetchDefaultParametersValues } from '../../../services/utils';
import { fetchDefaultParametersValues } from '@gridsuite/commons-ui';
import { ParamLine, ParameterType } from './widget';
import { mergeSx } from '../../utils/functions';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
*/

import React, { useCallback, useEffect, useRef, useState } from 'react';
import { useSnackMessage } from '@gridsuite/commons-ui';
import {
useSnackMessage,
fetchDirectoryElementPath,
} from '@gridsuite/commons-ui';
import { useDispatch, useSelector } from 'react-redux';
import LineAttachToVoltageLevelDialog from 'components/dialogs/network-modifications/line-attach-to-voltage-level/line-attach-to-voltage-level-dialog';
import NetworkModificationsMenu from 'components/graph/menus/network-modifications-menu';
Expand Down Expand Up @@ -85,7 +88,6 @@ import ByFilterDeletionDialog from '../../dialogs/network-modifications/by-filte
import { useModificationLabelComputer } from '../util/use-modification-label-computer';
import { createModifications } from '../../../services/explore';
import { areUuidsEqual } from 'components/utils/utils';
import { fetchDirectoryElementPath } from '@gridsuite/commons-ui';

export const styles = {
listContainer: (theme) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/components/network/filter-creation-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
CustomFormProvider,
DirectoryItemSelector,
ElementType,
fetchDirectoryElementPath,
SelectInput,
TreeViewFinderNodeProps,
} from '@gridsuite/commons-ui';
Expand All @@ -27,7 +28,6 @@ import {
EQUIPMENT_TYPES,
} from '../utils/equipment-types';
import { UUID } from 'crypto';
import { fetchDirectoryElementPath } from '@gridsuite/commons-ui';
import CircularProgress from '@mui/material/CircularProgress';
import FolderOutlined from '@mui/icons-material/FolderOutlined';

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

import { useSnackMessage } from '@gridsuite/commons-ui';
import { useSnackMessage, downloadFile, FileType } from '@gridsuite/commons-ui';
import { ExportButton } from 'components/utils/export-button';
import { UUID } from 'crypto';
import {
Expand All @@ -17,7 +17,6 @@ import {
} from 'react';
import { useIntl } from 'react-intl';
import { downloadSecurityAnalysisResultZippedCsv } from 'services/study/security-analysis';
import { downloadZipFile } from 'services/utils';
import { RESULT_TYPE } from './security-analysis-result-utils';
import { PERMANENT_LIMIT_NAME } from '../common/utils';

Expand Down Expand Up @@ -85,7 +84,11 @@ export const SecurityAnalysisExportButton: FunctionComponent<
enumValueTranslations
)
.then((fileBlob) => {
downloadZipFile(fileBlob, `${resultType}-results.zip`);
downloadFile(
fileBlob,
`${resultType}-results.zip`,
FileType.ZIP
);
setIsCsvExportSuccessful(true);
})
.catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import { useOpenLoaderShortWait } from '../../dialogs/commons/handle-loader';
import { RESULTS_LOADING_DELAY } from '../../network/constants';
import React, { useCallback } from 'react';
import { exportSensitivityResultsAsCsv } from '../../../services/study/sensitivity-analysis';
import { downloadZipFile } from '../../../services/utils';
import { useSnackMessage } from '@gridsuite/commons-ui';
import { useSnackMessage, downloadFile, FileType } from '@gridsuite/commons-ui';
import { useIntl } from 'react-intl';
import { ExportButton } from '../../utils/export-button';
import { setSensitivityAnalysisResultFilter } from 'redux/actions';
Expand Down Expand Up @@ -76,8 +75,8 @@ const SensitivityAnalysisResultTab = ({ studyUuid, nodeUuid }) => {
initSort(nOrNkIndex ? 'valueAfter' : 'value');

/* set page to 0 to avoid being in out of range (0 to 0, but page is > 0)
for the page prop of MUI TablePagination if was not on the first page
for the prev sensiKind */
for the page prop of MUI TablePagination if was not on the first page
for the prev sensiKind */
setPage(0);

setIsCsvExportSuccessful(false);
Expand Down Expand Up @@ -129,7 +128,11 @@ const SensitivityAnalysisResultTab = ({ studyUuid, nodeUuid }) => {
})
.then((response) => {
response.blob().then((blob) => {
downloadZipFile(blob, 'sensitivity_analyse_results.zip');
downloadFile(
blob,
'sensitivity_analyse_results.zip',
FileType.ZIP
);
setIsCsvExportSuccessful(true);
});
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import {
useState,
} from 'react';
import { ExportButton } from '../../utils/export-button';
import { useSnackMessage } from '@gridsuite/commons-ui';
import { useSnackMessage, downloadFile, FileType } from '@gridsuite/commons-ui';
import { useIntl } from 'react-intl';
import { downloadShortCircuitResultZippedCsv } from '../../../services/study/short-circuit-analysis';
import { downloadZipFile } from '../../../services/utils';
import { ShortCircuitAnalysisType } from './shortcircuit-analysis-result.type';
import { UUID } from 'crypto';

Expand Down Expand Up @@ -82,11 +81,12 @@ export const ShortCircuitExportButton: FunctionComponent<
)
.then((response) => {
response.blob().then((fileBlob: Blob) => {
downloadZipFile(
downloadFile(
fileBlob,
analysisType === ShortCircuitAnalysisType.ONE_BUS
? 'oneBus-results.zip'
: 'allBuses_results.zip'
: 'allBuses_results.zip',
FileType.ZIP
);
setIsCsvExportSuccessful(true);
});
Expand Down
7 changes: 5 additions & 2 deletions src/components/study-container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import {
limitReductionModified,
} from '../redux/actions';
import WaitingLoader from './utils/waiting-loader';
import { useIntlRef, useSnackMessage } from '@gridsuite/commons-ui';
import {
useIntlRef,
useSnackMessage,
fetchDirectoryElementPath,
} from '@gridsuite/commons-ui';
import NetworkModificationTreeModel from './graph/network-modification-tree-model';
import {
getFirstNodeOfType,
Expand Down Expand Up @@ -53,7 +57,6 @@ import { invalidateLoadFlowStatus } from 'services/study/loadflow';
import { HttpStatusCode } from 'utils/http-status-code';
import { usePrevious } from './utils/utils';
import { StudyIndexationStatus } from 'redux/reducer.type';
import { fetchDirectoryElementPath } from '@gridsuite/commons-ui';

function isWorthUpdate(
studyUpdatedForce,
Expand Down
2 changes: 1 addition & 1 deletion src/services/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { UUID } from 'crypto';
import { backendFetchJson } from './utils';
import { backendFetchJson } from '@gridsuite/commons-ui';

const PREFIX_CASE_QUERIES = import.meta.env.VITE_API_GATEWAY + '/case';

Expand Down
2 changes: 1 addition & 1 deletion src/services/config-notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { APP_NAME } from '../utils/config-params';
import ReconnectingWebSocket from 'reconnecting-websocket';
import { getUrlWithToken, getWsBase } from './utils';
import { getWsBase, getUrlWithToken } from '@gridsuite/commons-ui';

const PREFIX_CONFIG_NOTIFICATION_WS =
import.meta.env.VITE_WS_GATEWAY + '/config-notification';
Expand Down
2 changes: 1 addition & 1 deletion src/services/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { getAppName } from '../utils/config-params';
import { backendFetch, backendFetchJson } from './utils';
import { backendFetch, backendFetchJson } from '@gridsuite/commons-ui';

const PREFIX_CONFIG_QUERIES = import.meta.env.VITE_API_GATEWAY + '/config';

Expand Down
8 changes: 6 additions & 2 deletions src/services/directory-notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
*/

import ReconnectingWebSocket from 'reconnecting-websocket';
import { getToken, getUrlWithToken, getWsBase } from './utils';
import {
getWsBase,
getUserToken,
getUrlWithToken,
} from '@gridsuite/commons-ui';

const PREFIX_DIRECTORY_NOTIFICATION_WS =
import.meta.env.VITE_WS_GATEWAY + '/directory-notification';
Expand Down Expand Up @@ -38,7 +42,7 @@ export function connectNotificationsWsUpdateDirectories() {
const webSocketUrl = `${webSocketBaseUrl}${PREFIX_DIRECTORY_NOTIFICATION_WS}/notify?updateType=directories`;

const reconnectingWebSocket = new ReconnectingWebSocket(
() => `${webSocketUrl}&access_token=${getToken()}`
() => `${webSocketUrl}&access_token=${getUserToken()}`
);
reconnectingWebSocket.onopen = function () {
console.info(
Expand Down
5 changes: 4 additions & 1 deletion src/services/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { backendFetchJson, getRequestParamFromList } from './utils';
import {
backendFetchJson,
getRequestParamFromList,
} from '@gridsuite/commons-ui';

const PREFIX_DIRECTORY_SERVER_QUERIES =
import.meta.env.VITE_API_GATEWAY + '/directory';
Expand Down
4 changes: 2 additions & 2 deletions src/services/dynamic-simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
backendFetch,
backendFetchJson,
getRequestParamFromList,
} from './utils';
} from '@gridsuite/commons-ui';
import { getStudyUrlWithNodeUuid } from './study';
import { UUID } from 'crypto';
import {
Expand Down Expand Up @@ -133,7 +133,7 @@ export function deleteDynamicSimulationEvents(
);

const eventIdsParams = getRequestParamFromList(
events.map((event) => event.uuid),
events.map((event) => event.uuid) as string[],
'eventUuids'
);

Expand Down
Loading
Loading