@truedat/dd 4.28.7 → 4.28.8

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
+ ## [4.28.8] 2021-09-20
4
+
5
+ ### Added
6
+
7
+ - [TD-3970] `StructureFieldsDropdown` support for cast type and modifier
8
+
3
9
  ## [4.28.6] 2021-09-20
4
10
 
5
11
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/dd",
3
- "version": "4.28.7",
3
+ "version": "4.28.8",
4
4
  "description": "Truedat Web Data Dictionary",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -16,8 +16,8 @@
16
16
  "scripts": {
17
17
  "clean": "rimraf yarn-error.log",
18
18
  "debug": "node --inspect-brk node_modules/.bin/jest --runInBand",
19
- "test": "jest --coverage",
20
- "test:watch": "jest --watch",
19
+ "test": "TZ=UTC jest --coverage",
20
+ "test:watch": "TZ=UTC jest --watch",
21
21
  "eslint": "eslint src/**",
22
22
  "eslint:fix": "eslint --fix src/**"
23
23
  },
@@ -34,7 +34,7 @@
34
34
  "@testing-library/jest-dom": "^5.14.1",
35
35
  "@testing-library/react": "^12.0.0",
36
36
  "@testing-library/user-event": "^13.2.1",
37
- "@truedat/test": "4.28.7",
37
+ "@truedat/test": "4.28.8",
38
38
  "babel-jest": "^27.0.6",
39
39
  "babel-plugin-dynamic-import-node": "^2.3.3",
40
40
  "babel-plugin-lodash": "^3.3.4",
@@ -84,9 +84,9 @@
84
84
  ]
85
85
  },
86
86
  "dependencies": {
87
- "@truedat/auth": "4.28.7",
88
- "@truedat/core": "4.28.7",
89
- "@truedat/df": "4.28.7",
87
+ "@truedat/auth": "4.28.8",
88
+ "@truedat/core": "4.28.8",
89
+ "@truedat/df": "4.28.8",
90
90
  "lodash": "^4.17.21",
91
91
  "path-to-regexp": "^1.7.0",
92
92
  "prop-types": "^15.7.2",
@@ -107,5 +107,5 @@
107
107
  "react-dom": ">= 16.8.6 < 17",
108
108
  "semantic-ui-react": ">= 0.88.2 < 2.1"
109
109
  },
110
- "gitHead": "d5cfc6f850ec38066139c97836b75d2f21d61d54"
110
+ "gitHead": "33a7f73dd4ffbd31d1df270c8453c3a876412990"
111
111
  }
@@ -6,52 +6,6 @@ import { OptionGroup } from "@truedat/core/components";
6
6
  import { useIntl } from "react-intl";
7
7
  import { getStructuresFields } from "../selectors/getStructuresFields";
8
8
 
9
- const withFilters = (structureFields, filters) =>
10
- filters
11
- ? _.filter((f) =>
12
- _.every.convert({ cap: false })((v, k) => v.includes(_.prop(k)(f)))(
13
- filters
14
- )
15
- )(structureFields)
16
- : structureFields;
17
-
18
- const getOptions = (structureFields, formatMessage) =>
19
- _.flow(
20
- _.sortBy(_.flow(_.prop("name"), _.toLower)),
21
- _.groupBy("label"),
22
- _.reduce.convert({ cap: false })(
23
- (acc, v, k) =>
24
- _.isNil(k) || k === "undefined"
25
- ? [...acc, ...v]
26
- : [...acc, { label: k, options: v }],
27
- []
28
- ),
29
- _.map.convert({ cap: false })((field) =>
30
- toFieldOption(field, formatMessage)
31
- )
32
- )(structureFields);
33
-
34
- const toFieldOption = (field, formatMessage) =>
35
- _.has("options")(field)
36
- ? {
37
- icon: "table",
38
- label: field.label,
39
- options: _.map((field) => formatOption(field, formatMessage))(
40
- field.options
41
- ),
42
- }
43
- : formatOption(field, formatMessage);
44
-
45
- const formatOption = (field, formatMessage) => ({
46
- key: field.data_structure_id,
47
- text: field.name,
48
- value: field.data_structure_id,
49
- icon: formatMessage({
50
- id: `field_type.icon.${field.field_type}`,
51
- defaultMessage: "hashtag",
52
- }),
53
- });
54
-
55
9
  export const StructureFieldsDropdown = ({
56
10
  label,
57
11
  inline,
@@ -59,13 +13,77 @@ export const StructureFieldsDropdown = ({
59
13
  structureFields,
60
14
  filters,
61
15
  value,
16
+ typeCastModifiers,
62
17
  }) => {
63
18
  const { formatMessage } = useIntl();
64
- const onClick = ({ value }) => {
19
+ const onClick = ({ value, modifier }) => {
65
20
  const field = _.find(_.propEq("data_structure_id", value))(structureFields);
66
- onSelectField(field);
21
+ onSelectField(field, modifier);
67
22
  };
68
23
 
24
+ const formatOption = (field) => {
25
+ const modifier = _.find({sourceType: field.field_type})(typeCastModifiers)
26
+ if(modifier){
27
+ return({
28
+ key: field.data_structure_id,
29
+ text: `${field.name} (${formatMessage({
30
+ id: `filtersGrid.field.modifier.${modifier.name}`
31
+ })})`,
32
+ modifier,
33
+ value: field.data_structure_id,
34
+ icon: formatMessage({
35
+ id: `field_type.icon.${field.field_type}`,
36
+ defaultMessage: "hashtag",
37
+ }),
38
+ })
39
+ }
40
+
41
+ return({
42
+ key: field.data_structure_id,
43
+ text: field.name,
44
+ value: field.data_structure_id,
45
+ icon: formatMessage({
46
+ id: `field_type.icon.${field.field_type}`,
47
+ defaultMessage: "hashtag",
48
+ }),
49
+ })
50
+
51
+ };
52
+ const toFieldOption = (field) =>
53
+ _.has("options")(field)
54
+ ? {
55
+ icon: "table",
56
+ label: field.label,
57
+ options: _.map(formatOption)(field.options),
58
+ }
59
+ : formatOption(field);
60
+
61
+ const getOptions = _.flow(
62
+ _.sortBy(_.flow(_.prop("name"), _.toLower)),
63
+ _.groupBy("label"),
64
+ _.reduce.convert({ cap: false })(
65
+ (acc, v, k) =>
66
+ _.isNil(k) || k === "undefined"
67
+ ? [...acc, ...v]
68
+ : [...acc, { label: k, options: v }],
69
+ []
70
+ ),
71
+ _.map(toFieldOption),
72
+ )
73
+
74
+ const castSourceTypes = _.flow(
75
+ _.map(({sourceType})=>sourceType),
76
+ _.uniq
77
+ )(typeCastModifiers)
78
+ const options = _.flow(
79
+ _.filter((f) =>
80
+ _.every.convert({ cap: false })((v, k) => v.includes(_.prop(k)(f)))(
81
+ filters
82
+ ) || castSourceTypes.includes(f.field_type)
83
+ ),
84
+ getOptions
85
+ )(structureFields);
86
+
69
87
  return (
70
88
  <OptionGroup
71
89
  inline={inline}
@@ -75,7 +93,7 @@ export const StructureFieldsDropdown = ({
75
93
  placeholder={formatMessage({
76
94
  id: "structureFields.dropdown.placeholder",
77
95
  })}
78
- options={getOptions(withFilters(structureFields, filters), formatMessage)}
96
+ options={options}
79
97
  />
80
98
  );
81
99
  };
@@ -87,6 +105,7 @@ StructureFieldsDropdown.propTypes = {
87
105
  structureFields: PropTypes.array,
88
106
  onSelectField: PropTypes.func,
89
107
  filters: PropTypes.object,
108
+ typeCastModifiers: PropTypes.array,
90
109
  };
91
110
 
92
111
  const mapStateToProps = (state, props) => ({
@@ -52,7 +52,7 @@ describe("<ValueConditionStructure />", () => {
52
52
  data_structure_id: 2,
53
53
  field_type: "string",
54
54
  label: "bar",
55
- });
55
+ }, undefined);
56
56
  });
57
57
  });
58
58
  });