Skip to content

Commit

Permalink
Hide some contextual menu items while creating case or study (#318)
Browse files Browse the repository at this point in the history
Signed-off-by: David BRAQUART <david.braquart@rte-france.com>
  • Loading branch information
dbraquart authored Jan 23, 2024
1 parent 0b46474 commit ff2be1d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 23 deletions.
14 changes: 13 additions & 1 deletion src/components/directory-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,12 @@ const DirectoryContent = () => {

if (element && element.uploading !== null) {
if (element.type !== 'DIRECTORY') {
setActiveElement(element);
setActiveElement({
hasMetadata:
childrenMetadata[event.rowData.elementUuid] !==
undefined,
...element,
});

if (contextualMixPolicy === contextualMixPolicies.BIG) {
// If some elements were already selected and the active element is not in them, we deselect the already selected elements.
Expand Down Expand Up @@ -347,6 +352,7 @@ const DirectoryContent = () => {
selectedUuids,
contextualMixPolicies,
contextualMixPolicy,
childrenMetadata,
]
);

Expand Down Expand Up @@ -781,6 +787,9 @@ const DirectoryContent = () => {
return {
subtype:
childrenMetadata[child.elementUuid]?.subtype,
hasMetadata:
childrenMetadata[child.elementUuid] !==
undefined,
...child,
};
});
Expand All @@ -792,6 +801,9 @@ const DirectoryContent = () => {
...activeElement,
subtype:
childrenMetadata[activeElement.elementUuid]?.subtype,
hasMetadata:
childrenMetadata[activeElement.elementUuid] !==
undefined,
});
}
}
Expand Down
31 changes: 17 additions & 14 deletions src/components/menus/content-contextual-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ const ContentContextualMenu = (props) => {
false
);

const isNotUploadingElement = useCallback(() => {
return selectedElements.every((el) => !el.uploading);
const noCreationInProgress = useCallback(() => {
return selectedElements.every((el) => el.hasMetadata);
}, [selectedElements]);

// Allowance
Expand All @@ -434,44 +434,45 @@ const ContentContextualMenu = (props) => {
}, [selectedElements, userId]);

const allowsDelete = useCallback(() => {
return isUserAllowed() && isNotUploadingElement();
}, [isUserAllowed, isNotUploadingElement]);
return isUserAllowed() && noCreationInProgress();
}, [isUserAllowed, noCreationInProgress]);

const allowsRename = useCallback(() => {
return (
selectedElements.length === 1 &&
isUserAllowed() &&
!selectedElements[0].uploading
selectedElements[0].hasMetadata
);
}, [isUserAllowed, selectedElements]);

const allowsMove = useCallback(() => {
return (
selectedElements.every(
(element) =>
element.type !== ElementType.DIRECTORY && !element.uploading
element.type !== ElementType.DIRECTORY &&
element.hasMetadata
) && isUserAllowed()
);
}, [isUserAllowed, selectedElements]);

const allowsDuplicate = useCallback(() => {
return (
selectedElements[0].hasMetadata &&
selectedElements.length === 1 &&
(selectedElements[0].type === ElementType.CASE ||
selectedElements[0].type === ElementType.STUDY ||
selectedElements[0].type === ElementType.CONTINGENCY_LIST ||
selectedElements[0].type === ElementType.FILTER ||
selectedElements[0].type ===
ElementType.VOLTAGE_INIT_PARAMETERS) &&
!selectedElements[0].uploading
ElementType.VOLTAGE_INIT_PARAMETERS)
);
}, [selectedElements]);

const allowsCreateNewStudyFromCase = useCallback(() => {
return (
selectedElements.length === 1 &&
selectedElements[0].type === ElementType.CASE &&
!selectedElements[0].uploading
selectedElements[0].hasMetadata
);
}, [selectedElements]);

Expand All @@ -496,10 +497,12 @@ const ContentContextualMenu = (props) => {

const allowsDownloadCase = useCallback(() => {
//if selectedElements contains at least one case
return selectedElements.some(
(element) => element.type === ElementType.CASE
return (
selectedElements.some(
(element) => element.type === ElementType.CASE
) && noCreationInProgress()
);
}, [selectedElements]);
}, [selectedElements, noCreationInProgress]);

const handleDownloadCases = useCallback(async () => {
const casesUuids = selectedElements
Expand Down Expand Up @@ -613,9 +616,9 @@ const ContentContextualMenu = (props) => {

if (menuItems.length === 0) {
menuItems.push({
messageDescriptorId: isNotUploadingElement()
messageDescriptorId: noCreationInProgress()
? 'notElementCreator'
: 'uploadingElement',
: 'elementCreationInProgress',
icon: <DoNotDisturbAltIcon fontSize="small" />,
disabled: true,
});
Expand Down
22 changes: 16 additions & 6 deletions src/components/toolbars/content-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,32 @@ const ContentToolbar = (props) => {
[selectedElements, userId]
);

const allowsDelete = useMemo(() => isUserAllowed, [isUserAllowed]);
const noCreationInProgress = useMemo(
() => selectedElements.every((el) => el.hasMetadata),
[selectedElements]
);

const allowsDelete = useMemo(
() => isUserAllowed && noCreationInProgress,
[isUserAllowed, noCreationInProgress]
);

const allowsMove = useMemo(
() =>
selectedElements.every(
(element) => element.type !== ElementType.DIRECTORY
) && isUserAllowed,
[isUserAllowed, selectedElements]
) &&
isUserAllowed &&
noCreationInProgress,
[isUserAllowed, selectedElements, noCreationInProgress]
);

const allowsDownloadCases = useMemo(
() =>
selectedElements.every(
selectedElements.some(
(element) => element.type === ElementType.CASE
),
[selectedElements]
) && noCreationInProgress,
[selectedElements, noCreationInProgress]
);

const items = useMemo(
Expand Down
2 changes: 1 addition & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
"moveElementNotFoundError": "The element or the targeted folder was not found",
"moveElementNotAllowedError": "You cannot move this element to the targeted folder. Unauthorized action",
"notElementCreator": "You are not the element's creator",
"uploadingElement": "Upload in progress: no operation permitted",
"elementCreationInProgress": "Creation in progress: no operation permitted",
"serverConnectionFailed": "Failed to connect to server. Please retry later.",
"invalidFormatOrName": "Imported file name or format invalid",
"parameterLoadingProblem": "problem of loading parameters",
Expand Down
2 changes: 1 addition & 1 deletion src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
"moveElementNotFoundError": "L'élément ou le dossier cible n'a pas été trouvé",
"moveElementNotAllowedError": "Vous ne pouvez pas déplacer cet élément dans le dossier cible. Action non autorisée",
"notElementCreator": "Vous n'êtes pas le créateur de l'élément",
"uploadingElement": "Téléversement en cours : pas d'opération autorisée",
"elementCreationInProgress": "Création en cours : pas d'opération autorisée",
"serverConnectionFailed": "Échec de connexion avec le serveur. Veuillez réessayer ultérieurement",
"invalidFormatOrName": "Format ou nom du fichier importé non valide",
"parameterLoadingProblem": "Problème de chargement des paramètres",
Expand Down

0 comments on commit ff2be1d

Please sign in to comment.