orc-shared 1.3.0-dev.6 → 1.3.0-dev.7

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.
@@ -71,7 +71,7 @@ var useStyles = (0, _styles.makeStyles)(function (theme) {
71
71
  });
72
72
 
73
73
  var SubPage = function SubPage(_ref) {
74
- var _props$title, _props$title2, _props$title3;
74
+ var _props$title, _props$title2, _props$title3, _props$componentProps, _props$componentProps2;
75
75
 
76
76
  var config = _ref.config,
77
77
  match = _ref.match,
@@ -127,6 +127,29 @@ var SubPage = function SubPage(_ref) {
127
127
  onClick: closeSubPage
128
128
  }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, _sharedMessages.default.close)));
129
129
 
130
+ if (((_props$componentProps = props.componentProps) == null ? void 0 : (_props$componentProps2 = _props$componentProps.actionPanel()) == null ? void 0 : _props$componentProps2.length) > 0) {
131
+ var _props$componentProps3;
132
+
133
+ actionPanel = /*#__PURE__*/_react.default.createElement("div", {
134
+ className: classes.actionPanel
135
+ }, (_props$componentProps3 = props.componentProps) == null ? void 0 : _props$componentProps3.actionPanel().map(function (action) {
136
+ var _action$label;
137
+
138
+ return /*#__PURE__*/_react.default.createElement(_Button.default, {
139
+ key: (_action$label = action.label) == null ? void 0 : _action$label.id,
140
+ variant: action.isPrimary ? "contained" : "outlined",
141
+ color: action.isPrimary ? "primary" : "default",
142
+ disableElevation: action.isPrimary,
143
+ onMouseDown: function onMouseDown(e) {
144
+ setTimeout(function () {
145
+ action.handler && action.handler(e);
146
+ closeSubPage();
147
+ }, action.timeoutDelay || 200);
148
+ }
149
+ }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, action.label));
150
+ }));
151
+ }
152
+
130
153
  modalProps.set(_modalProps.default.propNames.actionPanel, actionPanel);
131
154
  return /*#__PURE__*/_react.default.createElement(_Modal.default, {
132
155
  message: message,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-shared",
3
- "version": "1.3.0-dev.6",
3
+ "version": "1.3.0-dev.7",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -61,7 +61,7 @@ export const SubPage = ({ config, match, location, history, root, modulePrependP
61
61
  modalProps.set(ModalProps.propNames.type, "fullwidth");
62
62
  modalProps.set(ModalProps.propNames.backdropClickCallback, closeSubPage);
63
63
 
64
- const actionPanel = (
64
+ let actionPanel = (
65
65
  <div className={classes.actionPanel}>
66
66
  <Button variant="contained" color="primary" disableElevation onClick={closeSubPage}>
67
67
  <FormattedMessage {...sharedMessages.close} />
@@ -69,6 +69,29 @@ export const SubPage = ({ config, match, location, history, root, modulePrependP
69
69
  </div>
70
70
  );
71
71
 
72
+ if (props.componentProps?.actionPanel()?.length > 0) {
73
+ actionPanel = (
74
+ <div className={classes.actionPanel}>
75
+ {props.componentProps?.actionPanel().map(action => (
76
+ <Button
77
+ key={action.label?.id}
78
+ variant={action.isPrimary ? "contained" : "outlined"}
79
+ color={action.isPrimary ? "primary" : "default"}
80
+ disableElevation={action.isPrimary}
81
+ onMouseDown={e => {
82
+ setTimeout(() => {
83
+ action.handler && action.handler(e);
84
+ closeSubPage();
85
+ }, action.timeoutDelay || 200);
86
+ }}
87
+ >
88
+ <FormattedMessage {...action.label} />
89
+ </Button>
90
+ ))}
91
+ </div>
92
+ );
93
+ }
94
+
72
95
  modalProps.set(ModalProps.propNames.actionPanel, actionPanel);
73
96
 
74
97
  return <Modal message={message} modalProps={modalProps} />;
@@ -11,7 +11,7 @@ import Modal from "../MaterialUI/DataDisplay/Modal";
11
11
  import ModalProps from "../MaterialUI/DataDisplay/modalProps";
12
12
  import Button from "@material-ui/core/Button";
13
13
  import translations from "~/translations/en-US.json";
14
-
14
+ import { act } from "unexpected-reaction";
15
15
  import { TestWrapper, createMuiTheme } from "../../utils/testUtils";
16
16
  import sharedMessages from "../../sharedMessages";
17
17
 
@@ -181,4 +181,99 @@ describe("SubPage", () => {
181
181
  expect(history.push, "to have calls satisfying", [{ args: ["/foo"] }]);
182
182
  expect(dispatch, "to have calls satisfying", [{ args: [mapHref("/foo", "/foo")] }]);
183
183
  });
184
+
185
+ it("renders action panel passed from props", () => {
186
+ const clock = sinon.useFakeTimers();
187
+
188
+ const actions = () => [{ label: sharedMessages.cancel }, { label: sharedMessages.applyChanges }];
189
+
190
+ const component = (
191
+ <TestWrapper provider={{ store }} intlProvider={intlProvider} stylesProvider muiThemeProvider={{ theme }}>
192
+ <div>
193
+ <div id="outer" />
194
+ <Router history={history}>
195
+ <Route
196
+ path="/foo/bar"
197
+ render={route => (
198
+ <SubPage
199
+ config={{
200
+ component: InnerView,
201
+ set: true,
202
+ title: "Item Details",
203
+ componentProps: { actionPanel: actions },
204
+ }}
205
+ root="/foo"
206
+ path="/foo/bar"
207
+ {...route}
208
+ />
209
+ )}
210
+ />
211
+ </Router>
212
+ </div>
213
+ </TestWrapper>
214
+ );
215
+ const mountedComponent = mount(component);
216
+
217
+ const closeButton = mountedComponent.find("button").at(0);
218
+ const applyButton = mountedComponent.find("button").at(1);
219
+
220
+ closeButton.invoke("onMouseDown")();
221
+
222
+ act(() => {
223
+ clock.tick(500); // Wait for the setTimeout inside the onMouseDown event to execute
224
+ });
225
+
226
+ expect(applyButton, "not to be", null);
227
+ expect(history.push, "to have calls satisfying", [{ args: ["/foo"] }]);
228
+ expect(dispatch, "to have calls satisfying", [{ args: [mapHref("/foo", "/foo")] }]);
229
+ });
230
+
231
+ it("Executes handler from button received from props", () => {
232
+ const someEvent = sinon.spy().named("someEvent");
233
+ const clock = sinon.useFakeTimers();
234
+
235
+ const actions = () => [
236
+ { label: sharedMessages.applyChanges, isPrimary: true, handler: someEvent, timeoutDelay: 500 },
237
+ ];
238
+
239
+ const component = (
240
+ <TestWrapper provider={{ store }} intlProvider={intlProvider} stylesProvider muiThemeProvider={{ theme }}>
241
+ <div>
242
+ <div id="outer" />
243
+ <Router history={history}>
244
+ <Route
245
+ path="/foo/bar"
246
+ render={route => (
247
+ <SubPage
248
+ config={{
249
+ component: InnerView,
250
+ set: true,
251
+ title: "Item Details",
252
+ componentProps: { actionPanel: actions },
253
+ }}
254
+ root="/foo"
255
+ path="/foo/bar"
256
+ {...route}
257
+ />
258
+ )}
259
+ />
260
+ </Router>
261
+ </div>
262
+ </TestWrapper>
263
+ );
264
+ const mountedComponent = mount(component);
265
+
266
+ const applyButton = mountedComponent.find("button").at(0);
267
+
268
+ applyButton.invoke("onMouseDown")();
269
+
270
+ act(() => {
271
+ clock.tick(500); // Wait for the setTimeout inside the onMouseDown event to execute
272
+ });
273
+
274
+ const applyButtonClassName = applyButton.props().className;
275
+ expect(applyButtonClassName, "to contain", "MuiButton-contained");
276
+ expect(applyButtonClassName, "to contain", "MuiButton-containedPrimary");
277
+ expect(someEvent, "was called");
278
+ });
184
279
  });