@truedat/audit 4.43.1 → 4.43.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
+ ## [4.43.3] 2022-05-04
4
+
5
+ ### Changed
6
+
7
+ - [TD-3936] Updated `react-hook-form`, refactored `SubscriptionForm`
8
+
3
9
  ## [4.38.4] 2022-02-20
4
10
 
5
11
  ### Fixed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/audit",
3
- "version": "4.43.1",
3
+ "version": "4.43.4",
4
4
  "description": "Truedat Web Audit Module",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -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.43.1",
37
+ "@truedat/test": "4.43.4",
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,13 +84,13 @@
84
84
  ]
85
85
  },
86
86
  "dependencies": {
87
- "@truedat/auth": "4.43.1",
88
- "@truedat/core": "4.43.1",
87
+ "@truedat/auth": "4.43.4",
88
+ "@truedat/core": "4.43.4",
89
89
  "axios": "^0.19.2",
90
90
  "path-to-regexp": "^1.7.0",
91
91
  "prop-types": "^15.7.2",
92
92
  "react-color": "^2.17.3",
93
- "react-hook-form": "^6.15.8",
93
+ "react-hook-form": "^7.30.0",
94
94
  "react-intl": "^5.20.10",
95
95
  "react-redux": "^7.2.4",
96
96
  "react-router-dom": "^5.2.0",
@@ -105,5 +105,5 @@
105
105
  "react-dom": ">= 16.8.6 < 17",
106
106
  "semantic-ui-react": ">= 0.88.2 < 2.1"
107
107
  },
108
- "gitHead": "7ea6f37972e3a70706913ada33751b955313801f"
108
+ "gitHead": "7f0463a65a0b8137f1598487bf26fefa52e5fa59"
109
109
  }
@@ -1,10 +1,11 @@
1
1
  import _ from "lodash/fp";
2
2
  import React, { useEffect } from "react";
3
- import { Controller } from "react-hook-form";
3
+ import { Controller, useWatch } from "react-hook-form";
4
4
  import PropTypes from "prop-types";
5
5
  import { Form } from "semantic-ui-react";
6
6
  import { useIntl } from "react-intl";
7
7
  import { connect } from "react-redux";
8
+ import { CONCEPT_EVENTS, isSubset } from "../subscriptionConstants";
8
9
 
9
10
  const toTemplateOptions = (templates) =>
10
11
  _.flow(
@@ -49,10 +50,18 @@ export const ContentFilters = ({
49
50
  conceptType,
50
51
  control,
51
52
  setValue,
52
- watch,
53
53
  templates,
54
54
  }) => {
55
55
  const { formatMessage } = useIntl();
56
+ const [templateId, filterName, filtersEnabled, events] = useWatch({
57
+ control,
58
+ name: [
59
+ "scope.filters.template.id",
60
+ "scope.filters.content.name",
61
+ "filtersEnabled",
62
+ "scope.events",
63
+ ],
64
+ });
56
65
 
57
66
  useEffect(() => {
58
67
  if (conceptType) {
@@ -63,9 +72,6 @@ export const ContentFilters = ({
63
72
  }
64
73
  }, [conceptType, setValue, templates]);
65
74
 
66
- const templateId = watch("scope.filters.template.id");
67
- const filterName = watch("scope.filters.content.name");
68
-
69
75
  const setDefaultCondition = () => {
70
76
  setValue("scope.filters.content.name", null, {
71
77
  shouldValidate: true,
@@ -86,124 +92,129 @@ export const ContentFilters = ({
86
92
  const fieldOptions = toFieldOptions(fields);
87
93
  const valueOptions = toValueOptions(field);
88
94
 
89
- return (
95
+ return isSubset(events, CONCEPT_EVENTS) ? (
90
96
  <>
91
97
  <Controller
92
98
  control={control}
93
- name="scope.filters.template.id"
94
- defaultValue={null}
95
- render={({ onChange }) => (
96
- <Form.Dropdown
97
- clearable
98
- disabled={
99
- _.isEmpty(templateOptions) || _.negate(_.isNil)(conceptType)
100
- }
101
- label={formatMessage({
102
- id: "subscriptions.template.label",
103
- })}
104
- placeholder={formatMessage({
105
- id: "subscriptions.template.placeholder",
106
- })}
107
- fluid
108
- options={templateOptions}
109
- onChange={(e, { value }) => {
110
- setDefaultCondition();
111
- value === "" ? onChange(null) : onChange(value);
112
- }}
113
- search
114
- selection
115
- value={templateId}
99
+ name="filtersEnabled"
100
+ render={({ field: { onBlur, onChange, value } }) => (
101
+ <Form.Radio
102
+ checked={value}
103
+ onBlur={onBlur}
104
+ onChange={(_e, { checked }) => onChange(checked)}
105
+ label={formatMessage({ id: "subscriptions.selectFilters" })}
106
+ toggle
116
107
  />
117
108
  )}
118
109
  />
119
- <Form.Group widths="equal">
120
- <Controller
121
- control={control}
122
- defaultValue={null}
123
- name="scope.filters.content.name"
124
- rules={{
125
- validate: {
126
- requiredOnTemplate: (value) =>
127
- _.negate(_.isNil)(templateId) && _.negate(_.isNil)(value),
128
- },
129
- }}
130
- render={({ onChange, value }) =>
131
- templateId ? (
110
+ {filtersEnabled ? (
111
+ <>
112
+ <Controller
113
+ control={control}
114
+ name="scope.filters.template.id"
115
+ defaultValue={null}
116
+ render={({ field: { onChange } }) => (
132
117
  <Form.Dropdown
133
118
  clearable
134
- disabled={_.isEmpty(fieldOptions)}
135
- label={formatMessage({
136
- id: "subscriptions.template.field",
137
- })}
119
+ disabled={_.isEmpty(templateOptions) || !_.isNil(conceptType)}
120
+ label={formatMessage({ id: "subscriptions.template.label" })}
138
121
  placeholder={formatMessage({
139
- id: "subscriptions.template.field.placeholder",
122
+ id: "subscriptions.template.placeholder",
140
123
  })}
141
124
  fluid
142
- options={fieldOptions}
143
- onChange={(_e, { value }) => {
144
- setValue("scope.filters.content.value", null, {
145
- shouldValidate: true,
146
- shouldDirty: true,
147
- });
125
+ options={templateOptions}
126
+ onChange={(e, { value }) => {
127
+ setDefaultCondition();
148
128
  value === "" ? onChange(null) : onChange(value);
149
129
  }}
150
- required={_.negate(_.isNil)(templateId)}
151
130
  search
152
131
  selection
153
- value={value}
132
+ value={templateId}
154
133
  />
155
- ) : null
156
- }
157
- />
158
- <Controller
159
- control={control}
160
- defaultValue={null}
161
- name="scope.filters.content.value"
162
- rules={{
163
- validate: {
164
- requiredOnTemplate: (value) =>
165
- _.negate(_.isNil)(templateId) && _.negate(_.isNil)(value),
166
- },
167
- }}
168
- render={({ onChange, value }) =>
169
- templateId ? (
170
- <Form.Dropdown
171
- clearable
172
- required={_.negate(_.isNil)(templateId)}
173
- disabled={_.isEmpty(valueOptions)}
174
- label={formatMessage({
175
- id: "subscriptions.template.field.value",
176
- })}
177
- placeholder={formatMessage({
178
- id: "subscriptions.template.field.value.placeholder",
179
- })}
180
- fluid
181
- options={valueOptions}
182
- onChange={(_e, { value }) =>
183
- value === "" ? onChange(null) : onChange(value)
184
- }
185
- search
186
- selection
187
- value={value}
188
- />
189
- ) : null
190
- }
191
- />
192
- </Form.Group>
134
+ )}
135
+ />
136
+ <Form.Group widths="equal">
137
+ <Controller
138
+ control={control}
139
+ name="scope.filters.content.name"
140
+ defaultValue={null}
141
+ rules={{
142
+ validate: {
143
+ requiredOnTemplate: (value) =>
144
+ !_.isNil(templateId) && !_.isNil(value),
145
+ },
146
+ }}
147
+ render={({ field: { onChange, value } }) => (
148
+ <Form.Dropdown
149
+ clearable
150
+ disabled={!templateId || _.isEmpty(fieldOptions)}
151
+ label={formatMessage({
152
+ id: "subscriptions.template.field",
153
+ })}
154
+ placeholder={formatMessage({
155
+ id: "subscriptions.template.field.placeholder",
156
+ })}
157
+ fluid
158
+ options={fieldOptions}
159
+ onChange={(_e, { value }) => {
160
+ setValue("scope.filters.content.value", null, {
161
+ shouldValidate: true,
162
+ shouldDirty: true,
163
+ });
164
+ value === "" ? onChange(null) : onChange(value);
165
+ }}
166
+ required={!!templateId}
167
+ search
168
+ selection
169
+ value={value}
170
+ />
171
+ )}
172
+ />
173
+ <Controller
174
+ control={control}
175
+ name="scope.filters.content.value"
176
+ defaultValue={null}
177
+ rules={{
178
+ validate: {
179
+ requiredOnTemplate: (value) => !!templateId && !!value,
180
+ },
181
+ }}
182
+ render={({ field: { onChange, value } }) => (
183
+ <Form.Dropdown
184
+ clearable
185
+ required={!!templateId}
186
+ disabled={!templateId || _.isEmpty(valueOptions)}
187
+ label={formatMessage({
188
+ id: "subscriptions.template.field.value",
189
+ })}
190
+ placeholder={formatMessage({
191
+ id: "subscriptions.template.field.value.placeholder",
192
+ })}
193
+ fluid
194
+ options={valueOptions}
195
+ onChange={(_e, { value }) =>
196
+ value === "" ? onChange(null) : onChange(value)
197
+ }
198
+ search
199
+ selection
200
+ value={value}
201
+ />
202
+ )}
203
+ />
204
+ </Form.Group>
205
+ </>
206
+ ) : null}
193
207
  </>
194
- );
208
+ ) : null;
195
209
  };
196
210
 
197
211
  ContentFilters.propTypes = {
198
212
  conceptType: PropTypes.string,
199
213
  control: PropTypes.object.isRequired,
200
214
  setValue: PropTypes.func.isRequired,
201
- watch: PropTypes.func.isRequired,
202
215
  templates: PropTypes.array.isRequired,
203
216
  };
204
217
 
205
- const mapStateToProps = ({ templates }) => ({
206
- templates,
207
- });
218
+ const mapStateToProps = ({ templates }) => ({ templates });
208
219
 
209
220
  export default connect(mapStateToProps)(ContentFilters);