UNPKG

@hawtio/react

Version:

A Hawtio reimplementation based on TypeScript + React.

262 lines (210 loc) 11.9 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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 _chunkHS42NURZjs = require('./chunk-HS42NURZ.js'); var _chunkUB6QWSAJjs = require('./chunk-UB6QWSAJ.js'); require('./chunk-BLJGIIMV.js'); require('./chunk-WYFZRJ4C.js'); var _chunkBJ6TSPQKjs = require('./chunk-BJ6TSPQK.js'); var _chunkBHIEXRGKjs = require('./chunk-BHIEXRGK.js'); // src/plugins/jmx/Jmx.tsx var _reactcore = require('@patternfly/react-core'); var _cubesicon = require('@patternfly/react-icons/dist/esm/icons/cubes-icon'); var _reactsplit = require('react-split'); var _reactsplit2 = _interopRequireDefault(_reactsplit); // src/plugins/jmx/context.ts var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _reactrouterdom = require('react-router-dom'); function useMBeanTree() { const [tree, setTree] = _react.useState.call(void 0, _chunkBJ6TSPQKjs.MBeanTree.createEmpty(_chunkHS42NURZjs.pluginName2)); const [loaded, setLoaded] = _react.useState.call(void 0, false); const { selectedNode, setSelectedNode } = _react.useContext.call(void 0, _chunkBJ6TSPQKjs.PluginNodeSelectionContext); const navigate = _reactrouterdom.useNavigate.call(void 0, ); const refSelectedNode = _react.useRef.call(void 0, ); refSelectedNode.current = selectedNode; const populateTree = async () => { const wkspTree = await _chunkBJ6TSPQKjs.workspace.getTree(); setTree(wkspTree); if (!refSelectedNode.current) return; const path = [...refSelectedNode.current.path()]; wkspTree.forEach(path, (node) => { node.defaultExpanded = true; }); const newSelected = wkspTree.navigate(...path); if (newSelected) setSelectedNode(newSelected); navigate(_chunkHS42NURZjs.pluginPath2); }; _react.useEffect.call(void 0, () => { const loadTree = async () => { await populateTree(); setLoaded(true); }; const listener = () => { setLoaded(false); loadTree(); }; _chunkBHIEXRGKjs.eventService.onRefresh(listener); loadTree(); return () => _chunkBHIEXRGKjs.eventService.removeListener(_chunkBHIEXRGKjs.EVENT_REFRESH, listener); }, []); return { tree, loaded, selectedNode, setSelectedNode }; } var MBeanTreeContext = _react.createContext.call(void 0, { tree: _chunkBJ6TSPQKjs.MBeanTree.createEmpty(_chunkHS42NURZjs.pluginName2), selectedNode: null, setSelectedNode: () => { } }); // src/plugins/jmx/JmxContent.tsx var _jsxruntime = require('react/jsx-runtime'); var JmxContent = () => { const { selectedNode } = _react.useContext.call(void 0, MBeanTreeContext); const { pathname, search } = _reactrouterdom.useLocation.call(void 0, ); if (!selectedNode) { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { hasBodyWrapper: false, isFilled: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.EmptyState, { headingLevel: "h1", icon: _cubesicon.CubesIcon, titleText: "Select MBean", variant: _reactcore.EmptyStateVariant.full } ) }); } const mBeanApplicable = (node) => Boolean(node.objectName); const mBeanCollectionApplicable = (node) => Boolean(_optionalChain([node, 'access', _ => _.children, 'optionalAccess', _2 => _2.every, 'call', _3 => _3((child) => child.objectName)])); const hasAnyApplicableMBean = (node) => Boolean(node.objectName) || Boolean(_optionalChain([node, 'access', _4 => _4.children, 'optionalAccess', _5 => _5.some, 'call', _6 => _6((child) => child.objectName)])); const tableSelector = (node) => { const tablePriorityList = [ { condition: mBeanApplicable, element: _chunkBJ6TSPQKjs.Attributes }, { condition: mBeanCollectionApplicable, element: _chunkBJ6TSPQKjs.AttributeTable } ]; return _nullishCoalesce(_optionalChain([tablePriorityList, 'access', _7 => _7.find, 'call', _8 => _8((entry) => entry.condition(node)), 'optionalAccess', _9 => _9.element]), () => ( _chunkBJ6TSPQKjs.JmxContentMBeans)); }; const allNavItems = [ { id: "attributes", title: "Attributes", component: tableSelector(selectedNode), isApplicable: () => true }, { id: "operations", title: "Operations", component: _chunkBJ6TSPQKjs.Operations, isApplicable: mBeanApplicable }, { id: "chart", title: "Chart", component: _chunkBJ6TSPQKjs.Chart, isApplicable: hasAnyApplicableMBean } ]; const navItems = allNavItems.filter((nav) => nav.isApplicable(selectedNode)); const mbeanNav = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Nav, { "aria-label": "MBean Nav", variant: "horizontal-subnav", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.NavList, { children: navItems.map((nav) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.NavItem, { isActive: pathname === `${_chunkHS42NURZjs.pluginPath2}/${nav.id}`, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.NavLink, { to: { pathname: nav.id, search }, children: nav.title }) }, nav.id)) }) }); const mbeanRoutes = navItems.map((nav) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Route, { path: nav.id, element: _react2.default.createElement(nav.component) }, nav.id)); return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.PageGroup, { id: "jmx-content", children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.PageSection, { id: "jmx-content-header", hasBodyWrapper: false, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Title, { headingLevel: "h1", children: selectedNode.name }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Content, { component: "small", children: selectedNode.objectName }) ] }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { type: "tabs", hasBodyWrapper: false, children: mbeanNav }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { id: "jmx-content-main", padding: { default: "noPadding" }, hasOverflowScroll: true, "aria-label": "jmx-content-main", hasBodyWrapper: false, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactrouterdom.Routes, { children: [ mbeanRoutes, /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Route, { path: "/", element: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Navigate, { to: _nullishCoalesce(_optionalChain([navItems, 'access', _10 => _10[0], 'optionalAccess', _11 => _11.id]), () => ( "")) }) }, "root") ] }) } ) ] }); }; // src/plugins/jmx/JmxTreeView.tsx var JmxTreeView = () => { const { tree, selectedNode, setSelectedNode } = _react.useContext.call(void 0, MBeanTreeContext); const [expanded, setExpanded] = _react.useState.call(void 0, 0 /* Default */); const [filteredTree, setFilteredTree] = _react.useState.call(void 0, tree.getTree()); const navigate = _reactrouterdom.useNavigate.call(void 0, ); _react.useEffect.call(void 0, () => { setFilteredTree(tree.getTree()); }, [tree]); const onSearch = (event) => { setSelectedNode(null); setExpanded(0 /* Default */); const input = event.target.value; if (!input) setFilteredTree(tree.getTree()); const treeElements = _chunkBJ6TSPQKjs.MBeanTree.filter(tree.getTree(), (node) => node.name.toLowerCase().includes(input.toLowerCase())); if (treeElements.length === 0) setFilteredTree(tree.getTree()); else { setFilteredTree(treeElements); setExpanded(1 /* ExpandAll */); } }; const onSelect = (event, item) => { setSelectedNode(item); navigate(_chunkHS42NURZjs.pluginPath2); }; const setAllExpanded = (value) => { setExpanded(value ? 1 /* ExpandAll */ : 2 /* CollapseAll */); }; const expandedProp = () => { switch (expanded) { case 1 /* ExpandAll */: return { allExpanded: true }; case 2 /* CollapseAll */: return { allExpanded: false }; default: return {}; } }; return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.TreeView, { id: "jmx-tree-view", data: filteredTree, hasGuides: true, hasSelectableNodes: true, activeItems: selectedNode ? [selectedNode] : [], ...expandedProp(), onSelect, toolbar: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkBJ6TSPQKjs.PluginTreeViewToolbar, { onSearch, onSetExpanded: setAllExpanded }) } ); }; // src/plugins/jmx/Jmx.tsx var Jmx = () => { const { tree, loaded, selectedNode, setSelectedNode } = useMBeanTree(); if (!loaded) { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { hasBodyWrapper: false, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Spinner, { "aria-label": "Loading MBean tree" }) }); } if (tree.isEmpty()) { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { hasBodyWrapper: false, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.EmptyState, { headingLevel: "h1", icon: _cubesicon.CubesIcon, titleText: "No MBeans found", variant: _reactcore.EmptyStateVariant.full } ) }); } return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MBeanTreeContext.Provider, { value: { tree, selectedNode, setSelectedNode }, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactsplit2.default, { className: "jmx-split", sizes: [30, 70], minSize: 200, gutterSize: 5, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, JmxTreeView, {}) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, JmxContent, {}) }) ] }) }); }; // src/plugins/jmx/JmxPreferences.tsx var JmxPreferences = () => { const [options, setOptions] = _react.useState.call(void 0, _chunkBJ6TSPQKjs.jmxPreferencesService.loadOptions()); const updateOptions = (updated) => { _chunkBJ6TSPQKjs.jmxPreferencesService.saveOptions(updated); setOptions({ ...options, ...updated }); }; return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CardBody, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Form, { isHorizontal: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.FormGroup, { label: "Serialize long to string", fieldId: "serialize-long-to-string", labelHelp: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkUB6QWSAJjs.TooltipHelpIcon, { tooltip: "Serialize long values in the JSON responses from Jolokia to string" }), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Checkbox, { id: "serialize-long-to-string-input", isChecked: options.serializeLong, onChange: (_event, serializeLong) => updateOptions({ serializeLong }) } ) } ) }) }); }; exports.Jmx = Jmx; exports.JmxContent = JmxContent; exports.JmxPreferences = JmxPreferences; exports.JmxTreeView = JmxTreeView; //# sourceMappingURL=ui-OB3OMSB7.js.map