@qoretechnologies/reqraft 0.0.1 → 0.2.0
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/__tests__/ mock.ts +44 -0
- package/__tests__/utils.ts +11 -0
- package/dist/__tests__/ mock.d.ts +23 -0
- package/dist/__tests__/ mock.d.ts.map +1 -0
- package/dist/__tests__/ mock.js +44 -0
- package/dist/__tests__/ mock.js.map +1 -0
- package/dist/__tests__/utils.d.ts +3 -0
- package/dist/__tests__/utils.d.ts.map +1 -0
- package/dist/__tests__/utils.js +60 -0
- package/dist/__tests__/utils.js.map +1 -0
- package/dist/mock/interfaceCategories.json +155 -0
- package/dist/mock/menu.d.ts +70 -0
- package/dist/mock/menu.d.ts.map +1 -0
- package/dist/mock/menu.js +301 -0
- package/dist/mock/menu.js.map +1 -0
- package/dist/src/components/form/fields/Field.d.ts +10 -0
- package/dist/src/components/form/fields/Field.d.ts.map +1 -0
- package/dist/src/components/form/fields/Field.js +44 -0
- package/dist/src/components/form/fields/Field.js.map +1 -0
- package/dist/{components/form → src/components/form/fields}/string/String.d.ts +3 -2
- package/dist/src/components/form/fields/string/String.d.ts.map +1 -0
- package/dist/src/components/form/fields/string/String.js.map +1 -0
- package/dist/src/components/form/fields/string/String.stories.d.ts.map +1 -0
- package/dist/src/components/form/fields/string/String.stories.js.map +1 -0
- package/dist/src/components/menu/Menu.d.ts +31 -0
- package/dist/src/components/menu/Menu.d.ts.map +1 -0
- package/dist/src/components/menu/Menu.js +130 -0
- package/dist/src/components/menu/Menu.js.map +1 -0
- package/dist/src/components/menu/Menu.stories.d.ts +12 -0
- package/dist/src/components/menu/Menu.stories.d.ts.map +1 -0
- package/dist/src/components/menu/Menu.stories.js +159 -0
- package/dist/src/components/menu/Menu.stories.js.map +1 -0
- package/dist/src/contexts/FetchContext.d.ts +10 -0
- package/dist/src/contexts/FetchContext.d.ts.map +1 -0
- package/dist/src/contexts/FetchContext.js +63 -0
- package/dist/src/contexts/FetchContext.js.map +1 -0
- package/dist/src/contexts/ReqraftContext.d.ts +9 -0
- package/dist/src/contexts/ReqraftContext.d.ts.map +1 -0
- package/dist/src/contexts/ReqraftContext.js +11 -0
- package/dist/src/contexts/ReqraftContext.js.map +1 -0
- package/dist/src/contexts/StorageContext.d.ts +11 -0
- package/dist/src/contexts/StorageContext.d.ts.map +1 -0
- package/dist/src/contexts/StorageContext.js +17 -0
- package/dist/src/contexts/StorageContext.js.map +1 -0
- package/dist/src/hooks/useFetch/useFetch.d.ts +21 -0
- package/dist/src/hooks/useFetch/useFetch.d.ts.map +1 -0
- package/dist/src/hooks/useFetch/useFetch.js +106 -0
- package/dist/src/hooks/useFetch/useFetch.js.map +1 -0
- package/dist/src/hooks/useFetch/useFetch.stories.d.ts +9 -0
- package/dist/src/hooks/useFetch/useFetch.stories.d.ts.map +1 -0
- package/dist/src/hooks/useFetch/useFetch.stories.js +177 -0
- package/dist/src/hooks/useFetch/useFetch.stories.js.map +1 -0
- package/dist/src/hooks/useReqraftProperty.d.ts +3 -0
- package/dist/src/hooks/useReqraftProperty.d.ts.map +1 -0
- package/dist/src/hooks/useReqraftProperty.js +16 -0
- package/dist/src/hooks/useReqraftProperty.js.map +1 -0
- package/dist/src/hooks/useStorage/useStorage.d.ts +8 -0
- package/dist/src/hooks/useStorage/useStorage.d.ts.map +1 -0
- package/dist/src/hooks/useStorage/useStorage.js +22 -0
- package/dist/src/hooks/useStorage/useStorage.js.map +1 -0
- package/dist/src/hooks/useStorage/useStorage.stories.d.ts +9 -0
- package/dist/src/hooks/useStorage/useStorage.stories.d.ts.map +1 -0
- package/dist/src/hooks/useStorage/useStorage.stories.js +162 -0
- package/dist/src/hooks/useStorage/useStorage.stories.js.map +1 -0
- package/dist/src/hooks/useValidation.d.ts +3 -0
- package/dist/src/hooks/useValidation.d.ts.map +1 -0
- package/dist/src/hooks/useValidation.js +11 -0
- package/dist/src/hooks/useValidation.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +15 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/providers/FetchProvider.d.ts +6 -0
- package/dist/src/providers/FetchProvider.d.ts.map +1 -0
- package/dist/src/providers/FetchProvider.js +112 -0
- package/dist/src/providers/FetchProvider.js.map +1 -0
- package/dist/src/providers/ReqraftProvider.d.ts +10 -0
- package/dist/src/providers/ReqraftProvider.d.ts.map +1 -0
- package/dist/src/providers/ReqraftProvider.js +15 -0
- package/dist/src/providers/ReqraftProvider.js.map +1 -0
- package/dist/src/providers/StorageProvider.d.ts +6 -0
- package/dist/src/providers/StorageProvider.d.ts.map +1 -0
- package/dist/src/providers/StorageProvider.js +55 -0
- package/dist/src/providers/StorageProvider.js.map +1 -0
- package/dist/src/types/Form.d.ts +3 -0
- package/dist/src/types/Form.d.ts.map +1 -0
- package/dist/src/types/Form.js +3 -0
- package/dist/src/types/Form.js.map +1 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/fetch.d.ts +22 -0
- package/dist/src/utils/fetch.d.ts.map +1 -0
- package/dist/src/utils/fetch.js +140 -0
- package/dist/src/utils/fetch.js.map +1 -0
- package/mock/interfaceCategories.json +155 -0
- package/mock/menu.ts +301 -0
- package/package.json +8 -3
- package/src/components/form/fields/Field.tsx +37 -0
- package/src/components/form/{string → fields/string}/String.stories.tsx +1 -1
- package/src/components/form/{string → fields/string}/String.tsx +3 -2
- package/src/components/menu/Menu.stories.tsx +73 -0
- package/src/components/menu/Menu.tsx +244 -0
- package/src/contexts/FetchContext.tsx +25 -0
- package/src/contexts/ReqraftContext.tsx +16 -0
- package/src/contexts/StorageContext.tsx +33 -0
- package/src/hooks/useFetch/useFetch.stories.tsx +123 -0
- package/src/hooks/useFetch/useFetch.tsx +71 -0
- package/src/hooks/useReqraftProperty.ts +16 -0
- package/src/hooks/useStorage/useStorage.stories.tsx +84 -0
- package/src/hooks/useStorage/useStorage.ts +30 -0
- package/src/hooks/useValidation.ts +9 -0
- package/src/index.tsx +12 -1
- package/src/providers/FetchProvider.tsx +62 -0
- package/src/providers/ReqraftProvider.tsx +33 -0
- package/src/providers/StorageProvider.tsx +80 -0
- package/src/types/Form.ts +57 -0
- package/src/utils/fetch.ts +121 -0
- package/tests.json +1 -1
- package/dist/components/form/string/String.d.ts.map +0 -1
- package/dist/components/form/string/String.js.map +0 -1
- package/dist/components/form/string/String.stories.d.ts.map +0 -1
- package/dist/components/form/string/String.stories.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -6
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- /package/dist/{components/form → src/components/form/fields}/string/String.js +0 -0
- /package/dist/{components/form → src/components/form/fields}/string/String.stories.d.ts +0 -0
- /package/dist/{components/form → src/components/form/fields}/string/String.stories.js +0 -0
- /package/dist/{types.d.ts → src/types.d.ts} +0 -0
- /package/dist/{types.js → src/types.js} +0 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ReqoreButton, ReqoreControlGroup, ReqoreP } from '@qoretechnologies/reqore';
|
|
2
|
+
import { StoryObj } from '@storybook/react';
|
|
3
|
+
import { fireEvent, within } from '@storybook/test';
|
|
4
|
+
import { storiesStorageMock } from '../../../__tests__/ mock';
|
|
5
|
+
import { testsWaitForText } from '../../../__tests__/utils';
|
|
6
|
+
import { StoryMeta } from '../../types';
|
|
7
|
+
import { useReqraftStorage } from './useStorage';
|
|
8
|
+
|
|
9
|
+
const meta = {
|
|
10
|
+
title: 'Hooks/useStorage',
|
|
11
|
+
render: () => {
|
|
12
|
+
const [storage, setStorage, removeValue] = useReqraftStorage<string>(
|
|
13
|
+
'some-path',
|
|
14
|
+
'This is a default value'
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<ReqoreControlGroup>
|
|
19
|
+
<ReqoreP>{storage}</ReqoreP>
|
|
20
|
+
<ReqoreButton onClick={() => setStorage('This is a NEW value')}>
|
|
21
|
+
Update storage
|
|
22
|
+
</ReqoreButton>
|
|
23
|
+
<ReqoreButton onClick={() => removeValue()}>Remove value</ReqoreButton>
|
|
24
|
+
</ReqoreControlGroup>
|
|
25
|
+
);
|
|
26
|
+
},
|
|
27
|
+
} as StoryMeta<any>;
|
|
28
|
+
|
|
29
|
+
export default meta;
|
|
30
|
+
export type Story = StoryObj<typeof meta>;
|
|
31
|
+
|
|
32
|
+
export const DefaultValue: Story = {
|
|
33
|
+
args: {
|
|
34
|
+
method: 'GET',
|
|
35
|
+
},
|
|
36
|
+
parameters: {
|
|
37
|
+
mockData: [
|
|
38
|
+
{
|
|
39
|
+
url: 'https://hq.qoretechnologies.com:8092/api/latest/users/_current_/storage',
|
|
40
|
+
method: 'GET',
|
|
41
|
+
status: 200,
|
|
42
|
+
response: {},
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
play: async () => {
|
|
47
|
+
await testsWaitForText('This is a default value');
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const StorageValue: Story = {
|
|
52
|
+
parameters: {
|
|
53
|
+
mockData: [...storiesStorageMock],
|
|
54
|
+
},
|
|
55
|
+
play: async () => {
|
|
56
|
+
await testsWaitForText('This is a storage value');
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const ValueCanBeUpdated: Story = {
|
|
61
|
+
...StorageValue,
|
|
62
|
+
play: async ({ canvasElement }) => {
|
|
63
|
+
const canvas = within(canvasElement);
|
|
64
|
+
|
|
65
|
+
//await sleep(1000);
|
|
66
|
+
|
|
67
|
+
await testsWaitForText('This is a storage value');
|
|
68
|
+
await testsWaitForText('Update storage');
|
|
69
|
+
await fireEvent.click(canvas.getByText('Update storage'));
|
|
70
|
+
await testsWaitForText('This is a NEW value');
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const ValueCanBeRemoved: Story = {
|
|
75
|
+
...StorageValue,
|
|
76
|
+
play: async ({ canvasElement }) => {
|
|
77
|
+
const canvas = within(canvasElement);
|
|
78
|
+
|
|
79
|
+
await testsWaitForText('This is a storage value');
|
|
80
|
+
await testsWaitForText('Remove value');
|
|
81
|
+
await fireEvent.click(canvas.getByText('Remove value'));
|
|
82
|
+
await testsWaitForText('This is a default value');
|
|
83
|
+
},
|
|
84
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useContextSelector } from 'use-context-selector';
|
|
2
|
+
import { ReqraftStorageContext } from '../../contexts/StorageContext';
|
|
3
|
+
|
|
4
|
+
export type TReqraftStorageValue = string | number | boolean | Record<string | number, any> | any[];
|
|
5
|
+
export type TReqraftStorageHook<T extends TReqraftStorageValue> = [
|
|
6
|
+
T,
|
|
7
|
+
(newStorage: T) => void,
|
|
8
|
+
() => void,
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
export function useReqraftStorage<T extends TReqraftStorageValue>(
|
|
12
|
+
path: string,
|
|
13
|
+
defaultValue?: T,
|
|
14
|
+
includeAppPrefix?: boolean
|
|
15
|
+
): TReqraftStorageHook<T> {
|
|
16
|
+
const { getStorage, updateStorage, removeStorageValue } = useContextSelector(
|
|
17
|
+
ReqraftStorageContext,
|
|
18
|
+
({ getStorage, updateStorage, removeStorageValue }) => ({
|
|
19
|
+
getStorage,
|
|
20
|
+
updateStorage,
|
|
21
|
+
removeStorageValue,
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return [
|
|
26
|
+
getStorage(path, defaultValue, includeAppPrefix),
|
|
27
|
+
(newStorage: T) => updateStorage(path, newStorage, includeAppPrefix),
|
|
28
|
+
() => removeStorageValue(path, includeAppPrefix),
|
|
29
|
+
];
|
|
30
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TFormFieldType } from '../types/Form';
|
|
2
|
+
|
|
3
|
+
// @ts-expect-error "need to implement this"
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
+
export const useValidation = (value: any, type?: TFormFieldType) => {
|
|
6
|
+
// Build validation...
|
|
7
|
+
|
|
8
|
+
return true;
|
|
9
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
IReqraftMenuItem,
|
|
3
|
+
IReqraftMenuProps,
|
|
4
|
+
ReqraftMenu,
|
|
5
|
+
TReqraftMenu,
|
|
6
|
+
TReqraftMenuItem,
|
|
7
|
+
} from './components/menu/Menu';
|
|
8
|
+
|
|
9
|
+
export { FormStringField, IStringFormFieldProps } from './components/form/fields/string/String';
|
|
10
|
+
export { IReqraftUseFetch, useFetch } from './hooks/useFetch/useFetch';
|
|
11
|
+
export { ReqraftProvider, ReqraftQueryClient } from './providers/ReqraftProvider';
|
|
12
|
+
export { query } from './utils/fetch';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useEffectOnce } from 'react-use';
|
|
4
|
+
import { FetchContext, TReqraftContextQueryConfig } from '../contexts/FetchContext';
|
|
5
|
+
import { useReqraftProperty } from '../hooks/useReqraftProperty';
|
|
6
|
+
import { query, setupFetch } from '../utils/fetch';
|
|
7
|
+
|
|
8
|
+
export interface IReqraftFetchProviderProps {
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const ReqraftFetchProvider = ({ children }: IReqraftFetchProviderProps) => {
|
|
13
|
+
const queryClient = useQueryClient();
|
|
14
|
+
const instance = useReqraftProperty('instance');
|
|
15
|
+
const instanceToken = useReqraftProperty('instanceToken');
|
|
16
|
+
const instanceUnauthorizedRedirect = useReqraftProperty('instanceUnauthorizedRedirect');
|
|
17
|
+
|
|
18
|
+
const [ready, setReady] = useState(false);
|
|
19
|
+
|
|
20
|
+
useEffectOnce(() => {
|
|
21
|
+
setupFetch({
|
|
22
|
+
instance,
|
|
23
|
+
instanceToken,
|
|
24
|
+
unauthorizedRedirect: instanceUnauthorizedRedirect,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
setReady(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (!ready) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function get<T>(config: TReqraftContextQueryConfig) {
|
|
35
|
+
return query<T>({ queryClient, ...config, method: 'GET' });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function post<T>(config: TReqraftContextQueryConfig) {
|
|
39
|
+
return query<T>({ queryClient, ...config, method: 'POST' });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function put<T>(config: TReqraftContextQueryConfig) {
|
|
43
|
+
return query<T>({ queryClient, ...config, method: 'PUT' });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function del<T>(config: TReqraftContextQueryConfig) {
|
|
47
|
+
return query<T>({ queryClient, ...config, method: 'DELETE' });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<FetchContext.Provider
|
|
52
|
+
value={{
|
|
53
|
+
get,
|
|
54
|
+
post,
|
|
55
|
+
put,
|
|
56
|
+
del,
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
{children}
|
|
60
|
+
</FetchContext.Provider>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { IReqraftContext, ReqraftContext } from '../contexts/ReqraftContext';
|
|
4
|
+
import { ReqraftFetchProvider } from './FetchProvider';
|
|
5
|
+
import { ReqraftStorageProvider } from './StorageProvider';
|
|
6
|
+
|
|
7
|
+
export const ReqraftQueryClient = new QueryClient();
|
|
8
|
+
|
|
9
|
+
export interface IReqraftProviderProps extends IReqraftContext {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
reactQueryClient?: QueryClient;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const ReqraftProvider = ({
|
|
15
|
+
appName,
|
|
16
|
+
children,
|
|
17
|
+
instance,
|
|
18
|
+
instanceToken,
|
|
19
|
+
instanceUnauthorizedRedirect,
|
|
20
|
+
reactQueryClient,
|
|
21
|
+
}: IReqraftProviderProps) => {
|
|
22
|
+
return (
|
|
23
|
+
<ReqraftContext.Provider
|
|
24
|
+
value={{ appName, instanceToken, instance, instanceUnauthorizedRedirect }}
|
|
25
|
+
>
|
|
26
|
+
<QueryClientProvider client={reactQueryClient || ReqraftQueryClient}>
|
|
27
|
+
<ReqraftFetchProvider>
|
|
28
|
+
<ReqraftStorageProvider>{children}</ReqraftStorageProvider>
|
|
29
|
+
</ReqraftFetchProvider>
|
|
30
|
+
</QueryClientProvider>
|
|
31
|
+
</ReqraftContext.Provider>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { cloneDeep, get, set } from 'lodash';
|
|
2
|
+
import { ReactNode, useEffect, useState } from 'react';
|
|
3
|
+
import type { Get } from 'type-fest';
|
|
4
|
+
import { ReqraftStorageContext, TReqraftStorage } from '../contexts/StorageContext';
|
|
5
|
+
import { useFetch } from '../hooks/useFetch/useFetch';
|
|
6
|
+
import { useReqraftProperty } from '../hooks/useReqraftProperty';
|
|
7
|
+
import { TReqraftStorageValue } from '../hooks/useStorage/useStorage';
|
|
8
|
+
|
|
9
|
+
export interface IReqraftStorageProviderProps {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const ReqraftStorageProvider = ({ children }: IReqraftStorageProviderProps) => {
|
|
14
|
+
const appName = useReqraftProperty('appName');
|
|
15
|
+
|
|
16
|
+
const { data, loading } = useFetch({
|
|
17
|
+
url: 'users/_current_/storage',
|
|
18
|
+
cache: false,
|
|
19
|
+
loadOnMount: true,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const { load } = useFetch({
|
|
23
|
+
url: 'users/_current_/',
|
|
24
|
+
method: 'PUT',
|
|
25
|
+
cache: false,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const [storage, setStorage] = useState<TReqraftStorage>(data);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (data) {
|
|
32
|
+
setStorage(data);
|
|
33
|
+
}
|
|
34
|
+
}, [data]);
|
|
35
|
+
|
|
36
|
+
const getStorage = function <T extends TReqraftStorageValue>(
|
|
37
|
+
path: string,
|
|
38
|
+
defaultValue: T,
|
|
39
|
+
includeAppPrefix: boolean = true
|
|
40
|
+
): Get<TReqraftStorage, string> {
|
|
41
|
+
const _path = includeAppPrefix ? `${appName}.${path}` : path;
|
|
42
|
+
|
|
43
|
+
return get(storage, _path) ?? defaultValue;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const updateStorage = function <T extends TReqraftStorageValue>(
|
|
47
|
+
path: string,
|
|
48
|
+
value: T,
|
|
49
|
+
includeAppPrefix: boolean = true
|
|
50
|
+
) {
|
|
51
|
+
const _path = includeAppPrefix ? `${appName}.${path}` : path;
|
|
52
|
+
const updatedStorage = set(cloneDeep(storage), _path, value);
|
|
53
|
+
|
|
54
|
+
setStorage(updatedStorage);
|
|
55
|
+
|
|
56
|
+
load({ body: { storage: updatedStorage } });
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const removeStorageValue = function (path: string, includeAppPrefix: boolean = true) {
|
|
60
|
+
const _path = includeAppPrefix ? `${appName}.${path}` : path;
|
|
61
|
+
|
|
62
|
+
const updatedStorage = set(cloneDeep(storage), _path, null);
|
|
63
|
+
|
|
64
|
+
setStorage(updatedStorage);
|
|
65
|
+
|
|
66
|
+
load({ body: { storage_path: _path } });
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (loading || !storage) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<ReqraftStorageContext.Provider
|
|
75
|
+
value={{ storage, getStorage, updateStorage, removeStorageValue }}
|
|
76
|
+
>
|
|
77
|
+
{children}
|
|
78
|
+
</ReqraftStorageContext.Provider>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export type TFormFieldType =
|
|
2
|
+
| 'string'
|
|
3
|
+
| 'number'
|
|
4
|
+
| 'boolean'
|
|
5
|
+
| 'date'
|
|
6
|
+
| 'time'
|
|
7
|
+
| 'datetime'
|
|
8
|
+
| 'select'
|
|
9
|
+
| 'multiSelect'
|
|
10
|
+
| 'radio'
|
|
11
|
+
| 'checkbox'
|
|
12
|
+
| 'file'
|
|
13
|
+
| 'image'
|
|
14
|
+
| 'color'
|
|
15
|
+
| 'password'
|
|
16
|
+
| 'email'
|
|
17
|
+
| 'phone'
|
|
18
|
+
| 'url'
|
|
19
|
+
| 'markdown';
|
|
20
|
+
|
|
21
|
+
export type TFormFieldValueType<T> = T extends 'string'
|
|
22
|
+
? string
|
|
23
|
+
: T extends 'number'
|
|
24
|
+
? number
|
|
25
|
+
: T extends 'boolean'
|
|
26
|
+
? boolean
|
|
27
|
+
: T extends 'date'
|
|
28
|
+
? Date | string
|
|
29
|
+
: T extends 'time'
|
|
30
|
+
? Date | string
|
|
31
|
+
: T extends 'datetime'
|
|
32
|
+
? Date | string
|
|
33
|
+
: T extends 'select'
|
|
34
|
+
? string
|
|
35
|
+
: T extends 'multiSelect'
|
|
36
|
+
? string[]
|
|
37
|
+
: T extends 'radio'
|
|
38
|
+
? string
|
|
39
|
+
: T extends 'checkbox'
|
|
40
|
+
? boolean
|
|
41
|
+
: T extends 'file'
|
|
42
|
+
? File
|
|
43
|
+
: T extends 'image'
|
|
44
|
+
? string
|
|
45
|
+
: T extends 'color'
|
|
46
|
+
? string
|
|
47
|
+
: T extends 'password'
|
|
48
|
+
? string
|
|
49
|
+
: T extends 'email'
|
|
50
|
+
? string
|
|
51
|
+
: T extends 'phone'
|
|
52
|
+
? string
|
|
53
|
+
: T extends 'url'
|
|
54
|
+
? string
|
|
55
|
+
: T extends 'markdown'
|
|
56
|
+
? string
|
|
57
|
+
: any;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { ReqraftQueryClient } from '../providers/ReqraftProvider';
|
|
3
|
+
|
|
4
|
+
export interface IReqraftFetchConfig {
|
|
5
|
+
instance: string;
|
|
6
|
+
instanceToken: string;
|
|
7
|
+
unauthorizedRedirect?: (pathname: string) => string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface IReqraftFetchResponse<T> {
|
|
11
|
+
data: T;
|
|
12
|
+
ok: boolean;
|
|
13
|
+
code?: number;
|
|
14
|
+
error?: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const fetchConfig: IReqraftFetchConfig = {
|
|
18
|
+
instance: window.location.origin + '/',
|
|
19
|
+
instanceToken: '',
|
|
20
|
+
unauthorizedRedirect: (pathname: string) => `/?next=${pathname}`,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const CACHE_EXPIRATION_TIME = 5 * 60 * 1000; // 5 minutes
|
|
24
|
+
|
|
25
|
+
export const setupFetch = ({
|
|
26
|
+
instance,
|
|
27
|
+
instanceToken,
|
|
28
|
+
unauthorizedRedirect,
|
|
29
|
+
}: IReqraftFetchConfig) => {
|
|
30
|
+
fetchConfig.instance = instance;
|
|
31
|
+
fetchConfig.instanceToken = instanceToken;
|
|
32
|
+
|
|
33
|
+
if (unauthorizedRedirect) {
|
|
34
|
+
fetchConfig.unauthorizedRedirect = unauthorizedRedirect;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
async function doFetchData(
|
|
39
|
+
url: string,
|
|
40
|
+
method = 'GET',
|
|
41
|
+
body?: { [key: string]: any }
|
|
42
|
+
): Promise<Response> {
|
|
43
|
+
if (!fetchConfig.instanceToken) {
|
|
44
|
+
return new Response(JSON.stringify({}), {
|
|
45
|
+
status: 401,
|
|
46
|
+
statusText: 'Unauthorized',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return fetch(`${fetchConfig.instance}api/latest/${url}`, {
|
|
51
|
+
method,
|
|
52
|
+
headers: {
|
|
53
|
+
'Content-Type': 'application/json',
|
|
54
|
+
Authorization: `Bearer ${fetchConfig.instanceToken}`,
|
|
55
|
+
},
|
|
56
|
+
body: JSON.stringify(body),
|
|
57
|
+
}).catch((error) => {
|
|
58
|
+
return new Response(JSON.stringify({}), {
|
|
59
|
+
status: 500,
|
|
60
|
+
statusText: `Request failed ${error.message}`,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface IReqraftQueryConfig {
|
|
66
|
+
url: string;
|
|
67
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
68
|
+
body?: Record<string | number, any>;
|
|
69
|
+
cache?: boolean;
|
|
70
|
+
queryClient?: QueryClient;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function query<T>({
|
|
74
|
+
url,
|
|
75
|
+
method = 'GET',
|
|
76
|
+
body,
|
|
77
|
+
cache = true,
|
|
78
|
+
queryClient = ReqraftQueryClient,
|
|
79
|
+
}: IReqraftQueryConfig): Promise<IReqraftFetchResponse<T>> {
|
|
80
|
+
const shouldCache = method === 'DELETE' || method === 'POST' ? false : cache;
|
|
81
|
+
const cacheKey = `${url}:${method}:${JSON.stringify(body || {})}`;
|
|
82
|
+
|
|
83
|
+
const requestData = await queryClient.fetchQuery({
|
|
84
|
+
queryKey: [cacheKey],
|
|
85
|
+
queryFn: async () => {
|
|
86
|
+
const response = await doFetchData(url, method, body);
|
|
87
|
+
|
|
88
|
+
const clone = response.clone();
|
|
89
|
+
const json = await clone.json();
|
|
90
|
+
|
|
91
|
+
if (response.status === 401) {
|
|
92
|
+
window.location.href = fetchConfig.unauthorizedRedirect(window.location.pathname);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
data: json,
|
|
97
|
+
ok: response.ok,
|
|
98
|
+
status: response.status,
|
|
99
|
+
statusText: response.statusText,
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
staleTime: shouldCache ? CACHE_EXPIRATION_TIME : 0,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
if (!requestData.ok) {
|
|
106
|
+
queryClient.invalidateQueries({ queryKey: [cacheKey] });
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
data: null,
|
|
110
|
+
ok: false,
|
|
111
|
+
code: requestData.status,
|
|
112
|
+
error: requestData.statusText,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
data: requestData.data,
|
|
118
|
+
ok: true,
|
|
119
|
+
code: requestData.status,
|
|
120
|
+
};
|
|
121
|
+
}
|
package/tests.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"numFailedTestSuites":0,"numFailedTests":0,"numPassedTestSuites":0,"numPassedTests":0,"numPendingTestSuites":0,"numPendingTests":0,"numRuntimeErrorTestSuites":0,"numTodoTests":0,"numTotalTestSuites":0,"numTotalTests":0,"openHandles":[],"snapshot":{"added":0,"didUpdate":false,"failure":false,"filesAdded":0,"filesRemoved":0,"filesRemovedList":[],"filesUnmatched":0,"filesUpdated":0,"matched":0,"total":0,"unchecked":0,"uncheckedKeysByFile":[],"unmatched":0,"updated":0},"startTime":
|
|
1
|
+
{"numFailedTestSuites":0,"numFailedTests":0,"numPassedTestSuites":0,"numPassedTests":0,"numPendingTestSuites":0,"numPendingTests":0,"numRuntimeErrorTestSuites":0,"numTodoTests":0,"numTotalTestSuites":0,"numTotalTests":0,"openHandles":[],"snapshot":{"added":0,"didUpdate":false,"failure":false,"filesAdded":0,"filesRemoved":0,"filesRemovedList":[],"filesUnmatched":0,"filesUpdated":0,"matched":0,"total":0,"unchecked":0,"uncheckedKeysByFile":[],"unmatched":0,"updated":0},"startTime":1716290987363,"success":true,"testResults":[],"wasInterrupted":false}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"String.d.ts","sourceRoot":"","sources":["../../../../src/components/form/string/String.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,uDAAuD,CAAC;AACjG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAe,MAAM,OAAO,CAAC;AAEjD,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,UAAU,GAAG,OAAO,CAAC;IAC1F,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IACjC,aAAa,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;IACpD,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,YAAY,CAAC,EAAE,wBAAwB,CAAC;IACxC,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;CAC5E;AAED,eAAO,MAAM,eAAe,qFAQzB,qBAAqB,4CA0CvB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"String.js","sourceRoot":"","sources":["../../../../src/components/form/string/String.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAsF;AAItF,+BAAiD;AAY1C,IAAM,eAAe,GAAG,UAAC,EAQR;IAPtB,IAAA,QAAQ,cAAA,EACR,YAAY,kBAAA,EACZ,UAAU,gBAAA,EACV,KAAK,WAAA,EACL,qBAAqB,EAArB,aAAa,mBAAG,KAAK,KAAA,EACrB,SAAS,eAAA,EACN,IAAI,cAPuB,iFAQ/B,CADQ;IAEP,2BAA2B;IAC3B,IAAM,YAAY,GAAG,IAAA,mBAAW,EAAC,UAAC,KAAoC;;QACpE,KAAK,CAAC,OAAO,EAAE,CAAC;QAEhB,QAAQ,CAAC,MAAA,KAAK,CAAC,MAAM,CAAC,KAAK,0CAAE,QAAQ,EAAE,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,iCAAiC;IACjC,IAAM,gBAAgB,GAAG,IAAA,mBAAW,EAAC;QACnC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACf,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,wBAAC,2BAAkB,aACjB,KAAK,UACD,YAAY,IAChB,QAAQ,EAAE,aAAa,KAAK,QAAQ,IAAI,aAAa,KAAK,KAAK,aAE9D,CAAC,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,aAAa,KAAK,KAAK,IAAI,aAAa,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CACjF,uBAAC,kBAAS,aAAC,KAAK,EAAE,KAAK,EAAE,KAAK,UAAK,UAAU,EAAI,CAClD,CAAC,CAAC,CAAC,IAAI,EACR,uBAAC,oBAAW,aACV,KAAK,QACL,OAAO,EAAE,UAAC,KAAK;;oBACb,KAAK,CAAC,eAAe,EAAE,CAAC;oBACxB,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,qDAAG,KAAK,CAAC,CAAC;gBACzB,CAAC,EACD,OAAO,EAAE,UAAC,KAAK;;oBACb,KAAK,CAAC,eAAe,EAAE,CAAC;oBACxB,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,qDAAG,KAAK,CAAC,CAAC;gBACzB,CAAC,EACD,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,EACrC,YAAY,EAAE,gBAAgB,IAC1B,IAAI,EACR,EACD,CAAC,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,aAAa,KAAK,QAAQ,IAAI,aAAa,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CACrF,uBAAC,kBAAS,aAAC,KAAK,EAAE,KAAK,EAAE,KAAK,UAAK,UAAU,EAAI,CAClD,CAAC,CAAC,CAAC,IAAI,KACW,CACtB,CAAC;AACJ,CAAC,CAAC;AAlDW,QAAA,eAAe,mBAkD1B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"String.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/form/string/String.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAI5C,QAAA,MAAM,IAAI;;EAG4B,CAAC;AAEvC,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC;AACjC,eAAO,MAAM,KAAK,EAAE,KAInB,CAAC;AACF,eAAO,MAAM,SAAS,EAAE,KAIvB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"String.stories.js","sourceRoot":"","sources":["../../../../src/components/form/string/String.stories.tsx"],"names":[],"mappings":";;;AAEA,mCAA2C;AAE3C,IAAM,IAAI,GAAG;IACX,SAAS,EAAE,wBAAe;IAC1B,KAAK,EAAE,wBAAwB;CACK,CAAC;AAEvC,kBAAe,IAAI,CAAC;AAGP,QAAA,OAAO,GAAU,EAAE,CAAC;AACpB,QAAA,KAAK,GAAU;IAC1B,IAAI,EAAE;QACJ,KAAK,EAAE,eAAe;KACvB;CACF,CAAC;AACW,QAAA,SAAS,GAAU;IAC9B,IAAI,EAAE;QACJ,KAAK,EAAE,OAAO;KACf;CACF,CAAC"}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FormStringField = void 0;
|
|
4
|
-
var String_1 = require("./components/form/string/String");
|
|
5
|
-
Object.defineProperty(exports, "FormStringField", { enumerable: true, get: function () { return String_1.FormStringField; } });
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";;;AAAA,0DAAyF;AAAhF,yGAAA,eAAe,OAAA"}
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAC;AAC7F,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,MAAM,MAAM,SAAS,CACnB,SAAS,SAAS,MAAM,GAAG,CAAC,iBAAiB,GAAG,KAAK,CAAC,qBAAqB,CAAC,GAAG,CAAC,EAChF,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAClC,IAAI,CACN,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,GAC7B,cAAc,GAAG;IACf,aAAa,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;CAClD,CACJ,CAAC"}
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|