orc-shared 5.7.0-dev.7 → 5.7.0-dev.9

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.
@@ -51,11 +51,13 @@ var ActionModal = function ActionModal(_ref) {
51
51
  var actionPanel = /*#__PURE__*/_react.default.createElement("div", {
52
52
  className: classes.actionPanel
53
53
  }, actions.map(function (action) {
54
+ var _action$disabled;
54
55
  return /*#__PURE__*/_react.default.createElement(_Button.default, {
55
56
  key: action.label.id,
56
57
  variant: action.isPrimary ? "contained" : "outlined",
57
58
  color: action.isPrimary ? "primary" : "default",
58
59
  disableElevation: action.isPrimary,
60
+ disabled: (_action$disabled = action.disabled) != null ? _action$disabled : false,
59
61
  onClick: function onClick(e) {
60
62
  return action.handler(e);
61
63
  }
@@ -7,6 +7,7 @@ var _filterHelper = require("../../../utils/filterHelper");
7
7
  var _metadata = require("../../../selectors/metadata");
8
8
  var _localizationHelper = require("../../../utils/localizationHelper");
9
9
  var _createInput = _interopRequireWildcard(require("./createInput"));
10
+ var _excluded = ["moduleName", "lookupName", "value", "onChange", "disabled", "metadata"];
10
11
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
11
12
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
13
  (function () {
@@ -17,6 +18,8 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
17
18
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
18
19
  enterModule && enterModule(module);
19
20
  })();
21
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
22
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
20
23
  var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
21
24
  return a;
22
25
  };
@@ -29,7 +32,8 @@ var LookupSelect = function LookupSelect(_ref) {
29
32
  value = _ref.value,
30
33
  onChange = _ref.onChange,
31
34
  disabled = _ref.disabled,
32
- metadata = _ref.metadata;
35
+ metadata = _ref.metadata,
36
+ props = _objectWithoutProperties(_ref, _excluded);
33
37
  var options = (0, _filterHelper.extractDropboxOptions)((0, _reactRedux.useSelector)((0, _metadata.namedLookupValuesSelector)(moduleName, lookupName)));
34
38
  if (value !== null && !options.some(function (x) {
35
39
  return x.value === value;
@@ -40,13 +44,18 @@ var LookupSelect = function LookupSelect(_ref) {
40
44
  sortOrder: 0
41
45
  });
42
46
  }
47
+ var inputProps = {};
48
+ if (props != null && props["data-qa"]) {
49
+ inputProps["data-qa"] = props["data-qa"];
50
+ }
43
51
  return (0, _createInput.default)(_createInput.inputTypes.select, {
44
52
  options: options,
45
53
  value: value,
46
54
  update: function update(newValue) {
47
55
  return onChange(newValue, metadata);
48
56
  },
49
- disabled: disabled
57
+ disabled: disabled,
58
+ inputProps: inputProps
50
59
  });
51
60
  };
52
61
  __signature__(LookupSelect, "useSelector{}", function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-shared",
3
- "version": "5.7.0-dev.7",
3
+ "version": "5.7.0-dev.9",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -20,7 +20,7 @@ const ActionModal = ({
20
20
  message,
21
21
  open,
22
22
  type,
23
- actions, // Array of objects containing three properties: label, handler, isPrimary
23
+ actions, // Array of objects containing four properties: label, handler, isPrimary & disabled
24
24
  backdropClickCallback,
25
25
  }) => {
26
26
  const classes = useStyles();
@@ -42,6 +42,7 @@ const ActionModal = ({
42
42
  variant={action.isPrimary ? "contained" : "outlined"}
43
43
  color={action.isPrimary ? "primary" : "default"}
44
44
  disableElevation={action.isPrimary}
45
+ disabled={action.disabled ?? false}
45
46
  onClick={e => action.handler(e)}
46
47
  >
47
48
  <FormattedMessage {...action.label} />
@@ -17,8 +17,8 @@ describe("ActionModal", () => {
17
17
  const open = true;
18
18
  const message = "message";
19
19
 
20
- const actionOne = { label: sharedMessages.yes, handler: jest.fn(), isPrimary: true };
21
- const actionTwo = { label: sharedMessages.no, handler: jest.fn() };
20
+ const actionOne = { label: sharedMessages.yes, handler: jest.fn(), isPrimary: true, disabled: false };
21
+ const actionTwo = { label: sharedMessages.no, handler: jest.fn(), disabled: false };
22
22
  const actionThree = { label: sharedMessages.cancel, handler: jest.fn() };
23
23
 
24
24
  const backdropClickCallback = jest.fn();
@@ -32,13 +32,81 @@ describe("ActionModal", () => {
32
32
 
33
33
  const actionPanel = (
34
34
  <div>
35
- <Button key="1" variant="contained" color="primary" onClick={() => actionOne.handler()} disableElevation>
35
+ <Button
36
+ key="1"
37
+ variant="contained"
38
+ color="primary"
39
+ disabled={false}
40
+ onClick={() => actionOne.handler()}
41
+ disableElevation
42
+ >
36
43
  {stringifyWithoutQuotes(messages["orc-shared.yes"])}
37
44
  </Button>
38
- <Button key="2" variant="outlined" onClick={() => actionTwo.handler()}>
45
+ <Button key="2" variant="outlined" disabled={false} onClick={() => actionTwo.handler()}>
39
46
  {stringifyWithoutQuotes(messages["orc-shared.no"])}
40
47
  </Button>
41
- <Button key="3" variant="outlined" onClick={() => actionThree.handler()}>
48
+ <Button key="3" variant="outlined" disabled={false} onClick={() => actionThree.handler()}>
49
+ {stringifyWithoutQuotes(messages["orc-shared.cancel"])}
50
+ </Button>
51
+ </div>
52
+ );
53
+
54
+ modalProps.set(ModalProps.propNames.actionPanel, actionPanel);
55
+
56
+ const component = (
57
+ <IntlProvider locale="en-US" messages={messages}>
58
+ <ActionModal
59
+ message={message}
60
+ open={open}
61
+ actions={[actionOne, actionTwo, actionThree]}
62
+ backdropClickCallback={backdropClickCallback}
63
+ />
64
+ </IntlProvider>
65
+ );
66
+
67
+ const expected = (
68
+ <IntlProvider locale="en-US" messages={messages}>
69
+ <Modal message={message} modalProps={modalProps} />
70
+ </IntlProvider>
71
+ );
72
+
73
+ expect(component, "when mounted", "to satisfy", expected);
74
+ });
75
+
76
+ it("Renders ActionModal correctly with disabled actions", () => {
77
+ const open = true;
78
+ const message = "message";
79
+
80
+ const actionOne = { label: sharedMessages.yes, handler: jest.fn(), isPrimary: true, disabled: true };
81
+ const actionTwo = { label: sharedMessages.no, handler: jest.fn(), disabled: false };
82
+ const actionThree = { label: sharedMessages.cancel, handler: jest.fn() };
83
+
84
+ const backdropClickCallback = jest.fn();
85
+ const modalProps = new ModalProps();
86
+
87
+ const titleComponent = stringifyWithoutQuotes(messages["orc-shared.confirmation"]);
88
+
89
+ modalProps.set(ModalProps.propNames.title, titleComponent);
90
+ modalProps.set(ModalProps.propNames.open, open);
91
+ modalProps.set(ModalProps.propNames.backdropClickCallback, backdropClickCallback);
92
+ modalProps.set(ModalProps.propNames.type, "fullwidth");
93
+
94
+ const actionPanel = (
95
+ <div>
96
+ <Button
97
+ key="1"
98
+ variant="contained"
99
+ color="primary"
100
+ disabled={true}
101
+ onClick={() => actionOne.handler()}
102
+ disableElevation
103
+ >
104
+ {stringifyWithoutQuotes(messages["orc-shared.yes"])}
105
+ </Button>
106
+ <Button key="2" variant="outlined" disabled={false} onClick={() => actionTwo.handler()}>
107
+ {stringifyWithoutQuotes(messages["orc-shared.no"])}
108
+ </Button>
109
+ <Button key="3" variant="outlined" disabled={false} onClick={() => actionThree.handler()}>
42
110
  {stringifyWithoutQuotes(messages["orc-shared.cancel"])}
43
111
  </Button>
44
112
  </div>
@@ -51,6 +119,7 @@ describe("ActionModal", () => {
51
119
  <ActionModal
52
120
  message={message}
53
121
  open={open}
122
+ type={"fullwidth"}
54
123
  actions={[actionOne, actionTwo, actionThree]}
55
124
  backdropClickCallback={backdropClickCallback}
56
125
  />
@@ -4,7 +4,7 @@ import { namedLookupValuesSelector } from "../../../selectors/metadata";
4
4
  import { getNotLocalizedString } from "../../../utils/localizationHelper";
5
5
  import createInput, { inputTypes } from "./createInput";
6
6
 
7
- const LookupSelect = ({ moduleName, lookupName, value, onChange, disabled, metadata }) => {
7
+ const LookupSelect = ({ moduleName, lookupName, value, onChange, disabled, metadata, ...props }) => {
8
8
  const options = extractDropboxOptions(useSelector(namedLookupValuesSelector(moduleName, lookupName)));
9
9
 
10
10
  if (value !== null && !options.some(x => x.value === value)) {
@@ -15,11 +15,18 @@ const LookupSelect = ({ moduleName, lookupName, value, onChange, disabled, metad
15
15
  });
16
16
  }
17
17
 
18
+ const inputProps = {};
19
+
20
+ if (props?.["data-qa"]) {
21
+ inputProps["data-qa"] = props["data-qa"];
22
+ }
23
+
18
24
  return createInput(inputTypes.select, {
19
25
  options: options,
20
26
  value: value,
21
27
  update: newValue => onChange(newValue, metadata),
22
28
  disabled: disabled,
29
+ inputProps: inputProps,
23
30
  });
24
31
  };
25
32
 
@@ -210,4 +210,25 @@ describe("LookupSelect Component", () => {
210
210
 
211
211
  expect(update, "to have calls satisfying", [{ args: ["CanceledReason2", { a: 123 }] }]);
212
212
  });
213
+
214
+ it("LookupSelect component with data-qa", () => {
215
+ const update = sinon.spy().named("update");
216
+ const component = (
217
+ <TestWrapper provider={{ store }} stylesProvider muiThemeProvider={{ theme }}>
218
+ <LookupSelect
219
+ moduleName={"order"}
220
+ lookupName={"CanceledStatusReasons"}
221
+ value={"CanceledReason3"}
222
+ onChange={update}
223
+ metadata={{ a: 123 }}
224
+ data-qa="custom-value"
225
+ />
226
+ </TestWrapper>
227
+ );
228
+
229
+ const mountedComponent = mount(component);
230
+
231
+ const controls = mountedComponent.find("[data-qa='custom-value']").hostNodes();
232
+ expect(controls.length, "to equal", 1);
233
+ });
213
234
  });