UNPKG

@hawtio/react

Version:

A Hawtio reimplementation based on TypeScript + React.

943 lines (779 loc) 92.9 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _chunkS4RWX7OXjs = require('./chunk-S4RWX7OX.js'); var _chunkURJD3F2Kjs = require('./chunk-URJD3F2K.js'); var _chunkTM6OCU7Kjs = require('./chunk-TM6OCU7K.js'); var _chunkZYPGXT7Qjs = require('./chunk-ZYPGXT7Q.js'); // src/ui/page/HawtioLoadingPage.tsx var _reactcore = require('@patternfly/react-core'); var _jsxruntime = require('react/jsx-runtime'); var HawtioLoadingPage = () => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Page, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Bullseye, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { style: { justifyContent: "center" }, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Spinner, { diameter: "60px", "aria-label": "Loading Hawtio" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.TextContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Text, { className: "--pf-v5-global--Color--200", component: _reactcore.TextVariants.h3, children: "Loading ..." }) }) ] }) }) }); // src/help/HawtioHelp.tsx var _react = require('react'); var React11 = _interopRequireWildcard(_react); var _reactmarkdown = require('react-markdown'); var _reactmarkdown2 = _interopRequireDefault(_reactmarkdown); var _reactrouterdom = require('react-router-dom'); // src/help/help.md var help_default = "## Hawtio Help\n\nHawtio is a lightweight and modular Web console for managing Java and JVM applications.\n\n### Plugin help\n\nBrowse the available help topics for plugin specific documentation using the help navigation bar.\n\n### Further reading\n\n- [Hawtio](https://hawt.io 'Hawtio') website\n- Help improve Hawtio by [contributing](https://hawt.io/docs/contributing.html)\n- Hawtio on [GitHub](https://github.com/hawtio/hawtio)\n"; // src/help/HawtioHelp.tsx _chunkS4RWX7OXjs.helpRegistry.add("home", "Home", help_default, 1); var HawtioHelp = () => { const location = _reactrouterdom.useLocation.call(void 0, ); const { plugins } = _chunkZYPGXT7Qjs.usePlugins.call(void 0, ); const helps = _react.useMemo.call(void 0, () => { const pluginIds = _chunkZYPGXT7Qjs.hawtio.getPlugins().map((p) => p.id); const activePlugins = plugins.map((p) => p.id); return _chunkS4RWX7OXjs.helpRegistry.getHelps().filter((help) => { if (pluginIds.includes(help.id)) { return activePlugins.includes(help.id); } return true; }); }, [plugins]); return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, React11.default.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { variant: _reactcore.PageSectionVariants.light, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Title, { headingLevel: "h1", children: "Help" }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Divider, {}), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { type: "tabs", hasShadowBottom: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Nav, { "aria-label": "Nav", variant: "tertiary", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.NavList, { children: helps.map((help) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.NavItem, { isActive: location.pathname === `/help/${help.id}`, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.NavLink, { to: help.id, children: help.title }) }, help.id)) }) }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Divider, {}), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { variant: _reactcore.PageSectionVariants.light, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactrouterdom.Routes, { children: [ _chunkS4RWX7OXjs.helpRegistry.getHelps().map((help) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Route, { path: help.id, element: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CardBody, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.TextContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactmarkdown2.default, { children: help.content }) }) }) }, help.id )), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Route, { path: "/", element: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Navigate, { to: "home" }) }) ] }) }) ] }); }; // src/img/hawtio-logo.svg var hawtio_logo_default = 'data:image/svg+xml,<?xml version="1.0" standalone="no"?><!-- Generator: Gravit.io --><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="isolation:isolate" viewBox="0 0 152.958 35" width="152.958" height="35"><defs><clipPath id="_clipPath_UDv2l4WSLMxqxM50Ng6HAmwBuRqLVpI1"><rect width="152.958" height="35"/></clipPath></defs><g clip-path="url(%23_clipPath_UDv2l4WSLMxqxM50Ng6HAmwBuRqLVpI1)"><g id="Group"><path d=" M 46.436 12.599 C 43.113 12.599 41.303 13.984 39.502 15.286 L 39.502 2.633 L 33.779 2.633 L 33.779 27.135 L 39.524 32.878 L 39.524 19.101 C 41.216 17.809 42.478 17.212 44.789 17.212 C 46.245 17.212 47.195 17.993 47.195 20.159 L 47.195 34.752 L 52.939 34.752 L 52.939 20.25 C 52.939 16.098 51.506 12.599 46.436 12.599 Z " fill="rgb(192,192,192)"/><path d=" M 54.679 27.148 C 54.679 23.979 56.392 21.174 61.062 21.174 C 61.062 21.174 67.46 21.214 67.46 21.174 C 67.46 21.174 67.502 19.818 67.46 19.777 C 67.46 17.455 66.375 17.091 64.548 17.091 C 62.655 17.091 57.191 17.43 55.399 17.56 L 55.399 14.015 C 58.268 12.9 61.264 12.576 65.326 12.557 C 70.018 12.538 73.206 14.159 73.206 19.552 L 73.206 34.753 L 68.67 34.753 L 67.46 32.353 C 67.221 32.825 64.164 35.066 60.836 34.998 C 56.644 34.886 54.679 32.032 54.679 29.199 L 54.679 27.148 L 54.679 27.148 Z M 62.46 30.383 C 64.863 30.383 67.46 28.697 67.46 28.697 L 67.46 24.704 L 62.191 25.11 C 60.674 25.252 60.424 26.374 60.424 27.327 L 60.424 28.385 C 60.424 30.197 61.404 30.383 62.46 30.383 Z " fill="rgb(192,192,192)"/><path d=" M 79.45 12.968 L 83.815 28.024 L 87.717 12.968 L 93.435 12.968 L 91.919 18.836 L 95.528 28.024 L 99.826 12.968 L 105.993 12.968 L 98.952 34.753 L 92.53 34.753 L 89.27 26.86 L 86.806 34.753 L 80.273 34.753 L 73.306 12.968 L 79.45 12.968 L 79.45 12.968 Z " fill="rgb(192,192,192)"/><path d=" M 107.198 14.116 L 110.716 12.927 L 111.68 6.854 L 116.46 6.854 L 116.46 12.927 L 121.331 12.927 L 121.331 17.316 L 116.46 17.316 L 116.46 26.055 C 116.46 29.263 117.2 29.949 118.325 30.366 C 118.325 30.366 120.787 31.228 121.072 31.228 L 121.072 34.756 L 116.064 34.756 C 112.839 34.756 110.716 32.742 110.716 26.957 L 110.716 17.316 L 107.198 17.316 L 107.198 14.116 Z " fill="rgb(192,192,192)"/><path d=" M 123.767 6.096 C 123.767 5.481 124.094 5.069 124.752 5.069 L 129.06 5.069 C 129.674 5.069 129.98 5.522 129.98 6.096 L 129.98 9.733 C 129.98 10.347 129.633 10.677 129.06 10.677 L 124.752 10.677 C 124.177 10.677 123.767 10.308 123.767 9.733 L 123.767 6.096 Z M 123.974 12.968 L 129.717 12.968 L 129.717 34.753 L 123.974 34.753 L 123.974 12.968 Z " fill="rgb(192,192,192)"/><path d=" M 143.018 12.763 C 150.521 12.763 152.958 15.512 152.958 24.167 C 152.958 32.25 150.634 34.957 143.018 34.957 C 135.495 34.957 133.08 31.962 133.08 24.167 C 133.08 15.266 135.655 12.763 143.018 12.763 Z M 143.018 30.343 C 146.255 30.343 147.214 29.903 147.214 24.167 C 147.214 18.066 146.442 17.378 143.018 17.378 C 139.62 17.378 138.824 18.07 138.824 24.167 C 138.824 29.805 139.966 30.343 143.018 30.343 Z " fill="rgb(192,192,192)"/></g><path d=" M 4.673 27.231 C 7.685 30.244 11.693 31.905 15.954 31.905 C 18.882 31.905 21.76 31.087 24.279 29.541 L 24.812 29.215 L 30.438 34.843 L 39.25 34.843 L 29.216 24.809 L 29.543 24.278 C 33.416 17.967 32.466 9.905 27.234 4.673 C 24.221 1.66 20.214 0 15.954 0 C 11.692 0 7.688 1.66 4.675 4.673 C 1.661 7.686 0 11.693 0 15.953 C 0 20.212 1.66 24.218 4.673 27.231 Z M 9.08 9.079 C 10.914 7.242 13.356 6.231 15.954 6.231 C 18.55 6.231 20.991 7.242 22.826 9.079 C 24.663 10.916 25.674 13.357 25.674 15.953 C 25.674 18.55 24.663 20.991 22.826 22.827 C 20.992 24.662 18.55 25.673 15.954 25.673 C 13.356 25.673 10.915 24.663 9.079 22.827 C 7.243 20.989 6.232 18.549 6.232 15.953 C 6.232 13.357 7.243 10.916 9.08 9.079 Z " fill="rgb(192,192,192)"/><g id="Group"><path d=" M 19.975 17.071 L 19.975 17.095 C 20.095 17.314 20.163 17.563 20.166 17.829 C 20.166 18.668 19.485 19.349 18.646 19.349 C 17.806 19.349 17.127 18.668 17.127 17.829 C 17.127 17.459 17.259 17.119 17.481 16.855 C 17.481 16.855 21.193 11.687 15.996 8.258 C 15.996 8.258 17.504 12.328 13.91 14.039 C 13.91 14.039 12.917 14.74 14.012 12.414 C 14.012 12.414 10.961 14.129 10.961 18.269 C 10.961 20.14 11.93 21.782 13.392 22.728 C 13.347 22.559 13.318 22.366 13.318 22.138 C 13.32 20.478 14.808 18.537 15.265 18.54 C 15.265 18.54 15.38 20.507 15.908 21.434 C 16.324 22.219 16.071 23.088 15.52 23.523 C 15.767 23.559 16.019 23.583 16.276 23.583 C 17.679 23.583 18.957 23.038 19.907 22.148 C 19.907 22.148 19.905 22.143 19.905 22.142 C 21.678 19.812 20.65 17.917 19.975 17.071 Z " fill="rgb(236,121,41)"/></g></g></svg>'; // src/img/img_avatar.svg var img_avatar_default = 'data:image/svg+xml,<?xml version="1.0" encoding="UTF-8"?>%0A<svg enable-background="new 0 0 36 36" version="1.1" viewBox="0 0 36 36" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">%0A<style type="text/css">%0A%09/*stylelint-disable*/%0A%09.st0{fill-rule:evenodd;clip-rule:evenodd;fill:%23FFFFFF;}%0A%09.st1{filter:url(%23b);}%0A%09.st2{mask:url(%23a);}%0A%09.st3{fill-rule:evenodd;clip-rule:evenodd;fill:%23BBBBBB;}%0A%09.st4{opacity:0.1;fill-rule:evenodd;clip-rule:evenodd;enable-background:new ;}%0A%09.st5{opacity:8.000000e-02;fill-rule:evenodd;clip-rule:evenodd;fill:%23231F20;enable-background:new ;}%0A%09/*stylelint-enable*/%0A</style>%0A%09%09%09<circle class="st0" cx="18" cy="18.5" r="18"/>%0A%09%09<defs>%0A%09%09%09<filter id="b" x="5.2" y="7.2" width="25.6" height="53.6" filterUnits="userSpaceOnUse">%0A%09%09%09%09<feColorMatrix values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0"/>%0A%09%09%09</filter>%0A%09%09</defs>%0A%09%09<mask id="a" x="5.2" y="7.2" width="25.6" height="53.6" maskUnits="userSpaceOnUse">%0A%09%09%09<g class="st1">%0A%09%09%09%09<circle class="st0" cx="18" cy="18.5" r="18"/>%0A%09%09%09</g>%0A%09%09</mask>%0A%09%09<g class="st2">%0A%09%09%09<g transform="translate(5.04 6.88)">%0A%09%09%09%09<path class="st3" d="m22.6 18.1c-1.1-1.4-2.3-2.2-3.5-2.6s-1.8-0.6-6.3-0.6-6.1 0.7-6.1 0.7 0 0 0 0c-1.2 0.4-2.4 1.2-3.4 2.6-2.3 2.8-3.2 12.3-3.2 14.8 0 3.2 0.4 12.3 0.6 15.4 0 0-0.4 5.5 4 5.5l-0.3-6.3-0.4-3.5 0.2-0.9c0.9 0.4 3.6 1.2 8.6 1.2 5.3 0 8-0.9 8.8-1.3l0.2 1-0.2 3.6-0.3 6.3c3 0.1 3.7-3 3.8-4.4s0.6-12.6 0.6-16.5c0.1-2.6-0.8-12.1-3.1-15z"/>%0A%09%09%09%09<path class="st4" d="m22.5 26c-0.1-2.1-1.5-2.8-4.8-2.8l2.2 9.6s1.8-1.7 3-1.8c0 0-0.4-4.6-0.4-5z"/>%0A%09%09%09%09<path class="st3" d="m12.7 13.2c-3.5 0-6.4-2.9-6.4-6.4s2.9-6.4 6.4-6.4 6.4 2.9 6.4 6.4-2.8 6.4-6.4 6.4z"/>%0A%09%09%09%09<path class="st5" d="m9.4 6.8c0-3 2.1-5.5 4.9-6.3-0.5-0.1-1-0.2-1.6-0.2-3.5 0-6.4 2.9-6.4 6.4s2.9 6.4 6.4 6.4c0.6 0 1.1-0.1 1.6-0.2-2.8-0.6-4.9-3.1-4.9-6.1z"/>%0A%09%09%09%09<path class="st4" d="m8.3 22.4c-2 0.4-2.9 1.4-3.1 3.5l-0.6 18.6s1.7 0.7 3.6 0.9l0.1-23z"/>%0A%09%09%09</g>%0A%09%09</g>%0A</svg>%0A'; // src/img/background.svg var background_default = 'data:image/svg+xml,<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 110.27 105.77">%0A <defs>%0A <style>.cls-1{fill:%2326292d;}</style>%0A </defs>%0A <polygon class="cls-1" points="110.27 87.87 97.53 105.77 99.28 105.77 110.27 90.32 110.27 87.87"/>%0A <path class="cls-1"%0A d="M23.22,105.77H25L1.86,73.05,67.4,9,27,58.44,40.58,77l-4.37,9.93L49.6,105.77h1.75l-13.51-19,3.71-8.43,20.06,27.35-.32.08h2.49L74.21,4.22l.23-.54.23.53L85.1,105.77h2.49l-.32-.08,20.06-27.35L110.27,85V81.47l-2-4.46,2-2.68V71.92l-2.63,3.59L76.8,5.52l33.47,40.92V44.19L81.49,9l28.78,28.14v-2L74.61.28V.15l-.06.08,0,0,0-.21-.12.11L74.32,0l0,.21,0,0L74.26.15V.28L0,72.88Zm83.44-28.94-19.82,27L76.7,8.8ZM62,103.87l-19.83-27,30-68ZM41.24,75.51l-12.47-17,43.31-53Z"/>%0A</svg>%0A'; // src/preferences/HawtioPreferences.tsx // src/preferences/help.md var help_default2 = "## Preferences\n\nThe preferences page is used to configure application preferences and individual plugin preferences.\n\nThe preferences page is accessible by clicking the user icon in the main navigation bar (the top-right corner), and then by choosing the preferences sub menu option.\n"; // src/preferences/HomePreferences.tsx // src/preferences/globals.ts var log = _chunkZYPGXT7Qjs.Logger.get("hawtio-preferences"); // src/preferences/preferences-service.ts var STORAGE_KEY_SHOW_VERTICAL_NAV_BY_DEFAULT = "preferences.showVerticalNavByDefault"; var SESSION_KEY_RESET_SUCCESS = "preferences.resetSuccess"; var STORAGE_KEYS_TO_PRESERVE = [ "connect.connections" //'osAuthCreds', ]; var PreferencesService = class { isShowVerticalNavByDefault() { const value = localStorage.getItem(STORAGE_KEY_SHOW_VERTICAL_NAV_BY_DEFAULT); return value ? JSON.parse(value) : true; } saveShowVerticalNavByDefault(value) { localStorage.setItem(STORAGE_KEY_SHOW_VERTICAL_NAV_BY_DEFAULT, JSON.stringify(value)); } reset() { log.info("Reset preferences"); const backup = STORAGE_KEYS_TO_PRESERVE.reduce( (acc, key) => { const value = localStorage.getItem(key); if (value) { acc[key] = value; } return acc; }, {} ); localStorage.clear(); Object.entries(backup).forEach(([key, value]) => localStorage.setItem(key, value)); sessionStorage.setItem(SESSION_KEY_RESET_SUCCESS, "true"); } isResetSuccess() { const value = sessionStorage.getItem(SESSION_KEY_RESET_SUCCESS); setTimeout(() => sessionStorage.removeItem(SESSION_KEY_RESET_SUCCESS), 1e3); return value ? JSON.parse(value) : false; } }; var preferencesService = new PreferencesService(); // src/preferences/HomePreferences.tsx var HomePreferences = () => { const { hawtconfig, hawtconfigLoaded } = _chunkZYPGXT7Qjs.useHawtconfig.call(void 0, ); if (!hawtconfigLoaded) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, HawtioLoadingPage, {}); const sideBarShown = _nullishCoalesce(_optionalChain([hawtconfig, 'access', _ => _.appearance, 'optionalAccess', _2 => _2.showSideBar]), () => ( true)); return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CardBody, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Form, { isHorizontal: true, children: [ sideBarShown && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.FormSection, { title: "UI", titleElement: "h2", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, UIForm, {}) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.FormSection, { title: "Reset", titleElement: "h2", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ResetForm, {}) }) ] }) }); }; var UIForm = () => { const [showVerticalNav, setShowVerticalNav] = _react.useState.call(void 0, preferencesService.isShowVerticalNavByDefault()); const handleShowVerticalNavChange = (value) => { setShowVerticalNav(value); preferencesService.saveShowVerticalNavByDefault(value); }; return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.FormGroup, { label: "Default vertical nav state", fieldId: "ui-form-vertical-nav-switch", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Switch, { "data-testid": "switch-vertical-nav-state", label: "Show vertical navigation", labelOff: "Hide vertical navigation", isChecked: showVerticalNav, onChange: (_event, value) => handleShowVerticalNavChange(value) } ) }); }; var ResetForm = () => { const navigate = _reactrouterdom.useNavigate.call(void 0, ); const [isConfirmResetOpen, setIsConfirmResetOpen] = _react.useState.call(void 0, false); const reset = () => { preferencesService.reset(); navigate(0); }; const confirmReset = () => { setIsConfirmResetOpen(!isConfirmResetOpen); }; const ConfirmResetModal = () => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Modal, { "data-testid": "reset-settings-modal", variant: _reactcore.ModalVariant.small, title: "Reset settings", titleIconVariant: "danger", isOpen: isConfirmResetOpen, onClose: confirmReset, actions: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Button, { "data-testid": "reset-btn", variant: "danger", onClick: reset, children: "Reset" }, "reset"), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Button, { "data-testid": "cancel-btn", variant: "link", onClick: confirmReset, children: "Cancel" }, "cancel") ], children: "You are about to reset all the Hawtio settings." } ); const resetSuccess = preferencesService.isResetSuccess(); return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, React11.default.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.FormGroup, { label: "Reset settings", fieldId: "reset-form-reset", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Button, { "data-testid": "reset-btn", variant: "danger", onClick: confirmReset, children: "Reset" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.FormHelperText, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.HelperText, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.HelperTextItem, { children: "Clear all custom settings stored in your browser`s local storage and reset to defaults." }) }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ConfirmResetModal, {}) ] }), resetSuccess && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Alert, { variant: "success", isInline: true, title: "Settings reset successfully!" }) ] }); }; // src/preferences/LogsPreferences.tsx var _plusicon = require('@patternfly/react-icons/dist/esm/icons/plus-icon'); var _trashicon = require('@patternfly/react-icons/dist/esm/icons/trash-icon'); // src/preferences/context.ts function useChildLoggers() { const [childLoggers, setChildLoggers] = _react.useState.call(void 0, _chunkZYPGXT7Qjs.Logger.getChildLoggers()); const [availableChildLoggers, setAvailableChildLoggers] = _react.useState.call(void 0, _chunkZYPGXT7Qjs.Logger.getAvailableChildLoggers()); const reloadChildLoggers = () => { setChildLoggers(_chunkZYPGXT7Qjs.Logger.getChildLoggers()); setAvailableChildLoggers(_chunkZYPGXT7Qjs.Logger.getAvailableChildLoggers()); }; return { childLoggers, setChildLoggers, availableChildLoggers, setAvailableChildLoggers, reloadChildLoggers }; } var LogsContext = _react.createContext.call(void 0, { childLoggers: [], availableChildLoggers: [], reloadChildLoggers: () => { } }); // src/preferences/LogsPreferences.tsx var LogsPreferences = () => { const { childLoggers, availableChildLoggers, reloadChildLoggers } = useChildLoggers(); const ChildLoggerList = () => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DataList, { id: "logs-child-logger-list", "aria-label": "logs child logger list", isCompact: true, children: childLoggers.map((childLogger) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ChildLoggerItem, { logger: childLogger }, childLogger.name)) }); return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LogsContext.Provider, { value: { childLoggers, availableChildLoggers, reloadChildLoggers }, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CardBody, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Form, { isHorizontal: true, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.FormSection, { title: "Global log settings", titleElement: "h2", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, GlobalForms, {}) }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.FormSection, { title: "Child loggers", titleElement: "h2", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ChildLoggerToolbar, {}), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ChildLoggerList, {}) ] }) ] }) }) }); }; var LOG_LEVEL_OPTIONS = ["OFF", "ERROR", "WARN", "INFO", "DEBUG"]; var GlobalForms = () => { const [logLevel, setLogLevel] = _react.useState.call(void 0, _chunkZYPGXT7Qjs.Logger.getLevel().name); const handleLogLevelChange = (level) => { if (!level) { return; } setLogLevel(level); _chunkZYPGXT7Qjs.Logger.setLevel(level); }; return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, React11.default.Fragment, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.FormGroup, { label: "Log level", fieldId: "logs-global-form-log-level", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Slider, { id: "logs-global-form-log-level-slider", value: LOG_LEVEL_OPTIONS.findIndex((level) => level === logLevel), max: LOG_LEVEL_OPTIONS.length - 1, customSteps: LOG_LEVEL_OPTIONS.map((level, index) => ({ value: index, label: level })), onChange: (_event, value) => handleLogLevelChange(LOG_LEVEL_OPTIONS[value]) } ) }) }); }; var ChildLoggerToolbar = () => { const { availableChildLoggers, reloadChildLoggers } = _react.useContext.call(void 0, LogsContext); const [isAddOpen, setIsAddOpen] = _react.useState.call(void 0, false); const handleAddToggle = () => { setIsAddOpen(!isAddOpen); }; const addChildLogger = (logger) => () => { _chunkZYPGXT7Qjs.Logger.addChildLogger(logger); reloadChildLoggers(); }; const availableChildLoggerItems = availableChildLoggers.map((logger) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DropdownItem, { onClick: addChildLogger(logger), children: logger.name }, logger.name)); return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Toolbar, { id: "connect-toolbar", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.ToolbarContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.ToolbarItem, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Dropdown, { onSelect: handleAddToggle, onOpenChange: setIsAddOpen, toggle: (toggleRef) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.MenuToggle, { ref: toggleRef, id: "logs-child-logger-toolbar-dropdown-toggle", variant: "secondary", onClick: handleAddToggle, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _plusicon.PlusIcon, {}), " Add" ] } ), isOpen: isAddOpen, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DropdownList, { children: availableChildLoggerItems }) } ) }) }) }); }; var ChildLoggerItem = (props) => { const { logger } = props; const { reloadChildLoggers } = _react.useContext.call(void 0, LogsContext); const name = logger.name; const onLogLevelChange = (level) => { if (!level) { return; } _chunkZYPGXT7Qjs.Logger.updateChildLogger(logger.name, level); reloadChildLoggers(); }; const deleteChildLogger = () => { _chunkZYPGXT7Qjs.Logger.removeChildLogger(logger); reloadChildLoggers(); }; return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DataListItem, { "aria-labelledby": `logs child logger ${name}`, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DataListItemRow, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DataListItemCells, { dataListCells: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DataListCell, { width: 1, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "b", { children: name }) }, `logs-child-logger-name-${name}`), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DataListCell, { width: 2, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Slider, { id: `logs-child-logger-actions-log-level-slider-${name}`, value: LOG_LEVEL_OPTIONS.findIndex((level) => level === logger.filterLevel.name), max: LOG_LEVEL_OPTIONS.length - 1, customSteps: LOG_LEVEL_OPTIONS.map((level, index) => ({ value: index, label: level })), onChange: (_event, value) => onLogLevelChange(LOG_LEVEL_OPTIONS[value]) } ) }, `logs-child-logger-log-level-${name}`) ] } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DataListAction, { id: `logs-child-logger-actions-${name}`, "aria-label": `logs child logger actions ${name}`, "aria-labelledby": `${name} logs-child-logger-actions-${name}`, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Button, { variant: "secondary", onClick: deleteChildLogger, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _trashicon.TrashIcon, {}) }) } ) ] }) }, `logs-child-logger-${name}`); }; // src/preferences/HawtioPreferences.tsx _chunkS4RWX7OXjs.helpRegistry.add("preferences", "Preferences", help_default2, 2); _chunkS4RWX7OXjs.preferencesRegistry.add("home", "Home", HomePreferences, 1); _chunkS4RWX7OXjs.preferencesRegistry.add("console-logs", "Console Logs", LogsPreferences, 2); var HawtioPreferences = () => { const location = _reactrouterdom.useLocation.call(void 0, ); return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, React11.default.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { variant: _reactcore.PageSectionVariants.light, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Title, { headingLevel: "h1", children: "Preferences" }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Divider, {}), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { type: "tabs", hasShadowBottom: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Nav, { "aria-label": "Nav", variant: "tertiary", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.NavList, { children: _chunkS4RWX7OXjs.preferencesRegistry.getPreferences().map((prefs) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.NavItem, { isActive: location.pathname === `/preferences/${prefs.id}`, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.NavLink, { to: prefs.id, children: prefs.title }) }, prefs.id)) }) }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Divider, {}), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { variant: _reactcore.PageSectionVariants.light, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactrouterdom.Routes, { children: [ _chunkS4RWX7OXjs.preferencesRegistry.getPreferences().map((prefs) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Route, { path: prefs.id, element: React11.default.createElement(prefs.component) }, prefs.id)), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Route, { path: "/", element: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Navigate, { to: "home" }) }) ] }) }) ] }); }; // src/ui/page/HawtioPage.tsx var _cubesicon = require('@patternfly/react-icons/dist/esm/icons/cubes-icon'); // src/ui/notification/HawtioNotification.tsx var MAX_ALERTS_TO_DISPLAY = 5; var HawtioNotification = () => { const [alerts, setAlerts] = _react.useState.call(void 0, []); const [overflowMessage, setOverflowMessage] = _react.useState.call(void 0, ""); const [maxDisplayed, setMaxDisplayed] = _react.useState.call(void 0, MAX_ALERTS_TO_DISPLAY); const getOverflowMessage = (alertsNumber) => { const overflow = alertsNumber - maxDisplayed; return overflow > 0 ? `View ${overflow} more alerts` : ""; }; const addAlert = (title, variant, key) => { const newAlerts = [...alerts, { title, variant, key }]; setAlerts(newAlerts); setOverflowMessage(getOverflowMessage(newAlerts.length)); setMaxDisplayed(MAX_ALERTS_TO_DISPLAY); }; const removeAlert = (key) => { const newAlerts = alerts.filter((alert) => alert.key !== key); setAlerts(newAlerts); setOverflowMessage(getOverflowMessage(newAlerts.length)); setMaxDisplayed(MAX_ALERTS_TO_DISPLAY); }; const getUniqueKey = () => (/* @__PURE__ */ new Date()).getTime(); _react.useEffect.call(void 0, () => { const listener = (notification) => { const key = getUniqueKey(); addAlert(notification.message, notification.type, key); if (notification.duration) { setTimeout(() => { removeAlert(key); }, notification.duration); } }; _chunkZYPGXT7Qjs.eventService.onNotify(listener); return () => _chunkZYPGXT7Qjs.eventService.removeListener(_chunkZYPGXT7Qjs.EVENT_NOTIFY, listener); }, []); const onOverflowClick = () => { setMaxDisplayed(alerts.length); setOverflowMessage(""); }; return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.AlertGroup, { isToast: true, isLiveRegion: true, onOverflowClick, overflowMessage, children: alerts.slice(0, maxDisplayed).map(({ key, variant, title }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Alert, { variant, title, actionClose: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.AlertActionCloseButton, { title, variantLabel: `${variant} alert`, onClose: () => key && removeAlert(key) } ) }, key )) }); }; // src/ui/about/HawtioAbout.tsx // src/ui/about/context.ts function useAbout() { const [about, setAbout] = _react.useState.call(void 0, {}); const [aboutLoaded, setAboutLoaded] = _react.useState.call(void 0, false); _react.useEffect.call(void 0, () => { const loadAbout = async () => { const config = await _chunkZYPGXT7Qjs.configManager.getHawtconfig(); if (config.about) { setAbout(config.about); } setAboutLoaded(true); }; loadAbout(); }, []); return { about, aboutLoaded }; } // src/ui/about/globals.ts var log2 = _chunkZYPGXT7Qjs.Logger.get("hawtio-ui-about"); // src/ui/about/HawtioAbout.tsx var HawtioAbout = (props) => { const { about, aboutLoaded } = useAbout(); if (!aboutLoaded) { return null; } const imgSrc = about.imgSrc || hawtio_logo_default; const backgroundImgSrc = about.backgroundImgSrc; const title = about.title || "Hawtio Management Console"; const copyright = about.copyright || "\xA9 Hawtio project"; const AboutDescription = () => { if (about.description) { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.TextContent, { id: "hawtio-about-description", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Text, { component: "p", children: about.description }) }); } return null; }; const productInfo = about.productInfo || []; productInfo.sort((a, b) => _chunkZYPGXT7Qjs.stringSorter.call(void 0, a.name, b.name)); log2.debug("Product info:", productInfo); const AboutProductInfo = () => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.TextContent, { id: "hawtio-about-product-info", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Text, { component: "h3", children: "Component versions" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.TextList, { component: "dl", children: productInfo.map((info, index) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, React11.default.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.TextListItem, { component: "dt", children: info.name }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.TextListItem, { component: "dd", children: info.value }) ] }, `product-info-${index}`)) }) ] }); return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.AboutModal, { isOpen: props.isOpen, onClose: props.onClose, productName: title, brandImageSrc: imgSrc, backgroundImageSrc: backgroundImgSrc, brandImageAlt: title, trademark: copyright, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AboutDescription, {}), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AboutProductInfo, {}) ] } ); }; // src/ui/page/HawtioHeader.tsx var _barsicon = require('@patternfly/react-icons/dist/esm/icons/bars-icon'); var _helpicon = require('@patternfly/react-icons/dist/esm/icons/help-icon'); // src/ui/page/context.ts var PageContext = _react.createContext.call(void 0, { username: "", plugins: [] }); // src/ui/page/HawtioHeader.tsx var HawtioHeader = ({ loginMethod }) => { const { hawtconfig, hawtconfigLoaded } = _chunkZYPGXT7Qjs.useHawtconfig.call(void 0, ); const [navOpen, setNavOpen] = _react.useState.call(void 0, preferencesService.isShowVerticalNavByDefault()); if (!hawtconfigLoaded) { return null; } const onNavToggle = () => setNavOpen(!navOpen); const sideBarShown = _nullishCoalesce(_optionalChain([hawtconfig, 'access', _3 => _3.appearance, 'optionalAccess', _4 => _4.showSideBar]), () => ( true)); const isBrandShown = _nullishCoalesce(_optionalChain([hawtconfig, 'access', _5 => _5.appearance, 'optionalAccess', _6 => _6.showBrand]), () => ( true)); return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Masthead, { id: "hawtio-header", display: { default: "inline" }, children: [ sideBarShown && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.MastheadToggle, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageToggleButton, { variant: "plain", "aria-label": "Global navigation", isSidebarOpen: navOpen, onSidebarToggle: onNavToggle, id: "vertical-nav-toggle", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _barsicon.BarsIcon, {}) } ) }), isBrandShown && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.MastheadMain, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, HawtioBrand, { hawtconfig }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.MastheadContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, HawtioHeaderToolbar, { hawtconfig, loginMethod }) }) ] }); }; var HawtioBrand = (props) => { const appLogo = _nullishCoalesce(_optionalChain([props, 'access', _7 => _7.hawtconfig, 'access', _8 => _8.branding, 'optionalAccess', _9 => _9.appLogoUrl]), () => ( hawtio_logo_default)); const appName = _nullishCoalesce(_optionalChain([props, 'access', _10 => _10.hawtconfig, 'access', _11 => _11.branding, 'optionalAccess', _12 => _12.appName]), () => ( _chunkZYPGXT7Qjs.DEFAULT_APP_NAME)); const showAppName = _nullishCoalesce(_optionalChain([props, 'access', _13 => _13.hawtconfig, 'access', _14 => _14.branding, 'optionalAccess', _15 => _15.showAppName]), () => ( false)); return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.MastheadBrand, { id: "hawtio-header-brand", component: (props2) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Link, { to: "/", ...props2 }), children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Brand, { src: appLogo, alt: appName }), showAppName && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Title, { headingLevel: "h1", size: "xl", children: appName }) ] }); }; var HawtioHeaderToolbar = (props) => { const { username, plugins } = _react.useContext.call(void 0, PageContext); const location = _reactrouterdom.useLocation.call(void 0, ); const isPublic = username === _chunkZYPGXT7Qjs.PUBLIC_USER; const [helpOpen, setHelpOpen] = _react.useState.call(void 0, false); const [userOpen, setUserOpen] = _react.useState.call(void 0, false); const [aboutOpen, setAboutOpen] = _react.useState.call(void 0, false); const onHelpSelect = () => setHelpOpen(!helpOpen); const onUserSelect = () => setUserOpen(!userOpen); const onAboutToggle = () => setAboutOpen(!aboutOpen); const logout = async () => { const success = await _chunkZYPGXT7Qjs.userService.logout(); if (!success) { _chunkZYPGXT7Qjs.eventService.notify({ type: "danger", message: "Logout failed. Please check console logs.", duration: 3e3 }); } }; const userHeaderShown = _nullishCoalesce(_optionalChain([props, 'access', _16 => _16.hawtconfig, 'access', _17 => _17.appearance, 'optionalAccess', _18 => _18.showUserHeader]), () => ( true)); const helpItems = [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DropdownItem, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Link, { to: "../help", children: "Help" }), " " ] }, "help"), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DropdownItem, { onClick: onAboutToggle, children: "About" }, "about") ]; const userItems = [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DropdownItem, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Link, { to: "../preferences", children: "Preferences" }) }, "preferences"), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DropdownItem, { onClick: logout, children: "Log out" }, "logout") ]; if (isPublic) { userItems.pop(); } const collectHeaderItems = () => { const path = location.pathname; const components = []; plugins.forEach((plugin) => { if (!plugin.headerItems || plugin.headerItems.length === 0) return; if (plugin.path && path.startsWith(plugin.path)) { components.push( ...plugin.headerItems.map( (headerItem) => _chunkZYPGXT7Qjs.isUniversalHeaderItem.call(void 0, headerItem) ? headerItem.component : headerItem ) ); return; } components.push( ...plugin.headerItems.filter( (headerItem) => _chunkZYPGXT7Qjs.isUniversalHeaderItem.call(void 0, headerItem) && headerItem.universal === true ).map((headerItem) => headerItem.component) ); }); return components; }; const headerComponents = collectHeaderItems(); return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Toolbar, { id: "hawtio-header-toolbar", isFullHeight: true, children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.ToolbarContent, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.ToolbarGroup, { children: headerComponents.map((component, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.ToolbarItem, { children: React11.default.createElement(component) }, `hawtio-header-toolbar-plugin-item-${index}`)) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.ToolbarGroup, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.ToolbarItem, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Dropdown, { onSelect: onHelpSelect, onOpenChange: setHelpOpen, toggle: (toggleRef) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.MenuToggle, { variant: "plain", ref: toggleRef, onClick: () => setHelpOpen(!helpOpen), isExpanded: helpOpen, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _helpicon.HelpIcon, {}) } ), isOpen: helpOpen, children: helpItems } ) }) }), userHeaderShown && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.ToolbarGroup, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.ToolbarItem, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Dropdown, { onSelect: onUserSelect, isOpen: userOpen, onOpenChange: setUserOpen, toggle: (toggleRef) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.MenuToggle, { ref: toggleRef, id: "hawtio-header-user-dropdown-toggle", onClick: () => setUserOpen(!userOpen), icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Avatar, { src: img_avatar_default, alt: "user" }), isExpanded: userOpen, isFullHeight: true, children: isPublic ? "" : username } ), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DropdownList, { children: userItems }) } ) }) }) ] }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, HawtioAbout, { isOpen: aboutOpen, onClose: onAboutToggle }) ] }); }; // src/ui/page/HawtioSidebar.tsx var HawtioSidebar = () => { const { plugins } = _react.useContext.call(void 0, PageContext); const { pathname } = _reactrouterdom.useLocation.call(void 0, ); const pathMatch = (path, pluginPath) => { if (!pluginPath.startsWith("/")) { pluginPath = "/" + pluginPath; } return path.startsWith(pluginPath); }; const pageNav = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Nav, { theme: "dark", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.NavList, { children: plugins.filter((plugin) => plugin.path != null).map((plugin) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.NavItem, { isActive: pathMatch(pathname, plugin.path), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.NavLink, { to: plugin.path, children: plugin.title }) }, plugin.id)) }) }); return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSidebar, { theme: "dark", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSidebarBody, { children: pageNav }) }); }; // src/ui/page/globals.ts var log3 = _chunkZYPGXT7Qjs.Logger.get("hawtio-ui-page"); // src/ui/session/globals.ts var log4 = _chunkZYPGXT7Qjs.Logger.get("hawtio-ui-session"); // src/ui/session/session-service.ts var SessionService = (_class = class { __init() {this.lastActivity = 0} __init2() {this.lastRefresh = 0} // flag set to true by all user interaction. If set, a periodic "refresh" request is sent and the flag is cleared // if the flag is not set again with another user interaction, the refreshes stop and session may expire at server side __init3() {this.keepAlive = true} // when this flag is set, SessionMonitor component should be informed. it'll reset its state then __init4() {this.resetTimer = false} // a flag which may be used to disable "userActivity()" handler __init5() {this.refresh = true} __init6() {this.sessionConfig = null} __init7() {this.sessionConfigReady = null} __init8() {this.sessionTimeout = -1} constructor() {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this); this.sessionConfigReadyPromise = new Promise((resolve) => { this.sessionConfigReady = resolve; }); this.fetchConfiguration(); } /** * Calling this method means that user performed some action and is expecting to keep the (server-side) session * alive. * We can use this method in various places depending on needs. * Initially I used it in useEffect(..., [location]), where "location" was from useLocation hook (react-router). * But this didn't work when clicking on JMX tree nodes. */ userActivity() { if (!this.refresh) { return; } this.keepAlive = true; const now = Date.now(); if (now - this.lastRefresh > 5e3) { this.updateSession(); this.resetTimer = true; } this.lastActivity = Date.now(); } /** * This method should be called when there's a need to ping server, so the (server-side) session is kept alive. * Normally this should not be called on each call to userActivity(). */ updateSession() { if (!this.keepAlive || this.sessionTimeout <= 0) { return false; } fetch("refresh").catch(() => false); this.keepAlive = false; this.lastRefresh = Date.now(); return true; } /** * Indicates whether given "time before session end" means that the session is expiring (to display alert) * @param time */ sessionEnding(time) { return time >= 0 && time < 21; } /** * Indicates whether the session is ended and user should be logged-out * @param time */ sessionEnded(time) { return time <= 0 && this.sessionTimeout > 0; } /** * Returns session timeout in seconds. If "-1", there's no session and session tracking is enabled. */ getSessionTimeout() { return this.sessionTimeout; } shouldResetTimer() { return this.resetTimer; } clearResetTimerFlag() { this.resetTimer = false; } async configReady() { return this.sessionConfigReadyPromise; } async fetchConfiguration() { this.sessionTimeout = -1; _chunkZYPGXT7Qjs.configManager.initItem("Checking session support", 0 /* started */, "config"); this.sessionConfig = await fetch("auth/config/session-timeout?t=" + Date.now()).then((response) => { if (!response.ok) { _chunkZYPGXT7Qjs.configManager.initItem("Checking session support", 1 /* skipped */, "config"); return { timeout: -1 }; } return response.json(); }).then((json) => { if (!json.timeout || json.timeout <= 0) { json.timeout = -1; } json.res = Date.now(); log4.debug("Session configuration", json); _chunkZYPGXT7Qjs.configManager.initItem("Checking session support", 2 /* finished */, "config"); this.sessionConfigReady(true); return json; }).catch(() => { _chunkZYPGXT7Qjs.configManager.initItem("Checking session support", 1 /* skipped */, "config"); this.sessionConfigReady(false); return { timeout: -1 }; }); if (this.sessionConfig.timeout > 0) { this.sessionTimeout = Math.floor( (this.sessionConfig.timeout * 1e3 + this.sessionConfig.now - this.sessionConfig.req) / 1e3 ); if (this.sessionTimeout <= 30) { this.sessionTimeout = -1; } } } /** * Can be used to enable/disable on-click refreshes. Should be disabled when we display a Modal with explicit * "keep session" button */ setRefresh(refresh) { this.refresh = refresh; } }, _class); var sessionService = new SessionService(); // src/ui/session/SessionMonitor.tsx var SessionMonitor = () => { const [sessionAlertVisible, setSessionAlertVisible] = _react.useState.call(void 0, false); const [time, setTime] = _react.useState.call(void 0, -1); const [configured, setConfigured] = _react.useState.call(void 0, false); _react.useEffect.call(void 0, () => { let ticker = null; const configureSession = setTimeout(async () => { await sessionService.configReady(); const sessionTimeout = sessionService.getSessionTimeout(); if (sessionTimeout > 0) { setTime(sessionTimeout); setConfigured(true); ticker = setInterval(() => { if (sessionService.shouldResetTimer()) { setTime(sessionService.getSessionTimeout()); sessionService.clearResetTimerFlag(); } else { setTime((v) => { return v > 0 ? v - 1 : v; }); } }, 1e3); } }, 0); const periodicalRefresh = setInterval(async () => { if (sessionService.updateSession()) { setTime(sessionService.getSessionTimeout()); } }, 5e3); return () => { clearTimeout(configureSession); if (ticker != null) { clearInterval(ticker); } clearInterval(periodicalRefresh); }; }, []); _react.useEffect.call(void 0, () => { if (!configured) { return; } if (sessionService.sessionEnding(time)) { sessionService.setRefresh(false); setSessionAlertVisible(true); } if (sessionService.sessionEnded(time)) { setTimeout(() => { _chunkZYPGXT7Qjs.userService.logout(); }, 1e3); } }, [time, configured]); const keepSessionAlive = () => { setSessionAlertVisible(false); sessionService.setRefresh(true); sessionService.updateSession(); setTime(sessionService.getSessionTimeout()); }; return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, React11.default.Fragment, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Modal,