@k-int/stripes-kint-components 2.3.0 → 2.3.3

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,3 +1,16 @@
1
+ ## 2.3.3 2022-04-04
2
+ * Fixed inconsistent `retiredName` labelOverride function behaviour, where in `filters` the function accepted the name, and in `view` the function accepted the entire object. The behaviour has been standardised to be the name alone in both scenarios.
3
+ * Fixed improper custom property count behaviour in view mode, now only _set_ primary properties are included in the count.
4
+
5
+ ## 2.3.2 2022-04-01
6
+ * Fix to actionAssigner callback pattern
7
+ * Tweak to remove marginBottom0 warning
8
+ * FormModal buttons have marginBottom0 prop on them now
9
+ * Fixed issue where cusotm property updates would not be reflected on the open view pane in settings
10
+
11
+ ## 2.3.1 2022-03-28
12
+ * Custom Property component fixes
13
+
1
14
  ## 2.3.0 2022-03-25
2
15
  * FormModal
3
16
  * Ability to override labels for "save" and "cancel"
@@ -137,14 +137,14 @@ var ActionListFieldArray = function ActionListFieldArray(_ref) {
137
137
  };
138
138
 
139
139
  var handleSave = function handleSave(index) {
140
- var _actionAssigner$find;
140
+ var _actionAssigner, _actionAssigner$find;
141
141
 
142
142
  var _fields$value$index = fields.value[index],
143
143
  _a = _fields$value$index.actionListActions,
144
144
  rowData = _objectWithoutProperties(_fields$value$index, _excluded2); // Find "edit" entry in actionAssigner
145
145
 
146
146
 
147
- var editCallback = (_actionAssigner$find = actionAssigner.find(function (act) {
147
+ var editCallback = (_actionAssigner = actionAssigner(rowData)) === null || _actionAssigner === void 0 ? void 0 : (_actionAssigner$find = _actionAssigner.find(function (act) {
148
148
  return act.name === 'edit';
149
149
  })) === null || _actionAssigner$find === void 0 ? void 0 : _actionAssigner$find.callback;
150
150
 
@@ -255,7 +255,6 @@ var ActionListFieldArray = function ActionListFieldArray(_ref) {
255
255
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.IconButton, {
256
256
  disabled: editing,
257
257
  icon: action.icon,
258
- marginBottom0: true,
259
258
  onClick: function onClick() {
260
259
  return actionFunction ? actionFunction() : function () {
261
260
  return null;
@@ -134,20 +134,23 @@ var CustomPropertiesSettings = function CustomPropertiesSettings(_ref) {
134
134
 
135
135
  var _useMutateCustomPrope = (0, _hooks.useMutateCustomProperties)({
136
136
  afterQueryCalls: {
137
- put: function put() {
137
+ put: function put(res) {
138
138
  setMode(VIEWING);
139
139
  queryClient.invalidateQueries(['stripes-kint-components', 'useCustomProperties', 'custprops']);
140
- afterQueryCallsSafe.put();
140
+ setCustomProperty(res);
141
+ afterQueryCallsSafe.put(res);
141
142
  },
142
- post: function post() {
143
+ post: function post(res) {
143
144
  setMode(VIEWING);
144
145
  queryClient.invalidateQueries(['stripes-kint-components', 'useCustomProperties', 'custprops']);
145
- afterQueryCallsSafe.post();
146
+ setCustomProperty(res);
147
+ afterQueryCallsSafe.post(res);
146
148
  },
147
- delete: function _delete() {
149
+ delete: function _delete(res) {
148
150
  setMode(VIEWING);
149
151
  queryClient.invalidateQueries(['stripes-kint-components', 'useCustomProperties', 'custprops']);
150
- afterQueryCallsSafe.delete();
152
+ setCustomProperty();
153
+ afterQueryCallsSafe.delete(res);
151
154
  }
152
155
  },
153
156
  endpoint: customPropertiesEndpoint,
@@ -55,7 +55,8 @@ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoader
55
55
  var CustomPropertiesFilterField = function CustomPropertiesFilterField(_ref) {
56
56
  var _labelOverrides$custo, _customProperties$fin, _customProperties$fin2, _fields$value$index2;
57
57
 
58
- var customProperties = _ref.customProperties,
58
+ var _ref$customProperties = _ref.customProperties,
59
+ customProperties = _ref$customProperties === void 0 ? [] : _ref$customProperties,
59
60
  fields = _ref.fields,
60
61
  index = _ref.index,
61
62
  _ref$labelOverrides = _ref.labelOverrides,
@@ -41,10 +41,11 @@ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoader
41
41
  };
42
42
 
43
43
  var CustomPropertiesViewCtx = function CustomPropertiesViewCtx(_ref) {
44
- var _custprops$filter$len, _custprops$filter, _Object$entries$filte, _Object$entries, _Object$entries$filte2;
44
+ var _custprops$filter$len, _custprops$filter;
45
45
 
46
46
  var ctx = _ref.ctx,
47
- customProperties = _ref.customProperties,
47
+ _ref$customProperties = _ref.customProperties,
48
+ customProperties = _ref$customProperties === void 0 ? [] : _ref$customProperties,
48
49
  customPropertiesEndpoint = _ref.customPropertiesEndpoint,
49
50
  id = _ref.id,
50
51
  labelOverrides = _ref.labelOverrides;
@@ -111,30 +112,37 @@ var CustomPropertiesViewCtx = function CustomPropertiesViewCtx(_ref) {
111
112
  label: getAccordionLabel(),
112
113
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Spinner, {})
113
114
  });
114
- } // We need to display any set properties, along with any non-set primary properties
115
+ }
116
+
117
+ var countSetProperties = function countSetProperties(primary) {
118
+ var _Object$entries$filte, _Object$entries, _Object$entries$filte2;
119
+
120
+ return (_Object$entries$filte = (_Object$entries = Object.entries(customProperties)) === null || _Object$entries === void 0 ? void 0 : (_Object$entries$filte2 = _Object$entries.filter(function (_ref2) {
121
+ var _cp$, _cp$$type, _cp$2, _cp$2$type, _cp$3, _cp$3$type;
122
+
123
+ var _ref3 = _slicedToArray(_ref2, 2),
124
+ _key = _ref3[0],
125
+ cp = _ref3[1];
126
+
127
+ return (((_cp$ = cp[0]) === null || _cp$ === void 0 ? void 0 : (_cp$$type = _cp$.type) === null || _cp$$type === void 0 ? void 0 : _cp$$type.ctx) === ctx || ctx === 'isNull' && !((_cp$2 = cp[0]) !== null && _cp$2 !== void 0 && (_cp$2$type = _cp$2.type) !== null && _cp$2$type !== void 0 && _cp$2$type.ctx)) && // Either the ctx string matches, or isNull matches blank
128
+ ((_cp$3 = cp[0]) === null || _cp$3 === void 0 ? void 0 : (_cp$3$type = _cp$3.type) === null || _cp$3$type === void 0 ? void 0 : _cp$3$type.primary) === primary // Only count non-primary set custprops
129
+ ;
130
+ })) === null || _Object$entries$filte2 === void 0 ? void 0 : _Object$entries$filte2.length) !== null && _Object$entries$filte !== void 0 ? _Object$entries$filte : 0;
131
+ }; // We need to display any set properties, along with any non-set primary properties
115
132
 
116
133
 
117
134
  var primaryCount = (_custprops$filter$len = custprops === null || custprops === void 0 ? void 0 : (_custprops$filter = custprops.filter(function (cp) {
118
135
  return cp.primary === true;
119
136
  })) === null || _custprops$filter === void 0 ? void 0 : _custprops$filter.length) !== null && _custprops$filter$len !== void 0 ? _custprops$filter$len : 0;
120
- var optionalCount = (_Object$entries$filte = (_Object$entries = Object.entries(customProperties)) === null || _Object$entries === void 0 ? void 0 : (_Object$entries$filte2 = _Object$entries.filter(function (_ref2) {
121
- var _cp$, _cp$$type, _cp$2, _cp$2$type, _cp$3, _cp$3$type;
122
-
123
- var _ref3 = _slicedToArray(_ref2, 2),
124
- _key = _ref3[0],
125
- cp = _ref3[1];
126
-
127
- return (((_cp$ = cp[0]) === null || _cp$ === void 0 ? void 0 : (_cp$$type = _cp$.type) === null || _cp$$type === void 0 ? void 0 : _cp$$type.ctx) === ctx || ctx === 'isNull' && !((_cp$2 = cp[0]) !== null && _cp$2 !== void 0 && (_cp$2$type = _cp$2.type) !== null && _cp$2$type !== void 0 && _cp$2$type.ctx)) && // Either the ctx string matches, or isNull matches blank
128
- ((_cp$3 = cp[0]) === null || _cp$3 === void 0 ? void 0 : (_cp$3$type = _cp$3.type) === null || _cp$3$type === void 0 ? void 0 : _cp$3$type.primary) === false // Only count non-primary set custprops
129
- ;
130
- })) === null || _Object$entries$filte2 === void 0 ? void 0 : _Object$entries$filte2.length) !== null && _Object$entries$filte !== void 0 ? _Object$entries$filte : 0;
137
+ var optionalCount = countSetProperties(false);
138
+ var setPrimaryCount = countSetProperties(true);
131
139
  return primaryCount + optionalCount > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Accordion, {
132
140
  closedByDefault: true,
133
141
  displayWhenClosed: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Badge, {
134
- children: primaryCount + optionalCount
142
+ children: setPrimaryCount + optionalCount
135
143
  }),
136
144
  displayWhenOpen: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Badge, {
137
- children: primaryCount + optionalCount
145
+ children: setPrimaryCount + optionalCount
138
146
  }),
139
147
  id: "".concat(id, "-accordion-").concat(ctx),
140
148
  label: getAccordionLabel(),
@@ -37,7 +37,8 @@ var CustomPropertyCard = function CustomPropertyCard(_ref) {
37
37
 
38
38
  var ctx = _ref.ctx,
39
39
  customProperty = _ref.customProperty,
40
- customPropertyDefinition = _ref.customPropertyDefinition,
40
+ _ref$customPropertyDe = _ref.customPropertyDefinition,
41
+ customPropertyDefinition = _ref$customPropertyDe === void 0 ? {} : _ref$customPropertyDe,
41
42
  index = _ref.index,
42
43
  labelOverrides = _ref.labelOverrides;
43
44
  // We only need to display primary and set properties
@@ -54,7 +55,7 @@ var CustomPropertyCard = function CustomPropertyCard(_ref) {
54
55
 
55
56
  // Label override for default card title,
56
57
  if (labelOverrides.retiredName && typeof labelOverrides.retiredName === 'function') {
57
- return labelOverrides.retiredName(customPropertyDefinition);
58
+ return labelOverrides.retiredName(customPropertyDefinition.name);
58
59
  } // Label override for default title or finally built in default
59
60
 
60
61
 
@@ -75,11 +75,13 @@ var FormModal = function FormModal(_ref) {
75
75
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.ModalFooter, {
76
76
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
77
77
  buttonStyle: "primary",
78
+ marginBottom0: true,
78
79
  onClick: handleSubmit,
79
80
  children: (_labelOverrides$save = labelOverrides.save) !== null && _labelOverrides$save !== void 0 ? _labelOverrides$save : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
80
81
  id: "stripes-kint-components.save"
81
82
  })
82
83
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
84
+ marginBottom0: true,
83
85
  onClick: handleClose,
84
86
  children: (_labelOverrides$cance = labelOverrides.cancel) !== null && _labelOverrides$cance !== void 0 ? _labelOverrides$cance : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
85
87
  id: "stripes-kint-components.cancel"
@@ -32,7 +32,8 @@ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoader
32
32
  return a;
33
33
  };
34
34
 
35
- var groupCustomPropertiesByCtx = function groupCustomPropertiesByCtx(customProperties) {
35
+ var groupCustomPropertiesByCtx = function groupCustomPropertiesByCtx() {
36
+ var customProperties = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
36
37
  return customProperties.reduce(function (acc, curr) {
37
38
  var _curr$ctx, _acc$ctx;
38
39
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k-int/stripes-kint-components",
3
- "version": "2.3.0",
3
+ "version": "2.3.3",
4
4
  "description": "Stripes Component library for K-Int specific applications",
5
5
  "sideEffects": [
6
6
  "*.css"
@@ -61,7 +61,7 @@ const ActionListFieldArray = ({
61
61
  const { actionListActions: _a, ...rowData } = fields.value[index];
62
62
 
63
63
  // Find "edit" entry in actionAssigner
64
- const editCallback = actionAssigner.find(act => act.name === 'edit')?.callback;
64
+ const editCallback = actionAssigner(rowData)?.find(act => act.name === 'edit')?.callback;
65
65
  if (editCallback) {
66
66
  editCallback(rowData);
67
67
  } else {
@@ -167,7 +167,6 @@ const ActionListFieldArray = ({
167
167
  key={`action-${action.name}[${data.rowIndex}]`}
168
168
  disabled={editing}
169
169
  icon={action.icon}
170
- marginBottom0
171
170
  onClick={() => (actionFunction ? actionFunction() : () => null)}
172
171
  to={action.to}
173
172
  />
@@ -78,20 +78,23 @@ const CustomPropertiesSettings = ({
78
78
  delete: deleteCustProp
79
79
  } = useMutateCustomProperties({
80
80
  afterQueryCalls: {
81
- put: () => {
81
+ put: res => {
82
82
  setMode(VIEWING);
83
83
  queryClient.invalidateQueries(['stripes-kint-components', 'useCustomProperties', 'custprops']);
84
- afterQueryCallsSafe.put();
84
+ setCustomProperty(res);
85
+ afterQueryCallsSafe.put(res);
85
86
  },
86
- post: () => {
87
+ post: res => {
87
88
  setMode(VIEWING);
88
89
  queryClient.invalidateQueries(['stripes-kint-components', 'useCustomProperties', 'custprops']);
89
- afterQueryCallsSafe.post();
90
+ setCustomProperty(res);
91
+ afterQueryCallsSafe.post(res);
90
92
  },
91
- delete: () => {
93
+ delete: res => {
92
94
  setMode(VIEWING);
93
95
  queryClient.invalidateQueries(['stripes-kint-components', 'useCustomProperties', 'custprops']);
94
- afterQueryCallsSafe.delete();
96
+ setCustomProperty();
97
+ afterQueryCallsSafe.delete(res);
95
98
  }
96
99
  },
97
100
  endpoint: customPropertiesEndpoint,
@@ -19,7 +19,7 @@ import { required as requiredValidator } from '../../utils/validators';
19
19
  import CustomPropertiesRule from './CustomPropertiesRule';
20
20
 
21
21
  const CustomPropertiesFilterField = ({
22
- customProperties,
22
+ customProperties = [],
23
23
  fields,
24
24
  index,
25
25
  labelOverrides = {},
@@ -8,7 +8,7 @@ import CustomPropertyCard from './CustomPropertyCard';
8
8
 
9
9
  const CustomPropertiesViewCtx = ({
10
10
  ctx,
11
- customProperties,
11
+ customProperties = [],
12
12
  customPropertiesEndpoint,
13
13
  id,
14
14
  labelOverrides
@@ -69,21 +69,26 @@ const CustomPropertiesViewCtx = ({
69
69
  );
70
70
  }
71
71
 
72
+ const countSetProperties = (primary) => (
73
+ Object.entries(customProperties)?.filter(
74
+ ([_key, cp]) => (
75
+ (cp[0]?.type?.ctx === ctx || (ctx === 'isNull' && !cp[0]?.type?.ctx)) && // Either the ctx string matches, or isNull matches blank
76
+ cp[0]?.type?.primary === primary // Only count non-primary set custprops
77
+ )
78
+ )?.length ?? 0
79
+ );
80
+
72
81
  // We need to display any set properties, along with any non-set primary properties
73
82
  const primaryCount = custprops?.filter(cp => cp.primary === true)?.length ?? 0;
74
- const optionalCount = Object.entries(customProperties)?.filter(
75
- ([_key, cp]) => (
76
- (cp[0]?.type?.ctx === ctx || (ctx === 'isNull' && !cp[0]?.type?.ctx)) && // Either the ctx string matches, or isNull matches blank
77
- cp[0]?.type?.primary === false // Only count non-primary set custprops
78
- )
79
- )?.length ?? 0;
83
+ const optionalCount = countSetProperties(false);
84
+ const setPrimaryCount = countSetProperties(true);
80
85
 
81
86
  return (
82
87
  (primaryCount + optionalCount) > 0 &&
83
88
  <Accordion
84
89
  closedByDefault
85
- displayWhenClosed={<Badge>{primaryCount + optionalCount}</Badge>}
86
- displayWhenOpen={<Badge>{primaryCount + optionalCount}</Badge>}
90
+ displayWhenClosed={<Badge>{setPrimaryCount + optionalCount}</Badge>}
91
+ displayWhenOpen={<Badge>{setPrimaryCount + optionalCount}</Badge>}
87
92
  id={`${id}-accordion-${ctx}`}
88
93
  label={getAccordionLabel()}
89
94
  >
@@ -16,7 +16,7 @@ import * as CUSTPROP_TYPES from '../../constants/customProperties';
16
16
  const CustomPropertyCard = ({
17
17
  ctx,
18
18
  customProperty,
19
- customPropertyDefinition,
19
+ customPropertyDefinition = {},
20
20
  index,
21
21
  labelOverrides
22
22
  }) => {
@@ -35,7 +35,7 @@ const CustomPropertyCard = ({
35
35
  // Label override for default card title,
36
36
  if (labelOverrides.retiredName && typeof labelOverrides.retiredName === 'function') {
37
37
  return (
38
- labelOverrides.retiredName(customPropertyDefinition)
38
+ labelOverrides.retiredName(customPropertyDefinition.name)
39
39
  );
40
40
  }
41
41
 
@@ -31,6 +31,7 @@ const FormModal = ({
31
31
  <ModalFooter>
32
32
  <Button
33
33
  buttonStyle="primary"
34
+ marginBottom0
34
35
  onClick={handleSubmit}
35
36
  >
36
37
  {
@@ -39,6 +40,7 @@ const FormModal = ({
39
40
  }
40
41
  </Button>
41
42
  <Button
43
+ marginBottom0
42
44
  onClick={handleClose}
43
45
  >
44
46
  {
@@ -1,4 +1,4 @@
1
- const groupCustomPropertiesByCtx = (customProperties) => (
1
+ const groupCustomPropertiesByCtx = (customProperties = []) => (
2
2
  customProperties.reduce((acc, curr) => {
3
3
  const ctx = curr.ctx ?? 'isNull';
4
4
  const returnObj = {