@truedat/df 4.48.0 → 4.48.2

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 (32) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +4 -4
  3. package/src/components/DynamicFieldValue.js +52 -44
  4. package/src/components/DynamicForm.js +18 -13
  5. package/src/components/DynamicFormViewer.js +22 -20
  6. package/src/components/EditableDynamicFieldValue.js +21 -22
  7. package/src/components/FieldGroupSegment.js +2 -2
  8. package/src/components/FieldGroupSubSegment/__tests__/FieldGroupSubSegment.spec.js +2 -2
  9. package/src/components/FieldGroupSubSegment/__tests__/__snapshots__/FieldGroupSubSegment.spec.js.snap +4 -4
  10. package/src/components/FieldGroupSubSegment/handleCopyModule.js +18 -18
  11. package/src/components/__tests__/__snapshots__/DynamicForm.spec.js.snap +74 -80
  12. package/src/components/widgets/CheckboxField.js +17 -9
  13. package/src/components/widgets/DynamicField.js +3 -1
  14. package/src/components/widgets/RadioField.js +16 -8
  15. package/src/components/widgets/__tests__/CheckboxField.spec.js +4 -7
  16. package/src/components/widgets/__tests__/RadioField.spec.js +3 -3
  17. package/src/components/widgets/__tests__/__snapshots__/CheckboxField.spec.js.snap +12 -2
  18. package/src/components/widgets/__tests__/__snapshots__/RadioField.spec.js.snap +2 -0
  19. package/src/selectors/__tests__/getOptions.spec.js +2 -2
  20. package/src/selectors/getOptions.js +1 -1
  21. package/src/templates/components/Template.js +7 -2
  22. package/src/templates/components/TemplateCard.js +2 -1
  23. package/src/templates/components/__tests__/Template.spec.js +12 -10
  24. package/src/templates/components/__tests__/__snapshots__/Template.spec.js.snap +278 -27
  25. package/src/templates/components/templateForm/ActiveGroupForm.js +8 -7
  26. package/src/templates/components/templateForm/ConditionalFieldForm.js +12 -4
  27. package/src/templates/components/templateForm/GroupsList.js +2 -2
  28. package/src/templates/components/templateForm/__tests__/__snapshots__/ActiveGroupForm.spec.js.snap +1 -1
  29. package/src/templates/utils/__tests__/parseFieldOptions.spec.js +5 -5
  30. package/src/templates/utils/__tests__/parseGroups.spec.js +10 -4
  31. package/src/templates/utils/parseFieldOptions.js +4 -5
  32. package/src/templates/utils/parseGroups.js +2 -3
@@ -1,95 +1,89 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`<DynamicForm /> matches snapshot for default field 1`] = `
4
- <Fragment>
5
- <FieldGroupSegment
6
- fields={
7
- Array [
8
- Object {
9
- "name": "test",
10
- "required": false,
11
- "value": undefined,
12
- },
13
- ]
14
- }
15
- key="0"
16
- name="test-group"
17
- onFieldChange={[Function]}
18
- />
19
- </Fragment>
4
+ <FieldGroupSegment
5
+ fields={
6
+ Array [
7
+ Object {
8
+ "name": "test",
9
+ "required": false,
10
+ "value": undefined,
11
+ },
12
+ ]
13
+ }
14
+ key="0"
15
+ name="test-group"
16
+ onFieldChange={[Function]}
17
+ />
20
18
  `;
21
19
 
22
20
  exports[`<DynamicForm /> matches snapshot for domain values 1`] = `
23
- <Fragment>
24
- <FieldGroupSegment
25
- fields={
26
- Array [
27
- Object {
28
- "name": "test",
29
- "parsed_values": Array [
30
- Object {
31
- "text": "a",
32
- "value": "a",
33
- },
34
- Object {
35
- "text": "b",
36
- "value": "b",
37
- },
38
- Object {
39
- "text": "c",
40
- "value": "c",
41
- },
42
- ],
43
- "required": false,
44
- "value": undefined,
45
- "values": Object {
46
- "domain": Object {
47
- "1": Array [
48
- "a",
49
- "b",
50
- "c",
51
- ],
52
- },
21
+ <FieldGroupSegment
22
+ fields={
23
+ Array [
24
+ Object {
25
+ "name": "test",
26
+ "parsedValues": Array [
27
+ Object {
28
+ "text": "a",
29
+ "value": "a",
30
+ },
31
+ Object {
32
+ "text": "b",
33
+ "value": "b",
34
+ },
35
+ Object {
36
+ "text": "c",
37
+ "value": "c",
38
+ },
39
+ ],
40
+ "required": false,
41
+ "value": undefined,
42
+ "values": Object {
43
+ "domain": Object {
44
+ "1": Array [
45
+ "a",
46
+ "b",
47
+ "c",
48
+ ],
53
49
  },
54
50
  },
55
- ]
56
- }
57
- key="0"
58
- name="test-group"
59
- onFieldChange={[Function]}
60
- />
61
- </Fragment>
51
+ },
52
+ ]
53
+ }
54
+ key="0"
55
+ name="test-group"
56
+ onFieldChange={[Function]}
57
+ />
62
58
  `;
63
59
 
64
- exports[`<DynamicForm /> matches snapshot for empty content 1`] = `<Fragment />`;
60
+ exports[`<DynamicForm /> matches snapshot for empty content 1`] = `null`;
65
61
 
66
62
  exports[`<DynamicForm /> matches snapshot for role_users values 1`] = `
67
- <Fragment>
68
- <FieldGroupSegment
69
- fields={
70
- Array [
71
- Object {
72
- "name": "test",
73
- "parsed_values": Array [
74
- Object {
75
- "text": "user1",
76
- "value": "user1",
77
- },
78
- ],
79
- "required": false,
80
- "value": undefined,
81
- "values": Object {
82
- "processed_users": Array [
83
- "user1",
84
- ],
85
- "role_users": "role",
63
+ <FieldGroupSegment
64
+ fields={
65
+ Array [
66
+ Object {
67
+ "name": "test",
68
+ "parsedValues": Array [
69
+ Object {
70
+ "text": "user1",
71
+ "value": "user1",
86
72
  },
73
+ ],
74
+ "required": false,
75
+ "value": undefined,
76
+ "values": Object {
77
+ "processed_users": Array [
78
+ "user1",
79
+ ],
80
+ "role_users": "role",
87
81
  },
88
- ]
89
- }
90
- key="0"
91
- name="test-group"
92
- onFieldChange={[Function]}
93
- />
94
- </Fragment>
82
+ },
83
+ ]
84
+ }
85
+ key="0"
86
+ name="test-group"
87
+ onFieldChange={[Function]}
88
+ />
95
89
  `;
@@ -1,24 +1,32 @@
1
1
  import _ from "lodash/fp";
2
2
  import React from "react";
3
+ import { FormattedMessage } from "react-intl";
3
4
  import PropTypes from "prop-types";
4
5
  import { Form } from "semantic-ui-react";
5
6
 
6
7
  export const CheckboxField = ({
7
- field: { name, value, parsed_values, disabled },
8
+ field: { name, value: fieldValue, parsedValues, disabled },
8
9
  onChange,
9
10
  }) =>
10
- parsed_values ? (
11
- parsed_values.map(({ value: parsed_value, text }, i) => (
11
+ parsedValues ? (
12
+ parsedValues.map(({ value, text }, i) => (
12
13
  <Form.Checkbox
13
14
  name={name}
14
15
  key={i}
15
- label={text}
16
- value={parsed_value}
17
- checked={_.isArray(value) && _.includes(parsed_value)(value)}
16
+ label={
17
+ text ? (
18
+ <FormattedMessage
19
+ id={`fields.${name}.${text}`}
20
+ defaultMessage={text}
21
+ />
22
+ ) : null
23
+ }
24
+ value={value}
25
+ checked={_.isArray(fieldValue) && _.includes(value)(fieldValue)}
18
26
  onChange={(e, { checked, value: thisValue, ...changes }) => {
19
27
  const newValue = checked
20
- ? _.concat(thisValue)(value || [])
21
- : _.pull(thisValue)(value || []);
28
+ ? _.concat(thisValue)(fieldValue || [])
29
+ : _.pull(thisValue)(fieldValue || []);
22
30
  onChange(e, { ...changes, value: newValue });
23
31
  }}
24
32
  />
@@ -26,7 +34,7 @@ export const CheckboxField = ({
26
34
  ) : (
27
35
  <Form.Checkbox
28
36
  name={name}
29
- checked={value == "Si"}
37
+ checked={fieldValue === "Si"}
30
38
  onChange={(e, data) => {
31
39
  const { checked } = data;
32
40
  const value = checked ? "Si" : "No";
@@ -74,7 +74,9 @@ export const DynamicField = ({
74
74
  }) => (
75
75
  <Form.Field>
76
76
  <label>
77
- {label}
77
+ {label ? (
78
+ <FormattedMessage id={`fields.${label}`} defaultMessage={label} />
79
+ ) : null}
78
80
  {fieldProps?.required && (
79
81
  <span
80
82
  style={{
@@ -1,26 +1,34 @@
1
1
  import _ from "lodash/fp";
2
2
  import React from "react";
3
+ import { FormattedMessage } from "react-intl";
3
4
  import PropTypes from "prop-types";
4
5
  import { Form } from "semantic-ui-react";
5
6
 
6
7
  export const RadioField = ({
7
- field: { name, parsed_values, value },
8
- onChange
8
+ field: { name, parsedValues, value: fieldValue },
9
+ onChange,
9
10
  }) =>
10
- _.map.convert({ cap: false })(({ value: parsed_value, text }, i) => (
11
+ _.map.convert({ cap: false })(({ value, text }, i) => (
11
12
  <Form.Radio
12
13
  name={name}
13
14
  key={i}
14
- label={text}
15
- value={parsed_value}
16
- checked={value === parsed_value}
15
+ label={
16
+ text ? (
17
+ <FormattedMessage
18
+ id={`fields.${name}.${text}`}
19
+ defaultMessage={text}
20
+ />
21
+ ) : null
22
+ }
23
+ value={value}
24
+ checked={fieldValue === value}
17
25
  onChange={onChange}
18
26
  />
19
- ))(parsed_values);
27
+ ))(parsedValues);
20
28
 
21
29
  RadioField.propTypes = {
22
30
  field: PropTypes.object,
23
- onChange: PropTypes.func
31
+ onChange: PropTypes.func,
24
32
  };
25
33
 
26
34
  export default RadioField;
@@ -29,11 +29,11 @@ describe("<CheckboxField /> Multiple", () => {
29
29
  const label = "label";
30
30
  const name = "name";
31
31
  const value = [];
32
- const parsed_values = [
32
+ const parsedValues = [
33
33
  { value: "foo", text: "Foo" },
34
- { value: "bar", text: "Bar" }
34
+ { value: "bar", text: "Bar" },
35
35
  ];
36
- const field = { label, name, value, parsed_values };
36
+ const field = { label, name, value, parsedValues };
37
37
  const onChange = jest.fn();
38
38
  const props = { field, onChange };
39
39
 
@@ -44,10 +44,7 @@ describe("<CheckboxField /> Multiple", () => {
44
44
 
45
45
  it("call onChange function for multiple", () => {
46
46
  const wrapper = shallow(<CheckboxField {...props} />);
47
- const checkBox = wrapper
48
- .find(Form.Checkbox)
49
- .first()
50
- .dive();
47
+ const checkBox = wrapper.find(Form.Checkbox).first().dive();
51
48
 
52
49
  checkBox.simulate("change", null, { checked: true, value: "foo" });
53
50
  expect(onChange).toBeCalledWith(null, { value: ["foo"] });
@@ -7,11 +7,11 @@ describe("<RadioField />", () => {
7
7
  const name = "name";
8
8
  const cardinality = "1";
9
9
  const value = "Foo";
10
- const parsed_values = ["Foo", "Bar"];
10
+ const parsedValues = ["Foo", "Bar"];
11
11
  const onChange = jest.fn();
12
12
  const props = {
13
- field: { label, name, cardinality, value, parsed_values },
14
- onChange
13
+ field: { label, name, cardinality, value, parsedValues },
14
+ onChange,
15
15
  };
16
16
 
17
17
  it("matches the latest snapshot", () => {
@@ -7,7 +7,12 @@ Array [
7
7
  checked={false}
8
8
  control={[Function]}
9
9
  key="0"
10
- label="Foo"
10
+ label={
11
+ <Memo(MemoizedFormattedMessage)
12
+ defaultMessage="Foo"
13
+ id="fields.name.Foo"
14
+ />
15
+ }
11
16
  name="name"
12
17
  onChange={[Function]}
13
18
  value="foo"
@@ -17,7 +22,12 @@ Array [
17
22
  checked={false}
18
23
  control={[Function]}
19
24
  key="1"
20
- label="Bar"
25
+ label={
26
+ <Memo(MemoizedFormattedMessage)
27
+ defaultMessage="Bar"
28
+ id="fields.name.Bar"
29
+ />
30
+ }
21
31
  name="name"
22
32
  onChange={[Function]}
23
33
  value="bar"
@@ -7,6 +7,7 @@ Array [
7
7
  checked={false}
8
8
  control={[Function]}
9
9
  key="0"
10
+ label={null}
10
11
  name="name"
11
12
  onChange={[MockFunction]}
12
13
  />,
@@ -15,6 +16,7 @@ Array [
15
16
  checked={false}
16
17
  control={[Function]}
17
18
  key="1"
19
+ label={null}
18
20
  name="name"
19
21
  onChange={[MockFunction]}
20
22
  />,
@@ -5,14 +5,14 @@ describe("selectors: makeGetDropdownOptions", () => {
5
5
  { id: 1, name: "system", external_id: "external_id" },
6
6
  { id: 2, name: "system1", external_id: "external_id1" },
7
7
  ];
8
- const parsed_values = [
8
+ const parsedValues = [
9
9
  { text: "bar", value: "bar" },
10
10
  { text: "foo", value: "foo" },
11
11
  ];
12
12
  const type = "system";
13
13
 
14
14
  it("should return options depending on type", () => {
15
- const field = { parsed_values, type };
15
+ const field = { parsedValues, type };
16
16
  const props = { field };
17
17
  const state = { systems };
18
18
  const getOptions = makeGetDropdownOptions();
@@ -12,7 +12,7 @@ const transformValues = (systems) =>
12
12
  )(systems);
13
13
 
14
14
  const getValuesFromProps = (_state, props) =>
15
- _.path("field.parsed_values")(props);
15
+ _.path("field.parsedValues")(props);
16
16
 
17
17
  const getValuesFromState = (state, _props) => _.pick(["systems"])(state);
18
18
 
@@ -10,11 +10,14 @@ import TemplateForm from "./templateForm/TemplateForm";
10
10
  export const Template = ({ template, updateTemplate, deleteTemplate }) =>
11
11
  _.isUndefined(template.id) ? null : (
12
12
  <>
13
- <TemplateCrumbs name={template.label} />
13
+ <TemplateCrumbs name={template?.label} />
14
14
  <Segment>
15
15
  <Header as="h2">
16
16
  <Icon name="file code outline" circular />
17
- <Header.Content>{template.label}</Header.Content>
17
+ <Header.Content>
18
+ {template?.label}
19
+ <Header.Subheader>{template?.name}</Header.Subheader>
20
+ </Header.Content>
18
21
  </Header>
19
22
  <TemplateForm
20
23
  template={template}
@@ -27,7 +30,9 @@ export const Template = ({ template, updateTemplate, deleteTemplate }) =>
27
30
  );
28
31
 
29
32
  Template.propTypes = {
33
+ deleteTemplate: PropTypes.func,
30
34
  template: PropTypes.object,
35
+ updateTemplate: PropTypes.func,
31
36
  };
32
37
 
33
38
  const mapStateToProps = ({ template }) => ({ template });
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  import PropTypes from "prop-types";
3
+ import { FormattedMessage } from "react-intl";
3
4
  import { useHistory } from "react-router-dom";
4
5
  import { Icon, Card } from "semantic-ui-react";
5
6
  import { linkTo } from "@truedat/core/routes";
@@ -23,7 +24,7 @@ export const TemplateCard = ({ template: { id, name, label } }) => {
23
24
  };
24
25
 
25
26
  TemplateCard.propTypes = {
26
- template: PropTypes.object
27
+ template: PropTypes.object,
27
28
  };
28
29
 
29
30
  export default TemplateCard;
@@ -1,16 +1,18 @@
1
1
  import React from "react";
2
- import { shallow } from "enzyme";
3
- import { Template } from "../Template";
2
+ import { render } from "@truedat/test/render";
3
+ import Template from "../Template";
4
+
5
+ const renderOpts = {
6
+ state: {
7
+ template: { id: 1, label: "My Template", name: "template1" },
8
+ templateDeleting: false,
9
+ templateSaving: false,
10
+ },
11
+ };
4
12
 
5
13
  describe("<Template />", () => {
6
14
  it("matches the latest snapshot", () => {
7
- const updateTemplate = jest.fn();
8
- const template = {
9
- id: 1,
10
- label: "Label"
11
- };
12
- const props = { template, updateTemplate };
13
- const wrapper = shallow(<Template {...props} />);
14
- expect(wrapper).toMatchSnapshot();
15
+ const { container } = render(<Template />, renderOpts);
16
+ expect(container).toMatchSnapshot();
15
17
  });
16
18
  });