From b52f3e80c55c1015523dc67eda6c1c1dff5cd300 Mon Sep 17 00:00:00 2001 From: Jake Laderman Date: Mon, 1 Jul 2024 18:13:56 -0400 Subject: [PATCH] add fullscreen option to stack state (#1130) --- .../src/components/stacks/run/state/State.tsx | 21 ++- .../stacks/state/StackStateGraph.tsx | 143 +++++++++++------- 2 files changed, 103 insertions(+), 61 deletions(-) diff --git a/assets/src/components/stacks/run/state/State.tsx b/assets/src/components/stacks/run/state/State.tsx index adb57f91da..394372429a 100644 --- a/assets/src/components/stacks/run/state/State.tsx +++ b/assets/src/components/stacks/run/state/State.tsx @@ -1,18 +1,25 @@ +import { EmptyState } from '@pluralsh/design-system' import { ReactNode } from 'react' import { useOutletContext } from 'react-router-dom' -import { CodeEditor } from '@pluralsh/design-system' + +import { StackStateGraph } from 'components/stacks/state/StackStateGraph' +import { ReactFlowProvider } from 'reactflow' import { StackRun } from '../../../../generated/graphql' export default function StackRunState(): ReactNode { const { stackRun } = useOutletContext<{ stackRun: StackRun }>() - const value = JSON.stringify(stackRun.state?.state ?? {}, null, 2) + const { state } = stackRun return ( - +
+ {state ? ( + + + + ) : ( + + )} +
) } diff --git a/assets/src/components/stacks/state/StackStateGraph.tsx b/assets/src/components/stacks/state/StackStateGraph.tsx index 933c6c8c32..30431eac02 100644 --- a/assets/src/components/stacks/state/StackStateGraph.tsx +++ b/assets/src/components/stacks/state/StackStateGraph.tsx @@ -1,4 +1,11 @@ -import { IconFrame, ReloadIcon, usePrevious } from '@pluralsh/design-system' +import { + CloseIcon, + IconFrame, + LinkoutIcon, + ReloadIcon, + WrapWithIf, + usePrevious, +} from '@pluralsh/design-system' import { StackState } from 'generated/graphql' import { useCallback, @@ -21,6 +28,8 @@ import chroma from 'chroma-js' import 'reactflow/dist/style.css' import styled, { useTheme } from 'styled-components' +import { useKeyDown } from '@react-hooks-library/core' + import { type DagreDirection, getLayoutedElements, @@ -66,6 +75,10 @@ export function getNodesAndEdges(state: StackState) { export function StackStateGraph({ state }: { state: StackState }) { const theme = useTheme() const margin = theme.spacing.large + const [isFullscreen, setIsFullscreen] = useState(false) + + useKeyDown('Escape', () => setIsFullscreen(false)) + const { nodes: initialNodes, edges: initialEdges } = useMemo( () => getNodesAndEdges(state), [state] @@ -123,61 +136,75 @@ export function StackStateGraph({ state }: { state: StackState }) { }, [state, prevState, setEdges, setNodes]) return ( -
} > - - - - -
- } - tooltip="Reset view" - onClick={() => - setViewport({ x: 0, y: 0, zoom: 1 }, { duration: 500 }) - } +
+ + + + +
- Reset view - -
-
-
+ : } + tooltip={isFullscreen ? 'Exit fullscreen' : 'Fullscreen'} + onClick={() => setIsFullscreen(!isFullscreen)} + > + Fullscreen + + } + tooltip="Reset view" + onClick={() => + setViewport({ x: 0, y: 0, zoom: 1 }, { duration: 500 }) + } + > + Reset view + +
+
+
+ ) } @@ -195,3 +222,11 @@ const ReactFlowWrapperSC = styled.div<{ $hide?: boolean }>(({ $hide }) => ({ cursor: 'unset', }, })) + +const FullScreenWrapperSC = styled.div((_) => ({ + position: 'absolute', + top: 0, + bottom: 0, + left: 0, + right: 0, +}))