From 70c0af0257655847df2b4f569aa9e366e7727cbc Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Tue, 3 Oct 2023 13:15:03 -0400 Subject: [PATCH 1/5] fix archivist card stories --- .../modules/packages/archivist/package.json | 1 + .../src/components/Card/Card.stories.tsx | 50 ++++++++++--------- .../src/components/Card/Module/CardHeader.tsx | 3 +- yarn.lock | 1 + 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/packages/modules/packages/archivist/package.json b/packages/modules/packages/archivist/package.json index ecb0015fb5..f4d645f13c 100644 --- a/packages/modules/packages/archivist/package.json +++ b/packages/modules/packages/archivist/package.json @@ -40,6 +40,7 @@ "@xyo-network/archivist": "^2.75.6", "@xyo-network/boundwitness-builder": "^2.75.6", "@xyo-network/module": "^2.75.6", + "@xyo-network/node-memory": "^2.75.6", "@xyo-network/payload-model": "^2.75.6", "@xyo-network/react-storybook": "workspace:~", "typescript": "^5.2.2" diff --git a/packages/modules/packages/archivist/src/components/Card/Card.stories.tsx b/packages/modules/packages/archivist/src/components/Card/Card.stories.tsx index 4b15812c40..1df0a1afc6 100644 --- a/packages/modules/packages/archivist/src/components/Card/Card.stories.tsx +++ b/packages/modules/packages/archivist/src/components/Card/Card.stories.tsx @@ -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' @@ -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]) @@ -35,28 +35,30 @@ const clearArchivist = async (archivist?: ArchivistInstance) => { } const Template: StoryFn = () => { - const [module, setModule] = useState() + 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 ( diff --git a/packages/modules/packages/module/src/components/Card/Module/CardHeader.tsx b/packages/modules/packages/module/src/components/Card/Module/CardHeader.tsx index b8692ff6fa..fa64b7ad90 100644 --- a/packages/modules/packages/module/src/components/Card/Module/CardHeader.tsx +++ b/packages/modules/packages/module/src/components/Card/Module/CardHeader.tsx @@ -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' @@ -19,7 +20,7 @@ export const ModuleCardHeader: React.FC = ( {module ? ['sentinel', 'bridge', 'archivist', 'diviner', 'node', 'witness'].map((moduleType) => { const Icon = getModuleIcons(moduleType, module) - return Icon ? : null + return {Icon ? : null} }) : null} diff --git a/yarn.lock b/yarn.lock index 107051b8f8..31fb634b41 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8783,6 +8783,7 @@ __metadata: "@xyo-network/boundwitness-wrapper": ^2.75.6 "@xyo-network/module": ^2.75.6 "@xyo-network/module-model": ^2.75.6 + "@xyo-network/node-memory": ^2.75.6 "@xyo-network/payload-model": ^2.75.6 "@xyo-network/react-module": "workspace:~" "@xyo-network/react-node": "workspace:~" From 3b855bf11f0ba848047465dd0b1867213efea0d3 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Mon, 30 Oct 2023 16:06:32 -0400 Subject: [PATCH 2/5] wait till selected element has new address --- .../src/hooks/cytoscape/elements/useNewElements.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/sdk/packages/node-renderer/src/hooks/cytoscape/elements/useNewElements.tsx b/packages/sdk/packages/node-renderer/src/hooks/cytoscape/elements/useNewElements.tsx index 7bd0fee34d..cb1bfc0b85 100644 --- a/packages/sdk/packages/node-renderer/src/hooks/cytoscape/elements/useNewElements.tsx +++ b/packages/sdk/packages/node-renderer/src/hooks/cytoscape/elements/useNewElements.tsx @@ -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) From 4c6c064110fc35a5fadda31d089edc9696bfd561 Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Mon, 30 Oct 2023 17:09:56 -0400 Subject: [PATCH 3/5] fix console warnings --- .../module/src/components/Card/Module/CardHeader.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/modules/packages/module/src/components/Card/Module/CardHeader.tsx b/packages/modules/packages/module/src/components/Card/Module/CardHeader.tsx index fa64b7ad90..be501266f0 100644 --- a/packages/modules/packages/module/src/components/Card/Module/CardHeader.tsx +++ b/packages/modules/packages/module/src/components/Card/Module/CardHeader.tsx @@ -1,10 +1,11 @@ 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' +const moduleTypes = ['sentinel', 'bridge', 'archivist', 'diviner', 'node', 'witness'] + const getModuleIcons = (moduleType: string, module: Module) => { return module?.queries.find((query) => query.startsWith(`network.xyo.query.${moduleType}`)) ? findNetworkComponent(moduleType)?.icon : null } @@ -18,9 +19,9 @@ export const ModuleCardHeader: React.FC = ( avatar ?? ( <> {module - ? ['sentinel', 'bridge', 'archivist', 'diviner', 'node', 'witness'].map((moduleType) => { + ? moduleTypes.map((moduleType) => { const Icon = getModuleIcons(moduleType, module) - return {Icon ? : null} + return Icon ? : null }) : null} From 8424bab484f1860d6ec87cd6017ec6ab1d40a2ae Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Mon, 30 Oct 2023 17:11:41 -0400 Subject: [PATCH 4/5] remove inline bw payloads --- .../packages/archivist/src/components/Card/Card.stories.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/modules/packages/archivist/src/components/Card/Card.stories.tsx b/packages/modules/packages/archivist/src/components/Card/Card.stories.tsx index 1df0a1afc6..7d019227cf 100644 --- a/packages/modules/packages/archivist/src/components/Card/Card.stories.tsx +++ b/packages/modules/packages/archivist/src/components/Card/Card.stories.tsx @@ -24,7 +24,7 @@ const insertPayload = async (archivist?: ArchivistInstance) => { const payload = { schema: 'network.xyo.payload', timestamp: Date.now() } const insertQuery = { schema: ArchivistInsertQuerySchema } const account = Account.randomSync() - const builder = new QueryBoundWitnessBuilder({ inlinePayloads: true }).payloads([insertQuery, payload]).witness(account).query(insertQuery) + const builder = new QueryBoundWitnessBuilder().payloads([insertQuery, payload]).witness(account).query(insertQuery) const [insertQueryBoundWitness, payloads] = await builder.build() await archivist.insert([insertQueryBoundWitness, ...payloads]) } From 50e5ad93009f9b10a3f935bd127d9f5f545c4cda Mon Sep 17 00:00:00 2001 From: Matt Jones <885417+jonesmac@users.noreply.github.com> Date: Mon, 30 Oct 2023 17:28:46 -0400 Subject: [PATCH 5/5] fix story by adding node --- packages/modules/packages/archivist/package.json | 1 + .../Stats/MemoryArchivistStats.stories.tsx | 16 ++++++++++------ yarn.lock | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/modules/packages/archivist/package.json b/packages/modules/packages/archivist/package.json index 2b3f3d285d..5192d32c1d 100644 --- a/packages/modules/packages/archivist/package.json +++ b/packages/modules/packages/archivist/package.json @@ -39,6 +39,7 @@ "@xyo-network/archivist": "^2.77.7", "@xyo-network/boundwitness-builder": "^2.77.7", "@xyo-network/module": "^2.77.7", + "@xyo-network/node-memory": "^2.77.7", "@xyo-network/payload-model": "^2.77.7", "@xyo-network/react-storybook": "workspace:~", "typescript": "^5.2.2" diff --git a/packages/modules/packages/archivist/src/components/Card/components/Stats/MemoryArchivistStats.stories.tsx b/packages/modules/packages/archivist/src/components/Card/components/Stats/MemoryArchivistStats.stories.tsx index 4a0e0031f7..a73a8ec402 100644 --- a/packages/modules/packages/archivist/src/components/Card/components/Stats/MemoryArchivistStats.stories.tsx +++ b/packages/modules/packages/archivist/src/components/Card/components/Stats/MemoryArchivistStats.stories.tsx @@ -3,6 +3,7 @@ import { useAsyncEffect } from '@xylabs/react-async-effect' import { Account } from '@xyo-network/account' import { ArchivistInsertQuerySchema, ArchivistInstance, MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist' import { QueryBoundWitnessBuilder } from '@xyo-network/boundwitness-builder' +import { MemoryNode } from '@xyo-network/node-memory' import { useState } from 'react' import { MemoryArchivistsStats } from './MemoryArchivistStats' @@ -22,8 +23,9 @@ const Template: StoryFn = () => { useAsyncEffect( // eslint-disable-next-line react-hooks/exhaustive-deps - async (mounted) => { + async () => { if (!module) { + const node = await MemoryNode.create() const newParentModule = await MemoryArchivist.create() const newModule = await MemoryArchivist.create({ config: { @@ -34,13 +36,15 @@ const Template: StoryFn = () => { }) const payload = { schema: 'network.xyo.payload' } const insertQuery = { schema: ArchivistInsertQuerySchema } - const account = await Account.randomSync() - const builder = new QueryBoundWitnessBuilder({ inlinePayloads: true }).payloads([insertQuery, payload]).witness(account).query(insertQuery) + const account = Account.randomSync() + const builder = new QueryBoundWitnessBuilder().payloads([insertQuery, payload]).witness(account).query(insertQuery) const [insertQueryBoundWitness, payloads] = await builder.build() + await node.register(newParentModule) + await node.attach(newParentModule.address) + await node.register(newModule) + await node.attach(newModule.address) await newModule.insert([insertQueryBoundWitness, ...payloads]) - if (mounted()) { - setModule(newModule) - } + setModule(newModule) } }, [module], diff --git a/yarn.lock b/yarn.lock index f9a4a1e40d..62a431fbbb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8806,6 +8806,7 @@ __metadata: "@xyo-network/boundwitness-wrapper": ^2.77.7 "@xyo-network/module": ^2.77.7 "@xyo-network/module-model": ^2.77.7 + "@xyo-network/node-memory": ^2.77.7 "@xyo-network/payload-model": ^2.77.7 "@xyo-network/react-module": "workspace:~" "@xyo-network/react-node": "workspace:~"