@truedat/lm 5.2.2 → 5.2.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.2.3] 2023-02-23
4
+
5
+ ### Change
6
+
7
+ - [TD-4554] Reducers of the Relations for concept links manager
8
+
3
9
  ## [4.53.0] 2022-10-04
4
10
 
5
11
  ### Changed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/lm",
3
- "version": "5.2.2",
3
+ "version": "5.2.4",
4
4
  "description": "Truedat Link Manager",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -34,7 +34,7 @@
34
34
  "@testing-library/jest-dom": "^5.16.5",
35
35
  "@testing-library/react": "^12.0.0",
36
36
  "@testing-library/user-event": "^13.2.1",
37
- "@truedat/test": "5.2.2",
37
+ "@truedat/test": "5.2.4",
38
38
  "babel-jest": "^28.1.0",
39
39
  "babel-plugin-dynamic-import-node": "^2.3.3",
40
40
  "babel-plugin-lodash": "^3.3.4",
@@ -86,7 +86,7 @@
86
86
  ]
87
87
  },
88
88
  "dependencies": {
89
- "@truedat/core": "5.2.2",
89
+ "@truedat/core": "5.2.4",
90
90
  "path-to-regexp": "^1.7.0",
91
91
  "prop-types": "^15.8.1",
92
92
  "react-graph-vis": "1.0.5",
@@ -105,5 +105,5 @@
105
105
  "react-dom": ">= 16.8.6 < 17",
106
106
  "semantic-ui-react": ">= 2.0.3 < 2.2"
107
107
  },
108
- "gitHead": "39b2e1047e9a1ef56be526292208be23bfdd798d"
108
+ "gitHead": "30945576a3812f88a70b30553caec79bb8957d5c"
109
109
  }
@@ -0,0 +1,61 @@
1
+ import _ from "lodash/fp";
2
+ import React from "react";
3
+ import PropTypes from "prop-types";
4
+ import { Form, Dropdown } from "semantic-ui-react";
5
+ import { FormattedMessage, useIntl } from "react-intl";
6
+ import { connect } from "react-redux";
7
+ import { setSelectedRelationTags } from "../routines";
8
+
9
+ const formatOption = (formatMessage) => (options) =>
10
+ _.flow(
11
+ _.map(({ value, text }) =>
12
+ _.isNil(text) || text == ""
13
+ ? { value, text }
14
+ : {
15
+ value,
16
+ text: formatMessage({
17
+ id: `source.${text}`,
18
+ defaultMessage: formatMessage({ id: text, defaultMessage: text }),
19
+ }),
20
+ }
21
+ )
22
+ )(options);
23
+
24
+ export const TagTypeDropdownSelector = ({
25
+ options,
26
+ setSelectedRelationTags,
27
+ }) => {
28
+ const { formatMessage } = useIntl();
29
+
30
+ const onChange = (_e, { value }) => {
31
+ setSelectedRelationTags({
32
+ selectedRelationTags: value === "" ? [] : [value],
33
+ });
34
+ };
35
+ return (
36
+ <Form.Field>
37
+ <label>
38
+ <FormattedMessage id="relations.relationType" />
39
+ </label>
40
+ <div>
41
+ {options && (
42
+ <Dropdown
43
+ clearable
44
+ selection
45
+ options={formatOption(formatMessage)(options)}
46
+ onChange={onChange}
47
+ />
48
+ )}
49
+ </div>
50
+ </Form.Field>
51
+ );
52
+ };
53
+
54
+ TagTypeDropdownSelector.propTypes = {
55
+ options: PropTypes.array,
56
+ setSelectedRelationTags: PropTypes.func,
57
+ };
58
+
59
+ export default connect(null, { setSelectedRelationTags })(
60
+ TagTypeDropdownSelector
61
+ );
@@ -2,6 +2,7 @@ import { createRelation } from "../../routines";
2
2
  import { creatingRelation } from "..";
3
3
 
4
4
  const fooState = { foo: "bar" };
5
+ const payload = { data: fooState };
5
6
 
6
7
  describe("reducers: creatingRelation", () => {
7
8
  const initialState = false;
@@ -10,15 +11,15 @@ describe("reducers: creatingRelation", () => {
10
11
  expect(creatingRelation(undefined, {})).toEqual(initialState);
11
12
  });
12
13
 
13
- it("should handle the createRelation.TRIGGER action", () => {
14
+ it("should handle the createRelation.SUCCESS action", () => {
14
15
  expect(
15
- creatingRelation(fooState, { type: createRelation.TRIGGER })
16
- ).toEqual(true);
16
+ creatingRelation(fooState, { type: createRelation.SUCCESS, payload })
17
+ ).toEqual(fooState);
17
18
  });
18
19
 
19
- it("should handle the createRelation.FULFILL action", () => {
20
+ it("should handle the createRelation.FAILURE action", () => {
20
21
  expect(
21
- creatingRelation(fooState, { type: createRelation.FULFILL })
22
- ).toEqual(initialState);
22
+ creatingRelation(fooState, { type: createRelation.FAILURE })
23
+ ).toEqual(false);
23
24
  });
24
25
  });
@@ -12,8 +12,8 @@ describe("reducers: relations", () => {
12
12
  source_type: "source_type",
13
13
  target_id: 456,
14
14
  target_type: "target_type",
15
- context: {}
16
- }
15
+ context: {},
16
+ },
17
17
  ];
18
18
 
19
19
  it("should provide the initial state", () => {
@@ -35,7 +35,11 @@ describe("reducers: relations", () => {
35
35
  it("should handle the deleteRelation.SUCCESS action", () => {
36
36
  expect(
37
37
  relations(data, { type: deleteRelation.SUCCESS, meta: { id: "1" } })
38
- ).toEqual([]);
38
+ ).toEqual({ id: "1" });
39
+ });
40
+
41
+ it("should handle the deleteRelation.FAILURE action", () => {
42
+ expect(relations(data, { type: deleteRelation.FAILURE })).toEqual(false);
39
43
  });
40
44
 
41
45
  it("should handle the clearRelations.TRIGGER action", () => {
@@ -1,14 +1,12 @@
1
1
  import { createRelation } from "../routines";
2
2
 
3
- const creatingRelation = (state = false, { type }) => {
3
+ export const creatingRelation = (state = false, { type, payload }) => {
4
4
  switch (type) {
5
- case createRelation.TRIGGER:
6
- return true;
7
- case createRelation.FULFILL:
5
+ case createRelation.SUCCESS:
6
+ return payload.data;
7
+ case createRelation.FAILURE:
8
8
  return false;
9
9
  default:
10
10
  return state;
11
11
  }
12
12
  };
13
-
14
- export { creatingRelation };
@@ -2,7 +2,7 @@ import { clearRedirect } from "@truedat/core/routines";
2
2
  import {
3
3
  createRelation,
4
4
  deleteRelationTag,
5
- createRelationTag
5
+ createRelationTag,
6
6
  } from "../routines";
7
7
 
8
8
  const initialState = "";
@@ -12,8 +12,7 @@ export const relationRedirect = (state = initialState, { type, meta }) => {
12
12
  case clearRedirect.TRIGGER:
13
13
  return initialState;
14
14
  case createRelation.SUCCESS: {
15
- const { redirectUrl } = meta;
16
- return redirectUrl;
15
+ return meta?.redirectUrl || state;
17
16
  }
18
17
  case createRelationTag.SUCCESS: {
19
18
  const { redirectUrl } = meta;
@@ -10,7 +10,7 @@ const pickFields = _.pick([
10
10
  "target_id",
11
11
  "target_type",
12
12
  "context",
13
- "tags"
13
+ "tags",
14
14
  ]);
15
15
 
16
16
  const relations = (state = initialState, { type, payload, meta }) => {
@@ -20,8 +20,10 @@ const relations = (state = initialState, { type, payload, meta }) => {
20
20
  case fetchRelations.SUCCESS:
21
21
  return _.flow(_.propOr([], "data"), _.map(pickFields))(payload);
22
22
  case deleteRelation.SUCCESS: {
23
- const { id } = meta;
24
- return _.reject(_.propEq("id", id))(state);
23
+ return meta;
24
+ }
25
+ case deleteRelation.FAILURE: {
26
+ return false;
25
27
  }
26
28
  case clearRelations.TRIGGER:
27
29
  return initialState;