|
1 | 1 | import React, { FC, useEffect } from 'react'; |
2 | 2 | import PropTypes from 'prop-types'; |
3 | | -import { RootCluster } from '../contexts/RootCluster'; |
4 | | -import { Cluster } from '../contexts/Cluster'; |
| 3 | +import { ContainerCluster } from '../contexts/ContainerCluster'; |
| 4 | +import { CurrentCluster } from '../contexts/CurrentCluster'; |
5 | 5 | import { useDigraph } from '../hooks/use-digraph'; |
6 | 6 | import { useRenderedID } from '../hooks/use-rendered-id'; |
7 | | -import { useRootCluster } from '../hooks/use-root-cluster'; |
| 7 | +import { useContainerCluster } from '../hooks/use-container-cluster'; |
8 | 8 | import { DuplicatedRootClusterErrorMessage } from '../errors'; |
9 | 9 | import { useClusterMap } from '../hooks/use-cluster-map'; |
10 | | -import { RootClusterComponentProps } from '../types'; |
| 10 | +import { RootClusterProps } from '../types'; |
11 | 11 |
|
12 | | -export const Digraph: FC<RootClusterComponentProps> = ({ children, label, ...props }) => { |
13 | | - const root = useRootCluster(); |
14 | | - if (root !== null) { |
| 12 | +/** |
| 13 | + * `Digraph` component. |
| 14 | + */ |
| 15 | +export const Digraph: FC<RootClusterProps> = ({ children, label, ...options }) => { |
| 16 | + const container = useContainerCluster(); |
| 17 | + if (container !== null) { |
15 | 18 | throw Error(DuplicatedRootClusterErrorMessage); |
16 | 19 | } |
17 | 20 | const renderedLabel = useRenderedID(label); |
18 | | - if (renderedLabel !== undefined) Object.assign(props, { label: renderedLabel }); |
19 | | - const digraph = useDigraph(props); |
| 21 | + if (renderedLabel !== undefined) Object.assign(options, { label: renderedLabel }); |
| 22 | + const digraph = useDigraph(options); |
20 | 23 | const clusters = useClusterMap(); |
21 | 24 | useEffect(() => { |
22 | 25 | if (digraph.id !== undefined) { |
23 | 26 | clusters.set(digraph.id, digraph); |
24 | 27 | } |
25 | 28 | }, [clusters, digraph]); |
26 | 29 | return ( |
27 | | - <RootCluster.Provider value={digraph}> |
28 | | - <Cluster.Provider value={digraph}>{children}</Cluster.Provider> |
29 | | - </RootCluster.Provider> |
| 30 | + <ContainerCluster.Provider value={digraph}> |
| 31 | + <CurrentCluster.Provider value={digraph}>{children}</CurrentCluster.Provider> |
| 32 | + </ContainerCluster.Provider> |
30 | 33 | ); |
31 | 34 | }; |
32 | 35 |
|
|
0 commit comments