All files / src/components/dashboard/widgets/network FlowFrame.tsx

100% Statements 2/2
100% Branches 1/1
100% Functions 1/1
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74                                                11x                           38x                                                                      
import {
  Background,
  BackgroundVariant,
  Controls,
  ReactFlow,
  ReactFlowProvider,
  type Edge,
  type Node,
  type ReactFlowProps,
} from "@xyflow/react";
import "@xyflow/react/dist/style.css";
import React from "react";
 
/**
 * The frame every read-only graph canvas draws in — the network tiles, a
 * graph source's entities, a repository's source map: a bordered,
 * dot-gridded pane with zoom controls, fitted to what it holds, nothing
 * draggable or connectable.
 *
 * React Flow's own colour mode follows the OS rather than the app's theme
 * class, so its chrome is themed through its CSS variables here, once.
 */
 
const THEMED =
  "dark:[--xy-controls-button-background-color:theme(colors.gray.800)] dark:[--xy-controls-button-background-color-hover:theme(colors.gray.700)] dark:[--xy-controls-button-color:theme(colors.gray.300)] dark:[--xy-controls-button-color-hover:theme(colors.gray.100)] dark:[--xy-controls-button-border-color:theme(colors.gray.700)] dark:[--xy-attribution-background-color:transparent]";
 
export interface FlowFrameProps<N extends Node, E extends Edge> extends ReactFlowProps<N, E> {
  testId?: string;
  /** The pane's size, as whole class names (`min-h-[12rem] flex-1`). */
  frameClassName?: string;
}
 
export function FlowFrame<N extends Node = Node, E extends Edge = Edge>({
  testId,
  frameClassName = "min-h-[12rem] flex-1",
  children,
  ...flow
}: FlowFrameProps<N, E>) {
  return (
    <div
      className={`relative overflow-hidden rounded-lg border border-gray-100 dark:border-gray-700 ${THEMED} ${frameClassName}`}
      data-testid={testId}
    >
      <ReactFlowProvider>
        <ReactFlow<N, E>
          nodesConnectable={false}
          nodesDraggable={false}
          edgesFocusable={false}
          fitView
          fitViewOptions={{ padding: 0.12 }}
          minZoom={0.1}
          maxZoom={1.75}
          proOptions={{ hideAttribution: true }}
          {...flow}
        >
          <Background
            variant={BackgroundVariant.Dots}
            gap={20}
            size={1}
            className="!bg-gray-50 dark:!bg-gray-900"
          />
          <Controls
            showInteractive={false}
            className="!shadow-none !border !border-gray-200 dark:!border-gray-700 !rounded-lg overflow-hidden"
          />
          {children}
        </ReactFlow>
      </ReactFlowProvider>
    </div>
  );
}
 
export default FlowFrame;