@splunk/react-page 6.1.0 → 6.2.0

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,9 +1,24 @@
1
1
  Change Log
2
2
  ============
3
3
 
4
+ 6.2.0 - July 27, 2023
5
+ ----------
6
+ New Features:
7
+ * `options.lazyLoadLayout` parameter has been added to `layout` to allow lazy loading of layout (SPL-241546).
8
+ * `options.splunkBarFallback` and `options.appBarFallback` parameters have been added to `layout` to allow customization of fallback components for the layout (SPL-241546).
9
+
10
+ Notes:
11
+ * An container element has been added to the DOM for the app content to support `lazyLoadLayout`
12
+
13
+ 6.1.1 - June 6, 2023
14
+ ----------
15
+ API Changes:
16
+ * Added support for the latest `styled-components@5` (SUI-5467).
17
+
4
18
  6.1.0 - May 2, 2023
19
+ ----------
5
20
  New Features:
6
- * a new `options.loader` parameter has been added to `layout` to allow `requirejs` to be used instead of `scriptjs` (SUI-5341).
21
+ * A new `options.loader` parameter has been added to `layout` to allow `requirejs` to be used instead of `scriptjs` (SUI-5341).
7
22
 
8
23
  Bug Fixes:
9
24
  * `layout` will no longer automatically fall back to `requirejs` if `scriptjs` fails to load, reversing the behavior introduced in 6.0.4 (SUI-5341).
@@ -0,0 +1,21 @@
1
+ /* eslint-env node */
2
+ const { defineConfig } = require('cypress');
3
+
4
+ module.exports = defineConfig({
5
+ env: {},
6
+ defaultCommandTimeout: 1000,
7
+ fixturesFolder: false,
8
+ video: false,
9
+ videoUploadOnPasses: false,
10
+ e2e: {
11
+ setupNodeEvents(on) {
12
+ on('before:browser:launch', (browser = {}, launchOptions) => {
13
+ if (browser.name === 'chrome') {
14
+ launchOptions.args.push('--disable-gpu');
15
+ }
16
+ });
17
+ },
18
+ baseUrl: 'http://localhost:8000',
19
+ specPattern: 'src/tests/**.spec.js',
20
+ },
21
+ });
package/lib/index.js CHANGED
@@ -113,13 +113,13 @@ module.exports = require("react-dom");
113
113
  /* 4 */
114
114
  /***/ (function(module, exports) {
115
115
 
116
- module.exports = require("@splunk/themes/SplunkThemeProvider");
116
+ module.exports = require("prop-types");
117
117
 
118
118
  /***/ }),
119
119
  /* 5 */
120
120
  /***/ (function(module, exports) {
121
121
 
122
- module.exports = require("prop-types");
122
+ module.exports = require("@splunk/themes/SplunkThemeProvider");
123
123
 
124
124
  /***/ }),
125
125
  /* 6 */
@@ -177,20 +177,9 @@ var Layer_ = __webpack_require__(7);
177
177
  var url_ = __webpack_require__(8);
178
178
 
179
179
  // EXTERNAL MODULE: external "@splunk/themes/SplunkThemeProvider"
180
- var SplunkThemeProvider_ = __webpack_require__(4);
180
+ var SplunkThemeProvider_ = __webpack_require__(5);
181
181
  var SplunkThemeProvider_default = /*#__PURE__*/__webpack_require__.n(SplunkThemeProvider_);
182
182
 
183
- // EXTERNAL MODULE: external "prop-types"
184
- var external_prop_types_ = __webpack_require__(5);
185
- var external_prop_types_default = /*#__PURE__*/__webpack_require__.n(external_prop_types_);
186
-
187
- // EXTERNAL MODULE: external "@splunk/react-ui/ScreenReaderContent"
188
- var ScreenReaderContent_ = __webpack_require__(9);
189
- var ScreenReaderContent_default = /*#__PURE__*/__webpack_require__.n(ScreenReaderContent_);
190
-
191
- // EXTERNAL MODULE: external "@splunk/ui-utils/i18n"
192
- var i18n_ = __webpack_require__(10);
193
-
194
183
  // EXTERNAL MODULE: external "styled-components"
195
184
  var external_styled_components_ = __webpack_require__(2);
196
185
  var external_styled_components_default = /*#__PURE__*/__webpack_require__.n(external_styled_components_);
@@ -220,7 +209,7 @@ function _templateObject5() {
220
209
  }
221
210
 
222
211
  function _templateObject4() {
223
- var data = _taggedTemplateLiteral(["\n background-color: ", ";\n min-height: 44px;\n"]);
212
+ var data = _taggedTemplateLiteral(["\n background-color: ", ";\n min-height: ", "px;\n"]);
224
213
 
225
214
  _templateObject4 = function _templateObject4() {
226
215
  return data;
@@ -230,7 +219,7 @@ function _templateObject4() {
230
219
  }
231
220
 
232
221
  function _templateObject3() {
233
- var data = _taggedTemplateLiteral(["\n padding: 0;\n background-color: ", ";\n height: 34px;\n"]);
222
+ var data = _taggedTemplateLiteral(["\n padding: 0;\n background-color: ", ";\n height: ", "px;\n"]);
234
223
 
235
224
  _templateObject3 = function _templateObject3() {
236
225
  return data;
@@ -263,22 +252,35 @@ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(
263
252
 
264
253
 
265
254
 
255
+ var APPBAR_HEIGHT = 45;
256
+ var SPLUNKBAR_HEIGHT = 34;
266
257
  var blink = Object(external_styled_components_["keyframes"])(_templateObject());
267
258
  var Main = external_styled_components_default.a.div(_templateObject2(), themes_["variables"].backgroundColorPage);
268
259
  var SplunkBar = external_styled_components_default.a.div(_templateObject3(), Object(themes_["pick"])({
269
260
  prisma: themes_["variables"].backgroundColorSection,
270
261
  enterprise: themes_["variables"].gray20
271
- }));
262
+ }), SPLUNKBAR_HEIGHT);
272
263
  var AppBar = external_styled_components_default.a.div(_templateObject4(), Object(themes_["pick"])({
273
264
  prisma: themes_["variables"].backgroundColorPopup,
274
265
  enterprise: themes_["variables"].gray30
275
- }));
266
+ }), APPBAR_HEIGHT);
276
267
  var AppBody = external_styled_components_default.a.div(_templateObject5(), themes_["variables"].contentColorInverted);
277
268
  var Dot = external_styled_components_default.a.div(_templateObject6(), blink, themes_["variables"].neutral500, Object(themes_["pick"])({
278
269
  prisma: themes_["variables"].spacingMedium,
279
270
  enterprise: themes_["variables"].spacingHalf
280
271
  }));
281
272
 
273
+ // EXTERNAL MODULE: external "prop-types"
274
+ var external_prop_types_ = __webpack_require__(4);
275
+ var external_prop_types_default = /*#__PURE__*/__webpack_require__.n(external_prop_types_);
276
+
277
+ // EXTERNAL MODULE: external "@splunk/react-ui/ScreenReaderContent"
278
+ var ScreenReaderContent_ = __webpack_require__(9);
279
+ var ScreenReaderContent_default = /*#__PURE__*/__webpack_require__.n(ScreenReaderContent_);
280
+
281
+ // EXTERNAL MODULE: external "@splunk/ui-utils/i18n"
282
+ var i18n_ = __webpack_require__(10);
283
+
282
284
  // CONCATENATED MODULE: ./src/Loading.jsx
283
285
 
284
286
 
@@ -288,19 +290,25 @@ var Dot = external_styled_components_default.a.div(_templateObject6(), blink, th
288
290
  var propTypes = {
289
291
  hideAppBar: external_prop_types_default.a.bool,
290
292
  hideChrome: external_prop_types_default.a.bool,
291
- hideSplunkBar: external_prop_types_default.a.bool
293
+ hideSplunkBar: external_prop_types_default.a.bool,
294
+ AppBarFallback: external_prop_types_default.a.elementType,
295
+ SplunkBarFallback: external_prop_types_default.a.elementType
292
296
  };
293
297
  var defaultProps = {
294
298
  hideAppBar: false,
295
299
  hideChrome: false,
296
- hideSplunkBar: false
300
+ hideSplunkBar: false,
301
+ AppBarFallback: AppBar,
302
+ SplunkBarFallback: SplunkBar
297
303
  };
298
304
 
299
305
  function Loading(_ref) {
300
306
  var hideAppBar = _ref.hideAppBar,
301
307
  hideChrome = _ref.hideChrome,
302
- hideSplunkBar = _ref.hideSplunkBar;
303
- return /*#__PURE__*/external_react_default.a.createElement(Main, null, !hideChrome && !hideSplunkBar && /*#__PURE__*/external_react_default.a.createElement(SplunkBar, null), !hideChrome && !hideAppBar && /*#__PURE__*/external_react_default.a.createElement(AppBar, null), /*#__PURE__*/external_react_default.a.createElement(AppBody, null, /*#__PURE__*/external_react_default.a.createElement(Dot, null), /*#__PURE__*/external_react_default.a.createElement(Dot, null), /*#__PURE__*/external_react_default.a.createElement(Dot, null), /*#__PURE__*/external_react_default.a.createElement(ScreenReaderContent_default.a, null, Object(i18n_["_"])('Loading'))));
308
+ hideSplunkBar = _ref.hideSplunkBar,
309
+ SplunkBarFallback = _ref.SplunkBarFallback,
310
+ AppBarFallback = _ref.AppBarFallback;
311
+ return /*#__PURE__*/external_react_default.a.createElement(Main, null, !hideChrome && !hideSplunkBar && /*#__PURE__*/external_react_default.a.createElement(SplunkBarFallback, null), !hideChrome && !hideAppBar && /*#__PURE__*/external_react_default.a.createElement(AppBarFallback, null), /*#__PURE__*/external_react_default.a.createElement(AppBody, null, /*#__PURE__*/external_react_default.a.createElement(Dot, null), /*#__PURE__*/external_react_default.a.createElement(Dot, null), /*#__PURE__*/external_react_default.a.createElement(Dot, null), /*#__PURE__*/external_react_default.a.createElement(ScreenReaderContent_default.a, null, Object(i18n_["_"])('Loading'))));
304
312
  }
305
313
 
306
314
  Loading.propTypes = propTypes;
@@ -318,8 +326,10 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
318
326
 
319
327
 
320
328
 
329
+
321
330
  var LIGHT_LAYOUT = 'build/api/layout.js';
322
331
  var DARK_LAYOUT = 'build/api/layout-dark.js';
332
+ var HEADER_SELECTOR = 'header[data-view="splunkjs/mvc/headerview"]';
323
333
  /**
324
334
  * Loads the layout from the server, using requirejs if available on the window and scriptjs if not.
325
335
  *
@@ -352,6 +362,23 @@ function getLayoutApi(theme, callback) {
352
362
  throw new Error('Invalid options.loader configuration: must be "scriptjs" or "requirejs".');
353
363
  }
354
364
  }
365
+ /**
366
+ * renders body element and attaches it to container node in DOM
367
+ *
368
+ * @param {element} element
369
+ * @param {HTMLDivElement} container
370
+ * @param {boolean} useGlobalLayerStack
371
+ * @param {object} splunkTheme
372
+ * @private
373
+ */
374
+
375
+
376
+ function renderBody(element, container) {
377
+ var useGlobalLayerStack = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
378
+ var splunkTheme = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
379
+ var wrappedElement = useGlobalLayerStack ? /*#__PURE__*/external_react_default.a.createElement(Layer_["LayerStackGlobalProvider"], null, /*#__PURE__*/external_react_default.a.createElement(SplunkThemeProvider_default.a, splunkTheme, element)) : /*#__PURE__*/external_react_default.a.createElement(SplunkThemeProvider_default.a, splunkTheme, element);
380
+ Object(external_react_dom_["render"])(wrappedElement, container);
381
+ }
355
382
  /**
356
383
  * Renders a React element into the Layout API.
357
384
  * @public
@@ -371,6 +398,9 @@ function getLayoutApi(theme, callback) {
371
398
  * @param {String} [options.theme = 'light'] - Used to theme UI elements. Ex. "light" or "dark".
372
399
  * @param {String} [options.loader = 'scriptjs'] - Configures the loader used for the loading the layout - available loaders are "scriptjs" and "requirejs".
373
400
  * Change this only if the default loader does not work for your application.
401
+ * @param {Boolean} [options.lazyLoadLayout = false] - Prioritizes loading the React element and lazily fetches and compiles the layout API (navigation bar).
402
+ * @param {element} [options.SplunkBarFallback = SplunkBar] - A React element used as a placeholder for the splunk bar while the navigation bar is loading.
403
+ * @param {element} [options.AppBarFallback = AppBar] - A React element used as a placeholder for the app bar while the navigation bar is loading.
374
404
  */
375
405
 
376
406
 
@@ -390,7 +420,17 @@ function layout(element) {
390
420
  document.title = pageTitle;
391
421
  }
392
422
 
393
- var loadingContainer = document.createElement('div'); // The "theme" in enterprise used to be "enterprise" instead of "light"...
423
+ var hideChrome = layoutAPIOptions.hideChrome,
424
+ hideAppBar = layoutAPIOptions.hideAppBar,
425
+ hideSplunkBar = layoutAPIOptions.hideSplunkBar,
426
+ _layoutAPIOptions$Spl = layoutAPIOptions.SplunkBarFallback,
427
+ SplunkBarFallback = _layoutAPIOptions$Spl === void 0 ? SplunkBar : _layoutAPIOptions$Spl,
428
+ _layoutAPIOptions$App = layoutAPIOptions.AppBarFallback,
429
+ AppBarFallback = _layoutAPIOptions$App === void 0 ? AppBar : _layoutAPIOptions$App,
430
+ _layoutAPIOptions$laz = layoutAPIOptions.lazyLoadLayout,
431
+ lazyLoadLayout = _layoutAPIOptions$laz === void 0 ? false : _layoutAPIOptions$laz;
432
+ var bodyContainer = document.createElement('div');
433
+ var headerContainer = document.createElement('div'); // The "theme" in enterprise used to be "enterprise" instead of "light"...
394
434
 
395
435
  var colorScheme = theme === 'light' || theme === 'enterprise' ? 'light' : 'dark';
396
436
  var splunkTheme = {
@@ -398,8 +438,21 @@ function layout(element) {
398
438
  colorScheme: colorScheme,
399
439
  density: 'comfortable'
400
440
  };
401
- document.body.appendChild(loadingContainer);
402
- Object(external_react_dom_["render"])( /*#__PURE__*/external_react_default.a.createElement(SplunkThemeProvider_default.a, splunkTheme, /*#__PURE__*/external_react_default.a.createElement(src_Loading, layoutAPIOptions)), loadingContainer);
441
+
442
+ if (lazyLoadLayout) {
443
+ // render the React app immediately without waiting for layout API
444
+ document.body.appendChild(headerContainer);
445
+ Object(external_react_dom_["render"])( /*#__PURE__*/external_react_default.a.createElement(external_react_default.a.Fragment, null, !hideChrome && !hideSplunkBar && /*#__PURE__*/external_react_default.a.createElement(SplunkBarFallback, null), !hideChrome && !hideAppBar && /*#__PURE__*/external_react_default.a.createElement(AppBarFallback, null)), headerContainer); // explicitly set height of header container to avoid layout shift when fallback gets replaced
446
+
447
+ var headerHeight = headerContainer.offsetHeight;
448
+ headerContainer.style.cssText = "height: ".concat(headerHeight, "px");
449
+ document.body.appendChild(bodyContainer);
450
+ renderBody(element, bodyContainer, useGlobalLayerStack, splunkTheme);
451
+ } else {
452
+ document.body.appendChild(bodyContainer);
453
+ Object(external_react_dom_["render"])( /*#__PURE__*/external_react_default.a.createElement(SplunkThemeProvider_default.a, splunkTheme, /*#__PURE__*/external_react_default.a.createElement(src_Loading, layoutAPIOptions)), bodyContainer);
454
+ }
455
+
403
456
  getLayoutApi(theme, function (layoutApi) {
404
457
  var containerEl;
405
458
 
@@ -433,12 +486,21 @@ function layout(element) {
433
486
  document.body.appendChild(containerEl);
434
487
  }
435
488
 
436
- setTimeout(function () {
437
- Object(external_react_dom_["unmountComponentAtNode"])(loadingContainer);
438
- loadingContainer.parentNode.removeChild(loadingContainer);
439
- var wrappedElement = useGlobalLayerStack ? /*#__PURE__*/external_react_default.a.createElement(Layer_["LayerStackGlobalProvider"], null, /*#__PURE__*/external_react_default.a.createElement(SplunkThemeProvider_default.a, splunkTheme, element)) : /*#__PURE__*/external_react_default.a.createElement(SplunkThemeProvider_default.a, splunkTheme, element);
440
- Object(external_react_dom_["render"])(wrappedElement, containerEl);
441
- }, 30);
489
+ if (lazyLoadLayout) {
490
+ // replace placeholder nav bar with real nav bar
491
+ Object(external_react_dom_["unmountComponentAtNode"])(headerContainer);
492
+ var header = document.querySelector(HEADER_SELECTOR);
493
+ var containerHeight = (!hideChrome && !hideSplunkBar ? SPLUNKBAR_HEIGHT : 0) + (!hideChrome && !hideAppBar ? APPBAR_HEIGHT : 0);
494
+ headerContainer.style.cssText = "height: ".concat(containerHeight, "px");
495
+ headerContainer.appendChild(header);
496
+ containerEl.appendChild(bodyContainer);
497
+ } else {
498
+ setTimeout(function () {
499
+ Object(external_react_dom_["unmountComponentAtNode"])(bodyContainer);
500
+ renderBody(element, bodyContainer, useGlobalLayerStack, splunkTheme);
501
+ containerEl.appendChild(bodyContainer);
502
+ }, 30);
503
+ }
442
504
  }, {
443
505
  loader: loader
444
506
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splunk/react-page",
3
- "version": "6.1.0",
3
+ "version": "6.2.0",
4
4
  "description": "Load React components into the latest layout from Splunk Enterprise",
5
5
  "main": "lib/index.js",
6
6
  "license": "Apache-2.0",
@@ -22,16 +22,16 @@
22
22
  "test:cypress:ci": "node src/tests/run-cypress-tests.js"
23
23
  },
24
24
  "dependencies": {
25
- "@splunk/react-ui": "^4.16.3",
25
+ "@splunk/react-ui": "^4.18.0",
26
26
  "@splunk/splunk-utils": "^2.3.4",
27
- "@splunk/themes": "^0.16.0",
27
+ "@splunk/themes": "^0.16.1",
28
28
  "@splunk/ui-utils": "^1.6.0",
29
29
  "prop-types": "^15.6.2",
30
30
  "scriptjs": "^2.5.8"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@babel/core": "^7.2.0",
34
- "@splunk/babel-preset": "^3.0.0",
34
+ "@splunk/babel-preset": "^4.0.0",
35
35
  "@splunk/cicd-tools": "^0.5.0",
36
36
  "@splunk/eslint-config": "^4.0.0",
37
37
  "@splunk/stylelint-config": "^4.0.0",
@@ -40,6 +40,7 @@
40
40
  "babel-loader": "^8.0.4",
41
41
  "babel-plugin-transform-imports": "^2.0.0",
42
42
  "cross-env": "^6.0.3",
43
+ "cypress": "^12.17.1",
43
44
  "eslint": "^7.14.0",
44
45
  "eslint-config-airbnb": "^18.2.1",
45
46
  "eslint-config-prettier": "^6.15.0",
@@ -52,7 +53,7 @@
52
53
  "react": "^16.12.0",
53
54
  "react-dom": "^16.12.0",
54
55
  "style-loader": "^0.23.1",
55
- "styled-components": "5.1.1",
56
+ "styled-components": "^5.3.10",
56
57
  "stylelint": "^13.0.0",
57
58
  "webpack": "^4.16.2",
58
59
  "webpack-cli": "^4.9.2",
@@ -62,7 +63,7 @@
62
63
  "peerDependencies": {
63
64
  "react": "^16.8",
64
65
  "react-dom": "^16.8",
65
- "styled-components": "5.1.1"
66
+ "styled-components": "^5.3.10"
66
67
  },
67
68
  "engines": {
68
69
  "node": ">=6"
@@ -1,11 +0,0 @@
1
- /* eslint-env node */
2
-
3
- module.exports = (on, config) => {
4
- on('before:browser:launch', (browser = {}, launchOptions) => {
5
- if (browser.name === 'chrome') {
6
- launchOptions.args.push('--disable-gpu');
7
- }
8
- });
9
-
10
- return config;
11
- };
package/cypress.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "baseUrl": "http://localhost:8000",
3
- "env": {},
4
- "defaultCommandTimeout": 1000,
5
- "fixturesFolder": false,
6
- "integrationFolder": "src/tests",
7
- "testFiles": "**.spec.js",
8
- "video": false,
9
- "videoUploadOnPasses": false
10
- }
File without changes