Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display connected nodes / bridges in cytoscape #681

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Button } from '@mui/material'
import { Meta, StoryFn } from '@storybook/react'
import { useAsyncEffect } from '@xylabs/react-async-effect'
import { FlexCol } from '@xylabs/react-flexbox'
import { usePromise } from '@xylabs/react-promise'
import { Account } from '@xyo-network/account'
import { ArchivistInsertQuerySchema, ArchivistInstance, MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist'
import { QueryBoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
import { useState } from 'react'
import { MemoryNode } from '@xyo-network/node-memory'

import { ArchivistCard } from './Card'

Expand All @@ -23,7 +23,7 @@ const insertPayload = async (archivist?: ArchivistInstance) => {
if (archivist) {
const payload = { schema: 'network.xyo.payload', timestamp: Date.now() }
const insertQuery = { schema: ArchivistInsertQuerySchema }
const account = await Account.randomSync()
const account = Account.randomSync()
const builder = new QueryBoundWitnessBuilder({ inlinePayloads: true }).payloads([insertQuery, payload]).witness(account).query(insertQuery)
const [insertQueryBoundWitness, payloads] = await builder.build()
await archivist.insert([insertQueryBoundWitness, ...payloads])
Expand All @@ -35,28 +35,30 @@ const clearArchivist = async (archivist?: ArchivistInstance) => {
}

const Template: StoryFn<typeof ArchivistCard> = () => {
const [module, setModule] = useState<ArchivistInstance>()
const [node] = usePromise(async () => {
return await MemoryNode.create()
}, [])

useAsyncEffect(
// eslint-disable-next-line react-hooks/exhaustive-deps
async (mounted) => {
if (!module) {
const newParentModule = await MemoryArchivist.create()
const newModule = await MemoryArchivist.create({
config: {
name: 'MemoryArchivist',
parents: { commit: [newParentModule.address], read: [newParentModule.address], write: [newParentModule.address] },
schema: MemoryArchivistConfigSchema,
},
})
await insertPayload(newModule)
if (mounted()) {
setModule(newModule)
}
}
},
[module],
)
const [module] = usePromise(async () => {
if (node) {
const newParentModule = await MemoryArchivist.create()
await node?.register(newParentModule)
await node?.attach(newParentModule.address)

const newModule = await MemoryArchivist.create({
config: {
name: 'MemoryArchivist',
parents: { commit: [newParentModule.address], read: [newParentModule.address], write: [newParentModule.address] },
schema: MemoryArchivistConfigSchema,
},
})
await node?.register(newModule)
await node?.attach(newModule.address)

await insertPayload(newModule)
return newModule
}
}, [node])

return (
<FlexCol gap={2}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CardHeader, CardHeaderProps } from '@mui/material'
import { Module } from '@xyo-network/module'
import { findNetworkComponent } from '@xyo-network/react-shared'
import { Fragment } from 'react'

import { ModuleRenderProps } from '../../../ModuleRenderProps'

Expand All @@ -19,7 +20,7 @@ export const ModuleCardHeader: React.FC<ModuleRenderProps & CardHeaderProps> = (
{module
? ['sentinel', 'bridge', 'archivist', 'diviner', 'node', 'witness'].map((moduleType) => {
const Icon = getModuleIcons(moduleType, module)
return Icon ? <Icon fontSize={'large'} color="primary" /> : null
return <Fragment key={moduleType}>{Icon ? <Icon fontSize={'large'} color="primary" /> : null}</Fragment>
})
: null}
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { useModuleFromNode } from '@xyo-network/react-node'
import { NodeSingular } from 'cytoscape'
import { useMemo } from 'react'

import { useCytoscapeElements } from './useCytoscapeElements'

export const useNewElements = (selectedElement?: NodeSingular) => {
const { address: selectedAddress } = selectedElement?.data() ?? {}
const selectedAddress = useMemo(() => {
const { address: selectedAddress } = selectedElement?.data() ?? {}
return selectedAddress
}, [selectedElement])

const [module] = useModuleFromNode(selectedAddress)
const newElements = useCytoscapeElements(module)

Expand Down
Loading