@truedat/ai 6.0.1
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/LICENSE +685 -0
- package/README.md +13 -0
- package/package.json +101 -0
- package/src/api.js +6 -0
- package/src/components/AiRoutes.js +24 -0
- package/src/components/constants.js +20 -0
- package/src/components/index.js +2 -0
- package/src/components/prompts/PromptEditor.js +365 -0
- package/src/components/prompts/Prompts.js +136 -0
- package/src/components/prompts/__tests__/Prompt.spec.js +77 -0
- package/src/components/prompts/__tests__/PromptEditor.spec.js +208 -0
- package/src/components/prompts/__tests__/__snapshots__/Prompt.spec.js.snap +77 -0
- package/src/components/prompts/__tests__/__snapshots__/PromptEditor.spec.js.snap +896 -0
- package/src/components/resourceMappings/ResourceMappingEditor.js +203 -0
- package/src/components/resourceMappings/ResourceMappingFields.js +119 -0
- package/src/components/resourceMappings/ResourceMappings.js +140 -0
- package/src/components/resourceMappings/__tests__/ResourceMappingEditor.spec.js +204 -0
- package/src/components/resourceMappings/__tests__/ResourceMappings.spec.js +79 -0
- package/src/components/resourceMappings/__tests__/__snapshots__/ResourceMappingEditor.spec.js.snap +748 -0
- package/src/components/resourceMappings/__tests__/__snapshots__/ResourceMappings.spec.js.snap +77 -0
- package/src/components/resourceMappings/selectors/DataStructureSelector.js +80 -0
- package/src/components/resourceMappings/selectors/index.js +11 -0
- package/src/hooks/__tests__/usePrompts.spec.js +101 -0
- package/src/hooks/__tests__/useResourceMappings.spec.js +101 -0
- package/src/hooks/usePrompts.js +31 -0
- package/src/hooks/useResourceMappings.js +33 -0
- package/src/index.js +3 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`<ResourceMappings /> matches the latest snapshot 1`] = `
|
|
4
|
+
<div>
|
|
5
|
+
<div
|
|
6
|
+
class="ui segment"
|
|
7
|
+
>
|
|
8
|
+
<h2
|
|
9
|
+
class="ui header"
|
|
10
|
+
>
|
|
11
|
+
<i
|
|
12
|
+
aria-hidden="true"
|
|
13
|
+
class="map signs circular icon"
|
|
14
|
+
/>
|
|
15
|
+
<div
|
|
16
|
+
class="content"
|
|
17
|
+
>
|
|
18
|
+
resourceMappings.header
|
|
19
|
+
<div
|
|
20
|
+
class="sub header"
|
|
21
|
+
>
|
|
22
|
+
resourceMappings.subheader
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
</h2>
|
|
26
|
+
<div
|
|
27
|
+
class="ui grid"
|
|
28
|
+
>
|
|
29
|
+
<div
|
|
30
|
+
class="four wide column"
|
|
31
|
+
>
|
|
32
|
+
<button
|
|
33
|
+
class="ui fluid button"
|
|
34
|
+
>
|
|
35
|
+
resourceMappings.action.new
|
|
36
|
+
</button>
|
|
37
|
+
<div
|
|
38
|
+
class="ui divided selection list"
|
|
39
|
+
role="list"
|
|
40
|
+
>
|
|
41
|
+
<div
|
|
42
|
+
class="item"
|
|
43
|
+
role="listitem"
|
|
44
|
+
>
|
|
45
|
+
<div
|
|
46
|
+
class="content"
|
|
47
|
+
>
|
|
48
|
+
<div
|
|
49
|
+
class="header"
|
|
50
|
+
>
|
|
51
|
+
rm1
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
<div
|
|
58
|
+
class="eleven wide column"
|
|
59
|
+
>
|
|
60
|
+
<h2
|
|
61
|
+
class="ui icon center aligned header"
|
|
62
|
+
>
|
|
63
|
+
<i
|
|
64
|
+
aria-hidden="true"
|
|
65
|
+
class="hand pointer outline icon"
|
|
66
|
+
/>
|
|
67
|
+
<div
|
|
68
|
+
class="sub header"
|
|
69
|
+
>
|
|
70
|
+
resourceMappings.no_selection
|
|
71
|
+
</div>
|
|
72
|
+
</h2>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
`;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useIntl } from "react-intl";
|
|
3
|
+
import { Controller, useFormContext } from "react-hook-form";
|
|
4
|
+
import { Form } from "semantic-ui-react";
|
|
5
|
+
|
|
6
|
+
export default function DataStructureSelector() {
|
|
7
|
+
const { formatMessage } = useIntl();
|
|
8
|
+
const { control } = useFormContext();
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<>
|
|
12
|
+
<Controller
|
|
13
|
+
control={control}
|
|
14
|
+
name="selector.type"
|
|
15
|
+
rules={{
|
|
16
|
+
required: formatMessage(
|
|
17
|
+
{ id: "form.validation.required" },
|
|
18
|
+
{
|
|
19
|
+
prop: formatMessage({
|
|
20
|
+
id: "resourceMappings.form.selector.data_structure.type",
|
|
21
|
+
}),
|
|
22
|
+
}
|
|
23
|
+
),
|
|
24
|
+
}}
|
|
25
|
+
render={({
|
|
26
|
+
field: { onBlur, onChange, value },
|
|
27
|
+
fieldState: { error },
|
|
28
|
+
}) => (
|
|
29
|
+
<Form.Input
|
|
30
|
+
autoComplete="off"
|
|
31
|
+
placeholder={formatMessage({
|
|
32
|
+
id: "resourceMappings.form.selector.data_structure.type",
|
|
33
|
+
})}
|
|
34
|
+
error={error?.message}
|
|
35
|
+
label={formatMessage({
|
|
36
|
+
id: "resourceMappings.form.selector.data_structure.type",
|
|
37
|
+
})}
|
|
38
|
+
onBlur={onBlur}
|
|
39
|
+
onChange={(_e, { value }) => onChange(value)}
|
|
40
|
+
value={value}
|
|
41
|
+
required
|
|
42
|
+
/>
|
|
43
|
+
)}
|
|
44
|
+
/>
|
|
45
|
+
<Controller
|
|
46
|
+
control={control}
|
|
47
|
+
name="selector.system_external_id"
|
|
48
|
+
rules={{
|
|
49
|
+
required: formatMessage(
|
|
50
|
+
{ id: "form.validation.required" },
|
|
51
|
+
{
|
|
52
|
+
prop: formatMessage({
|
|
53
|
+
id: "resourceMappings.form.selector.data_structure.system_external_id",
|
|
54
|
+
}),
|
|
55
|
+
}
|
|
56
|
+
),
|
|
57
|
+
}}
|
|
58
|
+
render={({
|
|
59
|
+
field: { onBlur, onChange, value },
|
|
60
|
+
fieldState: { error },
|
|
61
|
+
}) => (
|
|
62
|
+
<Form.Input
|
|
63
|
+
autoComplete="off"
|
|
64
|
+
placeholder={formatMessage({
|
|
65
|
+
id: "resourceMappings.form.selector.data_structure.system_external_id",
|
|
66
|
+
})}
|
|
67
|
+
error={error?.message}
|
|
68
|
+
label={formatMessage({
|
|
69
|
+
id: "resourceMappings.form.selector.data_structure.system_external_id",
|
|
70
|
+
})}
|
|
71
|
+
onBlur={onBlur}
|
|
72
|
+
onChange={(_e, { value }) => onChange(value)}
|
|
73
|
+
value={value}
|
|
74
|
+
required
|
|
75
|
+
/>
|
|
76
|
+
)}
|
|
77
|
+
/>
|
|
78
|
+
</>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import DataStructureSelector from "./DataStructureSelector";
|
|
3
|
+
|
|
4
|
+
export function selectorFor(resourceType) {
|
|
5
|
+
switch (resourceType) {
|
|
6
|
+
case "data_structure":
|
|
7
|
+
return <DataStructureSelector />;
|
|
8
|
+
default:
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
import { compile } from "path-to-regexp";
|
|
3
|
+
import useSWR from "swr";
|
|
4
|
+
import useSWRMutations from "swr/mutation";
|
|
5
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
6
|
+
import {
|
|
7
|
+
apiJson,
|
|
8
|
+
apiJsonPost,
|
|
9
|
+
apiJsonPatch,
|
|
10
|
+
apiJsonDelete,
|
|
11
|
+
} from "@truedat/core/services/api";
|
|
12
|
+
import { API_PROMPTS, API_PROMPT } from "../../api";
|
|
13
|
+
import {
|
|
14
|
+
usePrompts,
|
|
15
|
+
usePromptCreate,
|
|
16
|
+
usePromptUpdate,
|
|
17
|
+
usePromptDelete,
|
|
18
|
+
} from "../usePrompts";
|
|
19
|
+
|
|
20
|
+
jest.mock("swr", () => ({
|
|
21
|
+
__esModule: true,
|
|
22
|
+
...jest.requireActual("swr"),
|
|
23
|
+
default: jest.fn(() => ({
|
|
24
|
+
data: { data: "data" },
|
|
25
|
+
error: null,
|
|
26
|
+
mutate: jest.fn(),
|
|
27
|
+
})),
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
jest.mock("swr/mutation", () => ({
|
|
31
|
+
__esModule: true,
|
|
32
|
+
...jest.requireActual("swr/mutation"),
|
|
33
|
+
default: jest.fn(),
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
jest.mock("@truedat/core/services/api", () => ({
|
|
37
|
+
__esModule: true,
|
|
38
|
+
...jest.requireActual("@truedat/core/services/api"),
|
|
39
|
+
apiJsonPost: jest.fn(),
|
|
40
|
+
apiJsonPatch: jest.fn(),
|
|
41
|
+
apiJsonDelete: jest.fn(),
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
describe("usePrompts", () => {
|
|
45
|
+
it("usePrompts calls useSWR with correct api route", () => {
|
|
46
|
+
const { result } = renderHook(() => usePrompts());
|
|
47
|
+
|
|
48
|
+
expect(result.current).toMatchObject({
|
|
49
|
+
data: "data",
|
|
50
|
+
error: null,
|
|
51
|
+
loading: false,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
expect(useSWR).toHaveBeenCalledWith(API_PROMPTS, apiJson);
|
|
55
|
+
});
|
|
56
|
+
it("usePromptCreate calls useSWRMutations with correct api route", () => {
|
|
57
|
+
renderHook(() => usePromptCreate());
|
|
58
|
+
const [url, func] = _.last(useSWRMutations.mock.calls);
|
|
59
|
+
const arg = { some: "arg" };
|
|
60
|
+
expect(url).toBe(API_PROMPTS);
|
|
61
|
+
func(url, { arg });
|
|
62
|
+
|
|
63
|
+
expect(apiJsonPost).toHaveBeenCalledWith(url, arg);
|
|
64
|
+
});
|
|
65
|
+
it("usePromptUpdate calls useSWRMutations with correct api route", () => {
|
|
66
|
+
const id = 8;
|
|
67
|
+
renderHook(() => usePromptUpdate({ id }));
|
|
68
|
+
const [url, func] = _.last(useSWRMutations.mock.calls);
|
|
69
|
+
const arg = { some: "arg" };
|
|
70
|
+
expect(url).toBe(compile(API_PROMPT)({ id }));
|
|
71
|
+
func(url, { arg });
|
|
72
|
+
|
|
73
|
+
expect(apiJsonPatch).toHaveBeenCalledWith(url, arg);
|
|
74
|
+
});
|
|
75
|
+
it("usePromptUpdate without args will render id 0", () => {
|
|
76
|
+
renderHook(() => usePromptUpdate());
|
|
77
|
+
const [url, func] = _.last(useSWRMutations.mock.calls);
|
|
78
|
+
const arg = { some: "arg" };
|
|
79
|
+
expect(url).toBe(compile(API_PROMPT)({ id: 0 }));
|
|
80
|
+
func(url, { arg });
|
|
81
|
+
expect(apiJsonPatch).toHaveBeenCalledWith(url, arg);
|
|
82
|
+
});
|
|
83
|
+
it("usePromptDelete calls useSWRMutations with correct api route", () => {
|
|
84
|
+
const id = 8;
|
|
85
|
+
renderHook(() => usePromptDelete({ id }));
|
|
86
|
+
const [url, func] = _.last(useSWRMutations.mock.calls);
|
|
87
|
+
const arg = { some: "arg" };
|
|
88
|
+
expect(url).toBe(compile(API_PROMPT)({ id }));
|
|
89
|
+
func(url, { arg });
|
|
90
|
+
|
|
91
|
+
expect(apiJsonDelete).toHaveBeenCalledWith(url, arg);
|
|
92
|
+
});
|
|
93
|
+
it("usePromptDelete without args will render id 0", () => {
|
|
94
|
+
renderHook(() => usePromptDelete());
|
|
95
|
+
const [url, func] = _.last(useSWRMutations.mock.calls);
|
|
96
|
+
const arg = { some: "arg" };
|
|
97
|
+
expect(url).toBe(compile(API_PROMPT)({ id: 0 }));
|
|
98
|
+
func(url, { arg });
|
|
99
|
+
expect(apiJsonDelete).toHaveBeenCalledWith(url, arg);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
import { compile } from "path-to-regexp";
|
|
3
|
+
import useSWR from "swr";
|
|
4
|
+
import useSWRMutations from "swr/mutation";
|
|
5
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
6
|
+
import {
|
|
7
|
+
apiJson,
|
|
8
|
+
apiJsonPost,
|
|
9
|
+
apiJsonPatch,
|
|
10
|
+
apiJsonDelete,
|
|
11
|
+
} from "@truedat/core/services/api";
|
|
12
|
+
import { API_RESOURCE_MAPPINGS, API_RESOURCE_MAPPING } from "../../api";
|
|
13
|
+
import {
|
|
14
|
+
useResourceMappings,
|
|
15
|
+
useResourceMappingCreate,
|
|
16
|
+
useResourceMappingUpdate,
|
|
17
|
+
useResourceMappingDelete,
|
|
18
|
+
} from "../useResourceMappings";
|
|
19
|
+
|
|
20
|
+
jest.mock("swr", () => ({
|
|
21
|
+
__esModule: true,
|
|
22
|
+
...jest.requireActual("swr"),
|
|
23
|
+
default: jest.fn(() => ({
|
|
24
|
+
data: { data: "data" },
|
|
25
|
+
error: null,
|
|
26
|
+
mutate: jest.fn(),
|
|
27
|
+
})),
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
jest.mock("swr/mutation", () => ({
|
|
31
|
+
__esModule: true,
|
|
32
|
+
...jest.requireActual("swr/mutation"),
|
|
33
|
+
default: jest.fn(),
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
jest.mock("@truedat/core/services/api", () => ({
|
|
37
|
+
__esModule: true,
|
|
38
|
+
...jest.requireActual("@truedat/core/services/api"),
|
|
39
|
+
apiJsonPost: jest.fn(),
|
|
40
|
+
apiJsonPatch: jest.fn(),
|
|
41
|
+
apiJsonDelete: jest.fn(),
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
describe("useResourceMappings", () => {
|
|
45
|
+
it("useResourceMappings calls useSWR with correct api route", () => {
|
|
46
|
+
const { result } = renderHook(() => useResourceMappings());
|
|
47
|
+
|
|
48
|
+
expect(result.current).toMatchObject({
|
|
49
|
+
data: "data",
|
|
50
|
+
error: null,
|
|
51
|
+
loading: false,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
expect(useSWR).toHaveBeenCalledWith(API_RESOURCE_MAPPINGS, apiJson);
|
|
55
|
+
});
|
|
56
|
+
it("useResourceMappingCreate calls useSWRMutations with correct api route", () => {
|
|
57
|
+
renderHook(() => useResourceMappingCreate());
|
|
58
|
+
const [url, func] = _.last(useSWRMutations.mock.calls);
|
|
59
|
+
const arg = { some: "arg" };
|
|
60
|
+
expect(url).toBe(API_RESOURCE_MAPPINGS);
|
|
61
|
+
func(url, { arg });
|
|
62
|
+
|
|
63
|
+
expect(apiJsonPost).toHaveBeenCalledWith(url, arg);
|
|
64
|
+
});
|
|
65
|
+
it("useResourceMappingUpdate calls useSWRMutations with correct api route", () => {
|
|
66
|
+
const id = 8;
|
|
67
|
+
renderHook(() => useResourceMappingUpdate({ id }));
|
|
68
|
+
const [url, func] = _.last(useSWRMutations.mock.calls);
|
|
69
|
+
const arg = { some: "arg" };
|
|
70
|
+
expect(url).toBe(compile(API_RESOURCE_MAPPING)({ id }));
|
|
71
|
+
func(url, { arg });
|
|
72
|
+
|
|
73
|
+
expect(apiJsonPatch).toHaveBeenCalledWith(url, arg);
|
|
74
|
+
});
|
|
75
|
+
it("useResourceMappingUpdate without args will render id 0", () => {
|
|
76
|
+
renderHook(() => useResourceMappingUpdate());
|
|
77
|
+
const [url, func] = _.last(useSWRMutations.mock.calls);
|
|
78
|
+
const arg = { some: "arg" };
|
|
79
|
+
expect(url).toBe(compile(API_RESOURCE_MAPPING)({ id: 0 }));
|
|
80
|
+
func(url, { arg });
|
|
81
|
+
expect(apiJsonPatch).toHaveBeenCalledWith(url, arg);
|
|
82
|
+
});
|
|
83
|
+
it("useResourceMappingDelete calls useSWRMutations with correct api route", () => {
|
|
84
|
+
const id = 8;
|
|
85
|
+
renderHook(() => useResourceMappingDelete({ id }));
|
|
86
|
+
const [url, func] = _.last(useSWRMutations.mock.calls);
|
|
87
|
+
const arg = { some: "arg" };
|
|
88
|
+
expect(url).toBe(compile(API_RESOURCE_MAPPING)({ id }));
|
|
89
|
+
func(url, { arg });
|
|
90
|
+
|
|
91
|
+
expect(apiJsonDelete).toHaveBeenCalledWith(url, arg);
|
|
92
|
+
});
|
|
93
|
+
it("useResourceMappingDelete without args will render id 0", () => {
|
|
94
|
+
renderHook(() => useResourceMappingDelete());
|
|
95
|
+
const [url, func] = _.last(useSWRMutations.mock.calls);
|
|
96
|
+
const arg = { some: "arg" };
|
|
97
|
+
expect(url).toBe(compile(API_RESOURCE_MAPPING)({ id: 0 }));
|
|
98
|
+
func(url, { arg });
|
|
99
|
+
expect(apiJsonDelete).toHaveBeenCalledWith(url, arg);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { compile } from "path-to-regexp";
|
|
2
|
+
import useSWR from "swr";
|
|
3
|
+
import useSWRMutations from "swr/mutation";
|
|
4
|
+
import {
|
|
5
|
+
apiJson,
|
|
6
|
+
apiJsonPost,
|
|
7
|
+
apiJsonPatch,
|
|
8
|
+
apiJsonDelete,
|
|
9
|
+
} from "@truedat/core/services/api";
|
|
10
|
+
import { API_PROMPTS, API_PROMPT } from "../api";
|
|
11
|
+
|
|
12
|
+
export const usePrompts = () => {
|
|
13
|
+
const { data, error, mutate } = useSWR(API_PROMPTS, apiJson);
|
|
14
|
+
return { data: data?.data, error, loading: !error && !data, mutate };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const usePromptCreate = () => {
|
|
18
|
+
return useSWRMutations(API_PROMPTS, (url, { arg }) => apiJsonPost(url, arg));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const usePromptUpdate = (func) => {
|
|
22
|
+
const id = func?.id || 0;
|
|
23
|
+
const url = compile(API_PROMPT)({ id });
|
|
24
|
+
return useSWRMutations(url, (url, { arg }) => apiJsonPatch(url, arg));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const usePromptDelete = (func) => {
|
|
28
|
+
const id = func?.id || 0;
|
|
29
|
+
const url = compile(API_PROMPT)({ id });
|
|
30
|
+
return useSWRMutations(url, (url, { arg }) => apiJsonDelete(url, arg));
|
|
31
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { compile } from "path-to-regexp";
|
|
2
|
+
import useSWR from "swr";
|
|
3
|
+
import useSWRMutations from "swr/mutation";
|
|
4
|
+
import {
|
|
5
|
+
apiJson,
|
|
6
|
+
apiJsonPost,
|
|
7
|
+
apiJsonPatch,
|
|
8
|
+
apiJsonDelete,
|
|
9
|
+
} from "@truedat/core/services/api";
|
|
10
|
+
import { API_RESOURCE_MAPPINGS, API_RESOURCE_MAPPING } from "../api";
|
|
11
|
+
|
|
12
|
+
export const useResourceMappings = () => {
|
|
13
|
+
const { data, error, mutate } = useSWR(API_RESOURCE_MAPPINGS, apiJson);
|
|
14
|
+
return { data: data?.data, error, loading: !error && !data, mutate };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const useResourceMappingCreate = () => {
|
|
18
|
+
return useSWRMutations(API_RESOURCE_MAPPINGS, (url, { arg }) =>
|
|
19
|
+
apiJsonPost(url, arg)
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const useResourceMappingUpdate = (func) => {
|
|
24
|
+
const id = func?.id || 0;
|
|
25
|
+
const url = compile(API_RESOURCE_MAPPING)({ id });
|
|
26
|
+
return useSWRMutations(url, (url, { arg }) => apiJsonPatch(url, arg));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const useResourceMappingDelete = (func) => {
|
|
30
|
+
const id = func?.id || 0;
|
|
31
|
+
const url = compile(API_RESOURCE_MAPPING)({ id });
|
|
32
|
+
return useSWRMutations(url, (url, { arg }) => apiJsonDelete(url, arg));
|
|
33
|
+
};
|
package/src/index.js
ADDED