@xyo-network/react-archivist 2.49.7 → 2.49.9
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/cjs/components/Card/CardContent.js +1 -7
- package/dist/cjs/components/Card/CardContent.js.map +1 -1
- package/dist/cjs/components/Card/CardHeader.js +13 -1
- package/dist/cjs/components/Card/CardHeader.js.map +1 -1
- package/dist/cjs/components/Card/components/ArchivistParents.js +19 -0
- package/dist/cjs/components/Card/components/ArchivistParents.js.map +1 -0
- package/dist/cjs/components/Card/components/Stats/ArchivistStats.js +13 -0
- package/dist/cjs/components/Card/components/Stats/ArchivistStats.js.map +1 -0
- package/dist/cjs/components/Card/components/Stats/MemoryArchivistStats.js +63 -0
- package/dist/cjs/components/Card/components/Stats/MemoryArchivistStats.js.map +1 -0
- package/dist/cjs/components/Card/components/Stats/index.js +6 -0
- package/dist/cjs/components/Card/components/Stats/index.js.map +1 -0
- package/dist/cjs/components/Card/components/index.js +2 -0
- package/dist/cjs/components/Card/components/index.js.map +1 -1
- package/dist/docs.json +1512 -576
- package/dist/esm/components/Card/CardContent.js +3 -8
- package/dist/esm/components/Card/CardContent.js.map +1 -1
- package/dist/esm/components/Card/CardHeader.js +14 -2
- package/dist/esm/components/Card/CardHeader.js.map +1 -1
- package/dist/esm/components/Card/components/ArchivistParents.js +12 -0
- package/dist/esm/components/Card/components/ArchivistParents.js.map +1 -0
- package/dist/esm/components/Card/components/Stats/ArchivistStats.js +9 -0
- package/dist/esm/components/Card/components/Stats/ArchivistStats.js.map +1 -0
- package/dist/esm/components/Card/components/Stats/MemoryArchivistStats.js +48 -0
- package/dist/esm/components/Card/components/Stats/MemoryArchivistStats.js.map +1 -0
- package/dist/esm/components/Card/components/Stats/index.js +3 -0
- package/dist/esm/components/Card/components/Stats/index.js.map +1 -0
- package/dist/esm/components/Card/components/index.js +2 -0
- package/dist/esm/components/Card/components/index.js.map +1 -1
- package/dist/types/components/Card/CardContent.d.ts.map +1 -1
- package/dist/types/components/Card/CardHeader.d.ts.map +1 -1
- package/dist/types/components/Card/components/ArchivistParents.d.ts +8 -0
- package/dist/types/components/Card/components/ArchivistParents.d.ts.map +1 -0
- package/dist/types/components/Card/components/Stats/ArchivistStats.d.ts +10 -0
- package/dist/types/components/Card/components/Stats/ArchivistStats.d.ts.map +1 -0
- package/dist/types/components/Card/components/Stats/MemoryArchivistStats.d.ts +7 -0
- package/dist/types/components/Card/components/Stats/MemoryArchivistStats.d.ts.map +1 -0
- package/dist/types/components/Card/components/Stats/index.d.ts +3 -0
- package/dist/types/components/Card/components/Stats/index.d.ts.map +1 -0
- package/dist/types/components/Card/components/index.d.ts +2 -0
- package/dist/types/components/Card/components/index.d.ts.map +1 -1
- package/dist/types/hooks/useArchivist.d.ts +31 -1
- package/dist/types/hooks/useArchivist.d.ts.map +1 -1
- package/dist/types/hooks/useArchivistStates.d.ts +31 -1
- package/dist/types/hooks/useArchivistStates.d.ts.map +1 -1
- package/dist/types/hooks/useArchivists.d.ts +31 -1
- package/dist/types/hooks/useArchivists.d.ts.map +1 -1
- package/package.json +12 -9
- package/src/components/Card/Card.stories.tsx +29 -2
- package/src/components/Card/CardContent.tsx +7 -30
- package/src/components/Card/CardHeader.tsx +15 -2
- package/src/components/Card/components/ArchivistParents.tsx +43 -0
- package/src/components/Card/components/Stats/ArchivistStats.stories.tsx +36 -0
- package/src/components/Card/components/Stats/ArchivistStats.tsx +47 -0
- package/src/components/Card/components/Stats/MemoryArchivistStats.stories.tsx +61 -0
- package/src/components/Card/components/Stats/MemoryArchivistStats.tsx +70 -0
- package/src/components/Card/components/Stats/index.ts +2 -0
- package/src/components/Card/components/index.ts +2 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import ArrowRightRoundedIcon from '@mui/icons-material/ArrowRightRounded'
|
|
2
|
+
import { Collapse, IconButton, List, Paper, Typography } from '@mui/material'
|
|
3
|
+
import { FlexBoxProps, FlexCol } from '@xylabs/react-flexbox'
|
|
4
|
+
import { ArchivistConfig } from '@xyo-network/archivist'
|
|
5
|
+
import { useState } from 'react'
|
|
6
|
+
|
|
7
|
+
import { ArchivistParent } from './ArchivistParent'
|
|
8
|
+
|
|
9
|
+
export interface ArchivistParentsProps extends FlexBoxProps {
|
|
10
|
+
config?: ArchivistConfig
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const ArchivistParents: React.FC<ArchivistParentsProps> = ({ config, ...props }) => {
|
|
14
|
+
const [parentArchivistCollapse, setParentArchivistCollapse] = useState(false)
|
|
15
|
+
|
|
16
|
+
const { commit, read, write } = config?.parents ?? {}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<>
|
|
20
|
+
{commit || read || write ? (
|
|
21
|
+
<FlexCol alignItems="start" {...props}>
|
|
22
|
+
<span onClick={() => setParentArchivistCollapse(!parentArchivistCollapse)}>
|
|
23
|
+
<Typography variant="subtitle2" sx={{ cursor: 'pointer', display: 'inline-block' }}>
|
|
24
|
+
Parents
|
|
25
|
+
</Typography>
|
|
26
|
+
<IconButton size="small">
|
|
27
|
+
<ArrowRightRoundedIcon sx={{ rotate: parentArchivistCollapse ? '90deg' : '0deg', transition: 'all .25s' }} />
|
|
28
|
+
</IconButton>
|
|
29
|
+
</span>
|
|
30
|
+
<Collapse in={parentArchivistCollapse}>
|
|
31
|
+
<Paper elevation={2}>
|
|
32
|
+
<List>
|
|
33
|
+
<ArchivistParent archivistType="Commit" parentArchivists={commit} />
|
|
34
|
+
<ArchivistParent archivistType="Read" parentArchivists={read} />
|
|
35
|
+
<ArchivistParent archivistType="Write" parentArchivists={write} />
|
|
36
|
+
</List>
|
|
37
|
+
</Paper>
|
|
38
|
+
</Collapse>
|
|
39
|
+
</FlexCol>
|
|
40
|
+
) : null}
|
|
41
|
+
</>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Meta, StoryFn } from '@storybook/react'
|
|
2
|
+
import { Account } from '@xyo-network/account'
|
|
3
|
+
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
4
|
+
import { Payload } from '@xyo-network/payload-model'
|
|
5
|
+
|
|
6
|
+
import { ArchivistStats } from './ArchivistStats'
|
|
7
|
+
|
|
8
|
+
const account = new Account()
|
|
9
|
+
const payload = () => ({ schema: 'network.xyo.payload', timestamp: Date.now() })
|
|
10
|
+
const boundWitness = () => new BoundWitnessBuilder().payload(payload()).witness(account).build()
|
|
11
|
+
|
|
12
|
+
const StorybookEntry = {
|
|
13
|
+
component: ArchivistStats,
|
|
14
|
+
parameters: {
|
|
15
|
+
docs: {
|
|
16
|
+
page: null,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
title: 'modules/archivist/ArchivistStats',
|
|
20
|
+
} as Meta<typeof ArchivistStats>
|
|
21
|
+
|
|
22
|
+
const Template: StoryFn<typeof ArchivistStats> = (props) => <ArchivistStats {...props} />
|
|
23
|
+
|
|
24
|
+
const Default = Template.bind({})
|
|
25
|
+
const WithStats = Template.bind({})
|
|
26
|
+
WithStats.args = {
|
|
27
|
+
addresses: { [account.addressValue.hex]: 1 },
|
|
28
|
+
boundWitnesses: [boundWitness() as unknown as Payload],
|
|
29
|
+
payloads: [payload(), boundWitness() as unknown as Payload],
|
|
30
|
+
schemas: { 'network.xyo.boundwitness': 1, 'network.xyo.payload': 1 },
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { Default, WithStats }
|
|
34
|
+
|
|
35
|
+
// eslint-disable-next-line import/no-default-export
|
|
36
|
+
export default StorybookEntry
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Badge, Tooltip } from '@mui/material'
|
|
2
|
+
import { FlexRow } from '@xylabs/react-flexbox'
|
|
3
|
+
import { Payload } from '@xyo-network/payload-model'
|
|
4
|
+
import { BsFileEarmarkCode } from 'react-icons/bs'
|
|
5
|
+
import { VscOrganization, VscSymbolMethod, VscSymbolNamespace } from 'react-icons/vsc'
|
|
6
|
+
|
|
7
|
+
export interface ArchivistStatsProps {
|
|
8
|
+
addresses?: Record<string, number>
|
|
9
|
+
boundWitnesses?: Payload[] | null
|
|
10
|
+
payloads?: Payload[] | null
|
|
11
|
+
schemas?: Record<string, number>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const ArchivistStats: React.FC<ArchivistStatsProps> = ({ addresses = {}, boundWitnesses, payloads, schemas = {} }) => {
|
|
15
|
+
return (
|
|
16
|
+
<FlexRow gap={2} mr={0.5}>
|
|
17
|
+
{payloads?.length ? (
|
|
18
|
+
<Tooltip title="Payloads">
|
|
19
|
+
<Badge badgeContent={payloads?.length} color="primary">
|
|
20
|
+
<VscSymbolNamespace size={20} />
|
|
21
|
+
</Badge>
|
|
22
|
+
</Tooltip>
|
|
23
|
+
) : null}
|
|
24
|
+
{boundWitnesses?.length ? (
|
|
25
|
+
<Tooltip title="Blocks">
|
|
26
|
+
<Badge badgeContent={boundWitnesses?.length} color="primary">
|
|
27
|
+
<VscSymbolMethod size={20} />
|
|
28
|
+
</Badge>
|
|
29
|
+
</Tooltip>
|
|
30
|
+
) : null}
|
|
31
|
+
{Object.entries(schemas).length ? (
|
|
32
|
+
<Tooltip title="Schemas">
|
|
33
|
+
<Badge badgeContent={Object.entries(schemas).length} color="primary">
|
|
34
|
+
<BsFileEarmarkCode size={20} />
|
|
35
|
+
</Badge>
|
|
36
|
+
</Tooltip>
|
|
37
|
+
) : null}
|
|
38
|
+
{Object.entries(addresses).length ? (
|
|
39
|
+
<Tooltip title="Addresses">
|
|
40
|
+
<Badge badgeContent={Object.entries(addresses).length} color="primary">
|
|
41
|
+
<VscOrganization size={20} />
|
|
42
|
+
</Badge>
|
|
43
|
+
</Tooltip>
|
|
44
|
+
) : null}
|
|
45
|
+
</FlexRow>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Meta, StoryFn } from '@storybook/react'
|
|
2
|
+
import { useAsyncEffect } from '@xylabs/react-async-effect'
|
|
3
|
+
import { Account } from '@xyo-network/account'
|
|
4
|
+
import { ArchivistInsertQuerySchema, ArchivistModule, ArchivistWrapper, MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist'
|
|
5
|
+
import { QueryBoundWitnessBuilder } from '@xyo-network/module'
|
|
6
|
+
import { useState } from 'react'
|
|
7
|
+
|
|
8
|
+
import { MemoryArchivistsStats } from './MemoryArchivistStats'
|
|
9
|
+
|
|
10
|
+
const StorybookEntry = {
|
|
11
|
+
component: MemoryArchivistsStats,
|
|
12
|
+
parameters: {
|
|
13
|
+
docs: {
|
|
14
|
+
page: null,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
title: 'modules/archivist/MemoryArchivistsStats',
|
|
18
|
+
} as Meta<typeof MemoryArchivistsStats>
|
|
19
|
+
|
|
20
|
+
const Template: StoryFn<typeof MemoryArchivistsStats> = () => {
|
|
21
|
+
const [module, setModule] = useState<ArchivistModule>()
|
|
22
|
+
|
|
23
|
+
useAsyncEffect(
|
|
24
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
25
|
+
async (mounted) => {
|
|
26
|
+
if (!module) {
|
|
27
|
+
const newParentModule = await MemoryArchivist.create()
|
|
28
|
+
const newModule = await MemoryArchivist.create({
|
|
29
|
+
config: {
|
|
30
|
+
name: 'MemoryArchivist',
|
|
31
|
+
parents: { commit: [newParentModule.address], read: [newParentModule.address], write: [newParentModule.address] },
|
|
32
|
+
schema: MemoryArchivistConfigSchema,
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
const payload = { schema: 'network.xyo.payload' }
|
|
36
|
+
const insertQuery = { schema: ArchivistInsertQuerySchema }
|
|
37
|
+
const account = new Account()
|
|
38
|
+
const [insertQueryBoundWitness, payloads] = new QueryBoundWitnessBuilder({ inlinePayloads: true })
|
|
39
|
+
.payloads([insertQuery, payload])
|
|
40
|
+
.witness(account)
|
|
41
|
+
.query(insertQuery)
|
|
42
|
+
.build()
|
|
43
|
+
const wrapper = ArchivistWrapper.wrap(newModule, account)
|
|
44
|
+
await wrapper.insert([insertQueryBoundWitness, ...payloads])
|
|
45
|
+
if (mounted()) {
|
|
46
|
+
setModule(newModule)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
[module],
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
return <MemoryArchivistsStats archivist={module} />
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const Default = Template.bind({})
|
|
57
|
+
|
|
58
|
+
export { Default }
|
|
59
|
+
|
|
60
|
+
// eslint-disable-next-line import/no-default-export
|
|
61
|
+
export default StorybookEntry
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useAsyncEffect } from '@xylabs/react-async-effect'
|
|
2
|
+
import { ArchivistAllQuerySchema, ArchivistModule } from '@xyo-network/archivist'
|
|
3
|
+
import { BoundWitnessSchema } from '@xyo-network/boundwitness-model'
|
|
4
|
+
import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'
|
|
5
|
+
import { EventUnsubscribeFunction } from '@xyo-network/module'
|
|
6
|
+
import { Payload } from '@xyo-network/payload-model'
|
|
7
|
+
import { useCallback, useEffect, useMemo, useState } from 'react'
|
|
8
|
+
|
|
9
|
+
import { ArchivistStats } from './ArchivistStats'
|
|
10
|
+
|
|
11
|
+
export interface MemoryArchivistStatsProps {
|
|
12
|
+
archivist?: ArchivistModule
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const MemoryArchivistsStats: React.FC<MemoryArchivistStatsProps> = ({ archivist }) => {
|
|
16
|
+
const [all, setAll] = useState<Payload[] | null>()
|
|
17
|
+
|
|
18
|
+
const getAll = useCallback(async (archivist?: ArchivistModule) => {
|
|
19
|
+
const all = await archivist?.all?.()
|
|
20
|
+
setAll(all)
|
|
21
|
+
}, [])
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
let listener: EventUnsubscribeFunction
|
|
25
|
+
|
|
26
|
+
if (archivist?.queries.includes(ArchivistAllQuerySchema)) {
|
|
27
|
+
listener = archivist.on('inserted', async () => {
|
|
28
|
+
await getAll(archivist)
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return () => listener?.()
|
|
33
|
+
}, [archivist, getAll])
|
|
34
|
+
|
|
35
|
+
useAsyncEffect(
|
|
36
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
37
|
+
async () => {
|
|
38
|
+
if (archivist?.queries.includes(ArchivistAllQuerySchema)) {
|
|
39
|
+
await getAll(archivist)
|
|
40
|
+
} else {
|
|
41
|
+
setAll(null)
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
[archivist, getAll],
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
const payloads = useMemo(() => (all === null ? [] : all?.filter((payload) => payload.schema !== BoundWitnessSchema)), [all])
|
|
48
|
+
const boundWitnesses = useMemo(() => (all === null ? [] : all?.filter((payload) => payload.schema === BoundWitnessSchema)), [all])
|
|
49
|
+
const addresses = useMemo(
|
|
50
|
+
() =>
|
|
51
|
+
all?.reduce((prev, payload) => {
|
|
52
|
+
const w = BoundWitnessWrapper.tryParse(payload) as BoundWitnessWrapper | undefined
|
|
53
|
+
w?.addresses?.forEach((address) => {
|
|
54
|
+
prev[address] = (prev[address] ?? 0) + 1
|
|
55
|
+
})
|
|
56
|
+
return prev
|
|
57
|
+
}, {} as Record<string, number>) ?? {},
|
|
58
|
+
[all],
|
|
59
|
+
)
|
|
60
|
+
const schemas = useMemo(
|
|
61
|
+
() =>
|
|
62
|
+
all?.reduce((prev, payload) => {
|
|
63
|
+
prev[payload.schema] = (prev[payload.schema] ?? 0) + 1
|
|
64
|
+
return prev
|
|
65
|
+
}, {} as Record<string, number>) ?? {},
|
|
66
|
+
[all],
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
return <ArchivistStats addresses={addresses} boundWitnesses={boundWitnesses} payloads={payloads} schemas={schemas} />
|
|
70
|
+
}
|