@truedat/ai 7.5.9 → 7.5.11

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 (69) hide show
  1. package/package.json +39 -59
  2. package/src/components/AiRoutes.js +39 -46
  3. package/src/components/TranslationModal.js +8 -10
  4. package/src/components/__tests__/TranslationModal.spec.js +0 -1
  5. package/src/components/actions/Action.js +1 -2
  6. package/src/components/actions/ActionActions.js +4 -5
  7. package/src/components/actions/ActionBreadcrumbs.js +1 -2
  8. package/src/components/actions/ActionDetail.js +4 -3
  9. package/src/components/actions/ActionEdit.js +3 -3
  10. package/src/components/actions/ActionForm.js +7 -7
  11. package/src/components/actions/ActionNew.js +1 -1
  12. package/src/components/actions/Actions.js +1 -2
  13. package/src/components/actions/ActionsContext.js +3 -7
  14. package/src/components/actions/ActionsTable.js +1 -2
  15. package/src/components/actions/__tests__/Action.spec.js +14 -36
  16. package/src/components/actions/__tests__/ActionActions.spec.js +2 -20
  17. package/src/components/actions/__tests__/ActionBreadcrumbs.spec.js +1 -10
  18. package/src/components/actions/__tests__/ActionDetail.spec.js +5 -23
  19. package/src/components/actions/__tests__/ActionEdit.spec.js +7 -31
  20. package/src/components/actions/__tests__/ActionForm.spec.js +11 -27
  21. package/src/components/actions/__tests__/ActionNew.spec.js +7 -53
  22. package/src/components/actions/__tests__/Actions.spec.js +6 -15
  23. package/src/components/actions/__tests__/ActionsTable.spec.js +3 -23
  24. package/src/components/actions/__tests__/__snapshots__/Action.spec.js.snap +39 -11
  25. package/src/components/actions/__tests__/__snapshots__/ActionActions.spec.js.snap +4 -4
  26. package/src/components/actions/__tests__/__snapshots__/ActionBreadcrumbs.spec.js.snap +2 -1
  27. package/src/components/actions/__tests__/__snapshots__/ActionDetail.spec.js.snap +26 -3
  28. package/src/components/actions/__tests__/__snapshots__/ActionEdit.spec.js.snap +11 -73
  29. package/src/components/actions/__tests__/__snapshots__/ActionForm.spec.js.snap +91 -13
  30. package/src/components/actions/__tests__/__snapshots__/ActionNew.spec.js.snap +16 -263
  31. package/src/components/actions/__tests__/__snapshots__/Actions.spec.js.snap +5 -4
  32. package/src/components/actions/__tests__/__snapshots__/ActionsTable.spec.js.snap +7 -5
  33. package/src/components/aiSandbox/AiSandbox.js +3 -6
  34. package/src/components/aiSandbox/RequestForm.js +6 -4
  35. package/src/components/prompts/PromptEditor.js +1 -8
  36. package/src/components/prompts/Prompts.js +2 -6
  37. package/src/components/prompts/__tests__/PromptEditor.spec.js +62 -54
  38. package/src/components/prompts/__tests__/Prompts.spec.js +0 -2
  39. package/src/components/prompts/__tests__/__snapshots__/PromptEditor.spec.js.snap +115 -10
  40. package/src/components/providers/ProviderEditor.js +1 -5
  41. package/src/components/providers/Providers.js +1 -2
  42. package/src/components/providers/__tests__/ProviderEditor.spec.js +54 -75
  43. package/src/components/providers/__tests__/Providers.spec.js +0 -2
  44. package/src/components/providers/__tests__/__snapshots__/ProviderEditor.spec.js.snap +0 -4
  45. package/src/components/providers/providerProperties/AzureOpenai.js +0 -1
  46. package/src/components/providers/providerProperties/BedrockClaude.js +0 -1
  47. package/src/components/providers/providerProperties/Gemini.js +0 -1
  48. package/src/components/providers/providerProperties/Openai.js +0 -1
  49. package/src/components/resourceMappings/ResourceMappingEditor.js +2 -5
  50. package/src/components/resourceMappings/ResourceMappingFields.js +3 -2
  51. package/src/components/resourceMappings/ResourceMappings.js +4 -2
  52. package/src/components/resourceMappings/__tests__/ResourceMappingEditor.spec.js +51 -93
  53. package/src/components/resourceMappings/__tests__/ResourceMappings.spec.js +0 -2
  54. package/src/components/resourceMappings/__tests__/__snapshots__/ResourceMappingEditor.spec.js.snap +4 -4
  55. package/src/components/resourceMappings/selectors/DataStructureSelector.js +0 -1
  56. package/src/components/resourceMappings/selectors/index.js +0 -1
  57. package/src/components/suggestions/SuggestionsWidget.js +1 -1
  58. package/src/components/suggestions/__tests__/SuggestionsWidget.spec.js +3 -3
  59. package/src/components/suggestions/__tests__/__snapshots__/SuggestionsWidget.spec.js.snap +0 -3
  60. package/src/hooks/__mocks__/useActions.js +44 -0
  61. package/src/hooks/__mocks__/useSuggestions.js +5 -0
  62. package/src/hooks/__tests__/usePrompts.spec.js +5 -5
  63. package/src/hooks/__tests__/{useProviders.js → useProviders.spec.js} +5 -5
  64. package/src/hooks/__tests__/useResourceMappings.spec.js +5 -5
  65. package/src/hooks/useActions.js +5 -4
  66. package/src/hooks/usePrompts.js +6 -6
  67. package/src/hooks/useProviders.js +5 -5
  68. package/src/hooks/useResourceMappings.js +4 -4
  69. package/src/index.js +2 -1
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "@truedat/ai",
3
- "version": "7.5.9",
3
+ "version": "7.5.11",
4
4
  "description": "Truedat Web Artificial Intelligence package",
5
5
  "sideEffects": false,
6
- "jsnext:main": "src/index.js",
7
6
  "module": "src/index.js",
8
7
  "files": [
9
8
  "src"
@@ -15,63 +14,25 @@
15
14
  },
16
15
  "scripts": {
17
16
  "clean": "rimraf yarn-error.log",
18
- "debug": "node --inspect-brk node_modules/.bin/jest --runInBand",
19
17
  "test": "TZ=UTC jest --coverage",
20
- "test:watch": "TZ=UTC jest --watch",
21
18
  "eslint": "eslint src/**",
22
19
  "eslint:fix": "eslint --fix src/**"
23
20
  },
24
- "devDependencies": {
25
- "@babel/cli": "^7.19.3",
26
- "@babel/core": "^7.20.5",
27
- "@babel/plugin-proposal-class-properties": "^7.18.6",
28
- "@babel/plugin-proposal-object-rest-spread": "^7.20.2",
29
- "@babel/plugin-proposal-optional-chaining": "^7.18.9",
30
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
31
- "@babel/plugin-transform-modules-commonjs": "^7.19.6",
32
- "@babel/preset-env": "^7.20.2",
33
- "@babel/preset-react": "^7.18.6",
34
- "@testing-library/jest-dom": "^5.16.5",
35
- "@testing-library/react": "^12.0.0",
36
- "@testing-library/react-hooks": "^8.0.1",
37
- "@testing-library/user-event": "^13.2.1",
38
- "@truedat/test": "7.5.9",
39
- "babel-jest": "^28.1.0",
40
- "babel-plugin-dynamic-import-node": "^2.3.3",
41
- "babel-plugin-lodash": "^3.3.4",
42
- "babel-plugin-react-intl": "^5.1.18",
43
- "babel-plugin-transform-semantic-ui-react-imports": "^1.4.1",
44
- "identity-obj-proxy": "^3.0.0",
45
- "jest": "^29.0.0",
46
- "jest-environment-jsdom": "^29.0.0",
47
- "jsdom": "^26.0.0",
48
- "react": "^16.14.0",
49
- "react-dom": "^16.14.0",
50
- "rimraf": "^3.0.2",
51
- "semantic-ui-react": "^2.1.4"
52
- },
53
21
  "jest": {
54
22
  "maxWorkers": "50%",
55
23
  "testTimeout": 10000,
56
24
  "moduleDirectories": [
57
- "<rootDir>/src",
58
- "../../node_modules"
59
- ],
60
- "setupFilesAfterEnv": [
61
- "@truedat/test/setup"
25
+ "<rootDir>/src"
62
26
  ],
63
27
  "moduleNameMapper": {
64
- "\\.(css|less)$": "identity-obj-proxy",
28
+ "\\.(css|less|png)$": "identity-obj-proxy",
65
29
  "^@truedat/([^/]+)$": "<rootDir>/../$1/src/index",
66
30
  "^@truedat/([^/]+)/(.*)$": "<rootDir>/../$1/src/$2"
67
31
  },
68
- "snapshotSerializers": [
69
- "enzyme-to-json/serializer"
32
+ "setupFilesAfterEnv": [
33
+ "@truedat/test/setup"
70
34
  ],
71
35
  "testEnvironment": "jsdom",
72
- "testPathIgnorePatterns": [
73
- "<rootDir>/node_modules/"
74
- ],
75
36
  "transform": {
76
37
  "\\.js$": [
77
38
  "babel-jest",
@@ -79,23 +40,42 @@
79
40
  "rootMode": "upward"
80
41
  }
81
42
  ]
82
- },
83
- "transformIgnorePatterns": [
84
- "/node_modules/(?!@truedat).*"
85
- ]
43
+ }
44
+ },
45
+ "devDependencies": {
46
+ "@testing-library/dom": "^10.4.0",
47
+ "@testing-library/jest-dom": "^6.6.3",
48
+ "@testing-library/react": "^16.2.0",
49
+ "@testing-library/user-event": "^14.6.1",
50
+ "@truedat/test": "7.5.11",
51
+ "identity-obj-proxy": "^3.0.0",
52
+ "jest": "^29.7.0",
53
+ "redux-saga-test-plan": "^4.0.6"
86
54
  },
87
55
  "dependencies": {
88
- "@truedat/core": "7.5.9",
56
+ "axios": "^1.8.4",
57
+ "is-hotkey": "^0.2.0",
58
+ "is-url": "^1.2.4",
59
+ "lodash": "^4.17.21",
60
+ "moment": "^2.30.1",
61
+ "path-to-regexp": "^8.2.0",
89
62
  "prop-types": "^15.8.1",
90
- "react-hook-form": "^7.45.4",
91
- "react-intl": "^5.20.10",
92
- "semantic-ui-react": "^2.1.4",
93
- "swr": "^2.0.0"
94
- },
95
- "peerDependencies": {
96
- "react": ">= 16.8.6 < 17",
97
- "react-dom": ">= 16.8.6 < 17",
98
- "semantic-ui-react": ">= 2.0.3 < 2.2"
63
+ "query-string": "^7.1.2",
64
+ "react": "^19.0.0",
65
+ "react-csv": "^2.2.2",
66
+ "react-dom": "^19.0.0",
67
+ "react-dropzone": "^14.3.8",
68
+ "react-hook-form": "^7.54.2",
69
+ "react-intl": "^7.1.10",
70
+ "react-moment": "^1.1.3",
71
+ "react-redux": "^9.2.0",
72
+ "react-router": "^7.4.0",
73
+ "redux": "^5.0.1",
74
+ "redux-saga": "^1.3.0",
75
+ "redux-saga-routines": "^3.2.3",
76
+ "semantic-ui-calendar-react": "^0.15.3",
77
+ "semantic-ui-react": "^3.0.0-beta.2",
78
+ "swr": "^2.3.3"
99
79
  },
100
- "gitHead": "03770e3241daa955de2e6e40fdaea91e3d147860"
80
+ "gitHead": "cbb92d5206752fe2add4195432b0401da17a0f23"
101
81
  }
@@ -1,17 +1,7 @@
1
1
  import React from "react";
2
- import { Route, Switch } from "react-router-dom";
3
- import { Unauthorized } from "@truedat/core/components";
4
- import { useAuthorized } from "@truedat/core/hooks";
5
- import {
6
- AI_SANDBOX,
7
- ACTIONS,
8
- ACTION,
9
- ACTION_EDIT,
10
- ACTION_NEW,
11
- RESOURCE_MAPPINGS,
12
- PROMPTS,
13
- PROVIDERS,
14
- } from "@truedat/core/routes";
2
+ import { Route, Routes } from "react-router";
3
+ import { ProtectedRoute } from "@truedat/core/router";
4
+
15
5
  import ResourceMappings from "./resourceMappings/ResourceMappings";
16
6
  import Prompts from "./prompts/Prompts";
17
7
  import Providers from "./providers/Providers";
@@ -22,44 +12,47 @@ import ActionEdit from "./actions/ActionEdit";
22
12
  import ActionNew from "./actions/ActionNew";
23
13
 
24
14
  export default function AiRoutes() {
25
- const authorized = useAuthorized("manage_ai");
26
-
27
15
  return (
28
- <Switch>
29
- <Route
30
- path={RESOURCE_MAPPINGS}
31
- render={() => (authorized ? <ResourceMappings /> : <Unauthorized />)}
32
- />
33
- <Route
34
- path={PROMPTS}
35
- render={() => (authorized ? <Prompts /> : <Unauthorized />)}
36
- />
37
- <Route
38
- path={PROVIDERS}
39
- render={() => (authorized ? <Providers /> : <Unauthorized />)}
40
- />
16
+ <Routes>
41
17
  <Route
42
- path={AI_SANDBOX}
43
- render={() => (authorized ? <AiSandbox /> : <Unauthorized />)}
44
- />
18
+ path={"resource_mappings"}
19
+ element={<ProtectedRoute authorization={"manage_ai"} />}
20
+ >
21
+ <Route index element={<ResourceMappings />} />
22
+ </Route>
23
+
45
24
  <Route
46
- path={ACTIONS}
47
- exact
48
- render={() => (authorized ? <Actions /> : <Unauthorized />)}
49
- />
25
+ path={"prompts"}
26
+ element={<ProtectedRoute authorization={"manage_ai"} />}
27
+ >
28
+ <Route index element={<Prompts />} />
29
+ </Route>
30
+
50
31
  <Route
51
- path={ACTION_NEW}
52
- exact
53
- render={() => (authorized ? <ActionNew /> : <Unauthorized />)}
54
- />
32
+ path={"providers"}
33
+ element={<ProtectedRoute authorization={"manage_ai"} />}
34
+ >
35
+ <Route index element={<Providers />} />
36
+ </Route>
37
+
55
38
  <Route
56
- path={ACTION_EDIT}
57
- render={() => (authorized ? <ActionEdit /> : <Unauthorized />)}
58
- />
39
+ path={"aiSandbox"}
40
+ element={<ProtectedRoute authorization={"manage_ai"} />}
41
+ >
42
+ <Route index element={<AiSandbox />} />
43
+ </Route>
44
+
59
45
  <Route
60
- path={ACTION}
61
- render={() => (authorized ? <Action /> : <Unauthorized />)}
62
- />
63
- </Switch>
46
+ path={"tasks"}
47
+ element={<ProtectedRoute authorization={"manage_ai"} />}
48
+ >
49
+ <Route index element={<Actions />} />
50
+ <Route path={"new"} element={<ActionNew />} />
51
+ <Route path={":id/edit"} element={<ActionEdit />} />
52
+ <Route path={":id"} element={<Action />} />
53
+ </Route>
54
+
55
+ <Route path="*" element={null} />
56
+ </Routes>
64
57
  );
65
58
  }
@@ -1,5 +1,5 @@
1
1
  import _ from "lodash/fp";
2
- import React, { useEffect, useState } from "react";
2
+ import { Fragment, useEffect, useState } from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import {
5
5
  Button,
@@ -21,7 +21,7 @@ import {
21
21
  import { useIntl } from "react-intl";
22
22
  import FieldViewerValue from "@truedat/df/components/FieldViewerValue";
23
23
  import { splitTranslatableFields } from "@truedat/core/services/i18nContent";
24
- import { useRequestTranslation } from "../hooks/useTranslations";
24
+ import { useRequestTranslation } from "@truedat/ai/hooks/useTranslations";
25
25
 
26
26
  const TranslationModal = ({
27
27
  open,
@@ -44,7 +44,6 @@ const TranslationModal = ({
44
44
  const translatableFields = _.keysIn(translatable);
45
45
 
46
46
  const defaultContent = _.find({ is_default: true })(i18nContent);
47
-
48
47
  const initializeTemplate = () => {
49
48
  const templateContent = _.flow(
50
49
  _.map((group) => {
@@ -271,7 +270,7 @@ const TranslationModal = ({
271
270
  </dl>
272
271
  ) : null}
273
272
  {_.map(({ name: groupName, fields, checked }) => (
274
- <React.Fragment key={groupName}>
273
+ <Fragment key={groupName}>
275
274
  <Divider />
276
275
  <h3>
277
276
  <Checkbox
@@ -291,7 +290,7 @@ const TranslationModal = ({
291
290
  type,
292
291
  widget,
293
292
  }) => (
294
- <React.Fragment key={fieldName}>
293
+ <Fragment key={fieldName}>
295
294
  <dt>
296
295
  <h4>
297
296
  <Checkbox
@@ -350,11 +349,11 @@ const TranslationModal = ({
350
349
  widget={widget}
351
350
  />
352
351
  </dd>
353
- </React.Fragment>
352
+ </Fragment>
354
353
  )
355
354
  )(fields)}
356
355
  </dl>
357
- </React.Fragment>
356
+ </Fragment>
358
357
  ))(translateTemplate)}
359
358
  </Segment>
360
359
  </Grid.Column>
@@ -467,7 +466,6 @@ const TranslationModal = ({
467
466
  )(translateContent)}
468
467
  </TableRow>
469
468
  ) : null}
470
-
471
469
  {_.map(({ fields }) =>
472
470
  _.map(
473
471
  ({
@@ -592,8 +590,8 @@ const TranslationModal = ({
592
590
  {translateResult === "success"
593
591
  ? renderResult()
594
592
  : translateResult === "error"
595
- ? renderError()
596
- : renderRequest()}
593
+ ? renderError()
594
+ : renderRequest()}
597
595
  </Modal.Description>
598
596
  </Modal.Content>
599
597
  </Modal>
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import { act, fireEvent, waitFor } from "@testing-library/react";
3
2
  import { render } from "@truedat/test/render";
4
3
  import TranslationModal from "../TranslationModal";
@@ -1,7 +1,6 @@
1
1
  import _ from "lodash/fp";
2
- import React from "react";
3
2
  import PropTypes from "prop-types";
4
- import { useParams } from "react-router-dom";
3
+ import { useParams } from "react-router";
5
4
  import { Loading } from "@truedat/core/components";
6
5
  import { Header, Icon, Grid, Segment } from "semantic-ui-react";
7
6
  import { useIntl } from "react-intl";
@@ -1,9 +1,8 @@
1
- import React from "react";
2
1
  import PropTypes from "prop-types";
3
2
  import { useIntl } from "react-intl";
4
- import { Link } from "react-router-dom";
3
+ import { Link } from "react-router";
5
4
  import { linkTo, ACTIONS } from "@truedat/core/routes";
6
- import { useHistory } from "react-router-dom";
5
+ import { useNavigate } from "react-router";
7
6
  import { Button, Icon } from "semantic-ui-react";
8
7
  import { ConfirmModal, GroupActions } from "@truedat/core/components";
9
8
  import { useActionDelete, useActionSetActive } from "../../hooks/useActions";
@@ -72,7 +71,7 @@ ConfirmDeleteModal.propTypes = {
72
71
 
73
72
  export const ActionActions = ({ action, actionMutate }) => {
74
73
  const { formatMessage } = useIntl();
75
- const history = useHistory();
74
+ const navigate = useNavigate();
76
75
  const { is_enabled: active, id, name } = action || {};
77
76
 
78
77
  const { trigger: handleDelete } = useActionDelete({ id: id });
@@ -89,7 +88,7 @@ export const ActionActions = ({ action, actionMutate }) => {
89
88
 
90
89
  const onConfirmDelete = async () => {
91
90
  await handleDelete();
92
- history.push(ACTIONS);
91
+ navigate(ACTIONS);
93
92
  };
94
93
 
95
94
  const onConfirmToggle = async () => {
@@ -1,7 +1,6 @@
1
- import React from "react";
2
1
  import PropTypes from "prop-types";
3
2
  import { Breadcrumb } from "semantic-ui-react";
4
- import { Link } from "react-router-dom";
3
+ import { Link } from "react-router";
5
4
  import { FormattedMessage } from "react-intl";
6
5
  import { ACTIONS } from "@truedat/core/routes";
7
6
 
@@ -1,15 +1,16 @@
1
1
  import _ from "lodash/fp";
2
- import React from "react";
2
+ import { lazy } from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import { FormattedMessage } from "react-intl";
5
5
  import { Segment, List, Divider } from "semantic-ui-react";
6
6
 
7
- const DynamicFormViewer = React.lazy(() =>
8
- import("@truedat/df/components/DynamicFormViewer")
7
+ const DynamicFormViewer = lazy(
8
+ () => import("@truedat/df/components/DynamicFormViewer")
9
9
  );
10
10
 
11
11
  export const ActionDetail = ({ action }) => {
12
12
  const user = _.path("user.full_name")(action);
13
+
13
14
  return (
14
15
  <Segment attached="bottom">
15
16
  <List size="big" relaxed>
@@ -1,5 +1,5 @@
1
- import React, { useEffect, useState } from "react";
2
- import { useParams } from "react-router-dom";
1
+ import { useEffect, useState } from "react";
2
+ import { useParams } from "react-router";
3
3
  import {
4
4
  Checkbox,
5
5
  Container,
@@ -28,7 +28,7 @@ const ActionEdit = () => {
28
28
  const [isEnabled, setIsEnabled] = useState(true);
29
29
 
30
30
  useEffect(() => {
31
- if (action?.deleted_at) history.push(linkTo.ACTION({ id: action?.id }));
31
+ if (action?.deleted_at) navigate(linkTo.ACTION({ id: action?.id }));
32
32
  setIsEnabled(action?.is_enabled);
33
33
  }, [action]);
34
34
 
@@ -1,15 +1,15 @@
1
1
  import _ from "lodash/fp";
2
- import React, { useEffect, useState } from "react";
2
+ import { lazy, useEffect, useState } from "react";
3
3
  import PropTypes from "prop-types";
4
- import { useHistory } from "react-router-dom";
4
+ import { useNavigate } from "react-router";
5
5
  import { HistoryBackButton } from "@truedat/core/components";
6
- import { Form, Header, Label, Button } from "semantic-ui-react";
6
+ import { Form, Label, Button } from "semantic-ui-react";
7
7
  import { FormattedMessage, useIntl } from "react-intl";
8
8
  import { linkTo } from "@truedat/core/routes";
9
9
  import { useAgents } from "@truedat/auth/hooks/useUsers";
10
10
 
11
- const SelectableDynamicForm = React.lazy(() =>
12
- import("@truedat/df/components/SelectableDynamicForm")
11
+ const SelectableDynamicForm = lazy(
12
+ () => import("@truedat/df/components/SelectableDynamicForm")
13
13
  );
14
14
 
15
15
  const ActionForm = ({
@@ -19,7 +19,7 @@ const ActionForm = ({
19
19
  onSubmit,
20
20
  }) => {
21
21
  const { formatMessage } = useIntl();
22
- const history = useHistory();
22
+ const navigate = useNavigate();
23
23
  const { agents } = useAgents();
24
24
 
25
25
  const [action, setAction] = useState();
@@ -81,7 +81,7 @@ const ActionForm = ({
81
81
  };
82
82
 
83
83
  onSubmit(payload).then((response) => {
84
- history.push(linkTo.ACTION({ id: response?.data?.data?.id }));
84
+ navigate(linkTo.ACTION({ id: response?.data?.data?.id }));
85
85
  });
86
86
  };
87
87
 
@@ -1,4 +1,4 @@
1
- import React, { useState } from "react";
1
+ import { useState } from "react";
2
2
  import {
3
3
  Checkbox,
4
4
  Container,
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import {
3
2
  Header,
4
3
  Icon,
@@ -8,7 +7,7 @@ import {
8
7
  Button,
9
8
  } from "semantic-ui-react";
10
9
  import { FormattedMessage, useIntl } from "react-intl";
11
- import { Link } from "react-router-dom";
10
+ import { Link } from "react-router";
12
11
  import { ACTION_NEW } from "@truedat/core/routes";
13
12
  import { useActionsSearch } from "../../hooks/useActions";
14
13
  import { ActionsTable } from "./ActionsTable";
@@ -1,8 +1,8 @@
1
1
  import _ from "lodash/fp";
2
- import React, { useState, useEffect, useContext, createContext } from "react";
2
+ import { useState, useEffect, use, createContext } from "react";
3
3
 
4
4
  export const ActionsContext = createContext();
5
- export const useActionsContext = () => useContext(ActionsContext);
5
+ export const useActionsContext = () => use(ActionsContext);
6
6
 
7
7
  export const ActionsContextProvider = (props) => {
8
8
  const children = _.prop("children")(props);
@@ -44,9 +44,5 @@ export const ActionsContextProvider = (props) => {
44
44
  setSortDirection,
45
45
  };
46
46
 
47
- return (
48
- <ActionsContext.Provider value={context}>
49
- {children}
50
- </ActionsContext.Provider>
51
- );
47
+ return <ActionsContext value={context}>{children}</ActionsContext>;
52
48
  };
@@ -1,7 +1,6 @@
1
1
  import _ from "lodash/fp";
2
- import React from "react";
3
2
  import { FormattedMessage } from "react-intl";
4
- import { Link } from "react-router-dom";
3
+ import { Link } from "react-router";
5
4
  import { Table, Header, Icon } from "semantic-ui-react";
6
5
  import { linkTo } from "@truedat/core/routes";
7
6
  import { Loading } from "@truedat/core/components";
@@ -1,9 +1,10 @@
1
- import React from "react";
2
- import { render } from "@truedat/test/render";
1
+ import { render, waitForLoad } from "@truedat/test/render";
2
+ import { useAction } from "@truedat/ai/hooks/useActions";
3
+ import { templateByNameMock } from "@truedat/test/mocks";
3
4
  import Action from "../Action";
4
5
 
5
6
  const action = {
6
- id: 3,
7
+ id: "3",
7
8
  name: "foo",
8
9
  type: "baz",
9
10
  user: {
@@ -16,44 +17,21 @@ const action = {
16
17
  is_enabled: true,
17
18
  dynamic_content: {},
18
19
  };
19
- jest.mock("@truedat/ai/hooks/useActions", () => {
20
- const originalModule = jest.requireActual("@truedat/ai/hooks/useActions");
21
20
 
22
- return {
23
- __esModule: true,
24
- ...originalModule,
25
- useAction: () => ({
26
- action,
27
- loading: false,
28
- mutate: jest.fn(),
29
- }),
30
- };
31
- });
21
+ jest.mock("@truedat/ai/hooks/useActions");
22
+ useAction.mockImplementation(() => ({
23
+ action,
24
+ mutate: jest.fn(),
25
+ }));
32
26
 
33
27
  const renderOpts = {
34
- messages: {
35
- en: {
36
- "ai.actions.actions.delete.confirmation.content":
37
- "Action will be deleted. Are you sure?",
38
- "ai.actions.actions.delete.confirmation.header": "Delete action",
39
- "ai.actions.actions.delete": "Delete",
40
- "ai.actions.actions.disable.confirmation.content":
41
- " Action will be disabled. Are you sure?",
42
- "ai.actions.actions.disable.confirmation.header": "Disable action",
43
- "ai.actions.actions.disable": "Disable",
44
- "ai.actions.actions.edit": "Edit",
45
- "ai.actions.actions.form.user": "Agent",
46
- "ai.actions.is_enabled.true": "Active",
47
- "navigation.admin.actions": "Actions",
48
- "ai.actions.form.type": "Type",
49
- },
50
- },
51
- fallback: "lazy",
28
+ mocks: [templateByNameMock({ name: "baz", domainIds: undefined })],
52
29
  };
53
30
 
54
31
  describe("<Action />", () => {
55
- it("matches the latest snapshot", () => {
56
- const { container } = render(<Action />, renderOpts);
57
- expect(container).toMatchSnapshot();
32
+ it("matches the latest snapshot", async () => {
33
+ const rendered = render(<Action />, renderOpts);
34
+ await waitForLoad(rendered);
35
+ expect(rendered.container).toMatchSnapshot();
58
36
  });
59
37
  });
@@ -1,9 +1,8 @@
1
- import React from "react";
2
1
  import { render } from "@truedat/test/render";
3
2
  import ActionActions from "../ActionActions";
4
3
 
5
4
  const action = {
6
- id: 3,
5
+ id: "3",
7
6
  name: "foo",
8
7
  type: "baz",
9
8
  user: {
@@ -17,23 +16,6 @@ const action = {
17
16
  dynamic_content: {},
18
17
  };
19
18
 
20
- const renderOpts = {
21
- messages: {
22
- en: {
23
- "ai.actions.actions.delete.confirmation.content":
24
- "Action will be deleted. Are you sure?",
25
- "ai.actions.actions.delete.confirmation.header": "Delete action",
26
- "ai.actions.actions.delete": "Delete",
27
- "ai.actions.actions.disable.confirmation.content":
28
- " Action will be disabled. Are you sure?",
29
- "ai.actions.actions.disable.confirmation.header": "Disable action",
30
- "ai.actions.actions.disable": "Disable",
31
- "ai.actions.actions.edit": "Edit",
32
- "navigation.admin.actions": "Actions",
33
- },
34
- },
35
- };
36
-
37
19
  describe("<ActionActions />", () => {
38
20
  const props = {
39
21
  action,
@@ -41,7 +23,7 @@ describe("<ActionActions />", () => {
41
23
  };
42
24
 
43
25
  it("matches the latest snapshot", () => {
44
- const { container } = render(<ActionActions {...props} />, renderOpts);
26
+ const { container } = render(<ActionActions {...props} />);
45
27
  expect(container).toMatchSnapshot();
46
28
  });
47
29
  });
@@ -1,21 +1,12 @@
1
- import React from "react";
2
1
  import { render } from "@truedat/test/render";
3
2
  import ActionBreadcrumbs from "../ActionBreadcrumbs";
4
3
 
5
- const renderOpts = {
6
- messages: {
7
- en: {
8
- "navigation.admin.actions": "Actions",
9
- },
10
- },
11
- };
12
-
13
4
  describe("<ActionBreadcrumbs />", () => {
14
5
  const text = "edit";
15
6
  const props = { text };
16
7
 
17
8
  it("matches the latest snapshot", () => {
18
- const { container } = render(<ActionBreadcrumbs {...props} />, renderOpts);
9
+ const { container } = render(<ActionBreadcrumbs {...props} />);
19
10
  expect(container).toMatchSnapshot();
20
11
  });
21
12
  });