@xyo-network/react-archivist 2.26.36 → 2.26.39
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/docs.json +1 -1
- package/package.json +2 -2
- package/src/components/Details.stories.tsx +38 -0
- package/src/components/Details.tsx +51 -0
- package/src/components/index.ts +1 -0
- package/src/contexts/Context.ts +7 -0
- package/src/contexts/Provider.tsx +54 -0
- package/src/contexts/State.ts +7 -0
- package/src/contexts/index.ts +4 -0
- package/src/contexts/use.ts +7 -0
- package/src/index.ts +2 -0
package/dist/docs.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"fileName": "index.ts",
|
|
11
11
|
"line": 1,
|
|
12
12
|
"character": 0,
|
|
13
|
-
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/
|
|
13
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/413a933/packages/archivist/src/index.ts#L1"
|
|
14
14
|
}
|
|
15
15
|
]
|
|
16
16
|
}
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@xyo-network/api": "^2.22.15",
|
|
21
21
|
"@xyo-network/archivist": "^2.22.15",
|
|
22
22
|
"@xyo-network/payload": "^2.22.15",
|
|
23
|
-
"@xyo-network/react-shared": "^2.26.
|
|
23
|
+
"@xyo-network/react-shared": "^2.26.39",
|
|
24
24
|
"react": "^18.2.0",
|
|
25
25
|
"react-dom": "^18.2.0",
|
|
26
26
|
"tslib": "^2.4.0"
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
},
|
|
82
82
|
"sideEffects": false,
|
|
83
83
|
"types": "dist/esm/index.d.ts",
|
|
84
|
-
"version": "2.26.
|
|
84
|
+
"version": "2.26.39"
|
|
85
85
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ComponentMeta, ComponentStory } from '@storybook/react'
|
|
2
|
+
import { forget } from '@xylabs/sdk-js'
|
|
3
|
+
import { XyoMemoryArchivist } from '@xyo-network/archivist'
|
|
4
|
+
|
|
5
|
+
import { appThemeDecorator } from '../../../../.storybook'
|
|
6
|
+
import { ArchivistDetails } from './Details'
|
|
7
|
+
|
|
8
|
+
const StorybookEntry = {
|
|
9
|
+
argTypes: {},
|
|
10
|
+
component: ArchivistDetails,
|
|
11
|
+
parameters: {
|
|
12
|
+
docs: {
|
|
13
|
+
page: null,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
title: 'archivist/Details',
|
|
17
|
+
} as ComponentMeta<typeof ArchivistDetails>
|
|
18
|
+
|
|
19
|
+
const Template: ComponentStory<typeof ArchivistDetails> = (args) => <ArchivistDetails {...args}></ArchivistDetails>
|
|
20
|
+
|
|
21
|
+
const archivist = new XyoMemoryArchivist()
|
|
22
|
+
const initArchivist = async () => {
|
|
23
|
+
await archivist.insert?.([{ schema: 'network.xyo.test' }])
|
|
24
|
+
}
|
|
25
|
+
forget(initArchivist())
|
|
26
|
+
|
|
27
|
+
const Default = Template.bind({})
|
|
28
|
+
Default.args = {}
|
|
29
|
+
Default.decorators = [appThemeDecorator]
|
|
30
|
+
|
|
31
|
+
const WithData = Template.bind({})
|
|
32
|
+
WithData.args = { archivist }
|
|
33
|
+
WithData.decorators = [appThemeDecorator]
|
|
34
|
+
|
|
35
|
+
export { Default, WithData }
|
|
36
|
+
|
|
37
|
+
// eslint-disable-next-line import/no-default-export
|
|
38
|
+
export default StorybookEntry
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ButtonGroup, Typography } from '@mui/material'
|
|
2
|
+
import { ButtonEx } from '@xylabs/react-button'
|
|
3
|
+
import { FlexBoxProps, FlexCol } from '@xylabs/react-flexbox'
|
|
4
|
+
import { useAsyncEffect } from '@xylabs/react-shared'
|
|
5
|
+
import { XyoArchivist } from '@xyo-network/archivist'
|
|
6
|
+
import { XyoPayload } from '@xyo-network/payload'
|
|
7
|
+
import { useState } from 'react'
|
|
8
|
+
|
|
9
|
+
import { useArchivist } from '../contexts'
|
|
10
|
+
|
|
11
|
+
export interface ArchivistDetails extends FlexBoxProps {
|
|
12
|
+
archivist?: XyoArchivist
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const ArchivistDetails: React.FC<ArchivistDetails> = ({ archivist: archivistProp, ...props }) => {
|
|
16
|
+
const { archivist = archivistProp } = useArchivist()
|
|
17
|
+
const [payloads, setPayloads] = useState<XyoPayload[]>()
|
|
18
|
+
const [refresh, setRefresh] = useState(0)
|
|
19
|
+
|
|
20
|
+
useAsyncEffect(
|
|
21
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
22
|
+
async (mounted) => {
|
|
23
|
+
const payloads = await archivist?.all?.()
|
|
24
|
+
if (mounted()) {
|
|
25
|
+
setPayloads(payloads)
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
[archivist, refresh]
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<FlexCol {...props}>
|
|
33
|
+
<Typography>{`Payloads: ${payloads ? payloads.length : '-'}`}</Typography>
|
|
34
|
+
<ButtonGroup>
|
|
35
|
+
<ButtonEx disabled={archivist?.commit === undefined} onClick={() => archivist?.commit?.()}>
|
|
36
|
+
Commit
|
|
37
|
+
</ButtonEx>
|
|
38
|
+
<ButtonEx disabled={archivist?.clear === undefined} onClick={() => archivist?.clear?.()}>
|
|
39
|
+
Clear
|
|
40
|
+
</ButtonEx>
|
|
41
|
+
<ButtonEx
|
|
42
|
+
onClick={() => {
|
|
43
|
+
setRefresh(refresh + 1)
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
Refresh
|
|
47
|
+
</ButtonEx>
|
|
48
|
+
</ButtonGroup>
|
|
49
|
+
</FlexCol>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Details'
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { WithChildren } from '@xylabs/react-shared'
|
|
2
|
+
import { XyoRemoteArchivist, XyoRemoteArchivistConfig } from '@xyo-network/api'
|
|
3
|
+
import { XyoArchivist, XyoArchivistConfig, XyoMemoryArchivist } from '@xyo-network/archivist'
|
|
4
|
+
import { useState } from 'react'
|
|
5
|
+
|
|
6
|
+
import { ArchivistContext } from './Context'
|
|
7
|
+
import { useArchivist } from './use'
|
|
8
|
+
|
|
9
|
+
export interface ArchivistProviderProps {
|
|
10
|
+
required?: boolean
|
|
11
|
+
archivist?: XyoArchivist
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const ArchivistProvider: React.FC<WithChildren<ArchivistProviderProps>> = ({ archivist: archivistProp, required = false, children }) => {
|
|
15
|
+
const [archivist, setArchivist] = useState<XyoArchivist | undefined>(archivistProp)
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<ArchivistContext.Provider
|
|
19
|
+
value={{
|
|
20
|
+
archivist,
|
|
21
|
+
provided: true,
|
|
22
|
+
setArchivist,
|
|
23
|
+
}}
|
|
24
|
+
>
|
|
25
|
+
{archivist ? children : required ? null : children}
|
|
26
|
+
</ArchivistContext.Provider>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface MemoryArchivistProviderProps {
|
|
31
|
+
required?: boolean
|
|
32
|
+
config?: XyoArchivistConfig
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const MemoryArchivistProvider: React.FC<WithChildren<MemoryArchivistProviderProps>> = ({ config = {}, children, ...props }) => {
|
|
36
|
+
const { archivist } = useArchivist()
|
|
37
|
+
config.parent = config.parent ?? archivist
|
|
38
|
+
return (
|
|
39
|
+
<ArchivistProvider archivist={new XyoMemoryArchivist(config)} {...props}>
|
|
40
|
+
{children}
|
|
41
|
+
</ArchivistProvider>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ApiArchivistProviderProps {
|
|
46
|
+
required?: boolean
|
|
47
|
+
config?: XyoRemoteArchivistConfig
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const RemoteArchivistProvider: React.FC<WithChildren<ApiArchivistProviderProps>> = ({ config = {}, ...props }) => {
|
|
51
|
+
const { archivist } = useArchivist()
|
|
52
|
+
config.parent = config.parent ?? archivist
|
|
53
|
+
return <ArchivistProvider archivist={new XyoRemoteArchivist(config)} {...props} />
|
|
54
|
+
}
|
package/src/index.ts
ADDED