Skip to content

Commit

Permalink
Merge branch 'main' into feat_optim_users-identity_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
sBouzols authored Dec 19, 2024
2 parents 782193c + b10c6fb commit e9efc3a
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 44 deletions.
9 changes: 5 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.74.0",
"@gridsuite/commons-ui": "0.75.0",
"@hookform/resolvers": "^3.3.4",
"@mui/icons-material": "^5.15.14",
"@mui/lab": "5.0.0-alpha.169",
Expand Down
1 change: 1 addition & 0 deletions src/components/directory-content-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const getClickableRowStyle = (cellData: RowClassParams<ElementAttributes>) => {
ElementType.VOLTAGE_INIT_PARAMETERS,
ElementType.SHORT_CIRCUIT_PARAMETERS,
ElementType.SPREADSHEET_CONFIG,
ElementType.SPREADSHEET_CONFIG_COLLECTION,
].includes(cellData.data.type)
) {
style.cursor = 'pointer';
Expand Down
31 changes: 0 additions & 31 deletions src/components/directory-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useDispatch, useSelector } from 'react-redux';
import { FormattedMessage, useIntl } from 'react-intl';
import { Box, Button, CircularProgress, Grid, SxProps, Theme } from '@mui/material';
import {
CriteriaBasedFilterEditionDialog,
DescriptionModificationDialog,
ElementAttributes,
ElementType,
Expand Down Expand Up @@ -153,15 +152,6 @@ export default function DirectoryContent() {
setElementName('');
};

/** Filters dialog: window status value to edit CriteriaBased filters */
const [currentCriteriaBasedFilterId, setCurrentCriteriaBasedFilterId] = useState(null);
const handleCloseCriteriaBasedFilterDialog = () => {
setOpenDialog(constants.DialogsId.NONE);
setCurrentCriteriaBasedFilterId(null);
setActiveElement(null);
setElementName('');
};

const [currentExplicitNamingFilterId, setCurrentExplicitNamingFilterId] = useState(null);
/** Filters dialog: window status value to edit ExplicitNaming filters */
const handleCloseExplicitNamingFilterDialog = () => {
Expand Down Expand Up @@ -365,9 +355,6 @@ export default function DirectoryContent() {
if (subtype === FilterType.EXPLICIT_NAMING.id) {
setCurrentExplicitNamingFilterId(event.data.elementUuid);
setOpenDialog(subtype);
} else if (subtype === FilterType.CRITERIA_BASED.id) {
setCurrentCriteriaBasedFilterId(event.data.elementUuid);
setOpenDialog(subtype);
} else if (subtype === FilterType.EXPERT.id) {
setCurrentExpertFilterId(event.data.elementUuid);
setOpenDialog(subtype);
Expand Down Expand Up @@ -552,24 +539,6 @@ export default function DirectoryContent() {
language={languageLocal}
/>
);
case FilterType.CRITERIA_BASED.id:
return (
<CriteriaBasedFilterEditionDialog
// @ts-expect-error TODO: manage null case(s) here
id={currentCriteriaBasedFilterId}
open
onClose={handleCloseCriteriaBasedFilterDialog}
titleId="editFilter"
name={name}
broadcastChannel={broadcastChannel}
getFilterById={getFilterById}
selectionForCopy={selectionForCopy}
setSelectionForCopy={setItemSelectionForCopy}
activeDirectory={activeDirectory}
elementExists={elementExists}
language={languageLocal}
/>
);
case FilterType.EXPERT.id:
return (
<ExpertFilterEditionDialog
Expand Down
14 changes: 13 additions & 1 deletion src/components/menus/content-contextual-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
deleteElements,
duplicateElement,
duplicateSpreadsheetConfig,
duplicateSpreadsheetConfigCollection,
elementExists,
moveElementsToDirectory,
newScriptFromFilter,
Expand Down Expand Up @@ -169,6 +170,7 @@ export default function ContentContextualMenu(props: Readonly<ContentContextualM
case ElementType.LOADFLOW_PARAMETERS:
case ElementType.SHORT_CIRCUIT_PARAMETERS:
case ElementType.SPREADSHEET_CONFIG:
case ElementType.SPREADSHEET_CONFIG_COLLECTION:
console.info(
`${activeElement.type} with uuid ${activeElement.elementUuid} from directory ${selectedDirectory?.elementUuid} selected for copy`
);
Expand Down Expand Up @@ -241,6 +243,11 @@ export default function ContentContextualMenu(props: Readonly<ContentContextualM
handleDuplicateError(error.message);
});
break;
case ElementType.SPREADSHEET_CONFIG_COLLECTION:
duplicateSpreadsheetConfigCollection(activeElement.elementUuid).catch((error) => {
handleDuplicateError(error.message);
});
break;
default: {
handleLastError(intl.formatMessage({ id: 'unsupportedItem' }));
}
Expand Down Expand Up @@ -409,6 +416,7 @@ export default function ContentContextualMenu(props: Readonly<ContentContextualM
ElementType.SHORT_CIRCUIT_PARAMETERS,
ElementType.LOADFLOW_PARAMETERS,
ElementType.SPREADSHEET_CONFIG,
ElementType.SPREADSHEET_CONFIG_COLLECTION,
];

const hasMetadata = selectedElements[0]?.hasMetadata;
Expand Down Expand Up @@ -453,7 +461,11 @@ export default function ContentContextualMenu(props: Readonly<ContentContextualM
);

const allowsDownload = useCallback(() => {
const allowedTypes = [ElementType.CASE, ElementType.SPREADSHEET_CONFIG];
const allowedTypes = [
ElementType.CASE,
ElementType.SPREADSHEET_CONFIG,
ElementType.SPREADSHEET_CONFIG_COLLECTION,
];
// if selectedElements contains at least one of the allowed types
return selectedElements.some((element) => allowedTypes.includes(element.type)) && noCreationInProgress();
}, [selectedElements, noCreationInProgress]);
Expand Down
6 changes: 6 additions & 0 deletions src/components/menus/directory-tree-contextual-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
deleteElement,
duplicateElement,
duplicateSpreadsheetConfig,
duplicateSpreadsheetConfigCollection,
elementExists,
insertDirectory,
insertRootDirectory,
Expand Down Expand Up @@ -172,6 +173,11 @@ export default function DirectoryTreeContextualMenu(props: Readonly<DirectoryTre
handlePasteError(error)
);
break;
case ElementType.SPREADSHEET_CONFIG_COLLECTION:
duplicateSpreadsheetConfigCollection(selectionForPaste.sourceItemUuid, directoryUuid).catch(
(error: any) => handlePasteError(error)
);
break;
default:
handleError(
intl.formatMessage({
Expand Down
6 changes: 5 additions & 1 deletion src/components/toolbars/content-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ export default function ContentToolbar(props: Readonly<ContentToolbarProps>) {
);

const allowsDownload = useMemo(() => {
const allowedTypes = [ElementType.CASE, ElementType.SPREADSHEET_CONFIG];
const allowedTypes = [
ElementType.CASE,
ElementType.SPREADSHEET_CONFIG,
ElementType.SPREADSHEET_CONFIG_COLLECTION,
];
// if selectedElements contains at least one of the allowed types
return selectedElements.some((element) => allowedTypes.includes(element.type)) && noCreationInProgress;
}, [selectedElements, noCreationInProgress]);
Expand Down
25 changes: 24 additions & 1 deletion src/components/utils/downloadUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import { useIntl } from 'react-intl';
import { ElementAttributes, ElementType, useSnackMessage } from '@gridsuite/commons-ui';
import { useCallback, useState } from 'react';
import { UUID } from 'crypto';
import { downloadCase, downloadSpreadsheetConfig, fetchConvertedCase, getCaseOriginalName } from '../../utils/rest-api';
import {
downloadCase,
downloadSpreadsheetConfig,
downloadSpreadsheetConfigCollection,
fetchConvertedCase,
getCaseOriginalName,
} from '../../utils/rest-api';

interface DownloadData {
blob: Blob;
Expand Down Expand Up @@ -56,6 +62,23 @@ const downloadStrategies: { [key in ElementType]?: (element: ElementAttributes)
return { blob: await result.blob(), filename };
}
},
[ElementType.SPREADSHEET_CONFIG_COLLECTION]: async (element: ElementAttributes) => {
const result = await downloadSpreadsheetConfigCollection(element.elementUuid);
const filename = `${element.elementName}.json`;
try {
// Parse the JSON to ensure it's valid
const jsonContent = await result.json();
// Stringify with indentation for pretty formatting
const prettyJson = JSON.stringify(jsonContent, null, 2);
// Create a new Blob with the pretty-formatted JSON
const blob = new Blob([prettyJson], { type: 'application/json' });
return { blob, filename };
} catch (error) {
// If parsing fails, fall back to the original blob
console.error('Error parsing JSON:', error);
return { blob: await result.blob(), filename };
}
},
};

export function useDownloadUtils() {
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"editFilter": "Edit filter",
"STUDY": "Study",
"SPREADSHEET_CONFIG": "Spreadsheet model",
"SPREADSHEET_CONFIG_COLLECTION": "Spreadsheet model collection",
"VOLTAGE_INIT_PARAMETERS": "Settings (Voltage profile initialization)",
"SECURITY_ANALYSIS_PARAMETERS": "Settings (Security analysis)",
"SENSITIVITY_PARAMETERS": "Settings (Sensitivity analysis)",
Expand Down
3 changes: 1 addition & 2 deletions src/translations/external/backend-locale-en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ const BackendLocaleEn = {
MATPOWER: 'MATPOWER',
POWERFACTORY: 'POWERFACTORY',
'IEEE CDF': 'IEEE CDF',
EXPERT_FILTER: 'Filter (Expert)',
EXPERT_FILTER: 'Filter (Criteria based)',
FORM_FILTER: 'Filter (Form)',
IDENTIFIERS_CONTINGENCY_LIST: 'Contingency list (Explicit naming)',
FORM_CONTINGENCY_LIST: 'Contingency list (Criteria based)',
SCRIPT_FILTER: 'Filter (Script)',
SCRIPT_CONTINGENCY_LIST: 'Contingency list (Script)',
IDENTIFIER_LIST_FILTER: 'Filter (Explicit naming)',
CRITERIA_FILTER: 'Filter (Criteria based)',

// spreadsheet config metadata
Load: 'Load',
Expand Down
3 changes: 1 addition & 2 deletions src/translations/external/backend-locale-fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ const BackendLocaleFr = {
MATPOWER: 'MATPOWER',
POWERFACTORY: 'POWERFACTORY',
'IEEE CDF': 'IEEE CDF',
EXPERT_FILTER: 'Filtre (Expert)',
EXPERT_FILTER: 'Filtre (Par critères)',
FORM_FILTER: 'Filtre (Formulaire)',
IDENTIFIERS_CONTINGENCY_LIST: "Liste d'aléas (Par nommage)",
FORM_CONTINGENCY_LIST: "Liste d'aléas (Par critères)",
SCRIPT_FILTER: 'Filtre (Script)',
SCRIPT_CONTINGENCY_LIST: "Liste d'aléas (Script)",
IDENTIFIER_LIST_FILTER: 'Filtre (Par nommage)',
CRITERIA_FILTER: 'Filtre (Par critères)',

// spreadsheet config metadata
Load: 'Consommation',
Expand Down
1 change: 1 addition & 0 deletions src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"editFilter": "Éditer le filtre",
"STUDY": "Étude",
"SPREADSHEET_CONFIG": "Modèle de tableur",
"SPREADSHEET_CONFIG_COLLECTION": "Modèles de tableur",
"VOLTAGE_INIT_PARAMETERS": "Paramètres (Initialisation du plan de tension)",
"SECURITY_ANALYSIS_PARAMETERS": "Paramètres (Analyse de sécurité)",
"SENSITIVITY_PARAMETERS": "Paramètres (Analyse de sensibilité)",
Expand Down
1 change: 0 additions & 1 deletion src/utils/elementType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

export const FilterType = {
CRITERIA_BASED: { id: 'CRITERIA', label: 'filter.criteriaBased' },
EXPLICIT_NAMING: { id: 'IDENTIFIER_LIST', label: 'filter.explicitNaming' },
EXPERT: { id: 'EXPERT', label: 'filter.expert' },
};
Expand Down
28 changes: 28 additions & 0 deletions src/utils/rest-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,22 @@ export function duplicateSpreadsheetConfig(sourceCaseUuid: UUID, parentDirectory
});
}

export function duplicateSpreadsheetConfigCollection(sourceCaseUuid: UUID, parentDirectoryUuid?: UUID) {
console.info('Duplicating a spreadsheet config collection...');
const queryParams = new URLSearchParams();
queryParams.append('duplicateFrom', sourceCaseUuid);
if (parentDirectoryUuid) {
queryParams.append('parentDirectoryUuid', parentDirectoryUuid);
}
const url = `${PREFIX_EXPLORE_SERVER_QUERIES}/v1/explore/spreadsheet-config-collections/duplicate?${queryParams.toString()}`;

console.debug(url);

return backendFetch(url, {
method: 'post',
});
}

export function downloadSpreadsheetConfig(configId: string) {
console.info(`Downloading spreadsheet config with id: ${configId}`);
const fetchUrl = `${PREFIX_SPREADSHEET_CONFIG_QUERIES}/v1/spreadsheet-configs/${configId}`;
Expand All @@ -448,6 +464,18 @@ export function downloadSpreadsheetConfig(configId: string) {
});
}

export function downloadSpreadsheetConfigCollection(collectionId: string) {
console.info(`Downloading spreadsheet config collection with id: ${collectionId}`);
const fetchUrl = `${PREFIX_SPREADSHEET_CONFIG_QUERIES}/v1/spreadsheet-config-collections/${collectionId}`;

return backendFetch(fetchUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
}

export function elementExists(directoryUuid: UUID | null | undefined, elementName: string, type: string) {
const elementNameEncoded = encodeURIComponent(elementName);
const existsElementUrl = `${PREFIX_DIRECTORY_SERVER_QUERIES}/v1/directories/${directoryUuid}/elements/${elementNameEncoded}/types/${type}`;
Expand Down

0 comments on commit e9efc3a

Please sign in to comment.