@truedat/ai 6.11.0 → 6.12.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.
Files changed (33) hide show
  1. package/package.json +3 -3
  2. package/src/api.js +8 -0
  3. package/src/components/AiRoutes.js +26 -0
  4. package/src/components/actions/Action.js +90 -0
  5. package/src/components/actions/ActionActions.js +134 -0
  6. package/src/components/actions/ActionBreadcrumbs.js +22 -0
  7. package/src/components/actions/ActionDetail.js +41 -0
  8. package/src/components/actions/ActionEdit.js +70 -0
  9. package/src/components/actions/ActionForm.js +168 -0
  10. package/src/components/actions/ActionNew.js +50 -0
  11. package/src/components/actions/Actions.js +61 -0
  12. package/src/components/actions/ActionsContext.js +52 -0
  13. package/src/components/actions/ActionsTable.js +124 -0
  14. package/src/components/actions/__tests__/Action.spec.js +59 -0
  15. package/src/components/actions/__tests__/ActionActions.spec.js +47 -0
  16. package/src/components/actions/__tests__/ActionBreadcrumbs.spec.js +21 -0
  17. package/src/components/actions/__tests__/ActionDetail.spec.js +106 -0
  18. package/src/components/actions/__tests__/ActionEdit.spec.js +133 -0
  19. package/src/components/actions/__tests__/ActionForm.spec.js +146 -0
  20. package/src/components/actions/__tests__/ActionNew.spec.js +113 -0
  21. package/src/components/actions/__tests__/Actions.spec.js +21 -0
  22. package/src/components/actions/__tests__/ActionsTable.spec.js +72 -0
  23. package/src/components/actions/__tests__/__snapshots__/Action.spec.js.snap +159 -0
  24. package/src/components/actions/__tests__/__snapshots__/ActionActions.spec.js.snap +57 -0
  25. package/src/components/actions/__tests__/__snapshots__/ActionBreadcrumbs.spec.js.snap +25 -0
  26. package/src/components/actions/__tests__/__snapshots__/ActionDetail.spec.js.snap +46 -0
  27. package/src/components/actions/__tests__/__snapshots__/ActionEdit.spec.js.snap +316 -0
  28. package/src/components/actions/__tests__/__snapshots__/ActionForm.spec.js.snap +326 -0
  29. package/src/components/actions/__tests__/__snapshots__/ActionNew.spec.js.snap +518 -0
  30. package/src/components/actions/__tests__/__snapshots__/Actions.spec.js.snap +63 -0
  31. package/src/components/actions/__tests__/__snapshots__/ActionsTable.spec.js.snap +121 -0
  32. package/src/hooks/useActions.js +63 -0
  33. package/src/styles/aiActionEdit.less +19 -0
@@ -0,0 +1,146 @@
1
+ import React, { Suspense } from "react";
2
+ import { waitFor } from "@testing-library/react";
3
+ import { render } from "@truedat/test/render";
4
+ import { TEMPLATES_QUERY } from "@truedat/core/api/queries";
5
+ import ActionForm from "../ActionForm";
6
+
7
+ jest.mock("@truedat/auth/hooks/useUsers", () => ({
8
+ useAgents: jest.fn(() => ({
9
+ agents: [
10
+ { id: 1, full_name: "Agent 1" },
11
+ { id: 2, full_name: "Agent 2" },
12
+ ],
13
+ })),
14
+ }));
15
+
16
+ const template = {
17
+ __typename: "Template",
18
+ content: [
19
+ {
20
+ fields: [
21
+ {
22
+ cardinality: "1",
23
+ default: {
24
+ origin: "default",
25
+ value: "",
26
+ },
27
+ label: "Field Label",
28
+ name: "field_name",
29
+ type: "string",
30
+ values: {
31
+ fixed_tuple: [
32
+ {
33
+ text: "Value One",
34
+ value: "value_one",
35
+ },
36
+ ],
37
+ },
38
+ widget: "dropdown",
39
+ },
40
+ ],
41
+ name: "",
42
+ },
43
+ ],
44
+ id: "1",
45
+ label: "template_label",
46
+ name: "Template Name",
47
+ scope: "actions",
48
+ };
49
+
50
+ const templatesMock = {
51
+ request: {
52
+ query: TEMPLATES_QUERY,
53
+ variables: { scope: "actions", domainIds: null },
54
+ },
55
+ result: { data: { templates: [template] } },
56
+ };
57
+
58
+ const renderOpts = {
59
+ messages: {
60
+ en: {
61
+ "ai.actions.actions.form.name": "Name",
62
+ "ai.actions.actions.form.resource_type": "Resource Type",
63
+ "ai.actions.actions.form.user": "user",
64
+ "fields.dropdown.placeholder": "Select One...",
65
+ loading: "Loading",
66
+ "selector.no.selection": "No Selection",
67
+ "template.form.validation.empty_required": "Required Field",
68
+ "template.selector.label": "Template",
69
+ "actions.cancel": "Cancel",
70
+ "actions.create": "Create",
71
+ "actions.update": "Update",
72
+ },
73
+ },
74
+ mocks: [templatesMock],
75
+ };
76
+
77
+ describe("<ActionForm />", () => {
78
+ it("matches the latest snapshot when is creating", async () => {
79
+ const props = {
80
+ isEnabled: true,
81
+ onSubmit: jest.fn(),
82
+ };
83
+ const { container } = render(
84
+ <Suspense fallback={null}>
85
+ <ActionForm {...props} />
86
+ </Suspense>,
87
+ renderOpts
88
+ );
89
+
90
+ await waitFor(() => expect(container).toMatchSnapshot());
91
+ });
92
+
93
+ it("create button disable if has empty data", async () => {
94
+ const props = {
95
+ isEnabled: true,
96
+ onSubmit: jest.fn(),
97
+ };
98
+ const { getByRole } = render(
99
+ <Suspense fallback={null}>
100
+ <ActionForm {...props} />
101
+ </Suspense>,
102
+ renderOpts
103
+ );
104
+
105
+ expect(getByRole("button", { name: /create/i })).not.toBeEnabled();
106
+ });
107
+
108
+ it("matches the latest snapshot when is editing", async () => {
109
+ const action = {
110
+ deleted_at: null,
111
+ dynamic_content: {
112
+ field_name: {
113
+ origin: "user",
114
+ value: "value_one",
115
+ },
116
+ },
117
+ id: 123,
118
+ is_enabled: true,
119
+ name: "Action Name",
120
+ type: "Template Name",
121
+ updated_at: "2024-10-01T00:00:00.000000Z",
122
+ user: {
123
+ full_name: "Agent 1",
124
+ id: 1,
125
+ },
126
+ user_id: 1,
127
+ };
128
+
129
+ const props = {
130
+ action,
131
+ template,
132
+ isEnabled: true,
133
+ onSubmit: jest.fn(),
134
+ };
135
+ const { container, queryByText } = render(
136
+ <Suspense fallback={null}>
137
+ <ActionForm {...props} />
138
+ </Suspense>,
139
+ renderOpts
140
+ );
141
+ await waitFor(() =>
142
+ expect(queryByText(/Loading/i)).not.toBeInTheDocument()
143
+ );
144
+ await waitFor(() => expect(container).toMatchSnapshot());
145
+ });
146
+ });
@@ -0,0 +1,113 @@
1
+ import React from "react";
2
+ import { waitFor } from "@testing-library/react";
3
+ import { render } from "@truedat/test/render";
4
+ import { TEMPLATES_QUERY } from "@truedat/core/api/queries";
5
+ import ActionNew from "../ActionNew";
6
+
7
+ jest.mock("@truedat/auth/hooks/useUsers", () => ({
8
+ useAgents: jest.fn(() => ({
9
+ agents: [
10
+ { id: 1, full_name: "Agent 1" },
11
+ { id: 2, full_name: "Agent 2" },
12
+ ],
13
+ })),
14
+ }));
15
+
16
+ const template = {
17
+ __typename: "Template",
18
+ content: [
19
+ {
20
+ fields: [
21
+ {
22
+ cardinality: "1",
23
+ default: {
24
+ origin: "default",
25
+ value: "",
26
+ },
27
+ label: "Field Label",
28
+ name: "field_name",
29
+ type: "string",
30
+ values: {
31
+ fixed_tuple: [
32
+ {
33
+ text: "Value One",
34
+ value: "value_one",
35
+ },
36
+ ],
37
+ },
38
+ widget: "dropdown",
39
+ },
40
+ ],
41
+ name: "",
42
+ },
43
+ ],
44
+ id: "1",
45
+ label: "template_label",
46
+ name: "Template Name",
47
+ scope: "actions",
48
+ };
49
+
50
+ const templatesMock = {
51
+ request: {
52
+ query: TEMPLATES_QUERY,
53
+ variables: { scope: "actions", domainIds: null },
54
+ },
55
+ result: { data: { templates: [template] } },
56
+ };
57
+
58
+ const renderOpts = {
59
+ messages: {
60
+ en: {
61
+ "actions.cancel": "Cancel",
62
+ "actions.create": "Create",
63
+ "ai.actions.actions.create": "New Action",
64
+ "ai.actions.actions.form.active": "Active",
65
+ "ai.actions.actions.form.name": "Name",
66
+ "ai.actions.actions.form.user": "Agent",
67
+ "fields.dropdown.placeholder": "Select One...",
68
+ loading: "Loading",
69
+ "navigation.admin.actions": "Actions",
70
+ "selector.no.selection": "No Selection",
71
+ "template.form.validation.empty_required": "Can't be empty",
72
+ "template.selector.label": "Template",
73
+ },
74
+ },
75
+ mocks: [templatesMock],
76
+ fallback: "lazy",
77
+ };
78
+
79
+ describe("<ActionNew />", () => {
80
+ const setActionResource = jest.fn();
81
+ const props = {
82
+ setActionResource,
83
+ };
84
+ it("matches the latest snapshot", async () => {
85
+ const { queryByText, container } = render(
86
+ <ActionNew {...props} />,
87
+ renderOpts
88
+ );
89
+
90
+ await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
91
+ expect(container).toMatchSnapshot();
92
+ });
93
+
94
+ it("matches the latest snapshot", async () => {
95
+ const { queryByText, container } = render(
96
+ <ActionNew {...props} />,
97
+ renderOpts
98
+ );
99
+
100
+ await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
101
+ expect(container).toMatchSnapshot();
102
+ });
103
+
104
+ it("create button is disable", async () => {
105
+ const props = {
106
+ isEnabled: true,
107
+ onSubmit: jest.fn(),
108
+ };
109
+ const { getByRole } = render(<ActionNew {...props} />, renderOpts);
110
+
111
+ expect(getByRole("button", { name: /create/i })).not.toBeEnabled();
112
+ });
113
+ });
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ import { render } from "@truedat/test/render";
3
+ import Actions from "../Actions";
4
+
5
+ const renderOpts = {
6
+ messages: {
7
+ en: {
8
+ "ai.actions.search.results.empty": "Empty",
9
+ "ai.actions.actions.create": "Create",
10
+ "ai.actions.subheader": "AI actions",
11
+ "ai.actions.header": "AI actions",
12
+ },
13
+ },
14
+ };
15
+
16
+ describe("<Actions />", () => {
17
+ it("matches the latest snapshot", () => {
18
+ const { container } = render(<Actions />, renderOpts);
19
+ expect(container).toMatchSnapshot();
20
+ });
21
+ });
@@ -0,0 +1,72 @@
1
+ import React from "react";
2
+ import { render } from "@truedat/test/render";
3
+ import { ActionsContextProvider } from "../ActionsContext";
4
+ import { ActionsTable } from "../ActionsTable";
5
+
6
+ const data = {
7
+ data: [
8
+ {
9
+ id: 1,
10
+ name: "action_1",
11
+ type: "bar",
12
+ is_enabled: true,
13
+ user: { full_name: "agent 1" },
14
+ updated_at: "2020-01-01T00:00:00.000Z",
15
+ },
16
+ {
17
+ id: 2,
18
+ name: "action_2",
19
+ type: "foo",
20
+ is_enabled: false,
21
+ user: { full_name: "agent 2" },
22
+ updated_at: "2020-01-01T00:00:00.000Z",
23
+ },
24
+ ],
25
+ };
26
+
27
+ const useSearch = () => ({
28
+ trigger: () => ({
29
+ then: (callback) =>
30
+ callback({
31
+ data,
32
+ headers: {},
33
+ }),
34
+ }),
35
+ loading: false,
36
+ });
37
+
38
+ const searchProps = {
39
+ initialSortColumn: "updated_at",
40
+ initialSortDirection: "descending",
41
+ useSearch: useSearch,
42
+ };
43
+
44
+ const renderOpts = {
45
+ messages: {
46
+ en: {
47
+ "ai.actions.search.results.empty": "Empty",
48
+ "ai.actions.actions.create": "Create",
49
+ "ai.actions.subheader": "AI actions",
50
+ "ai.actions.header": "AI actions",
51
+ "ai.actions.resource_type.structures": "structures",
52
+ "ai.actions.is_enabled.true": "enabled",
53
+ "ai.actions.is_enabled.false": "disabled",
54
+ "ai.actions.form.user.full_name": "Agent",
55
+ "ai.actions.form.is_enabled": "status",
56
+ "ai.actions.form.name": "name",
57
+ "ai.actions.form.type": "Type",
58
+ },
59
+ },
60
+ };
61
+
62
+ describe("<ActionsTable />", () => {
63
+ it("matches the latest snapshot", () => {
64
+ const { container } = render(
65
+ <ActionsContextProvider {...searchProps}>
66
+ <ActionsTable />
67
+ </ActionsContextProvider>,
68
+ renderOpts
69
+ );
70
+ expect(container).toMatchSnapshot();
71
+ });
72
+ });
@@ -0,0 +1,159 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<Action /> matches the latest snapshot 1`] = `
4
+ <div>
5
+ <div
6
+ class="ui breadcrumb"
7
+ style="display: none;"
8
+ >
9
+ <a
10
+ class="section"
11
+ href="/actions"
12
+ >
13
+ Actions
14
+ </a>
15
+ <i
16
+ aria-hidden="true"
17
+ class="right angle icon divider"
18
+ />
19
+ <div
20
+ class="active section"
21
+ >
22
+ foo
23
+ </div>
24
+ </div>
25
+ <div
26
+ class="ui segment"
27
+ style="display: none;"
28
+ >
29
+ <div
30
+ class="ui grid"
31
+ >
32
+ <div
33
+ class="eight wide column"
34
+ >
35
+ <h2
36
+ class="ui header"
37
+ >
38
+ <i
39
+ aria-hidden="true"
40
+ class="caret square right circular icon"
41
+ />
42
+ <div
43
+ class="content"
44
+ >
45
+ foo
46
+ <div
47
+ class="sub header"
48
+ >
49
+ <p>
50
+ <i
51
+ aria-hidden="true"
52
+ class="green play fitted icon"
53
+ />
54
+
55
+ Active
56
+ </p>
57
+ </div>
58
+ </div>
59
+ </h2>
60
+ </div>
61
+ <div
62
+ class="right aligned eight wide column"
63
+ >
64
+ <div
65
+ aria-expanded="false"
66
+ class="ui floating dropdown button icon group-actions"
67
+ role="listbox"
68
+ tabindex="0"
69
+ >
70
+ <i
71
+ aria-hidden="true"
72
+ class="ellipsis vertical icon"
73
+ />
74
+ <div
75
+ class="left menu transition"
76
+ >
77
+ <a
78
+ aria-checked="false"
79
+ aria-selected="true"
80
+ class="selected item"
81
+ href="/actions/3/edit"
82
+ role="option"
83
+ style="pointer-events: all;"
84
+ >
85
+ <i
86
+ aria-hidden="true"
87
+ class="edit icon"
88
+ />
89
+ <span
90
+ class="text"
91
+ >
92
+ Edit
93
+ </span>
94
+ </a>
95
+ <button
96
+ class="ui button"
97
+ >
98
+ <i
99
+ aria-hidden="true"
100
+ class="pause icon"
101
+ />
102
+ Disable
103
+ </button>
104
+ <button
105
+ class="ui button"
106
+ >
107
+ <i
108
+ aria-hidden="true"
109
+ class="trash icon"
110
+ />
111
+ Delete
112
+ </button>
113
+ </div>
114
+ </div>
115
+ </div>
116
+ </div>
117
+ <div
118
+ class="ui bottom attached segment"
119
+ >
120
+ <div
121
+ class="ui big relaxed list"
122
+ role="list"
123
+ >
124
+ <div
125
+ class="item"
126
+ role="listitem"
127
+ >
128
+ <div
129
+ class="header dynamic-field-header"
130
+ >
131
+ Agent
132
+ </div>
133
+ <div
134
+ class="content"
135
+ >
136
+ agent
137
+ </div>
138
+ </div>
139
+ <div
140
+ class="item"
141
+ role="listitem"
142
+ >
143
+ <div
144
+ class="header dynamic-field-header"
145
+ >
146
+ Type
147
+ </div>
148
+ <div
149
+ class="content"
150
+ >
151
+ baz
152
+ </div>
153
+ </div>
154
+ </div>
155
+ </div>
156
+ </div>
157
+ lazy
158
+ </div>
159
+ `;
@@ -0,0 +1,57 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<ActionActions /> matches the latest snapshot 1`] = `
4
+ <div>
5
+ <div
6
+ aria-expanded="false"
7
+ class="ui floating dropdown button icon group-actions"
8
+ role="listbox"
9
+ tabindex="0"
10
+ >
11
+ <i
12
+ aria-hidden="true"
13
+ class="ellipsis vertical icon"
14
+ />
15
+ <div
16
+ class="left menu transition"
17
+ >
18
+ <a
19
+ aria-checked="false"
20
+ aria-selected="true"
21
+ class="selected item"
22
+ href="/actions/3/edit"
23
+ role="option"
24
+ style="pointer-events: all;"
25
+ >
26
+ <i
27
+ aria-hidden="true"
28
+ class="edit icon"
29
+ />
30
+ <span
31
+ class="text"
32
+ >
33
+ Edit
34
+ </span>
35
+ </a>
36
+ <button
37
+ class="ui button"
38
+ >
39
+ <i
40
+ aria-hidden="true"
41
+ class="pause icon"
42
+ />
43
+ Disable
44
+ </button>
45
+ <button
46
+ class="ui button"
47
+ >
48
+ <i
49
+ aria-hidden="true"
50
+ class="trash icon"
51
+ />
52
+ Delete
53
+ </button>
54
+ </div>
55
+ </div>
56
+ </div>
57
+ `;
@@ -0,0 +1,25 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<ActionBreadcrumbs /> matches the latest snapshot 1`] = `
4
+ <div>
5
+ <div
6
+ class="ui breadcrumb"
7
+ >
8
+ <a
9
+ class="section"
10
+ href="/actions"
11
+ >
12
+ Actions
13
+ </a>
14
+ <i
15
+ aria-hidden="true"
16
+ class="right angle icon divider"
17
+ />
18
+ <div
19
+ class="active section"
20
+ >
21
+ edit
22
+ </div>
23
+ </div>
24
+ </div>
25
+ `;
@@ -0,0 +1,46 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<ActionDetail /> matches the latest snapshot 1`] = `
4
+ <div>
5
+ <div
6
+ class="ui bottom attached segment"
7
+ style="display: none;"
8
+ >
9
+ <div
10
+ class="ui big relaxed list"
11
+ role="list"
12
+ >
13
+ <div
14
+ class="item"
15
+ role="listitem"
16
+ >
17
+ <div
18
+ class="header dynamic-field-header"
19
+ >
20
+ Agent
21
+ </div>
22
+ <div
23
+ class="content"
24
+ >
25
+ agent
26
+ </div>
27
+ </div>
28
+ <div
29
+ class="item"
30
+ role="listitem"
31
+ >
32
+ <div
33
+ class="header dynamic-field-header"
34
+ >
35
+ Type
36
+ </div>
37
+ <div
38
+ class="content"
39
+ >
40
+ baz
41
+ </div>
42
+ </div>
43
+ </div>
44
+ </div>
45
+ </div>
46
+ `;