orc-shared 1.6.0-dev.1 → 1.6.0-dev.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.
@@ -119,6 +119,7 @@ var StepperModal = function StepperModal(_ref) {
119
119
  open = _ref.open,
120
120
  closeCallback = _ref.closeCallback,
121
121
  confirmCallback = _ref.confirmCallback,
122
+ backdropCallback = _ref.backdropCallback,
122
123
  confirmTitle = _ref.confirmTitle,
123
124
  _ref$type = _ref.type,
124
125
  type = _ref$type === void 0 ? "wide" : _ref$type;
@@ -150,7 +151,7 @@ var StepperModal = function StepperModal(_ref) {
150
151
  }, (_steps$currentStep3 = steps[currentStep]) == null ? void 0 : _steps$currentStep3.content);
151
152
  modalProps.set(_modalProps.default.propNames.title, titleComponent);
152
153
  modalProps.set(_modalProps.default.propNames.open, open);
153
- modalProps.set(_modalProps.default.propNames.backdropClickCallback, closeCallback);
154
+ modalProps.set(_modalProps.default.propNames.backdropClickCallback, backdropCallback != null ? backdropCallback : closeCallback);
154
155
  modalProps.set(_modalProps.default.propNames.type, type);
155
156
  var nextClick = (0, _react.useCallback)(function () {
156
157
  return changeCurrentStep(function (step) {
@@ -8,6 +8,7 @@ var _withErrorBoundary = _interopRequireDefault(require("../../hocs/withErrorBou
8
8
  var _FullPage = _interopRequireDefault(require("./FullPage"));
9
9
  var _SubPage = _interopRequireDefault(require("./SubPage"));
10
10
  var _withWaypointing = _interopRequireDefault(require("./withWaypointing"));
11
+ var _urlPattern = _interopRequireDefault(require("url-pattern"));
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
13
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
14
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -45,6 +46,7 @@ var Page = function Page(_ref) {
45
46
  var WrappedView = (0, _react.useMemo)(function () {
46
47
  return (0, _withErrorBoundary.default)(path)((0, _withWaypointing.default)(View, isVisible));
47
48
  }, [path, View, isVisible]);
49
+ var parentUrlPattern = new _urlPattern.default(path);
48
50
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_reactRouter.Switch, null, Object.entries(pages).map(function (_ref2) {
49
51
  var _ref3 = _slicedToArray(_ref2, 2),
50
52
  subpath = _ref3[0],
@@ -83,7 +85,8 @@ var Page = function Page(_ref) {
83
85
  render: function render(route) {
84
86
  return /*#__PURE__*/_react.default.createElement(_SubPage.default, _extends({
85
87
  root: path,
86
- config: config
88
+ config: config,
89
+ parentUrlPattern: parentUrlPattern
87
90
  }, route, {
88
91
  modulePrependPath: modulePrependPath
89
92
  }));
@@ -230,6 +230,8 @@ var SegmentPage = function SegmentPage(_ref4) {
230
230
  }));
231
231
  }
232
232
  if (config.subpages) {
233
+ var parentUrl = path + segpath;
234
+ var parentUrlPattern = new _urlPattern.default(parentUrl);
233
235
  subpages.push.apply(subpages, Object.entries(config.subpages).map(function (_ref9) {
234
236
  var _ref10 = _slicedToArray(_ref9, 2),
235
237
  subpath = _ref10[0],
@@ -241,7 +243,8 @@ var SegmentPage = function SegmentPage(_ref4) {
241
243
  render: function render(route) {
242
244
  return /*#__PURE__*/_react.default.createElement(_SubPage.default, _extends({
243
245
  root: path,
244
- config: config
246
+ config: config,
247
+ parentUrlPattern: parentUrlPattern
245
248
  }, route, {
246
249
  modulePrependPath: modulePrependPath
247
250
  }));
@@ -52,7 +52,8 @@ var SubPage = function SubPage(_ref) {
52
52
  location = _ref.location,
53
53
  history = _ref.history,
54
54
  root = _ref.root,
55
- modulePrependPath = _ref.modulePrependPath;
55
+ modulePrependPath = _ref.modulePrependPath,
56
+ parentUrlPattern = _ref.parentUrlPattern;
56
57
  var classes = useStyles();
57
58
  var dispatch = (0, _reactRedux.useDispatch)();
58
59
  var View = config.component,
@@ -60,15 +61,13 @@ var SubPage = function SubPage(_ref) {
60
61
  var pattern = new _urlPattern.default(root);
61
62
  var baseHref = pattern.stringify(match.params);
62
63
  var path = location.pathname;
63
- var basePathArr = path.split("/");
64
- basePathArr.pop();
65
- var basePath = basePathArr.join("/");
66
64
  var WrappedView = (0, _react.useMemo)(function () {
67
65
  return (0, _withErrorBoundary.default)(path)((0, _withWaypointing.default)(View));
68
66
  }, [path, View]);
69
67
  var closeSubPage = function closeSubPage() {
70
- history.push(basePath);
71
- dispatch((0, _navigation.mapHref)(basePath, basePath));
68
+ var parentHref = parentUrlPattern.stringify(match.params);
69
+ history.push(parentHref);
70
+ dispatch((0, _navigation.mapHref)(parentHref, parentHref));
72
71
  };
73
72
  var message = /*#__PURE__*/_react.default.createElement(WrappedView, _extends({
74
73
  match: match,
@@ -47,7 +47,7 @@ var loadConfig = function loadConfig() {
47
47
  }).catch(function () {
48
48
  console.warn("Failed to load config.json, falling back to dev defaults");
49
49
  return {
50
- serviceApiUrl: "https://orc-dev-ocs-cm.develop.orckestra.cloud:443/api"
50
+ serviceApiUrl: "https://occ-dev-ocs-cm.develop.orckestra.cloud:443/api"
51
51
  };
52
52
  }).then(function (config) {
53
53
  var host = config.serviceApiUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-shared",
3
- "version": "1.6.0-dev.1",
3
+ "version": "1.6.0-dev.3",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -96,6 +96,7 @@ const StepperModal = ({
96
96
  open,
97
97
  closeCallback,
98
98
  confirmCallback,
99
+ backdropCallback,
99
100
  confirmTitle,
100
101
  type = "wide",
101
102
  }) => {
@@ -138,7 +139,7 @@ const StepperModal = ({
138
139
 
139
140
  modalProps.set(ModalProps.propNames.title, titleComponent);
140
141
  modalProps.set(ModalProps.propNames.open, open);
141
- modalProps.set(ModalProps.propNames.backdropClickCallback, closeCallback);
142
+ modalProps.set(ModalProps.propNames.backdropClickCallback, backdropCallback ?? closeCallback);
142
143
  modalProps.set(ModalProps.propNames.type, type);
143
144
 
144
145
  const nextClick = useCallback(() => changeCurrentStep(step => step + 1), []);
@@ -3,6 +3,7 @@ import StepperModal from "./StepperModal";
3
3
  import Modal from "./../Modal";
4
4
  import ModalProps from "./../modalProps";
5
5
  import Button from "@material-ui/core/Button";
6
+ import ModalMui from "@material-ui/core/Modal";
6
7
  import { mount } from "enzyme";
7
8
  import sinon from "sinon";
8
9
  import { IntlProvider } from "react-intl";
@@ -163,6 +164,25 @@ describe("StepperModal", () => {
163
164
  expect(cancelCallbackSpy, "was called");
164
165
  });
165
166
 
167
+ it("Calls backdropCallback when clicking away from component", () => {
168
+ const open = true;
169
+ const backdropCallbackSpy = sinon.spy();
170
+
171
+ const component = (
172
+ <IntlProvider locale="en-US" messages={messages}>
173
+ <StepperModal open={open} backdropCallback={backdropCallbackSpy} />
174
+ </IntlProvider>
175
+ );
176
+
177
+ const mountedComponent = mount(component);
178
+
179
+ const muiModal = mountedComponent.find(ModalMui);
180
+
181
+ muiModal.invoke("onClose")({}, "backdropClick");
182
+
183
+ expect(backdropCallbackSpy, "was called");
184
+ });
185
+
166
186
  it("Calls cancelCallback when ok button is pressed", () => {
167
187
  const open = true;
168
188
  const okCallback = sinon.spy();
@@ -4,9 +4,12 @@ import withErrorBoundary from "../../hocs/withErrorBoundary";
4
4
  import FullPage from "./FullPage";
5
5
  import SubPage from "./SubPage";
6
6
  import withWaypointing from "./withWaypointing";
7
+ import UrlPattern from "url-pattern";
7
8
 
8
9
  const Page = ({ component: View, path, pages = {}, subpages = {}, modulePrependPath, isVisible = true }) => {
9
10
  const WrappedView = useMemo(() => withErrorBoundary(path)(withWaypointing(View, isVisible)), [path, View, isVisible]);
11
+ const parentUrlPattern = new UrlPattern(path);
12
+
10
13
  return (
11
14
  <React.Fragment>
12
15
  <Switch>
@@ -38,7 +41,15 @@ const Page = ({ component: View, path, pages = {}, subpages = {}, modulePrependP
38
41
  <Route
39
42
  key={subpath}
40
43
  path={path + subpath}
41
- render={route => <SubPage root={path} config={config} {...route} modulePrependPath={modulePrependPath} />}
44
+ render={route => (
45
+ <SubPage
46
+ root={path}
47
+ config={config}
48
+ parentUrlPattern={parentUrlPattern}
49
+ {...route}
50
+ modulePrependPath={modulePrependPath}
51
+ />
52
+ )}
42
53
  />
43
54
  ))}
44
55
  </Switch>
@@ -197,6 +197,9 @@ const SegmentPage = ({
197
197
  );
198
198
  }
199
199
  if (config.subpages) {
200
+ const parentUrl = path + segpath;
201
+ const parentUrlPattern = new UrlPattern(parentUrl);
202
+
200
203
  subpages.push(
201
204
  ...Object.entries(config.subpages).map(([subpath, config]) => {
202
205
  const pagePath = segpath + subpath;
@@ -204,7 +207,15 @@ const SegmentPage = ({
204
207
  <Route
205
208
  key={pagePath}
206
209
  path={path + pagePath}
207
- render={route => <SubPage root={path} config={config} {...route} modulePrependPath={modulePrependPath} />}
210
+ render={route => (
211
+ <SubPage
212
+ root={path}
213
+ config={config}
214
+ parentUrlPattern={parentUrlPattern}
215
+ {...route}
216
+ modulePrependPath={modulePrependPath}
217
+ />
218
+ )}
208
219
  />
209
220
  );
210
221
  }),
@@ -20,22 +20,19 @@ const useStyles = makeStyles(theme => ({
20
20
  },
21
21
  }));
22
22
 
23
- export const SubPage = ({ config, match, location, history, root, modulePrependPath }) => {
23
+ export const SubPage = ({ config, match, location, history, root, modulePrependPath, parentUrlPattern }) => {
24
24
  const classes = useStyles();
25
25
  const dispatch = useDispatch();
26
26
  let { component: View, ...props } = config;
27
27
  const pattern = new UrlPattern(root);
28
28
  const baseHref = pattern.stringify(match.params);
29
-
30
29
  const path = location.pathname;
31
30
 
32
- const basePathArr = path.split("/");
33
- basePathArr.pop();
34
- const basePath = basePathArr.join("/");
35
31
  const WrappedView = useMemo(() => withErrorBoundary(path)(withWaypointing(View)), [path, View]);
36
32
  const closeSubPage = () => {
37
- history.push(basePath);
38
- dispatch(mapHref(basePath, basePath));
33
+ const parentHref = parentUrlPattern.stringify(match.params);
34
+ history.push(parentHref);
35
+ dispatch(mapHref(parentHref, parentHref));
39
36
  };
40
37
 
41
38
  const message = (
@@ -13,6 +13,7 @@ import Button from "@material-ui/core/Button";
13
13
  import translations from "~/translations/en-US.json";
14
14
  import { TestWrapper, createMuiTheme } from "../../utils/testUtils";
15
15
  import sharedMessages from "../../sharedMessages";
16
+ import UrlPattern from "url-pattern";
16
17
 
17
18
  const InnerView = ({ theme, pathname, search, mapFrom, match, location, routeIsAligned, set }) => (
18
19
  <PropStruct
@@ -92,6 +93,7 @@ describe("SubPage", () => {
92
93
  config={{ component: InnerView, set: true, title: "Item Details" }}
93
94
  root="/foo"
94
95
  path="/foo/bar"
96
+ parentUrlPattern={new UrlPattern("/foo")}
95
97
  {...route}
96
98
  />
97
99
  )}
@@ -140,6 +142,7 @@ describe("SubPage", () => {
140
142
  config={{ component: InnerView, set: true, title: sharedMessages.confirmation }}
141
143
  root="/foo"
142
144
  path="/foo/bar"
145
+ parentUrlPattern={new UrlPattern("/foo")}
143
146
  {...route}
144
147
  />
145
148
  )}
@@ -164,6 +167,7 @@ describe("SubPage", () => {
164
167
  config={{ component: InnerView, set: true, title: "Item Details" }}
165
168
  root="/foo"
166
169
  path="/foo/bar"
170
+ parentUrlPattern={new UrlPattern("/foo")}
167
171
  {...route}
168
172
  />
169
173
  )}
@@ -180,6 +184,42 @@ describe("SubPage", () => {
180
184
  expect(history.push, "to have calls satisfying", [{ args: ["/foo"] }]);
181
185
  expect(dispatch, "to have calls satisfying", [{ args: [mapHref("/foo", "/foo")] }]);
182
186
  });
187
+ it("closing the dialog navigate to the parentUrlPattern with parameters", () => {
188
+ history = createMemoryHistory({ initialEntries: ["/foo/bar/123/456"] });
189
+ sinon.spy(history, "push");
190
+ history.push.named("history.push");
191
+ dispatch.resetHistory();
192
+
193
+ const component = (
194
+ <TestWrapper provider={{ store }} intlProvider={intlProvider} stylesProvider muiThemeProvider={{ theme }}>
195
+ <div>
196
+ <div id="outer" />
197
+ <Router history={history}>
198
+ <Route
199
+ path="/foo/bar/:parentId/:id"
200
+ render={route => (
201
+ <SubPage
202
+ config={{ component: InnerView, set: true, title: "Item Details" }}
203
+ root="/foo/bar/:parentId/:id"
204
+ path="/foo/bar/123/456"
205
+ parentUrlPattern={new UrlPattern("/foo/bar/:parentId")}
206
+ {...route}
207
+ />
208
+ )}
209
+ />
210
+ </Router>
211
+ </div>
212
+ </TestWrapper>
213
+ );
214
+ const mountedComponent = mount(component);
215
+
216
+ const closeButton = mountedComponent.find("button").at(0);
217
+
218
+ closeButton.invoke("onClick")();
219
+ expect(history.push, "to have calls satisfying", [{ args: ["/foo/bar/123"] }]);
220
+ expect(dispatch, "to have a call satisfying", { args: [mapHref("/foo/bar/123", "/foo/bar/123")] });
221
+ });
222
+
183
223
  it("renders action panel passed from props", () => {
184
224
  const actions = () => [{ label: sharedMessages.cancel }, { label: sharedMessages.applyChanges }];
185
225
 
@@ -200,6 +240,7 @@ describe("SubPage", () => {
200
240
  }}
201
241
  root="/foo"
202
242
  path="/foo/bar"
243
+ parentUrlPattern={new UrlPattern("/foo")}
203
244
  {...route}
204
245
  />
205
246
  )}
@@ -242,6 +283,7 @@ describe("SubPage", () => {
242
283
  }}
243
284
  root="/foo"
244
285
  path="/foo/bar"
286
+ parentUrlPattern={new UrlPattern("/foo")}
245
287
  {...route}
246
288
  />
247
289
  )}
@@ -286,6 +328,7 @@ describe("SubPage", () => {
286
328
  }}
287
329
  root="/foo"
288
330
  path="/foo/bar"
331
+ parentUrlPattern={new UrlPattern("/foo")}
289
332
  {...route}
290
333
  />
291
334
  )}
@@ -327,6 +370,7 @@ describe("SubPage", () => {
327
370
  }}
328
371
  root="/foo"
329
372
  path="/foo/bar"
373
+ parentUrlPattern={new UrlPattern("/foo")}
330
374
  {...route}
331
375
  />
332
376
  )}
@@ -368,6 +412,7 @@ describe("SubPage", () => {
368
412
  }}
369
413
  root="/foo"
370
414
  path="/foo/bar"
415
+ parentUrlPattern={new UrlPattern("/foo")}
371
416
  {...route}
372
417
  />
373
418
  )}
@@ -411,6 +456,7 @@ describe("SubPage", () => {
411
456
  }}
412
457
  root="/foo"
413
458
  path="/foo/bar"
459
+ parentUrlPattern={new UrlPattern("/foo")}
414
460
  {...route}
415
461
  />
416
462
  )}
@@ -21,7 +21,7 @@ export const loadConfig = () =>
21
21
  .catch(() => {
22
22
  console.warn("Failed to load config.json, falling back to dev defaults");
23
23
  return {
24
- serviceApiUrl: "https://orc-dev-ocs-cm.develop.orckestra.cloud:443/api",
24
+ serviceApiUrl: "https://occ-dev-ocs-cm.develop.orckestra.cloud:443/api",
25
25
  };
26
26
  })
27
27
  .then(config => {