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

Fix and reinstall the minimap #2355

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion src/components/network-modification-tree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import { Box, Tooltip } from '@mui/material';
import { ReactFlow, Controls, useStore, useReactFlow, ControlButton } from '@xyflow/react';
import { ReactFlow, Controls, useStore, useReactFlow, ControlButton, MiniMap } from '@xyflow/react';
import MapIcon from '@mui/icons-material/Map';
import CenterGraphButton from './graph/util/center-graph-button';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { setModificationsDrawerOpen, setCurrentTreeNode } from '../redux/actions';
Expand All @@ -17,6 +18,7 @@ import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import CropFreeIcon from '@mui/icons-material/CropFree';
import { nodeTypes } from './graph/util/model-constants';
import { BUILD_STATUS } from './network/constants';
import { StudyDisplayMode } from './network-modification.type';

// snapGrid value set to [15, 15] which is the default value for ReactFlow
Expand All @@ -38,6 +40,32 @@ const NetworkModificationTree = ({
const treeModel = useSelector((state) => state.networkModificationTreeModel);

const [isMoving, setIsMoving] = useState(false);
const [isMinimapOpen, setIsMinimapOpen] = useState(false);

const nodeColor = useCallback(
(node) => {
if (!node) {
return '#9196a1';
}
if (node.type === 'ROOT') {
return 'rgba(0, 0, 0, 0.0)';
}
if (node.id === currentNode?.id) {
return '#4287f5';
}
if (node.data?.localBuildStatus === BUILD_STATUS.BUILT) {
return '#70d136';
}
if (node.data?.localBuildStatus === BUILD_STATUS.BUILT_WITH_WARNING) {
return '#FFA500';
}
if (node.data?.localBuildStatus === BUILD_STATUS.BUILT_WITH_ERROR) {
return '#DC143C';
}
return '#9196a1';
},
[currentNode]
);

const onNodeClick = useCallback(
(event, node) => {
Expand All @@ -49,6 +77,10 @@ const NetworkModificationTree = ({
[dispatch, currentNode]
);

const toggleMinimap = useCallback(() => {
setIsMinimapOpen((isMinimapOpen) => !isMinimapOpen);
}, []);

const onMove = useCallback((flowTransform) => {
setIsMoving(true);
}, []);
Expand Down Expand Up @@ -160,7 +192,27 @@ const NetworkModificationTree = ({
</span>
</Tooltip>
<CenterGraphButton currentNode={currentNode} />
<Tooltip
placement="left"
title={
isMinimapOpen
? intl.formatMessage({ id: 'HideMinimap' })
: intl.formatMessage({
id: 'DisplayMinimap',
})
}
arrow
enterDelay={TOOLTIP_DELAY}
enterNextDelay={TOOLTIP_DELAY}
>
<span>
<ControlButton onClick={() => toggleMinimap()}>
<MapIcon />
</ControlButton>
</span>
</Tooltip>
</Controls>
{isMinimapOpen && <MiniMap nodeColor={nodeColor} nodeStrokeWidth={0} />}
</ReactFlow>
</Box>
);
Expand Down
2 changes: 2 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@
"OnlyMin": "Min:\u202F{min}",
"OnlyMax": "Max:\u202F{max}",
"CenterSelectedNode": "Center on selected node",
"DisplayMinimap": "Display minimap",
"HideMinimap": "Hide minimap",
"DisplayTheWholeTree": "Display the whole tree",

"Logs": "Logs",
Expand Down
2 changes: 2 additions & 0 deletions src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,8 @@
"OnlyMin": "Min:\u202F{min}",
"OnlyMax": "Max:\u202F{max}",
"CenterSelectedNode": "Centrer sur le nœud sélectionné",
"DisplayMinimap": "Afficher la mini-carte",
"HideMinimap": "Masquer la mini-carte",
"DisplayTheWholeTree": "Visualiser l'arbre en entier",

"Logs": "Logs",
Expand Down
Loading