Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/gridsuite/gridexplore-app i…
Browse files Browse the repository at this point in the history
…nto add_fields_expert_filter
  • Loading branch information
AAJELLAL committed Jan 24, 2024
2 parents f851521 + ff2be1d commit fc7a259
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 75 deletions.
132 changes: 79 additions & 53 deletions src/components/directory-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ const DirectoryContent = () => {
};

/* User interactions */
const contextualMixPolicies = useMemo(
() => ({
BIG: 'GoogleMicrosoft', // if !selectedUuids.has(selected.Uuid) deselects selectedUuids
ALL: 'All', // union of activeElement.Uuid and selectedUuids (currently implemented)
}),
[]
);
const contextualMixPolicy = contextualMixPolicies.ALL;

const onContextMenu = useCallback(
(event) => {
const element = currentChildren.find(
Expand All @@ -294,7 +303,34 @@ 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.
if (
selectedUuids?.size &&
element?.elementUuid &&
!selectedUuids.has(element.elementUuid)
) {
setSelectedUuids(new Set());
}
} else {
// If some elements were already selected, we add the active element to the selected list if not already in it.
if (
selectedUuids?.size &&
element?.elementUuid &&
!selectedUuids.has(element.elementUuid)
) {
let updatedSelectedUuids = new Set(selectedUuids);
updatedSelectedUuids.add(element.elementUuid);
setSelectedUuids(updatedSelectedUuids);
}
}
}
setMousePosition({
mouseX: event.event.clientX + constants.HORIZONTAL_SHIFT,
Expand All @@ -309,7 +345,15 @@ const DirectoryContent = () => {
handleOpenDirectoryMenu(event);
}
},
[currentChildren, dispatch, selectedDirectory]
[
currentChildren,
dispatch,
selectedDirectory,
selectedUuids,
contextualMixPolicies,
contextualMixPolicy,
childrenMetadata,
]
);

const abbreviationFromUserName = (name) => {
Expand Down Expand Up @@ -728,60 +772,42 @@ const DirectoryContent = () => {
setSelectedUuids(new Set());
}, [handleError, currentChildren, currentChildrenRef]);

const contextualMixPolicies = {
BIG: 'GoogleMicrosoft', // if !selectedUuids.has(selected.Uuid) deselects selectedUuids
ZIMBRA: 'Zimbra', // if !selectedUuids.has(selected.Uuid) just use activeElement
ALL: 'All', // union of activeElement.Uuid and selectedUuids (actually implemented)
};
let contextualMixPolicy = contextualMixPolicies.ALL;

const getSelectedChildren = (mayChange = false) => {
let acc = [];
let ctxtUuid = activeElement ? activeElement.elementUuid : null;
if (activeElement) {
acc.push(
Object.assign(
{
subtype:
childrenMetadata[activeElement.elementUuid]
?.subtype,
},
activeElement
)
);
}
const getSelectedChildren = () => {
let selectedChildren = [];
if (currentChildren?.length > 0) {
// Adds the previously selected elements
if (selectedUuids?.size) {
selectedChildren = currentChildren
.filter(
(child) =>
selectedUuids.has(child.elementUuid) &&
child.elementUuid !== activeElement?.elementUuid
)
.map((child) => {
return {
subtype:
childrenMetadata[child.elementUuid]?.subtype,
hasMetadata:
childrenMetadata[child.elementUuid] !==
undefined,
...child,
};
});
}

if (selectedUuids && currentChildren) {
if (
contextualMixPolicy === contextualMixPolicies.ALL ||
ctxtUuid === null ||
selectedUuids.has(ctxtUuid)
) {
acc = acc.concat(
currentChildren
.filter(
(child) =>
selectedUuids.has(child.elementUuid) &&
child.elementUuid !== activeElement?.elementUuid
)
.map((child2) => {
return Object.assign(
{
subtype:
childrenMetadata[child2.elementUuid],
},
child2
);
})
);
} else if (
mayChange &&
contextualMixPolicy === contextualMixPolicies.BIG
) {
setSelectedUuids(null);
// Adds the active element
if (activeElement) {
selectedChildren.push({
...activeElement,
subtype:
childrenMetadata[activeElement.elementUuid]?.subtype,
hasMetadata:
childrenMetadata[activeElement.elementUuid] !==
undefined,
});
}
}
return [...new Set(acc)];
return [...new Set(selectedChildren)];
};

const rows = useMemo(
Expand Down
32 changes: 18 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 @@ -586,6 +589,7 @@ const ContentContextualMenu = (props) => {
icon: <FileCopyIcon fontSize="small" />,
});
}

if (allowsDownloadCase()) {
// is export allowed
menuItems.push({
Expand All @@ -612,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 fc7a259

Please sign in to comment.