fix(tests) adjusted FlowConfig type

This commit is contained in:
Peter
2023-11-16 11:18:11 +01:00
parent 14caf422c3
commit 99c24f86c6
4 changed files with 14 additions and 14 deletions
+5 -5
View File
@@ -2,10 +2,10 @@ import { BackgroundProps, ControlProps, Edge, MiniMapProps, Node, PanelProps, Re
declare global { declare global {
interface FlowConfig { interface FlowConfig {
flowProps: Omit<ReactFlowProps, 'nodes' | 'edges'> & { nodes: Node[]; edges: Edge[] }; flowProps?: Omit<ReactFlowProps, 'nodes' | 'edges'> & { nodes: Node[]; edges: Edge[] };
panelProps: PanelProps; panelProps?: PanelProps;
backgroundProps: BackgroundProps; backgroundProps?: BackgroundProps;
controlsProps: ControlProps; controlsProps?: ControlProps;
minimapProps: MiniMapProps; minimapProps?: MiniMapProps;
} }
} }
+2 -2
View File
@@ -18,8 +18,8 @@ type FlowProps = {
}; };
export default ({ flowConfig }: FlowProps) => { export default ({ flowConfig }: FlowProps) => {
const [nodes, setNodes] = useState(flowConfig.flowProps.nodes); const [nodes, setNodes] = useState(flowConfig.flowProps?.nodes);
const [edges, setEdges] = useState(flowConfig.flowProps.edges); const [edges, setEdges] = useState(flowConfig.flowProps?.edges);
const props = { ...flowConfig.flowProps, nodes, edges }; const props = { ...flowConfig.flowProps, nodes, edges };
const onNodesChange: OnNodesChange = useCallback((changes) => setNodes((nds) => applyNodeChanges(changes, nds)), []); const onNodesChange: OnNodesChange = useCallback((changes) => setNodes((nds) => applyNodeChanges(changes, nds)), []);
+5 -5
View File
@@ -20,11 +20,11 @@ declare global {
} }
interface FlowConfig { interface FlowConfig {
flowProps: Omit<SvelteFlowProps, 'nodes' | 'edges'> & { nodes: Node[]; edges: Edge[] }; flowProps?: Omit<SvelteFlowProps, 'nodes' | 'edges'> & { nodes: Node[]; edges: Edge[] };
panelProps: PanelProps; panelProps?: PanelProps;
backgroundProps: BackgroundProps; backgroundProps?: BackgroundProps;
controlsProps: ControlsProps; controlsProps?: ControlsProps;
minimapProps: MiniMapProps; minimapProps?: MiniMapProps;
} }
} }
@@ -7,8 +7,8 @@
export let flowConfig: FlowConfig; export let flowConfig: FlowConfig;
// Create writables here so it is easier to create test cases // Create writables here so it is easier to create test cases
const nodes = writable(flowConfig.flowProps.nodes); const nodes = writable(flowConfig.flowProps?.nodes);
const edges = writable(flowConfig.flowProps.edges); const edges = writable(flowConfig.flowProps?.edges);
const flowProps = { ...flowConfig.flowProps, nodes, edges }; const flowProps = { ...flowConfig.flowProps, nodes, edges };
</script> </script>