-
Notifications
You must be signed in to change notification settings - Fork 705
frontend: Add Map #2225
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
Merged
Merged
frontend: Add Map #2225
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1f44b2c
frontend: Allow Routes to take full width, add isFullWidth route para…
sniok 09d0708
frontend: Fix initial state for useQueryParamsState
sniok 71dadb3
frontend: Add Map page and route
sniok 4d9828b
frontend resourceMap: Add resource search
sniok 750427d
frontend: Add new /map route for Map view
sniok ab2e77c
frontend: Add basic story for GraphView component
sniok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { Icon } from '@iconify/react'; | ||
| import { Box, Button, ButtonGroup } from '@mui/material'; | ||
| import { useReactFlow, useStore } from '@xyflow/react'; | ||
| import { ReactNode } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| export function GraphControlButton({ | ||
| children, | ||
| onClick, | ||
| title, | ||
| disabled, | ||
| }: { | ||
| children?: ReactNode; | ||
| title: string; | ||
| onClick: () => void; | ||
| disabled?: boolean; | ||
| }) { | ||
| const sx = { | ||
| width: '32px', | ||
| height: '32px', | ||
| padding: 0, | ||
| minWidth: '32px', | ||
| borderRadius: '50%', | ||
| '> svg': { | ||
| width: '14px', | ||
| height: '14px', | ||
| }, | ||
| fontSize: 'x-small', | ||
| }; | ||
|
|
||
| return ( | ||
| <Button | ||
| disabled={disabled} | ||
| sx={sx} | ||
| color="primary" | ||
| variant="contained" | ||
| title={title} | ||
| onClick={onClick} | ||
| > | ||
| {children} | ||
| </Button> | ||
| ); | ||
| } | ||
|
|
||
| export function GraphControls({ children }: { children?: React.ReactNode }) { | ||
| const { t } = useTranslation(); | ||
| const minZoomReached = useStore(it => it.transform[2] <= it.minZoom); | ||
| const maxZoomReached = useStore(it => it.transform[2] >= it.maxZoom); | ||
| const { zoomIn, zoomOut, fitView } = useReactFlow(); | ||
|
|
||
| return ( | ||
| <Box display="flex" gap={1} flexDirection="column"> | ||
| <ButtonGroup | ||
| sx={{ | ||
| borderRadius: '40px', | ||
| '> .MuiButtonGroup-grouped': { | ||
| minWidth: '32px', | ||
| }, | ||
| }} | ||
| orientation="vertical" | ||
| aria-label="Vertical button group" | ||
| variant="contained" | ||
| > | ||
| <GraphControlButton disabled={maxZoomReached} title={t('Zoom in')} onClick={() => zoomIn()}> | ||
| <Icon icon="mdi:plus" /> | ||
| </GraphControlButton> | ||
| <GraphControlButton | ||
| disabled={minZoomReached} | ||
| title={t('Zoom out')} | ||
| onClick={() => zoomOut()} | ||
| > | ||
| <Icon icon="mdi:minus" /> | ||
| </GraphControlButton> | ||
| </ButtonGroup> | ||
| <GraphControlButton title={t('Fit to screen')} onClick={() => fitView()}> | ||
| <Icon icon="mdi:fit-to-screen" /> | ||
| </GraphControlButton> | ||
| {children} | ||
| </Box> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import { Box, Typography, useTheme } from '@mui/material'; | ||
| import { | ||
| Background, | ||
| BackgroundVariant, | ||
| ConnectionMode, | ||
| Controls, | ||
| Edge, | ||
| EdgeMouseHandler, | ||
| Node, | ||
| NodeMouseHandler, | ||
| OnMoveStart, | ||
| ReactFlow, | ||
| } from '@xyflow/react'; | ||
| import React from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { Loader } from '../common'; | ||
| import { KubeRelationEdge } from './edges/KubeRelationEdge'; | ||
| import { GraphControls } from './GraphControls'; | ||
| import { GroupNodeComponent } from './nodes/GroupNode'; | ||
| import { KubeGroupNodeComponent } from './nodes/KubeGroupNode'; | ||
| import { KubeObjectNodeComponent } from './nodes/KubeObjectNode'; | ||
|
|
||
| export const nodeTypes = { | ||
| kubeObject: KubeObjectNodeComponent, | ||
| kubeGroup: KubeGroupNodeComponent, | ||
| group: GroupNodeComponent, | ||
| }; | ||
|
|
||
| const edgeTypes = { | ||
| kubeRelation: KubeRelationEdge, | ||
| }; | ||
|
|
||
| export interface GraphRendererProps { | ||
| /** List of nodes to render */ | ||
| nodes: Node[]; | ||
| /** List of edges to render */ | ||
| edges: Edge[]; | ||
| /** Callback when a node is clicked */ | ||
| onNodeClick?: NodeMouseHandler<Node>; | ||
| /** Callback when an edge is clicked */ | ||
| onEdgeClick?: EdgeMouseHandler<Edge>; | ||
| /** Callback when the graph is started to be moved */ | ||
| onMoveStart?: OnMoveStart; | ||
| /** Callback when the background is clicked */ | ||
| onBackgroundClick?: () => void; | ||
| /** Additional components to render */ | ||
| children?: React.ReactNode; | ||
| /** Additional actions for the controls panael */ | ||
| controlActions?: React.ReactNode; | ||
| isLoading?: boolean; | ||
| } | ||
|
|
||
| const emptyArray: any[] = []; | ||
|
|
||
| export function GraphRenderer({ | ||
| nodes, | ||
| edges, | ||
| onNodeClick, | ||
| onEdgeClick, | ||
| onMoveStart, | ||
| onBackgroundClick, | ||
| children, | ||
| controlActions, | ||
| isLoading, | ||
| }: GraphRendererProps) { | ||
| const { t } = useTranslation(); | ||
| const theme = useTheme(); | ||
|
|
||
| return ( | ||
| <ReactFlow | ||
| nodes={isLoading ? emptyArray : nodes} | ||
| edges={isLoading ? emptyArray : edges} | ||
| edgeTypes={edgeTypes} | ||
| nodeTypes={nodeTypes} | ||
| nodesFocusable={false} | ||
| onNodeClick={onNodeClick} | ||
| onEdgeClick={onEdgeClick} | ||
| onMove={onMoveStart} | ||
| onClick={e => { | ||
| if ((e.target as HTMLElement)?.className?.includes?.('react-flow__pane')) { | ||
| onBackgroundClick?.(); | ||
| } | ||
| }} | ||
| minZoom={0.1} | ||
| maxZoom={2.0} | ||
| connectionMode={ConnectionMode.Loose} | ||
| > | ||
| <Background variant={BackgroundVariant.Dots} style={{ color: theme.palette.divider }} /> | ||
| <Controls showInteractive={false} showFitView={false} showZoom={false}> | ||
| <GraphControls>{controlActions}</GraphControls> | ||
| </Controls> | ||
| {isLoading && ( | ||
| <Box | ||
| sx={{ | ||
| position: 'absolute', | ||
| top: '50%', | ||
| left: '50%', | ||
| transform: 'translate(-50%, -50%)', | ||
| }} | ||
| > | ||
| <Loader title="Loading" /> | ||
| </Box> | ||
| )} | ||
| {!isLoading && nodes.length === 0 && ( | ||
| <Typography | ||
| sx={{ | ||
| position: 'absolute', | ||
| top: '50%', | ||
| left: '50%', | ||
| transform: 'translate(-50%, -50%)', | ||
| }} | ||
| > | ||
| {t('No data to be shown. Try to change filters or select a different namespace.')} | ||
| </Typography> | ||
| )} | ||
| {children} | ||
| </ReactFlow> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.