@xyo-network/react-shared 2.32.0-rc.4 → 2.32.0-rc.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/cjs/components/NotFound.d.ts +5 -0
- package/dist/cjs/components/NotFound.d.ts.map +1 -0
- package/dist/cjs/components/NotFound.js +11 -0
- package/dist/cjs/components/NotFound.js.map +1 -0
- package/dist/cjs/components/index.d.ts +1 -2
- package/dist/cjs/components/index.d.ts.map +1 -1
- package/dist/cjs/components/index.js +1 -2
- package/dist/cjs/components/index.js.map +1 -1
- package/dist/docs.json +2574 -21501
- package/dist/esm/components/NotFound.d.ts +5 -0
- package/dist/esm/components/NotFound.d.ts.map +1 -0
- package/dist/esm/components/NotFound.js +8 -0
- package/dist/esm/components/NotFound.js.map +1 -0
- package/dist/esm/components/index.d.ts +1 -2
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/index.js +1 -2
- package/dist/esm/components/index.js.map +1 -1
- package/package.json +4 -16
- package/src/components/NotFound.tsx +15 -0
- package/src/components/index.ts +1 -2
- package/dist/cjs/components/ApiErrorAlert.d.ts +0 -9
- package/dist/cjs/components/ApiErrorAlert.d.ts.map +0 -1
- package/dist/cjs/components/ApiErrorAlert.js +0 -13
- package/dist/cjs/components/ApiErrorAlert.js.map +0 -1
- package/dist/cjs/components/JsonRouteWrapper/JsonApiButton.d.ts +0 -4
- package/dist/cjs/components/JsonRouteWrapper/JsonApiButton.d.ts.map +0 -1
- package/dist/cjs/components/JsonRouteWrapper/JsonApiButton.js +0 -15
- package/dist/cjs/components/JsonRouteWrapper/JsonApiButton.js.map +0 -1
- package/dist/cjs/components/JsonRouteWrapper/JsonFromUrl.d.ts +0 -10
- package/dist/cjs/components/JsonRouteWrapper/JsonFromUrl.d.ts.map +0 -1
- package/dist/cjs/components/JsonRouteWrapper/JsonFromUrl.js +0 -43
- package/dist/cjs/components/JsonRouteWrapper/JsonFromUrl.js.map +0 -1
- package/dist/cjs/components/JsonRouteWrapper/JsonRouteWrapper.d.ts +0 -11
- package/dist/cjs/components/JsonRouteWrapper/JsonRouteWrapper.d.ts.map +0 -1
- package/dist/cjs/components/JsonRouteWrapper/JsonRouteWrapper.js +0 -47
- package/dist/cjs/components/JsonRouteWrapper/JsonRouteWrapper.js.map +0 -1
- package/dist/cjs/components/JsonRouteWrapper/index.d.ts +0 -4
- package/dist/cjs/components/JsonRouteWrapper/index.d.ts.map +0 -1
- package/dist/cjs/components/JsonRouteWrapper/index.js +0 -7
- package/dist/cjs/components/JsonRouteWrapper/index.js.map +0 -1
- package/dist/esm/components/ApiErrorAlert.d.ts +0 -9
- package/dist/esm/components/ApiErrorAlert.d.ts.map +0 -1
- package/dist/esm/components/ApiErrorAlert.js +0 -7
- package/dist/esm/components/ApiErrorAlert.js.map +0 -1
- package/dist/esm/components/JsonRouteWrapper/JsonApiButton.d.ts +0 -4
- package/dist/esm/components/JsonRouteWrapper/JsonApiButton.d.ts.map +0 -1
- package/dist/esm/components/JsonRouteWrapper/JsonApiButton.js +0 -11
- package/dist/esm/components/JsonRouteWrapper/JsonApiButton.js.map +0 -1
- package/dist/esm/components/JsonRouteWrapper/JsonFromUrl.d.ts +0 -10
- package/dist/esm/components/JsonRouteWrapper/JsonFromUrl.d.ts.map +0 -1
- package/dist/esm/components/JsonRouteWrapper/JsonFromUrl.js +0 -37
- package/dist/esm/components/JsonRouteWrapper/JsonFromUrl.js.map +0 -1
- package/dist/esm/components/JsonRouteWrapper/JsonRouteWrapper.d.ts +0 -11
- package/dist/esm/components/JsonRouteWrapper/JsonRouteWrapper.d.ts.map +0 -1
- package/dist/esm/components/JsonRouteWrapper/JsonRouteWrapper.js +0 -41
- package/dist/esm/components/JsonRouteWrapper/JsonRouteWrapper.js.map +0 -1
- package/dist/esm/components/JsonRouteWrapper/index.d.ts +0 -4
- package/dist/esm/components/JsonRouteWrapper/index.d.ts.map +0 -1
- package/dist/esm/components/JsonRouteWrapper/index.js +0 -4
- package/dist/esm/components/JsonRouteWrapper/index.js.map +0 -1
- package/src/components/ApiErrorAlert.tsx +0 -21
- package/src/components/JsonRouteWrapper/JsonApiButton.tsx +0 -19
- package/src/components/JsonRouteWrapper/JsonFromUrl.stories.tsx +0 -48
- package/src/components/JsonRouteWrapper/JsonFromUrl.tsx +0 -52
- package/src/components/JsonRouteWrapper/JsonRouteWrapper.stories.tsx +0 -68
- package/src/components/JsonRouteWrapper/JsonRouteWrapper.tsx +0 -85
- package/src/components/JsonRouteWrapper/index.ts +0 -3
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/* eslint-disable deprecation/deprecation */
|
|
2
|
-
/* eslint-disable import/no-deprecated */
|
|
3
|
-
import { ComponentStory, Meta } from '@storybook/react'
|
|
4
|
-
import { FlexCol } from '@xylabs/react-flexbox'
|
|
5
|
-
import { DeprecateStory } from '@xyo-network/react-storybook'
|
|
6
|
-
import { BrowserRouter } from 'react-router-dom'
|
|
7
|
-
|
|
8
|
-
import { JsonFromUrl } from './JsonFromUrl'
|
|
9
|
-
|
|
10
|
-
const StorybookEntry: Meta = {
|
|
11
|
-
args: {
|
|
12
|
-
apiDomain: 'http://localhost:8081',
|
|
13
|
-
},
|
|
14
|
-
component: JsonFromUrl,
|
|
15
|
-
parameters: {
|
|
16
|
-
docs: {
|
|
17
|
-
page: null,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
title: 'shared/JsonRouteWrapper/JsonFromUrl',
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const Template: ComponentStory<typeof JsonFromUrl> = (props) => {
|
|
24
|
-
return (
|
|
25
|
-
<>
|
|
26
|
-
<DeprecateStory />
|
|
27
|
-
<BrowserRouter>
|
|
28
|
-
<FlexCol>
|
|
29
|
-
<JsonFromUrl {...props}></JsonFromUrl>
|
|
30
|
-
</FlexCol>
|
|
31
|
-
</BrowserRouter>
|
|
32
|
-
</>
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const Default = Template.bind({})
|
|
37
|
-
Default.args = { pathname: '/stats' }
|
|
38
|
-
|
|
39
|
-
const CustomTheme = Template.bind({})
|
|
40
|
-
CustomTheme.args = { pathname: '/stats', theme: 'apathy:inverted' }
|
|
41
|
-
|
|
42
|
-
const ErrorState = Template.bind({})
|
|
43
|
-
ErrorState.args = { pathname: '/foo' }
|
|
44
|
-
|
|
45
|
-
export { CustomTheme, Default, ErrorState }
|
|
46
|
-
|
|
47
|
-
// eslint-disable-next-line import/no-default-export
|
|
48
|
-
export default StorybookEntry
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { ErrorDialog } from '@xylabs/react-dialogs'
|
|
2
|
-
import { FlexCol } from '@xylabs/react-flexbox'
|
|
3
|
-
import { useAsyncEffect } from '@xylabs/react-shared'
|
|
4
|
-
import axios, { AxiosError, AxiosResponse } from 'axios'
|
|
5
|
-
import { lazy, Suspense, useState } from 'react'
|
|
6
|
-
import { ThemeKeys, ThemeObject } from 'react-json-view'
|
|
7
|
-
import { useLocation } from 'react-router-dom'
|
|
8
|
-
|
|
9
|
-
const JsonView = lazy(() => import(/* webpackChunkName: "jsonView" */ 'react-json-view'))
|
|
10
|
-
|
|
11
|
-
const sanitizeUrlForApi = (path: string) => {
|
|
12
|
-
if (new RegExp(/json$/g).test(path)) {
|
|
13
|
-
return path.split('json')[0]
|
|
14
|
-
} else {
|
|
15
|
-
return path
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface JsonFromUrlProps {
|
|
20
|
-
apiDomain: string
|
|
21
|
-
pathname?: string
|
|
22
|
-
theme?: ThemeKeys | ThemeObject
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** @deprecated - Move to JsonRouteWrapper Component */
|
|
26
|
-
export const JsonFromUrl: React.FC<JsonFromUrlProps> = ({ pathname, apiDomain, ...JsonViewProps }) => {
|
|
27
|
-
const location = useLocation()
|
|
28
|
-
const path = pathname ? pathname : location.pathname
|
|
29
|
-
const [apiResponse, setApiResponse] = useState<AxiosResponse>()
|
|
30
|
-
const [apiError, setApiError] = useState<AxiosError>()
|
|
31
|
-
|
|
32
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
-
useAsyncEffect(async () => {
|
|
34
|
-
const apiPath = sanitizeUrlForApi(path)
|
|
35
|
-
const url = `${apiDomain}${apiPath}`
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
const response = await axios.get(url)
|
|
39
|
-
setApiResponse(response.data)
|
|
40
|
-
} catch (err) {
|
|
41
|
-
setApiError(err as AxiosError)
|
|
42
|
-
}
|
|
43
|
-
}, [apiDomain, path])
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<>
|
|
47
|
-
<p>Resource - {sanitizeUrlForApi(path)}</p>
|
|
48
|
-
<Suspense fallback={<FlexCol />}>{apiResponse && <JsonView src={apiResponse} collapseStringsAfterLength={64} {...JsonViewProps} />}</Suspense>
|
|
49
|
-
<ErrorDialog title="Error Fetching JSON" error={apiError} open={!!apiError} onAction={() => setApiError(undefined)} />
|
|
50
|
-
</>
|
|
51
|
-
)
|
|
52
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { ComponentMeta, ComponentStory, DecoratorFn } from '@storybook/react'
|
|
2
|
-
import { ButtonEx } from '@xylabs/react-button'
|
|
3
|
-
import { FlexCol } from '@xylabs/react-flexbox'
|
|
4
|
-
import { XyoArchivistApi } from '@xyo-network/api'
|
|
5
|
-
import { BrowserRouter, useSearchParams } from 'react-router-dom'
|
|
6
|
-
|
|
7
|
-
import { JsonRouteWrapper } from './JsonRouteWrapper'
|
|
8
|
-
|
|
9
|
-
const JsonDecorator: DecoratorFn = (Story) => (
|
|
10
|
-
<BrowserRouter>
|
|
11
|
-
<Story />
|
|
12
|
-
</BrowserRouter>
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
const StorybookEntry = {
|
|
16
|
-
argTypes: {
|
|
17
|
-
apiDomain: 'https://beta.api.archivist.xyo.network',
|
|
18
|
-
},
|
|
19
|
-
component: JsonRouteWrapper,
|
|
20
|
-
decorators: [JsonDecorator],
|
|
21
|
-
parameters: {
|
|
22
|
-
docs: {
|
|
23
|
-
page: null,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
title: 'shared/JsonRouteWrapper',
|
|
27
|
-
} as ComponentMeta<typeof JsonRouteWrapper>
|
|
28
|
-
|
|
29
|
-
const Template: ComponentStory<typeof JsonRouteWrapper> = (props) => {
|
|
30
|
-
const [searchParams, setSearchParams] = useSearchParams()
|
|
31
|
-
const activeJson = searchParams.get('json')
|
|
32
|
-
return (
|
|
33
|
-
<FlexCol>
|
|
34
|
-
<ButtonEx
|
|
35
|
-
marginY={3}
|
|
36
|
-
onClick={() => {
|
|
37
|
-
activeJson === 'true' ? searchParams.delete('json') : searchParams.set('json', 'true')
|
|
38
|
-
setSearchParams(searchParams)
|
|
39
|
-
}}
|
|
40
|
-
variant="outlined"
|
|
41
|
-
>
|
|
42
|
-
Toggle JSON Page
|
|
43
|
-
</ButtonEx>
|
|
44
|
-
<JsonRouteWrapper {...props}></JsonRouteWrapper>
|
|
45
|
-
</FlexCol>
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const Default = Template.bind({})
|
|
50
|
-
Default.args = {
|
|
51
|
-
callback: () => new XyoArchivistApi({ apiDomain: 'https://beta.api.archivist.xyo.network' }).archive('temp').block.stats.get(),
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const HideBackButton = Template.bind({})
|
|
55
|
-
HideBackButton.args = {
|
|
56
|
-
callback: () =>
|
|
57
|
-
new XyoArchivistApi({
|
|
58
|
-
apiDomain: 'https://beta.api.archivist.xyo.network',
|
|
59
|
-
})
|
|
60
|
-
.archive('temp')
|
|
61
|
-
.block.stats.get(),
|
|
62
|
-
noBackButton: true,
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export { Default, HideBackButton }
|
|
66
|
-
|
|
67
|
-
// eslint-disable-next-line import/no-default-export
|
|
68
|
-
export default StorybookEntry
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { ButtonEx } from '@xylabs/react-button'
|
|
2
|
-
import { ErrorDialog } from '@xylabs/react-dialogs'
|
|
3
|
-
import { FlexBoxProps, FlexCol, FlexRow } from '@xylabs/react-flexbox'
|
|
4
|
-
import { useAsyncEffect } from '@xylabs/react-shared'
|
|
5
|
-
import { XyoApiError } from '@xyo-network/api'
|
|
6
|
-
import { lazy, Suspense, useState } from 'react'
|
|
7
|
-
import { ReactJsonViewProps } from 'react-json-view'
|
|
8
|
-
import { useSearchParams } from 'react-router-dom'
|
|
9
|
-
|
|
10
|
-
import { JsonApiButton } from './JsonApiButton'
|
|
11
|
-
|
|
12
|
-
const JsonView = lazy(() => import(/* webpackChunkName: "jsonView" */ 'react-json-view'))
|
|
13
|
-
|
|
14
|
-
export interface JsonFromPromiseProps extends FlexBoxProps {
|
|
15
|
-
callback: () => Promise<object | undefined>
|
|
16
|
-
noBackButton?: boolean
|
|
17
|
-
noJsonButton?: boolean
|
|
18
|
-
jsonViewProps?: ReactJsonViewProps
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const JsonRouteWrapper: React.FC<JsonFromPromiseProps> = ({
|
|
22
|
-
callback,
|
|
23
|
-
children,
|
|
24
|
-
noBackButton = false,
|
|
25
|
-
noJsonButton = false,
|
|
26
|
-
jsonViewProps,
|
|
27
|
-
...props
|
|
28
|
-
}) => {
|
|
29
|
-
const [apiResponse, setApiResponse] = useState<object>()
|
|
30
|
-
const [apiError, setApiError] = useState<XyoApiError>()
|
|
31
|
-
const [searchParams, setSearchParams] = useSearchParams()
|
|
32
|
-
const active = !!searchParams.get('json')
|
|
33
|
-
|
|
34
|
-
useAsyncEffect(
|
|
35
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
36
|
-
async (mounted) => {
|
|
37
|
-
try {
|
|
38
|
-
const response = await callback()
|
|
39
|
-
if (mounted()) {
|
|
40
|
-
setApiResponse(response)
|
|
41
|
-
}
|
|
42
|
-
} catch (ex) {
|
|
43
|
-
if (mounted()) {
|
|
44
|
-
const error = ex as XyoApiError
|
|
45
|
-
if (error.isXyoError) {
|
|
46
|
-
setApiError(error)
|
|
47
|
-
} else {
|
|
48
|
-
throw ex
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
[callback],
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<FlexCol {...props}>
|
|
58
|
-
{active ? (
|
|
59
|
-
<>
|
|
60
|
-
<Suspense fallback={null}>{apiResponse && <JsonView src={apiResponse} collapseStringsAfterLength={64} {...jsonViewProps} />}</Suspense>
|
|
61
|
-
{!noBackButton && (
|
|
62
|
-
<FlexRow marginY={3}>
|
|
63
|
-
<ButtonEx
|
|
64
|
-
flexDirection="row"
|
|
65
|
-
variant="outlined"
|
|
66
|
-
onClick={() => {
|
|
67
|
-
searchParams.delete('json')
|
|
68
|
-
setSearchParams(searchParams)
|
|
69
|
-
}}
|
|
70
|
-
>
|
|
71
|
-
Back
|
|
72
|
-
</ButtonEx>
|
|
73
|
-
</FlexRow>
|
|
74
|
-
)}
|
|
75
|
-
<ErrorDialog title="Error Fetching JSON" error={apiError} open={!!apiError} onAction={() => setApiError(undefined)} />
|
|
76
|
-
</>
|
|
77
|
-
) : (
|
|
78
|
-
<>
|
|
79
|
-
{children}
|
|
80
|
-
{!noJsonButton && <JsonApiButton marginTop={2} />}
|
|
81
|
-
</>
|
|
82
|
-
)}
|
|
83
|
-
</FlexCol>
|
|
84
|
-
)
|
|
85
|
-
}
|