@xyo-network/react-node-renderer 2.71.5 → 2.71.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/components/lib/RelationalGraphProps.d.cts +2 -1
- package/dist/browser/components/lib/RelationalGraphProps.d.cts.map +1 -1
- package/dist/browser/components/lib/RelationalGraphProps.d.mts +2 -1
- package/dist/browser/components/lib/RelationalGraphProps.d.mts.map +1 -1
- package/dist/browser/components/lib/RelationalGraphProps.d.ts +2 -1
- package/dist/browser/components/lib/RelationalGraphProps.d.ts.map +1 -1
- package/dist/browser/components/module/graph/GraphFlexBox.d.cts +2 -0
- package/dist/browser/components/module/graph/GraphFlexBox.d.cts.map +1 -1
- package/dist/browser/components/module/graph/GraphFlexBox.d.mts +2 -0
- package/dist/browser/components/module/graph/GraphFlexBox.d.mts.map +1 -1
- package/dist/browser/components/module/graph/GraphFlexBox.d.ts +2 -0
- package/dist/browser/components/module/graph/GraphFlexBox.d.ts.map +1 -1
- package/dist/browser/components/relational/graph/Graph.d.cts.map +1 -1
- package/dist/browser/components/relational/graph/Graph.d.mts.map +1 -1
- package/dist/browser/components/relational/graph/Graph.d.ts.map +1 -1
- package/dist/browser/components/relational/graph/ProvidedNodeRenderer.d.cts +2 -1
- package/dist/browser/components/relational/graph/ProvidedNodeRenderer.d.cts.map +1 -1
- package/dist/browser/components/relational/graph/ProvidedNodeRenderer.d.mts +2 -1
- package/dist/browser/components/relational/graph/ProvidedNodeRenderer.d.mts.map +1 -1
- package/dist/browser/components/relational/graph/ProvidedNodeRenderer.d.ts +2 -1
- package/dist/browser/components/relational/graph/ProvidedNodeRenderer.d.ts.map +1 -1
- package/dist/browser/index.cjs +13 -3
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +15 -5
- package/dist/browser/index.js.map +1 -1
- package/dist/node/components/lib/RelationalGraphProps.d.cts +2 -1
- package/dist/node/components/lib/RelationalGraphProps.d.cts.map +1 -1
- package/dist/node/components/lib/RelationalGraphProps.d.mts +2 -1
- package/dist/node/components/lib/RelationalGraphProps.d.mts.map +1 -1
- package/dist/node/components/lib/RelationalGraphProps.d.ts +2 -1
- package/dist/node/components/lib/RelationalGraphProps.d.ts.map +1 -1
- package/dist/node/components/module/graph/GraphFlexBox.d.cts +2 -0
- package/dist/node/components/module/graph/GraphFlexBox.d.cts.map +1 -1
- package/dist/node/components/module/graph/GraphFlexBox.d.mts +2 -0
- package/dist/node/components/module/graph/GraphFlexBox.d.mts.map +1 -1
- package/dist/node/components/module/graph/GraphFlexBox.d.ts +2 -0
- package/dist/node/components/module/graph/GraphFlexBox.d.ts.map +1 -1
- package/dist/node/components/relational/graph/Graph.d.cts.map +1 -1
- package/dist/node/components/relational/graph/Graph.d.mts.map +1 -1
- package/dist/node/components/relational/graph/Graph.d.ts.map +1 -1
- package/dist/node/components/relational/graph/ProvidedNodeRenderer.d.cts +2 -1
- package/dist/node/components/relational/graph/ProvidedNodeRenderer.d.cts.map +1 -1
- package/dist/node/components/relational/graph/ProvidedNodeRenderer.d.mts +2 -1
- package/dist/node/components/relational/graph/ProvidedNodeRenderer.d.mts.map +1 -1
- package/dist/node/components/relational/graph/ProvidedNodeRenderer.d.ts +2 -1
- package/dist/node/components/relational/graph/ProvidedNodeRenderer.d.ts.map +1 -1
- package/dist/node/index.cjs +13 -3
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +15 -5
- package/dist/node/index.js.map +1 -1
- package/package.json +8 -7
- package/src/components/lib/RelationalGraphProps.ts +2 -1
- package/src/components/module/graph/GraphFlexBox.tsx +2 -0
- package/src/components/relational/graph/Graph.tsx +15 -5
- package/src/components/relational/graph/GraphDirected.stories.tsx +173 -0
- package/src/components/relational/graph/GraphDirectedSpread.stories.tsx +173 -0
- package/src/components/relational/graph/GraphSpread.stories.tsx +2 -2
- package/src/components/relational/graph/ProvidedNodeRenderer.tsx +2 -1
- package/src/types/global.d.ts +5 -0
package/package.json
CHANGED
|
@@ -22,14 +22,15 @@
|
|
|
22
22
|
"@xyo-network/module-events": "^2.94.9",
|
|
23
23
|
"@xyo-network/module-model": "^2.94.9",
|
|
24
24
|
"@xyo-network/node-model": "^2.94.9",
|
|
25
|
-
"@xyo-network/react-archivist": "~2.71.
|
|
26
|
-
"@xyo-network/react-module": "~2.71.
|
|
27
|
-
"@xyo-network/react-node": "~2.71.
|
|
28
|
-
"@xyo-network/react-shared": "~2.71.
|
|
25
|
+
"@xyo-network/react-archivist": "~2.71.7",
|
|
26
|
+
"@xyo-network/react-module": "~2.71.7",
|
|
27
|
+
"@xyo-network/react-node": "~2.71.7",
|
|
28
|
+
"@xyo-network/react-shared": "~2.71.7",
|
|
29
29
|
"@xyo-network/sentinel-model": "^2.94.9",
|
|
30
30
|
"@xyo-network/witness-model": "^2.94.9",
|
|
31
31
|
"cytoscape": "^3.28.1",
|
|
32
32
|
"cytoscape-cola": "^2.5.1",
|
|
33
|
+
"cytoscape-dagre": "^2.5.0",
|
|
33
34
|
"cytoscape-fcose": "^2.2.0"
|
|
34
35
|
},
|
|
35
36
|
"peerDependencies": {
|
|
@@ -50,8 +51,8 @@
|
|
|
50
51
|
"@xyo-network/http-bridge": "^2.94.9",
|
|
51
52
|
"@xyo-network/id-plugin": "^2.91.4",
|
|
52
53
|
"@xyo-network/node-memory": "^2.94.9",
|
|
53
|
-
"@xyo-network/react-storybook": "~2.71.
|
|
54
|
-
"@xyo-network/react-wallet": "~2.71.
|
|
54
|
+
"@xyo-network/react-storybook": "~2.71.7",
|
|
55
|
+
"@xyo-network/react-wallet": "~2.71.7",
|
|
55
56
|
"@xyo-network/sentinel": "^2.94.9",
|
|
56
57
|
"typescript": "^5.4.3"
|
|
57
58
|
},
|
|
@@ -106,6 +107,6 @@
|
|
|
106
107
|
},
|
|
107
108
|
"sideEffects": false,
|
|
108
109
|
"types": "dist/browser/index.d.ts",
|
|
109
|
-
"version": "2.71.
|
|
110
|
+
"version": "2.71.7",
|
|
110
111
|
"type": "module"
|
|
111
112
|
}
|
|
@@ -5,7 +5,8 @@ import { PropsWithChildren, ReactNode } from 'react'
|
|
|
5
5
|
export interface NodeRelationalGraphProps extends PropsWithChildren<FlexBoxProps> {
|
|
6
6
|
actions?: ReactNode
|
|
7
7
|
detail?: ReactNode
|
|
8
|
+
directed?: boolean | object
|
|
8
9
|
options?: CytoscapeOptions
|
|
9
10
|
showDetails?: boolean
|
|
10
|
-
spread?: boolean
|
|
11
|
+
spread?: boolean | object
|
|
11
12
|
}
|
|
@@ -12,8 +12,10 @@ import { ModuleGraphNodeHover } from './node'
|
|
|
12
12
|
import { StyledModuleHoverPopper } from './Popper'
|
|
13
13
|
|
|
14
14
|
export interface ModuleGraphFlexBoxProps extends FlexBoxProps {
|
|
15
|
+
directed?: boolean | object
|
|
15
16
|
disableModuleDetails?: boolean
|
|
16
17
|
rootModule?: ModuleInstance | null
|
|
18
|
+
spread?: boolean | object
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export const ModuleGraphFlexBox: React.FC<ModuleGraphFlexBoxProps> = ({ rootModule, disableModuleDetails, ...props }) => {
|
|
@@ -2,14 +2,15 @@ import { Button, ButtonGroup, useTheme } from '@mui/material'
|
|
|
2
2
|
import { FlexCol, FlexGrowRow, FlexRow } from '@xylabs/react-flexbox'
|
|
3
3
|
import { useShareForwardedRef } from '@xyo-network/react-shared'
|
|
4
4
|
import cytoscape, { Core } from 'cytoscape'
|
|
5
|
-
import
|
|
5
|
+
import dagre from 'cytoscape-dagre'
|
|
6
|
+
import fcose from 'cytoscape-fcose'
|
|
6
7
|
import { forwardRef, useEffect, useState } from 'react'
|
|
7
8
|
|
|
8
9
|
import { useCytoscapeInstance } from '../../../contexts'
|
|
9
10
|
import { NodeRelationalGraphProps } from '../../lib'
|
|
10
11
|
|
|
11
12
|
export const NodeRelationalGraphFlexBox = forwardRef<HTMLDivElement, NodeRelationalGraphProps>(
|
|
12
|
-
({ actions, children, showDetails, detail, spread, options, ...props }, ref) => {
|
|
13
|
+
({ actions, children, directed, showDetails, detail, spread, options, ...props }, ref) => {
|
|
13
14
|
const theme = useTheme()
|
|
14
15
|
const [cy, setCy] = useState<Core>()
|
|
15
16
|
const { setCy: setCyContext } = useCytoscapeInstance()
|
|
@@ -17,27 +18,36 @@ export const NodeRelationalGraphFlexBox = forwardRef<HTMLDivElement, NodeRelatio
|
|
|
17
18
|
|
|
18
19
|
const handleReset = () => {
|
|
19
20
|
cy?.reset()
|
|
21
|
+
if (directed) {
|
|
22
|
+
cy?.layout({ name: 'dagre', ...(typeof directed === 'object' ? directed : {}) }).run()
|
|
23
|
+
}
|
|
20
24
|
if (spread) {
|
|
21
|
-
cy?.layout({ name: 'fcose' }).run()
|
|
25
|
+
cy?.layout({ name: 'fcose', ...(typeof spread === 'object' ? spread : {}) }).run()
|
|
22
26
|
}
|
|
23
27
|
cy?.fit(undefined, 20)
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
useEffect(() => {
|
|
27
31
|
if (sharedRef) {
|
|
32
|
+
if (directed) {
|
|
33
|
+
cytoscape.use(dagre)
|
|
34
|
+
}
|
|
28
35
|
if (spread) {
|
|
29
|
-
cytoscape.use(
|
|
36
|
+
cytoscape.use(fcose)
|
|
30
37
|
}
|
|
31
38
|
const newCy = cytoscape({
|
|
32
39
|
container: sharedRef.current,
|
|
33
40
|
...options,
|
|
34
41
|
})
|
|
42
|
+
if (directed) {
|
|
43
|
+
newCy.layout({ name: 'dagre' }).run()
|
|
44
|
+
}
|
|
35
45
|
if (spread) {
|
|
36
46
|
newCy.layout({ name: 'fcose' }).run()
|
|
37
47
|
}
|
|
38
48
|
setCy(newCy)
|
|
39
49
|
}
|
|
40
|
-
}, [options, sharedRef, spread])
|
|
50
|
+
}, [options, sharedRef, spread, directed])
|
|
41
51
|
|
|
42
52
|
useEffect(() => {
|
|
43
53
|
setCyContext?.(cy)
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Button, ButtonGroup } from '@mui/material'
|
|
2
|
+
import { Decorator, Meta, StoryFn } from '@storybook/react'
|
|
3
|
+
import { useAsyncEffect } from '@xylabs/react-async-effect'
|
|
4
|
+
import { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist'
|
|
5
|
+
import { HttpBridge, HttpBridgeConfigSchema } from '@xyo-network/http-bridge'
|
|
6
|
+
import { IdWitness, IdWitnessConfigSchema } from '@xyo-network/id-plugin'
|
|
7
|
+
import { MemoryNode } from '@xyo-network/node-memory'
|
|
8
|
+
import { NodeConfigSchema } from '@xyo-network/node-model'
|
|
9
|
+
import { NodeProvider, useNodeFromNode, useProvidedNode } from '@xyo-network/react-node'
|
|
10
|
+
import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
|
|
11
|
+
import { useWallet, WalletProvider } from '@xyo-network/react-wallet'
|
|
12
|
+
import { MemorySentinel, SentinelConfigSchema } from '@xyo-network/sentinel'
|
|
13
|
+
import { useState } from 'react'
|
|
14
|
+
|
|
15
|
+
import { CytoscapeInstanceProvider } from '../../../contexts'
|
|
16
|
+
import { useCytoscapeElements, useCytoscapeOptions } from '../../../hooks'
|
|
17
|
+
import { NodeRelationalGraphFlexBox } from './Graph'
|
|
18
|
+
import { ProvidedNodeRenderer } from './ProvidedNodeRenderer'
|
|
19
|
+
import { options } from './story'
|
|
20
|
+
import { WithExtensions } from '../../cytoscape-extensions'
|
|
21
|
+
|
|
22
|
+
const nodeUrl = 'http://localhost:8080/node'
|
|
23
|
+
|
|
24
|
+
const MemoryNodeDecorator: Decorator = (Story, args) => {
|
|
25
|
+
const [node, setNode] = useState<MemoryNode>()
|
|
26
|
+
|
|
27
|
+
useAsyncEffect(
|
|
28
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
|
+
async () => {
|
|
30
|
+
try {
|
|
31
|
+
const node = await MemoryNode.create({ config: { name: 'GlobalNode', schema: NodeConfigSchema } })
|
|
32
|
+
const node1 = await MemoryNode.create({ config: { name: 'ChildNode', schema: NodeConfigSchema } })
|
|
33
|
+
const bridge = await HttpBridge.create({
|
|
34
|
+
config: { name: 'Bridge', nodeUrl, schema: HttpBridgeConfigSchema, security: { allowAnonymous: true } },
|
|
35
|
+
})
|
|
36
|
+
await node.register(bridge)
|
|
37
|
+
await node.attach(bridge.address, true)
|
|
38
|
+
|
|
39
|
+
const archivist = await MemoryArchivist.create({ config: { name: 'RootStorageArchivist', schema: MemoryArchivistConfigSchema } })
|
|
40
|
+
await node.register(archivist)
|
|
41
|
+
await node.attach(archivist.address, true)
|
|
42
|
+
|
|
43
|
+
const sentinel = await MemorySentinel.create({
|
|
44
|
+
config: { name: 'MemorySentinel', schema: SentinelConfigSchema, synchronous: true, tasks: [] },
|
|
45
|
+
})
|
|
46
|
+
await node.register(sentinel)
|
|
47
|
+
await node.attach(sentinel.address, true)
|
|
48
|
+
|
|
49
|
+
const archivist1 = await MemoryArchivist.create({ config: { name: 'RootStorageArchivist1', schema: MemoryArchivistConfigSchema } })
|
|
50
|
+
await node1.register(archivist1)
|
|
51
|
+
await node1.attach(archivist1.address, true)
|
|
52
|
+
|
|
53
|
+
await node.register(node1)
|
|
54
|
+
await node.attach(node1.address, true)
|
|
55
|
+
|
|
56
|
+
setNode(node)
|
|
57
|
+
} catch (e) {
|
|
58
|
+
console.error('Error Creating MemoryNode', e)
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
[],
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
const [wallet] = useWallet({ mnemonic: DefaultSeedPhrase })
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<WalletProvider rootWallet={wallet}>
|
|
68
|
+
<NodeProvider node={node}>
|
|
69
|
+
<CytoscapeInstanceProvider>
|
|
70
|
+
<Story {...args} />
|
|
71
|
+
</CytoscapeInstanceProvider>
|
|
72
|
+
</NodeProvider>
|
|
73
|
+
</WalletProvider>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// eslint-disable-next-line import/no-default-export
|
|
78
|
+
export default {
|
|
79
|
+
component: NodeRelationalGraphFlexBox,
|
|
80
|
+
title: 'node/renderer/directed/NodeRelationalGraph',
|
|
81
|
+
} as Meta
|
|
82
|
+
|
|
83
|
+
const Template: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => <NodeRelationalGraphFlexBox directed {...props} />
|
|
84
|
+
|
|
85
|
+
const TemplateDescribe: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
|
|
86
|
+
const [node] = useProvidedNode()
|
|
87
|
+
const elements = useCytoscapeElements(node)
|
|
88
|
+
const options = useCytoscapeOptions(elements)
|
|
89
|
+
return <NodeRelationalGraphFlexBox directed options={options} {...props} />
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const TemplateCustomAddress: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
|
|
93
|
+
const [node] = useNodeFromNode('ChildNode')
|
|
94
|
+
const elements = useCytoscapeElements(node)
|
|
95
|
+
const options = useCytoscapeOptions(elements)
|
|
96
|
+
return <NodeRelationalGraphFlexBox directed options={options} {...props} />
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const TemplateProvidedNodeRenderer: StoryFn<typeof ProvidedNodeRenderer> = (props) => <ProvidedNodeRenderer directed {...props} />
|
|
100
|
+
|
|
101
|
+
const TemplateAttachDetach: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
|
|
102
|
+
const [node] = useNodeFromNode('ChildNode')
|
|
103
|
+
const elements = useCytoscapeElements(node)
|
|
104
|
+
const options = useCytoscapeOptions(elements)
|
|
105
|
+
const [idWitness, setIdWitness] = useState<IdWitness>()
|
|
106
|
+
|
|
107
|
+
useAsyncEffect(
|
|
108
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
109
|
+
async () => {
|
|
110
|
+
const witnessModule = await IdWitness.create({ config: { name: 'IdWitness', salt: 'test', schema: IdWitnessConfigSchema } })
|
|
111
|
+
setIdWitness(witnessModule)
|
|
112
|
+
},
|
|
113
|
+
[],
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
const handleAddWitness = async () => {
|
|
117
|
+
if (node && idWitness) {
|
|
118
|
+
const memoryNode = node as MemoryNode
|
|
119
|
+
await memoryNode.register(idWitness)
|
|
120
|
+
await memoryNode.attach(idWitness.address, true)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const handleRemoveWitness = async () => {
|
|
125
|
+
if (node && idWitness) {
|
|
126
|
+
const memoryNode = node as MemoryNode
|
|
127
|
+
if (memoryNode.registered().includes(idWitness.address)) {
|
|
128
|
+
await memoryNode.unregister(idWitness)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<>
|
|
135
|
+
<ButtonGroup>
|
|
136
|
+
<Button onClick={handleAddWitness}>Add Witness</Button>
|
|
137
|
+
<Button onClick={handleRemoveWitness}>Remove Witness</Button>
|
|
138
|
+
</ButtonGroup>
|
|
139
|
+
<WithExtensions>
|
|
140
|
+
<NodeRelationalGraphFlexBox directed options={options} {...props} />
|
|
141
|
+
</WithExtensions>
|
|
142
|
+
</>
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const defaultProps = {
|
|
147
|
+
height: 'calc(100vh - 20px)',
|
|
148
|
+
width: '100%',
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const Default = Template.bind({})
|
|
152
|
+
Default.args = {}
|
|
153
|
+
|
|
154
|
+
const WithData = Template.bind({})
|
|
155
|
+
WithData.args = { options, ...defaultProps }
|
|
156
|
+
|
|
157
|
+
const WithDescribe = TemplateDescribe.bind({})
|
|
158
|
+
WithDescribe.args = { ...defaultProps }
|
|
159
|
+
WithDescribe.decorators = [MemoryNodeDecorator]
|
|
160
|
+
|
|
161
|
+
const WithCustomAddress = TemplateCustomAddress.bind({})
|
|
162
|
+
WithCustomAddress.args = { ...defaultProps }
|
|
163
|
+
WithCustomAddress.decorators = [MemoryNodeDecorator]
|
|
164
|
+
|
|
165
|
+
const WithAttachDetach = TemplateAttachDetach.bind({})
|
|
166
|
+
WithAttachDetach.args = { ...defaultProps }
|
|
167
|
+
WithAttachDetach.decorators = [MemoryNodeDecorator]
|
|
168
|
+
|
|
169
|
+
const WithProvidedNodeRenderer = TemplateProvidedNodeRenderer.bind({})
|
|
170
|
+
WithProvidedNodeRenderer.args = { ...defaultProps }
|
|
171
|
+
WithProvidedNodeRenderer.decorators = [MemoryNodeDecorator]
|
|
172
|
+
|
|
173
|
+
export { Default, WithAttachDetach, WithCustomAddress, WithData, WithDescribe, WithProvidedNodeRenderer }
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Button, ButtonGroup } from '@mui/material'
|
|
2
|
+
import { Decorator, Meta, StoryFn } from '@storybook/react'
|
|
3
|
+
import { useAsyncEffect } from '@xylabs/react-async-effect'
|
|
4
|
+
import { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist'
|
|
5
|
+
import { HttpBridge, HttpBridgeConfigSchema } from '@xyo-network/http-bridge'
|
|
6
|
+
import { IdWitness, IdWitnessConfigSchema } from '@xyo-network/id-plugin'
|
|
7
|
+
import { MemoryNode } from '@xyo-network/node-memory'
|
|
8
|
+
import { NodeConfigSchema } from '@xyo-network/node-model'
|
|
9
|
+
import { NodeProvider, useNodeFromNode, useProvidedNode } from '@xyo-network/react-node'
|
|
10
|
+
import { DefaultSeedPhrase } from '@xyo-network/react-storybook'
|
|
11
|
+
import { useWallet, WalletProvider } from '@xyo-network/react-wallet'
|
|
12
|
+
import { MemorySentinel, SentinelConfigSchema } from '@xyo-network/sentinel'
|
|
13
|
+
import { useState } from 'react'
|
|
14
|
+
|
|
15
|
+
import { CytoscapeInstanceProvider } from '../../../contexts'
|
|
16
|
+
import { useCytoscapeElements, useCytoscapeOptions } from '../../../hooks'
|
|
17
|
+
import { WithExtensions } from '../../cytoscape-extensions'
|
|
18
|
+
import { NodeRelationalGraphFlexBox } from './Graph'
|
|
19
|
+
import { ProvidedNodeRenderer } from './ProvidedNodeRenderer'
|
|
20
|
+
import { options } from './story'
|
|
21
|
+
|
|
22
|
+
const nodeUrl = 'http://localhost:8080/node'
|
|
23
|
+
|
|
24
|
+
const MemoryNodeDecorator: Decorator = (Story, args) => {
|
|
25
|
+
const [node, setNode] = useState<MemoryNode>()
|
|
26
|
+
|
|
27
|
+
useAsyncEffect(
|
|
28
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
|
+
async () => {
|
|
30
|
+
try {
|
|
31
|
+
const node = await MemoryNode.create({ config: { name: 'GlobalNode', schema: NodeConfigSchema } })
|
|
32
|
+
const node1 = await MemoryNode.create({ config: { name: 'ChildNode', schema: NodeConfigSchema } })
|
|
33
|
+
const bridge = await HttpBridge.create({
|
|
34
|
+
config: { name: 'Bridge', nodeUrl, schema: HttpBridgeConfigSchema, security: { allowAnonymous: true } },
|
|
35
|
+
})
|
|
36
|
+
await node.register(bridge)
|
|
37
|
+
await node.attach(bridge.address, true)
|
|
38
|
+
|
|
39
|
+
const archivist = await MemoryArchivist.create({ config: { name: 'RootStorageArchivist', schema: MemoryArchivistConfigSchema } })
|
|
40
|
+
await node.register(archivist)
|
|
41
|
+
await node.attach(archivist.address, true)
|
|
42
|
+
|
|
43
|
+
const sentinel = await MemorySentinel.create({
|
|
44
|
+
config: { name: 'MemorySentinel', schema: SentinelConfigSchema, synchronous: true, tasks: [] },
|
|
45
|
+
})
|
|
46
|
+
await node.register(sentinel)
|
|
47
|
+
await node.attach(sentinel.address, true)
|
|
48
|
+
|
|
49
|
+
const archivist1 = await MemoryArchivist.create({ config: { name: 'RootStorageArchivist1', schema: MemoryArchivistConfigSchema } })
|
|
50
|
+
await node1.register(archivist1)
|
|
51
|
+
await node1.attach(archivist1.address, true)
|
|
52
|
+
|
|
53
|
+
await node.register(node1)
|
|
54
|
+
await node.attach(node1.address, true)
|
|
55
|
+
|
|
56
|
+
setNode(node)
|
|
57
|
+
} catch (e) {
|
|
58
|
+
console.error('Error Creating MemoryNode', e)
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
[],
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
const [wallet] = useWallet({ mnemonic: DefaultSeedPhrase })
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<WalletProvider rootWallet={wallet}>
|
|
68
|
+
<NodeProvider node={node}>
|
|
69
|
+
<CytoscapeInstanceProvider>
|
|
70
|
+
<Story {...args} />
|
|
71
|
+
</CytoscapeInstanceProvider>
|
|
72
|
+
</NodeProvider>
|
|
73
|
+
</WalletProvider>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// eslint-disable-next-line import/no-default-export
|
|
78
|
+
export default {
|
|
79
|
+
component: NodeRelationalGraphFlexBox,
|
|
80
|
+
title: 'node/renderer/directed/spread/NodeRelationalGraph',
|
|
81
|
+
} as Meta
|
|
82
|
+
|
|
83
|
+
const Template: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => <NodeRelationalGraphFlexBox directed spread {...props} />
|
|
84
|
+
|
|
85
|
+
const TemplateDescribe: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
|
|
86
|
+
const [node] = useProvidedNode()
|
|
87
|
+
const elements = useCytoscapeElements(node)
|
|
88
|
+
const options = useCytoscapeOptions(elements)
|
|
89
|
+
return <NodeRelationalGraphFlexBox directed spread options={options} {...props} />
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const TemplateCustomAddress: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
|
|
93
|
+
const [node] = useNodeFromNode('ChildNode')
|
|
94
|
+
const elements = useCytoscapeElements(node)
|
|
95
|
+
const options = useCytoscapeOptions(elements)
|
|
96
|
+
return <NodeRelationalGraphFlexBox directed spread options={options} {...props} />
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const TemplateProvidedNodeRenderer: StoryFn<typeof ProvidedNodeRenderer> = (props) => <ProvidedNodeRenderer directed spread {...props} />
|
|
100
|
+
|
|
101
|
+
const TemplateAttachDetach: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
|
|
102
|
+
const [node] = useNodeFromNode('ChildNode')
|
|
103
|
+
const elements = useCytoscapeElements(node)
|
|
104
|
+
const options = useCytoscapeOptions(elements)
|
|
105
|
+
const [idWitness, setIdWitness] = useState<IdWitness>()
|
|
106
|
+
|
|
107
|
+
useAsyncEffect(
|
|
108
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
109
|
+
async () => {
|
|
110
|
+
const witnessModule = await IdWitness.create({ config: { name: 'IdWitness', salt: 'test', schema: IdWitnessConfigSchema } })
|
|
111
|
+
setIdWitness(witnessModule)
|
|
112
|
+
},
|
|
113
|
+
[],
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
const handleAddWitness = async () => {
|
|
117
|
+
if (node && idWitness) {
|
|
118
|
+
const memoryNode = node as MemoryNode
|
|
119
|
+
await memoryNode.register(idWitness)
|
|
120
|
+
await memoryNode.attach(idWitness.address, true)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const handleRemoveWitness = async () => {
|
|
125
|
+
if (node && idWitness) {
|
|
126
|
+
const memoryNode = node as MemoryNode
|
|
127
|
+
if (memoryNode.registered().includes(idWitness.address)) {
|
|
128
|
+
await memoryNode.unregister(idWitness)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<>
|
|
135
|
+
<ButtonGroup>
|
|
136
|
+
<Button onClick={handleAddWitness}>Add Witness</Button>
|
|
137
|
+
<Button onClick={handleRemoveWitness}>Remove Witness</Button>
|
|
138
|
+
</ButtonGroup>
|
|
139
|
+
<WithExtensions>
|
|
140
|
+
<NodeRelationalGraphFlexBox directed options={options} {...props} />
|
|
141
|
+
</WithExtensions>
|
|
142
|
+
</>
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const defaultProps = {
|
|
147
|
+
height: 'calc(100vh - 20px)',
|
|
148
|
+
width: '100%',
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const Default = Template.bind({})
|
|
152
|
+
Default.args = {}
|
|
153
|
+
|
|
154
|
+
const WithData = Template.bind({})
|
|
155
|
+
WithData.args = { options, ...defaultProps }
|
|
156
|
+
|
|
157
|
+
const WithDescribe = TemplateDescribe.bind({})
|
|
158
|
+
WithDescribe.args = { ...defaultProps }
|
|
159
|
+
WithDescribe.decorators = [MemoryNodeDecorator]
|
|
160
|
+
|
|
161
|
+
const WithCustomAddress = TemplateCustomAddress.bind({})
|
|
162
|
+
WithCustomAddress.args = { ...defaultProps }
|
|
163
|
+
WithCustomAddress.decorators = [MemoryNodeDecorator]
|
|
164
|
+
|
|
165
|
+
const WithAttachDetach = TemplateAttachDetach.bind({})
|
|
166
|
+
WithAttachDetach.args = { ...defaultProps }
|
|
167
|
+
WithAttachDetach.decorators = [MemoryNodeDecorator]
|
|
168
|
+
|
|
169
|
+
const WithProvidedNodeRenderer = TemplateProvidedNodeRenderer.bind({})
|
|
170
|
+
WithProvidedNodeRenderer.args = { ...defaultProps }
|
|
171
|
+
WithProvidedNodeRenderer.decorators = [MemoryNodeDecorator]
|
|
172
|
+
|
|
173
|
+
export { Default, WithAttachDetach, WithCustomAddress, WithData, WithDescribe, WithProvidedNodeRenderer }
|
|
@@ -77,10 +77,10 @@ const MemoryNodeDecorator: Decorator = (Story, args) => {
|
|
|
77
77
|
// eslint-disable-next-line import/no-default-export
|
|
78
78
|
export default {
|
|
79
79
|
component: NodeRelationalGraphFlexBox,
|
|
80
|
-
title: 'node/renderer/
|
|
80
|
+
title: 'node/renderer/spread/NodeRelationalGraph',
|
|
81
81
|
} as Meta
|
|
82
82
|
|
|
83
|
-
const Template: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => <NodeRelationalGraphFlexBox {...props} />
|
|
83
|
+
const Template: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => <NodeRelationalGraphFlexBox spread {...props} />
|
|
84
84
|
|
|
85
85
|
const TemplateDescribe: StoryFn<typeof NodeRelationalGraphFlexBox> = (props) => {
|
|
86
86
|
const [node] = useProvidedNode()
|
|
@@ -8,8 +8,9 @@ import { NodeRelationalGraphFlexBox } from './Graph'
|
|
|
8
8
|
|
|
9
9
|
export interface ProvidedNodeRendererProps extends NodeRelationalGraphProps {
|
|
10
10
|
account?: AccountInstance
|
|
11
|
+
directed?: boolean | object
|
|
11
12
|
node?: NodeInstance
|
|
12
|
-
spread?: boolean
|
|
13
|
+
spread?: boolean | object
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export const ProvidedNodeRenderer: React.FC<ProvidedNodeRendererProps> = ({ node, ...props }) => {
|