orc-shared 1.5.0-dev.3 → 1.5.0-dev.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.
@@ -107,7 +107,8 @@ var SubPage = function SubPage(_ref) {
107
107
  disableElevation: action.isPrimary,
108
108
  disabled: action.disabled,
109
109
  onClick: function onClick(e) {
110
- action.handler && action.handler(e);
110
+ var actionHandlerResult = action.handler && action.handler(e);
111
+ if (action.handler && action.validateBeforeClose && !actionHandlerResult) return;
111
112
  closeSubPage();
112
113
  }
113
114
  }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, action.label));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-shared",
3
- "version": "1.5.0-dev.3",
3
+ "version": "1.5.0-dev.4",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -80,7 +80,8 @@ export const SubPage = ({ config, match, location, history, root, modulePrependP
80
80
  disableElevation={action.isPrimary}
81
81
  disabled={action.disabled}
82
82
  onClick={e => {
83
- action.handler && action.handler(e);
83
+ let actionHandlerResult = action.handler && action.handler(e);
84
+ if (action.handler && action.validateBeforeClose && !actionHandlerResult) return;
84
85
  closeSubPage();
85
86
  }}
86
87
  >
@@ -180,7 +180,6 @@ describe("SubPage", () => {
180
180
  expect(history.push, "to have calls satisfying", [{ args: ["/foo"] }]);
181
181
  expect(dispatch, "to have calls satisfying", [{ args: [mapHref("/foo", "/foo")] }]);
182
182
  });
183
-
184
183
  it("renders action panel passed from props", () => {
185
184
  const actions = () => [{ label: sharedMessages.cancel }, { label: sharedMessages.applyChanges }];
186
185
 
@@ -262,4 +261,86 @@ describe("SubPage", () => {
262
261
  expect(applyButtonClassName, "to contain", "MuiButton-containedPrimary");
263
262
  expect(someEvent, "was called");
264
263
  });
264
+
265
+ it("Do not close when clicking action button has validateBeforeClose and result is false", () => {
266
+ const applyHandler = () => false;
267
+
268
+ const actions = () => [
269
+ { label: sharedMessages.applyChanges, isPrimary: true, handler: applyHandler, validateBeforeClose: true },
270
+ ];
271
+
272
+ const component = (
273
+ <TestWrapper provider={{ store }} intlProvider={intlProvider} stylesProvider muiThemeProvider={{ theme }}>
274
+ <div>
275
+ <div id="outer" />
276
+ <Router history={history}>
277
+ <Route
278
+ path="/foo/bar"
279
+ render={route => (
280
+ <SubPage
281
+ config={{
282
+ component: InnerView,
283
+ set: true,
284
+ title: "Item Details",
285
+ componentProps: { actionPanel: actions },
286
+ }}
287
+ root="/foo"
288
+ path="/foo/bar"
289
+ {...route}
290
+ />
291
+ )}
292
+ />
293
+ </Router>
294
+ </div>
295
+ </TestWrapper>
296
+ );
297
+ const mountedComponent = mount(component);
298
+
299
+ const applyButton = mountedComponent.find("button").at(0);
300
+
301
+ applyButton.invoke("onClick")();
302
+ expect(history.push, "not to have calls satisfying", [{ args: ["/foo"] }]);
303
+ expect(dispatch, "not to have calls satisfying", [{ args: [mapHref("/foo", "/foo")] }]);
304
+ });
305
+
306
+ it("Close when clicking action button has validateBeforeClose and result is true", () => {
307
+ const applyHandler = () => true;
308
+
309
+ const actions = () => [
310
+ { label: sharedMessages.applyChanges, isPrimary: true, handler: applyHandler, validateBeforeClose: true },
311
+ ];
312
+
313
+ const component = (
314
+ <TestWrapper provider={{ store }} intlProvider={intlProvider} stylesProvider muiThemeProvider={{ theme }}>
315
+ <div>
316
+ <div id="outer" />
317
+ <Router history={history}>
318
+ <Route
319
+ path="/foo/bar"
320
+ render={route => (
321
+ <SubPage
322
+ config={{
323
+ component: InnerView,
324
+ set: true,
325
+ title: "Item Details",
326
+ componentProps: { actionPanel: actions },
327
+ }}
328
+ root="/foo"
329
+ path="/foo/bar"
330
+ {...route}
331
+ />
332
+ )}
333
+ />
334
+ </Router>
335
+ </div>
336
+ </TestWrapper>
337
+ );
338
+ const mountedComponent = mount(component);
339
+
340
+ const applyButton = mountedComponent.find("button").at(0);
341
+
342
+ applyButton.invoke("onClick")();
343
+ expect(history.push, "to have calls satisfying", [{ args: ["/foo"] }]);
344
+ expect(dispatch, "to have calls satisfying", [{ args: [mapHref("/foo", "/foo")] }]);
345
+ });
265
346
  });