diff --git a/package-lock.json b/package-lock.json index b284e9a107..963349758f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,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", @@ -3201,8 +3201,9 @@ }, "node_modules/@gridsuite/commons-ui": { "version": "0.59.0", - "resolved": "https://registry.npmjs.org/@gridsuite/commons-ui/-/commons-ui-0.59.0.tgz", - "integrity": "sha512-RqQljHjIGi3P4kfHgXFIGXI3YyR6kg1n9YcpNkURgMRlwQjw5H6p3XasHIX8MJ1UuMm/+w1rbn9+lsrGNkpI9A==", + "resolved": "file:../commons-ui/gridsuite-commons-ui-0.59.0.tgz", + "integrity": "sha512-xfTfPhbRUQ2XcY+DN6l80C7iILrQ656N/rH8PFv77vDSi7Af+Dz9nlmSPydJgEAYI57T0PVnBwBnRdAVkyWp9g==", + "license": "MPL-2.0", "dependencies": { "@react-querybuilder/dnd": "^7.2.0", "@react-querybuilder/material": "^7.2.0", diff --git a/package.json b/package.json index 6e61568a52..2c86605fca 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/components/app-top-bar.jsx b/src/components/app-top-bar.jsx index 86082038ff..320339fb0a 100644 --- a/src/components/app-top-bar.jsx +++ b/src/components/app-top-bar.jsx @@ -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'; @@ -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: { diff --git a/src/components/app.jsx b/src/components/app.jsx index 5bf66386f8..853ef866d1 100644 --- a/src/components/app.jsx +++ b/src/components/app.jsx @@ -29,6 +29,9 @@ import { getPreLoginPath, initializeAuthenticationProd, useSnackMessage, + fetchAuthorizationCodeFlowFeatureFlag, + fetchDefaultParametersValues, + fetchIdpSettings, } from '@gridsuite/commons-ui'; import PageNotFound from './page-not-found'; @@ -72,11 +75,6 @@ import { fetchConfigParameter, fetchConfigParameters, } from '../services/config'; -import { - fetchAuthorizationCodeFlowFeatureFlag, - fetchDefaultParametersValues, - fetchIdpSettings, -} from '../services/utils'; import { getOptionalServices } from '../services/study'; import { changeDisplayedColumns, diff --git a/src/components/dialogs/commons/unique-name-input.tsx b/src/components/dialogs/commons/unique-name-input.tsx index fe2eae537d..6ba31388b9 100644 --- a/src/components/dialogs/commons/unique-name-input.tsx +++ b/src/components/dialogs/commons/unique-name-input.tsx @@ -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'; diff --git a/src/components/dialogs/network-modifications/generator-scaling/variation/variation-form.jsx b/src/components/dialogs/network-modifications/generator-scaling/variation/variation-form.jsx index 656d7ac675..5511217c94 100644 --- a/src/components/dialogs/network-modifications/generator-scaling/variation/variation-form.jsx +++ b/src/components/dialogs/network-modifications/generator-scaling/variation/variation-form.jsx @@ -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, @@ -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]; diff --git a/src/components/dialogs/network-modifications/tabular-creation/tabular-creation-dialog.jsx b/src/components/dialogs/network-modifications/tabular-creation/tabular-creation-dialog.jsx index d3392ceb02..5548b1662b 100644 --- a/src/components/dialogs/network-modifications/tabular-creation/tabular-creation-dialog.jsx +++ b/src/components/dialogs/network-modifications/tabular-creation/tabular-creation-dialog.jsx @@ -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, diff --git a/src/components/dialogs/network-modifications/tabular-modification/tabular-modification-dialog.jsx b/src/components/dialogs/network-modifications/tabular-modification/tabular-modification-dialog.jsx index 98c808f39a..21601bfb40 100644 --- a/src/components/dialogs/network-modifications/tabular-modification/tabular-modification-dialog.jsx +++ b/src/components/dialogs/network-modifications/tabular-modification/tabular-modification-dialog.jsx @@ -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, diff --git a/src/components/dialogs/parameters/common/parameters-creation-dialog.tsx b/src/components/dialogs/parameters/common/parameters-creation-dialog.tsx index c15bec871f..52db4771c2 100644 --- a/src/components/dialogs/parameters/common/parameters-creation-dialog.tsx +++ b/src/components/dialogs/parameters/common/parameters-creation-dialog.tsx @@ -17,6 +17,7 @@ import { CustomFormProvider, DirectoryItemSelector, ElementType, + fetchDirectoryElementPath, TreeViewFinderNodeProps, } from '@gridsuite/commons-ui'; import ModificationDialog from 'components/dialogs/commons/modificationDialog'; @@ -24,7 +25,6 @@ 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; diff --git a/src/components/dialogs/parameters/network-parameters.jsx b/src/components/dialogs/parameters/network-parameters.jsx index ae4e443402..4e669bb472 100644 --- a/src/components/dialogs/parameters/network-parameters.jsx +++ b/src/components/dialogs/parameters/network-parameters.jsx @@ -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'; diff --git a/src/components/graph/menus/network-modification-node-editor.jsx b/src/components/graph/menus/network-modification-node-editor.jsx index a3c94c5125..2b68406437 100644 --- a/src/components/graph/menus/network-modification-node-editor.jsx +++ b/src/components/graph/menus/network-modification-node-editor.jsx @@ -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'; @@ -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) => ({ diff --git a/src/components/network/filter-creation-panel.tsx b/src/components/network/filter-creation-panel.tsx index 773a53b896..b94b876411 100644 --- a/src/components/network/filter-creation-panel.tsx +++ b/src/components/network/filter-creation-panel.tsx @@ -11,6 +11,7 @@ import { CustomFormProvider, DirectoryItemSelector, ElementType, + fetchDirectoryElementPath, SelectInput, TreeViewFinderNodeProps, } from '@gridsuite/commons-ui'; @@ -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'; diff --git a/src/components/results/securityanalysis/security-analysis-export-button.tsx b/src/components/results/securityanalysis/security-analysis-export-button.tsx index 02340f8367..eb65f4e1d7 100644 --- a/src/components/results/securityanalysis/security-analysis-export-button.tsx +++ b/src/components/results/securityanalysis/security-analysis-export-button.tsx @@ -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 { @@ -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'; @@ -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) => { diff --git a/src/components/results/sensitivity-analysis/sensitivity-analysis-result-tab.jsx b/src/components/results/sensitivity-analysis/sensitivity-analysis-result-tab.jsx index e35d859147..862f0562cf 100644 --- a/src/components/results/sensitivity-analysis/sensitivity-analysis-result-tab.jsx +++ b/src/components/results/sensitivity-analysis/sensitivity-analysis-result-tab.jsx @@ -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'; @@ -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); @@ -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); }); }) diff --git a/src/components/results/shortcircuit/shortcircuit-analysis-export-button.tsx b/src/components/results/shortcircuit/shortcircuit-analysis-export-button.tsx index 581d89eab0..c119b12fb7 100644 --- a/src/components/results/shortcircuit/shortcircuit-analysis-export-button.tsx +++ b/src/components/results/shortcircuit/shortcircuit-analysis-export-button.tsx @@ -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'; @@ -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); }); diff --git a/src/components/study-container.jsx b/src/components/study-container.jsx index b6d29a4bf0..49eb45f122 100644 --- a/src/components/study-container.jsx +++ b/src/components/study-container.jsx @@ -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, @@ -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, diff --git a/src/services/case.ts b/src/services/case.ts index 1a6fec9098..0111a32411 100644 --- a/src/services/case.ts +++ b/src/services/case.ts @@ -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'; diff --git a/src/services/config-notification.js b/src/services/config-notification.js index c3441065f9..daa0c069ec 100644 --- a/src/services/config-notification.js +++ b/src/services/config-notification.js @@ -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'; diff --git a/src/services/config.js b/src/services/config.js index 9d78b22db7..980e5e5be7 100644 --- a/src/services/config.js +++ b/src/services/config.js @@ -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'; diff --git a/src/services/directory-notification.js b/src/services/directory-notification.js index 89314bb952..83d4e209bc 100644 --- a/src/services/directory-notification.js +++ b/src/services/directory-notification.js @@ -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'; @@ -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( diff --git a/src/services/directory.js b/src/services/directory.js index 921e850463..dd45acdd11 100644 --- a/src/services/directory.js +++ b/src/services/directory.js @@ -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'; diff --git a/src/services/dynamic-simulation.ts b/src/services/dynamic-simulation.ts index a3b2a109f9..b879ccc5a7 100644 --- a/src/services/dynamic-simulation.ts +++ b/src/services/dynamic-simulation.ts @@ -10,7 +10,7 @@ import { backendFetch, backendFetchJson, getRequestParamFromList, -} from './utils'; +} from '@gridsuite/commons-ui'; import { getStudyUrlWithNodeUuid } from './study'; import { UUID } from 'crypto'; import { @@ -133,7 +133,7 @@ export function deleteDynamicSimulationEvents( ); const eventIdsParams = getRequestParamFromList( - events.map((event) => event.uuid), + events.map((event) => event.uuid) as string[], 'eventUuids' ); diff --git a/src/services/explore.ts b/src/services/explore.ts index 27599abba9..ad1a73248d 100644 --- a/src/services/explore.ts +++ b/src/services/explore.ts @@ -5,13 +5,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { backendFetch } from './utils'; +import { backendFetch } from '@gridsuite/commons-ui'; import { UUID } from 'crypto'; const PREFIX_EXPLORE_SERVER_QUERIES = import.meta.env.VITE_API_GATEWAY + '/explore'; -const PREFIX_DIRECTORY_SERVER_QUERIES = - import.meta.env.VITE_API_GATEWAY + '/directory'; export function createParameter( newParameter: any, @@ -35,21 +33,6 @@ export function createParameter( ); } -export function elementExists( - directoryUuid: UUID, - elementName: string, - type: string -) { - const existsElementUrl = `${PREFIX_DIRECTORY_SERVER_QUERIES}/v1/directories/${directoryUuid}/elements/${elementName}/types/${type}`; - - console.debug(existsElementUrl); - return backendFetch(existsElementUrl, { method: 'head' }).then( - (response) => { - return response.status !== 204; // HTTP 204 : No-content - } - ); -} - export interface ModificationElementCreationProps { elementUuid: UUID; description: string; diff --git a/src/services/loadflow.js b/src/services/loadflow.js index f6b4acfbce..f4a507d68a 100644 --- a/src/services/loadflow.js +++ b/src/services/loadflow.js @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { backendFetchJson } from './utils'; +import { backendFetchJson } from '@gridsuite/commons-ui'; const PREFIX_LOADFLOW_SERVER_QUERIES = import.meta.env.VITE_API_GATEWAY + '/loadflow'; diff --git a/src/services/network-conversion.ts b/src/services/network-conversion.ts index 9da901593c..c30bb369a2 100644 --- a/src/services/network-conversion.ts +++ b/src/services/network-conversion.ts @@ -6,7 +6,7 @@ */ import { UUID } from 'crypto'; -import { backendFetchJson } from './utils'; +import { backendFetchJson } from '@gridsuite/commons-ui'; const PREFIX_NETWORK_CONVERSION_SERVER_QUERIES = import.meta.env.VITE_API_GATEWAY + '/network-conversion'; diff --git a/src/services/network-modification.js b/src/services/network-modification.js index e48d38b223..8f6d0f7c20 100644 --- a/src/services/network-modification.js +++ b/src/services/network-modification.js @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { backendFetch, backendFetchJson } from './utils'; +import { backendFetch, backendFetchJson } from '@gridsuite/commons-ui'; const PREFIX_NETWORK_MODIFICATION_QUERIES = import.meta.env.VITE_API_GATEWAY + '/network-modification'; diff --git a/src/services/security-analysis.js b/src/services/security-analysis.js index 2d86db534c..e18683621f 100644 --- a/src/services/security-analysis.js +++ b/src/services/security-analysis.js @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { backendFetchJson } from './utils'; +import { backendFetchJson } from '@gridsuite/commons-ui'; const PREFIX_SECURITY_ANALYSIS_SERVER_QUERIES = import.meta.env.VITE_API_GATEWAY + '/security-analysis'; diff --git a/src/services/sensitivity-analysis.js b/src/services/sensitivity-analysis.js index fe54dc9ac9..e9a18bcc5f 100644 --- a/src/services/sensitivity-analysis.js +++ b/src/services/sensitivity-analysis.js @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { backendFetchJson } from './utils'; +import { backendFetchJson } from '@gridsuite/commons-ui'; const PREFIX_SENSITIVITY_ANALYSIS_SERVER_QUERIES = import.meta.env.VITE_API_GATEWAY + '/sensitivity-analysis'; diff --git a/src/services/study-notification.js b/src/services/study-notification.js index 580507120a..ced54affa6 100644 --- a/src/services/study-notification.js +++ b/src/services/study-notification.js @@ -7,7 +7,7 @@ import ReconnectingWebSocket from 'reconnecting-websocket'; -import { getUrlWithToken, getWsBase } from './utils'; +import { getWsBase, getUrlWithToken } from '@gridsuite/commons-ui'; const PREFIX_STUDY_NOTIFICATION_WS = import.meta.env.VITE_WS_GATEWAY + '/study-notification'; diff --git a/src/services/study/dynamic-simulation.js b/src/services/study/dynamic-simulation.js index 813ff1888b..6fc7e36c99 100644 --- a/src/services/study/dynamic-simulation.js +++ b/src/services/study/dynamic-simulation.js @@ -16,7 +16,7 @@ import { backendFetchJson, backendFetchText, getRequestParamFromList, -} from '../utils'; +} from '@gridsuite/commons-ui'; export function getDynamicMappings(studyUuid) { console.info(`Fetching dynamic mappings on '${studyUuid}' ...`); diff --git a/src/services/study/filter.ts b/src/services/study/filter.ts index 453f9d1953..a7dbc6426f 100644 --- a/src/services/study/filter.ts +++ b/src/services/study/filter.ts @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { backendFetchJson } from '../utils'; +import { backendFetchJson } from '@gridsuite/commons-ui'; import { UUID } from 'crypto'; import { getStudyUrlWithNodeUuid } from './index'; import { RuleGroupTypeExport } from '../../components/dialogs/filter/expert/expert-filter.type'; diff --git a/src/services/study/geo-data.js b/src/services/study/geo-data.js index c2591e98df..d61a119b96 100644 --- a/src/services/study/geo-data.js +++ b/src/services/study/geo-data.js @@ -5,7 +5,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { backendFetchJson, getQueryParamsList } from '../utils'; +import { + backendFetchJson, + getRequestParamFromList, +} from '@gridsuite/commons-ui'; import { getStudyUrlWithNodeUuid } from './index'; export function fetchSubstationPositions( @@ -19,7 +22,7 @@ export function fetchSubstationPositions( const paramsList = substationsIds && substationsIds.length > 0 - ? '?' + getQueryParamsList(substationsIds, 'substationId') + ? '?' + getRequestParamFromList(substationsIds, 'substationId') : ''; const fetchSubstationPositionsUrl = @@ -37,7 +40,7 @@ export function fetchLinePositions(studyUuid, currentNodeUuid, linesIds) { const paramsList = linesIds && linesIds.length > 0 - ? '?' + getQueryParamsList(linesIds, 'lineId') + ? '?' + getRequestParamFromList(linesIds, 'lineId') : ''; const fetchLinePositionsUrl = diff --git a/src/services/study/index.js b/src/services/study/index.js index 9ce1ffe94a..21afe6f586 100644 --- a/src/services/study/index.js +++ b/src/services/study/index.js @@ -9,9 +9,14 @@ import { backendFetch, backendFetchJson, backendFetchText, - getQueryParamsList, getRequestParamFromList, -} from '../utils'; +} from '@gridsuite/commons-ui'; + +// By moving above utils functions in commons-ui and removing import from services/utils +// created multiple circular dependencies issues, so in the meantime its other +// functions are being exported as a crutch... To be removed once circular +// dependencies are fixed +export { fetchMapBoxToken } from '../utils'; export const PREFIX_STUDY_QUERIES = import.meta.env.VITE_API_GATEWAY + '/study'; @@ -53,7 +58,7 @@ export function getNetworkAreaDiagramUrl( depth: depth, }) + '&' + - getQueryParamsList(voltageLevelsIds, 'voltageLevelsIds').toString() + getRequestParamFromList(voltageLevelsIds, 'voltageLevelsIds').toString() ); } diff --git a/src/services/study/loadflow.js b/src/services/study/loadflow.js index 10d3e8097e..7ca4294a2c 100644 --- a/src/services/study/loadflow.js +++ b/src/services/study/loadflow.js @@ -10,7 +10,11 @@ import { getStudyUrlWithNodeUuid, PREFIX_STUDY_QUERIES, } from './index'; -import { backendFetch, backendFetchJson, backendFetchText } from '../utils'; +import { + backendFetch, + backendFetchJson, + backendFetchText, +} from '@gridsuite/commons-ui'; export function getDefaultLoadFlowProvider() { console.info('get default load flow provier'); diff --git a/src/services/study/network-map.js b/src/services/study/network-map.js index 07e2e7b2db..398e7380d4 100644 --- a/src/services/study/network-map.js +++ b/src/services/study/network-map.js @@ -6,10 +6,13 @@ */ import { getStudyUrlWithNodeUuid } from './index'; -import { backendFetchJson, getQueryParamsList } from '../utils'; +import { + backendFetchJson, + getRequestParamFromList, + createFilter, +} from '@gridsuite/commons-ui'; import { NAME } from '../../components/utils/field-constants.js'; import { EQUIPMENT_TYPES } from '../../components/utils/equipment-types.js'; -import { createFilter } from '@gridsuite/commons-ui'; export function fetchHvdcLineWithShuntCompensators( studyUuid, @@ -41,7 +44,7 @@ export function fetchAllEquipments(studyUuid, currentNodeUuid, substationsIds) { getStudyUrlWithNodeUuid(studyUuid, currentNodeUuid) + '/network-map/all' + '?' + - getQueryParamsList(substationsIds, 'substationId'); + getRequestParamFromList(substationsIds, 'substationId'); console.debug(fetchEquipmentsUrl); return backendFetchJson(fetchEquipmentsUrl); } @@ -71,7 +74,7 @@ export function fetchVoltageLevelEquipments( encodeURIComponent(voltageLevelId) + '/equipments' + '?' + - getQueryParamsList(substationsIds, 'substationId') + + getRequestParamFromList(substationsIds, 'substationId') + urlSearchParams.toString(); console.debug(fetchEquipmentsUrl); return backendFetchJson(fetchEquipmentsUrl); diff --git a/src/services/study/network-modifications.js b/src/services/study/network-modifications.js index 1a0fa465a4..07f880f138 100644 --- a/src/services/study/network-modifications.js +++ b/src/services/study/network-modifications.js @@ -10,7 +10,11 @@ import { toModificationOperation, toModificationUnsetOperation, } from '../../components/utils/utils'; -import { backendFetch, backendFetchJson, backendFetchText } from '../utils'; +import { + backendFetch, + backendFetchJson, + backendFetchText, +} from '@gridsuite/commons-ui'; import { getStudyUrlWithNodeUuid, PREFIX_STUDY_QUERIES } from './index'; import { EQUIPMENT_TYPES } from '../../components/utils/equipment-types'; import { @@ -1836,6 +1840,7 @@ export function modifyVsc( body: JSON.stringify(vscModification), }); } + export function modifyByFormula( studyUuid, currentNodeUuid, diff --git a/src/services/study/network.js b/src/services/study/network.js index 4f2b85e1ed..0acc9e300c 100644 --- a/src/services/study/network.js +++ b/src/services/study/network.js @@ -16,7 +16,7 @@ import { backendFetchText, getRequestParamFromList, getUrlWithToken, -} from '../utils'; +} from '@gridsuite/commons-ui'; /* voltage-levels */ export function getVoltageLevelSingleLineDiagram( diff --git a/src/services/study/non-evacuated-energy.js b/src/services/study/non-evacuated-energy.js index 230b7d8a16..330a4fdcb0 100644 --- a/src/services/study/non-evacuated-energy.js +++ b/src/services/study/non-evacuated-energy.js @@ -10,7 +10,11 @@ import { getStudyUrlWithNodeUuid, PREFIX_STUDY_QUERIES, } from './index'; -import { backendFetch, backendFetchJson, backendFetchText } from '../utils'; +import { + backendFetch, + backendFetchJson, + backendFetchText, +} from '@gridsuite/commons-ui'; export function startNonEvacuatedEnergy(studyUuid, currentNodeUuid) { console.info( diff --git a/src/services/study/security-analysis.js b/src/services/study/security-analysis.js index 376c712d3b..854d1c99bc 100644 --- a/src/services/study/security-analysis.js +++ b/src/services/study/security-analysis.js @@ -16,7 +16,7 @@ import { backendFetchJson, backendFetchText, getRequestParamFromList, -} from '../utils'; +} from '@gridsuite/commons-ui'; export function startSecurityAnalysis( studyUuid, diff --git a/src/services/study/sensitivity-analysis.js b/src/services/study/sensitivity-analysis.js index 30bc61dc71..33d01d63e8 100644 --- a/src/services/study/sensitivity-analysis.js +++ b/src/services/study/sensitivity-analysis.js @@ -10,7 +10,11 @@ import { getStudyUrl, getStudyUrlWithNodeUuid, } from './index'; -import { backendFetch, backendFetchJson, backendFetchText } from '../utils'; +import { + backendFetch, + backendFetchJson, + backendFetchText, +} from '@gridsuite/commons-ui'; const GET_PARAMETERS_PREFIX = import.meta.env.VITE_API_GATEWAY + '/sensitivity-analysis/v1/parameters'; diff --git a/src/services/study/short-circuit-analysis.js b/src/services/study/short-circuit-analysis.js index 3016d51126..6be1475810 100644 --- a/src/services/study/short-circuit-analysis.js +++ b/src/services/study/short-circuit-analysis.js @@ -10,7 +10,11 @@ import { getShortCircuitAnalysisTypeFromEnum, ShortCircuitAnalysisType, } from '../../components/results/shortcircuit/shortcircuit-analysis-result.type'; -import { backendFetch, backendFetchJson, backendFetchText } from '../utils'; +import { + backendFetch, + backendFetchJson, + backendFetchText, +} from '@gridsuite/commons-ui'; export function startShortCircuitAnalysis(studyUuid, currentNodeUuid, busId) { console.info( diff --git a/src/services/study/study.ts b/src/services/study/study.ts index 55c00de947..5a24d06b40 100644 --- a/src/services/study/study.ts +++ b/src/services/study/study.ts @@ -7,7 +7,7 @@ import { UUID } from 'crypto'; import { PREFIX_STUDY_QUERIES } from '.'; -import { backendFetch } from '../utils'; +import { backendFetch } from '@gridsuite/commons-ui'; interface BasicStudyInfos { uniqueId: string; diff --git a/src/services/study/tree-subtree.js b/src/services/study/tree-subtree.js index 2483cc87a7..d58930c0a3 100644 --- a/src/services/study/tree-subtree.js +++ b/src/services/study/tree-subtree.js @@ -6,7 +6,7 @@ */ import { getStudyUrl } from './index'; -import { backendFetch, backendFetchJson } from '../utils'; +import { backendFetch, backendFetchJson } from '@gridsuite/commons-ui'; export function copySubtree( sourceStudyUuid, diff --git a/src/services/study/voltage-init.js b/src/services/study/voltage-init.js index 5d2c29fdf7..64383a0aeb 100644 --- a/src/services/study/voltage-init.js +++ b/src/services/study/voltage-init.js @@ -6,7 +6,11 @@ */ import { getStudyUrl, getStudyUrlWithNodeUuid } from './index'; -import { backendFetch, backendFetchJson, backendFetchText } from '../utils'; +import { + backendFetch, + backendFetchJson, + backendFetchText, +} from '@gridsuite/commons-ui'; export function startVoltageInit(studyUuid, currentNodeUuid) { console.info( diff --git a/src/services/user-admin.js b/src/services/user-admin.js index 55d81fb592..cf6921a5a6 100644 --- a/src/services/user-admin.js +++ b/src/services/user-admin.js @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { backendFetch } from './utils'; +import { backendFetch } from '@gridsuite/commons-ui'; const PREFIX_USER_ADMIN_SERVER_QUERIES = import.meta.env.VITE_API_GATEWAY + '/user-admin'; diff --git a/src/services/utils.js b/src/services/utils.js index e9bbfedca3..d4acf3daee 100644 --- a/src/services/utils.js +++ b/src/services/utils.js @@ -4,8 +4,7 @@ * 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 { store } from '../redux/store'; -import { fetchAppsMetadata } from '@gridsuite/commons-ui'; +import { fetchEnv } from '@gridsuite/commons-ui'; export const FetchStatus = { SUCCEED: 'SUCCEED', @@ -14,204 +13,6 @@ export const FetchStatus = { RUNNING: 'RUNNING', }; -export const getWsBase = () => - document.baseURI - .replace(/^http:\/\//, 'ws://') - .replace(/^https:\/\//, 'wss://'); - -export const getRequestParamFromList = (params, paramName) => { - return new URLSearchParams( - params?.length ? params.map((param) => [paramName, param]) : [] - ); -}; - -const parseError = (text) => { - try { - return JSON.parse(text); - } catch (err) { - return null; - } -}; - -const handleError = (response) => { - return response.text().then((text) => { - const errorName = 'HttpResponseError : '; - let error; - const errorJson = parseError(text); - if ( - errorJson && - errorJson.status && - errorJson.error && - errorJson.message - ) { - error = new Error( - errorName + - errorJson.status + - ' ' + - errorJson.error + - ', message : ' + - errorJson.message - ); - error.status = errorJson.status; - } else { - error = new Error( - errorName + - response.status + - ' ' + - response.statusText + - ', message : ' + - text - ); - error.status = response.status; - } - throw error; - }); -}; - -export const getToken = () => { - const state = store.getState(); - return state.user.id_token; -}; - -const prepareRequest = (init, token) => { - if (!(typeof init == 'undefined' || typeof init == 'object')) { - throw new TypeError( - 'Argument 2 of backendFetch is not an object' + typeof init - ); - } - const initCopy = Object.assign({}, init); - initCopy.headers = new Headers(initCopy.headers || {}); - const tokenCopy = token ? token : getToken(); - initCopy.headers.append('Authorization', 'Bearer ' + tokenCopy); - return initCopy; -}; - -const safeFetch = (url, initCopy) => { - return fetch(url, initCopy).then((response) => - response.ok ? response : handleError(response) - ); -}; - -export const backendFetch = (url, init, token) => { - const initCopy = prepareRequest(init, token); - return safeFetch(url, initCopy); -}; - -export const backendFetchText = (url, init, token) => { - const initCopy = prepareRequest(init, token); - return safeFetch(url, initCopy).then((safeResponse) => safeResponse.text()); -}; - -export const backendFetchJson = (url, init, token) => { - const initCopy = prepareRequest(init, token); - return safeFetch(url, initCopy).then((safeResponse) => - safeResponse.status === 204 ? null : safeResponse.json() - ); -}; - -export const backendFetchFile = (url, init, token) => { - const initCopy = prepareRequest(init, token); - return safeFetch(url, initCopy).then((safeResponse) => safeResponse.blob()); -}; - -const FILE_TYPE = { - ZIP: 'ZIP', -}; -export const downloadZipFile = (blob, fileName) => { - downloadFile(blob, fileName, FILE_TYPE.ZIP); -}; - -const downloadFile = (blob, filename, type) => { - let contentType; - if (type === FILE_TYPE.ZIP) { - contentType = 'application/octet-stream'; - } - const href = window.URL.createObjectURL(new Blob([blob], { contentType })); - const link = document.createElement('a'); - link.href = href; - link.setAttribute('download', filename); - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); -}; - -function fetchEnv() { - return fetch('env.json').then((res) => res.json()); -} - -export function fetchIdpSettings() { - return fetch('idpSettings.json'); -} - -export function fetchAuthorizationCodeFlowFeatureFlag() { - console.info(`Fetching authorization code flow feature flag...`); - return fetchEnv() - .then((env) => - fetch(env.appsMetadataServerUrl + '/authentication.json') - ) - .then((res) => res.json()) - .then((res) => { - console.log( - `Authorization code flow is ${ - res.authorizationCodeFlowFeatureFlag - ? 'enabled' - : 'disabled' - }` - ); - return res.authorizationCodeFlowFeatureFlag; - }) - .catch((error) => { - console.error(error); - console.warn( - `Something wrong happened when retrieving authentication.json: authorization code flow will be disabled` - ); - return false; - }); -} - -export function fetchVersion() { - console.info(`Fetching global metadata...`); - return fetchEnv() - .then((env) => fetch(env.appsMetadataServerUrl + '/version.json')) - .then((response) => response.json()) - .catch((reason) => { - console.error('Error while fetching the version : ' + reason); - return reason; - }); -} - -export const fetchDefaultParametersValues = () => { - return fetchAppsMetadata().then((res) => { - console.info( - 'fecthing default parameters values from apps-metadata file' - ); - const studyMetadata = res.find((metadata) => metadata.name === 'Study'); - if (!studyMetadata) { - return Promise.reject( - 'Study entry could not be found in metadatas' - ); - } - - return studyMetadata.defaultParametersValues; - }); -}; -export const getQueryParamsList = (params, paramName) => { - if (params !== undefined && params.length > 0) { - const urlSearchParams = new URLSearchParams(); - params.forEach((id) => urlSearchParams.append(paramName, id)); - return urlSearchParams.toString(); - } - return ''; -}; - -export function getUrlWithToken(baseUrl) { - if (baseUrl.includes('?')) { - return baseUrl + '&access_token=' + getToken(); - } else { - return baseUrl + '?access_token=' + getToken(); - } -} - export function fetchMapBoxToken() { console.info(`Fetching MapBoxToken...`); return fetchEnv().then((res) => res.mapBoxToken); diff --git a/src/services/voltage-init.ts b/src/services/voltage-init.ts index 4284bbc413..81f8b0e174 100644 --- a/src/services/voltage-init.ts +++ b/src/services/voltage-init.ts @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { UUID } from 'crypto'; -import { backendFetchJson } from './utils'; +import { backendFetchJson } from '@gridsuite/commons-ui'; export const PREFIX_VOLTAGE_INIT_QUERIES = import.meta.env.VITE_API_GATEWAY + '/voltage-init';