@truedat/df 8.7.2 → 8.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/df",
3
- "version": "8.7.2",
3
+ "version": "8.7.4",
4
4
  "description": "Truedat Web Data Quality Module",
5
5
  "sideEffects": false,
6
6
  "module": "src/index.js",
@@ -51,14 +51,14 @@
51
51
  "@testing-library/jest-dom": "^6.6.3",
52
52
  "@testing-library/react": "^16.3.0",
53
53
  "@testing-library/user-event": "^14.6.1",
54
- "@truedat/test": "8.7.2",
54
+ "@truedat/test": "8.7.4",
55
55
  "identity-obj-proxy": "^3.0.0",
56
56
  "jest": "^29.7.0",
57
57
  "redux-saga-test-plan": "^4.0.6"
58
58
  },
59
59
  "dependencies": {
60
60
  "@apollo/client": "^3.13.8",
61
- "@truedat/core": "8.7.2",
61
+ "@truedat/core": "8.7.4",
62
62
  "axios": "^1.15.0",
63
63
  "graphql": "^16.11.0",
64
64
  "is-hotkey": "^0.2.0",
@@ -87,5 +87,5 @@
87
87
  "semantic-ui-react": "^3.0.0-beta.2",
88
88
  "swr": "^2.3.3"
89
89
  },
90
- "gitHead": "e971cd8773dc15ad949f260abbfe4d3236473af7"
90
+ "gitHead": "74bf59ddf29e05b518dc206271c4f1215d66a942"
91
91
  }
@@ -11,6 +11,7 @@ export const DynamicForm = ({
11
11
  applyTemplate,
12
12
  content,
13
13
  fieldsToOmit,
14
+ instanceId,
14
15
  isModification,
15
16
  loading,
16
17
  onChange,
@@ -21,15 +22,22 @@ export const DynamicForm = ({
21
22
  const { formatMessage } = useIntl();
22
23
  const domainId = selectedDomain?.id;
23
24
  const domainIds = selectedDomain?.ids;
24
- const appliedContentRef = useRef(null);
25
+ const appliedKeyRef = useRef(null);
26
+ const latestContentRef = useRef(content);
25
27
 
26
28
  useEffect(() => {
27
29
  if (!_.isEmpty(template)) {
30
+ const templateId = template?.id || template?.name;
28
31
  const domainKey = JSON.stringify(domainIds || domainId);
29
- const currentApplied = appliedContentRef.current;
30
- if (currentApplied !== domainKey) {
31
- appliedContentRef.current = domainKey;
32
- const newContent = applyTemplate(content, domainIds || domainId);
32
+ const compositeKey = `${templateId}::${domainKey}`;
33
+ if (appliedKeyRef.current !== compositeKey) {
34
+ const wasAlreadyApplied = appliedKeyRef.current !== null;
35
+ appliedKeyRef.current = compositeKey;
36
+ const newContent = applyTemplate(
37
+ wasAlreadyApplied ? {} : content,
38
+ domainIds || domainId,
39
+ );
40
+ latestContentRef.current = newContent;
33
41
  onChange(newContent);
34
42
  }
35
43
  }
@@ -47,10 +55,18 @@ export const DynamicForm = ({
47
55
 
48
56
  const handleChange = (e, { name, value }) => {
49
57
  e && e.preventDefault();
58
+ const fieldName =
59
+ instanceId && name.startsWith(`${instanceId}_`)
60
+ ? name.slice(instanceId.length + 1)
61
+ : name;
50
62
  const newContent = applyTemplate(
51
- { ...content, [name]: { value: value, origin: "user" } },
63
+ {
64
+ ...latestContentRef.current,
65
+ [fieldName]: { value: value, origin: "user" },
66
+ },
52
67
  domainIds || domainId,
53
68
  );
69
+ latestContentRef.current = newContent;
54
70
  onChange(newContent);
55
71
  };
56
72
 
@@ -63,6 +79,7 @@ export const DynamicForm = ({
63
79
 
64
80
  return parsedGroups.map(({ name, fields }, i) => (
65
81
  <FieldGroupSegment
82
+ instanceId={instanceId}
66
83
  key={i}
67
84
  name={
68
85
  name
@@ -85,6 +102,7 @@ DynamicForm.propTypes = {
85
102
  applyTemplate: PropTypes.func,
86
103
  content: PropTypes.object,
87
104
  fieldsToOmit: PropTypes.array,
105
+ instanceId: PropTypes.string,
88
106
  isModification: PropTypes.bool,
89
107
  loading: PropTypes.bool,
90
108
  onChange: PropTypes.func,
@@ -4,6 +4,7 @@ import { Segment, Header } from "semantic-ui-react";
4
4
  import DynamicField from "./widgets/DynamicField";
5
5
 
6
6
  export const FieldGroupSegment = ({
7
+ instanceId,
7
8
  scope,
8
9
  fields,
9
10
  isModification,
@@ -16,6 +17,7 @@ export const FieldGroupSegment = ({
16
17
  {fields &&
17
18
  fields.map((field, i) => (
18
19
  <DynamicField
20
+ instanceId={instanceId}
19
21
  scope={scope}
20
22
  field={{
21
23
  ...field,
@@ -36,6 +38,7 @@ export const FieldGroupSegment = ({
36
38
 
37
39
  FieldGroupSegment.propTypes = {
38
40
  fields: PropTypes.array,
41
+ instanceId: PropTypes.string,
39
42
  isModification: PropTypes.bool,
40
43
  name: PropTypes.string,
41
44
  onFieldChange: PropTypes.func,
@@ -1,10 +1,26 @@
1
1
  import _ from "lodash/fp";
2
- import { useState } from "react";
2
+ import { useState, useRef, useEffect } from "react";
3
3
  import PropTypes from "prop-types";
4
+ import { useQuery } from "@apollo/client";
5
+ import { TEMPLATES_QUERY } from "@truedat/core/api/queries";
4
6
  import { TemplateSelector } from "@truedat/core/components";
5
7
  import { validateContent } from "@truedat/df/utils";
6
8
  import DynamicForm from "./DynamicForm";
7
9
 
10
+ const TemplateQueryFetcher = ({ scope, domainIds, onLoad }) => {
11
+ const onLoadRef = useRef(onLoad);
12
+ onLoadRef.current = onLoad;
13
+
14
+ useQuery(TEMPLATES_QUERY, {
15
+ fetchPolicy: "cache-and-network",
16
+ variables: { scope, domainIds },
17
+ onCompleted: (data) => {
18
+ onLoadRef.current(data);
19
+ },
20
+ });
21
+ return null;
22
+ };
23
+
8
24
  export default function SelectableDynamicForm({
9
25
  content,
10
26
  domainIds,
@@ -28,7 +44,15 @@ export default function SelectableDynamicForm({
28
44
  selectedTemplate,
29
45
  }) {
30
46
  const [thisTemplate, setThisTemplate] = useState();
31
- const template = selectedTemplate || thisTemplate;
47
+ const instanceId = useRef(
48
+ `sdf-${Math.random().toString(36).substring(2, 9)}`,
49
+ ).current;
50
+
51
+ useEffect(() => {
52
+ setThisTemplate(undefined);
53
+ }, [selectedTemplate]);
54
+
55
+ const template = thisTemplate || selectedTemplate;
32
56
  const domainIdsArray = _.size(domainIds) > 0 ? domainIds : null;
33
57
  const domain = domainIdsArray
34
58
  ? { id: _.head(domainIdsArray), ids: domainIdsArray }
@@ -40,16 +64,16 @@ export default function SelectableDynamicForm({
40
64
 
41
65
  const handleLoad = ({ templates }) => {
42
66
  if (selectedTemplate) return;
43
- const template = name
67
+ const foundTemplate = name
44
68
  ? _.find(_.propEq("name", name))(templates)
45
69
  : _.size(templates) == 1
46
70
  ? _.head(templates)
47
71
  : null;
48
- if (template?.name !== name) {
49
- onNameChange(template?.name);
50
- onTemplateChange(template);
72
+ if (foundTemplate?.name !== name) {
73
+ onNameChange(foundTemplate?.name);
74
+ onTemplateChange(foundTemplate);
51
75
  }
52
- setThisTemplate(template);
76
+ setThisTemplate(foundTemplate);
53
77
  };
54
78
 
55
79
  const handleSelected = (_e, { template }) => {
@@ -60,7 +84,14 @@ export default function SelectableDynamicForm({
60
84
 
61
85
  return (
62
86
  <>
63
- {(!actionKey || actionKey == "create") && !disableSelector ? (
87
+ {disableSelector && scope && domainIds ? (
88
+ <TemplateQueryFetcher
89
+ scope={scope}
90
+ domainIds={domainIds}
91
+ onLoad={handleLoad}
92
+ />
93
+ ) : null}
94
+ {(!actionKey || actionKey == "create") && !disableSelector && scope ? (
64
95
  <TemplateSelector
65
96
  scope={scope}
66
97
  domainIds={domainIds}
@@ -81,6 +112,7 @@ export default function SelectableDynamicForm({
81
112
  {header}
82
113
  <DynamicForm
83
114
  content={content}
115
+ instanceId={instanceId}
84
116
  selectedDomain={domain}
85
117
  template={template}
86
118
  noTranslatableFields={noTranslatableFields}
@@ -3,13 +3,13 @@ import PropTypes from "prop-types";
3
3
  import { Form } from "semantic-ui-react";
4
4
 
5
5
  export const CheckboxField = ({
6
- field: { name, value: fieldValue, parsedValues, disabled },
6
+ field: { name, value: fieldValue, parsedValues, disabled, instanceId },
7
7
  onChange,
8
8
  }) =>
9
9
  parsedValues ? (
10
10
  parsedValues.map(({ value, text }, i) => (
11
11
  <Form.Checkbox
12
- name={name}
12
+ name={instanceId ? `${instanceId}_${name}` : name}
13
13
  key={i}
14
14
  label={text}
15
15
  value={value}
@@ -24,7 +24,7 @@ export const CheckboxField = ({
24
24
  ))
25
25
  ) : (
26
26
  <Form.Checkbox
27
- name={name}
27
+ name={instanceId ? `${instanceId}_${name}` : name}
28
28
  checked={fieldValue === "Si"}
29
29
  onChange={(e, data) => {
30
30
  const { checked } = data;
@@ -19,6 +19,7 @@ export const DynamicField = ({
19
19
  disabled = false,
20
20
  ...fieldProps
21
21
  },
22
+ instanceId,
22
23
  isModification,
23
24
  onChange,
24
25
  scope,
@@ -87,7 +88,7 @@ export const DynamicField = ({
87
88
  ) : null}
88
89
  </label>
89
90
  <FieldByWidget
90
- field={{ ...fieldProps, value, cardinality }}
91
+ field={{ ...fieldProps, value, cardinality, instanceId }}
91
92
  onChange={onChange}
92
93
  scope={scope}
93
94
  widget={_.prop("widget")(fieldProps)}
@@ -98,6 +99,7 @@ export const DynamicField = ({
98
99
 
99
100
  DynamicField.propTypes = {
100
101
  field: PropTypes.object.isRequired,
102
+ instanceId: PropTypes.string,
101
103
  isModification: PropTypes.bool,
102
104
  onChange: PropTypes.func.isRequired,
103
105
  scope: PropTypes.string,
@@ -3,12 +3,12 @@ import PropTypes from "prop-types";
3
3
  import { Form } from "semantic-ui-react";
4
4
 
5
5
  export const RadioField = ({
6
- field: { name, parsedValues, value: fieldValue },
6
+ field: { name, parsedValues, value: fieldValue, instanceId },
7
7
  onChange,
8
8
  }) =>
9
9
  _.map.convert({ cap: false })(({ value, text }, i) => (
10
10
  <Form.Radio
11
- name={name}
11
+ name={instanceId ? `${instanceId}_${name}` : name}
12
12
  key={i}
13
13
  label={text}
14
14
  value={value}