UNPKG

@hawtio/react

Version:

A Hawtio reimplementation based on TypeScript + React.

438 lines (406 loc) 21.9 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 _chunkXERDRIY3js = require('./chunk-XERDRIY3.js'); var _chunkS4RWX7OXjs = require('./chunk-S4RWX7OX.js'); require('./chunk-URJD3F2K.js'); require('./chunk-TM6OCU7K.js'); var _chunkZYPGXT7Qjs = require('./chunk-ZYPGXT7Q.js'); // src/plugins/springboot/Health.tsx var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _reactcore = require('@patternfly/react-core'); var _reacttable = require('@patternfly/react-table'); var _reactcharts = require('@patternfly/react-charts'); var _checkcircleicon = require('@patternfly/react-icons/dist/esm/icons/check-circle-icon'); var _exclamationcircleicon = require('@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon'); var _exclamationtriangleicon = require('@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon'); var _infocircleicon = require('@patternfly/react-icons/dist/esm/icons/info-circle-icon'); var _questioncircleicon = require('@patternfly/react-icons/dist/esm/icons/question-circle-icon'); var _jsxruntime = require('react/jsx-runtime'); var SPAN_6_COMPONENTS = ["diskSpace", "camelHealth", "camel"]; var ComponentDetails = ({ componentDetails }) => { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Table, { variant: "compact", borders: false, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Tbody, { style: { fontSize: "xx-small" }, children: componentDetails.map((detail, index) => { return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reacttable.Tr, { children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reacttable.Td, { children: [ _chunkZYPGXT7Qjs.humanizeLabels.call(void 0, detail.key), ":" ] }, detail.key + index), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Td, { children: typeof detail.value === "string" ? detail.value : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ComponentDetails, { componentDetails: detail.value }) }) ] }, "row" + detail.key + index); }) }) }); }; var HealthStatusIcon = ({ status }) => { switch (status) { case "UP": return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Icon, { status: "success", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _checkcircleicon.CheckCircleIcon, {}) }); case "DOWN": return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Icon, { status: "danger", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _exclamationcircleicon.ExclamationCircleIcon, {}) }); case "OUT_OF_SERVICE": return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Icon, { status: "warning", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _exclamationtriangleicon.ExclamationTriangleIcon, {}) }); case "UNKNOWN": return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Icon, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _questioncircleicon.QuestionCircleIcon, {}) }); default: return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Icon, { status: "info", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _infocircleicon.InfoCircleIcon, {}) }); } }; var DiskComponentDetails = ({ componentDetails }) => { const total = Number.parseInt(componentDetails.find((k) => k.key === "total").value); const free = Number.parseInt(componentDetails.find((k) => k.key === "free").value); const usedPercentage = Math.round((total - free) * 100 / total); return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Grid, { height: "100%", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.GridItem, { span: 6, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ComponentDetails, { componentDetails }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.GridItem, { span: 6, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcharts.ChartDonutUtilization, { ariaDesc: "Storage capacity", ariaTitle: "Donut utilization chart example", constrainToVisibleArea: true, data: { x: "Used Space", y: usedPercentage }, name: "chart2", subTitle: "of available space", title: `${usedPercentage}% used`, thresholds: [{ value: 90 }], width: 300 } ) }) ] }); }; var Health = () => { const [healthData, setHealthData] = _react.useState.call(void 0, ); _react.useEffect.call(void 0, () => { _chunkS4RWX7OXjs.springbootService.loadHealth().then((healthData2) => { setHealthData(healthData2); }); }, []); if (!healthData) { return null; } return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Grid, { hasGutter: true, span: 4, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.GridItem, { span: 12, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Card, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Flex, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, HealthStatusIcon, { status: _optionalChain([healthData, 'optionalAccess', _ => _.status]) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Title, { headingLevel: "h3", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { children: [ "Overall status: ", _optionalChain([healthData, 'optionalAccess', _2 => _2.status]) ] }) }) ] }) }) }) }), _optionalChain([healthData, 'optionalAccess', _3 => _3.components, 'access', _4 => _4.sort, 'call', _5 => _5((a, b) => { if (SPAN_6_COMPONENTS.includes(a.name)) return -1; else if (SPAN_6_COMPONENTS.includes(b.name)) return 1; else return a.name.localeCompare(b.name); }), 'access', _6 => _6.map, 'call', _7 => _7((component) => { const span = SPAN_6_COMPONENTS.includes(component.name) ? 6 : 4; return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.GridItem, { span, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Card, { isFullHeight: true, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Title, { headingLevel: "h3", children: _chunkZYPGXT7Qjs.humanizeLabels.call(void 0, component.name) }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CardBody, { style: { overflow: "auto" }, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Flex, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.FlexItem, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, HealthStatusIcon, { status: component.status }) }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.FlexItem, { children: [ "Status: ", component.status ] }), component.details && (component.name === "diskSpace" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, DiskComponentDetails, { componentDetails: component.details }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ComponentDetails, { componentDetails: component.details })) ] }) }) ] }) }, component.name); })]) ] }); }; // src/plugins/springboot/Info.tsx var Info = () => { const [systemProperties, setSystemProperties] = _react.useState.call(void 0, []); _react.useEffect.call(void 0, () => { _chunkS4RWX7OXjs.springbootService.getInfo().then((res) => { setSystemProperties(res); }); }, []); return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.FormGroup, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reacttable.Table, { "aria-label": "Message Table", variant: "compact", height: "80vh", isStriped: true, isStickyHeader: true, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Thead, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reacttable.Tr, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Th, { "data-testid": "name-header", children: "Property Name" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Th, { "data-testid": "value-header", children: "Property Value" }) ] }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Tbody, { children: systemProperties.map((prop, index) => { return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reacttable.Tr, { "data-testid": "row" + index, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Td, { style: { width: "20%" }, children: prop.key }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Td, { style: { flex: 3 }, children: prop.value }) ] }, "row" + index); }) }) ] }) }); }; // src/plugins/springboot/Loggers.tsx var SetLogDropdown = ({ currentLevel, loggerName, logLevels, setIsDropdownOpen, isDropdownOpen, reloadLoggers }) => { const items = logLevels.map((level) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DropdownItem, { onClick: () => { _chunkS4RWX7OXjs.springbootService.configureLogLevel(loggerName, level); reloadLoggers(); }, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LogLevel, { level }) }, loggerName + "" + level )); return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Dropdown, { onSelect: () => setIsDropdownOpen(null), onOpenChange: () => setIsDropdownOpen(null), defaultValue: currentLevel, toggle: (toggleRef) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.MenuToggle, { ref: toggleRef, id: `toggle-basic-${loggerName}`, onClick: () => setIsDropdownOpen((prevState) => prevState === loggerName ? null : loggerName), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LogLevel, { level: currentLevel }) } ), isOpen: isDropdownOpen === loggerName, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DropdownList, { children: items }) } ); }; var LogLevel = ({ level }) => { switch (level) { case "TRACE": case "OFF": case "DEBUG": return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Label, { color: "grey", children: level }); case "INFO": return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Label, { color: "blue", children: level }); case "WARN": return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Label, { color: "orange", children: level }); case "ERROR": return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Label, { color: "red", children: level }); default: return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react2.default.Fragment, { children: level }); } }; var Loggers = () => { const [loggers, setLoggers] = _react.useState.call(void 0, []); const [logLevels, setLogLevels] = _react.useState.call(void 0, []); const [isDropdownOpen, setIsDropdownOpen] = _react.useState.call(void 0, null); const [reloadLoggers, setReloadLoggers] = _react.useState.call(void 0, false); _react.useEffect.call(void 0, () => { _chunkS4RWX7OXjs.springbootService.getLoggerConfiguration().then((logConf) => { const sorted = logConf.loggers.sort((logger1, logger2) => { if (logger1.name === "ROOT") return -1; else if (logger2.name === "ROOT") return 1; else return logger1.name.localeCompare(logger2.name); }); setLoggers(sorted); setLogLevels([...logConf.levels]); }); }, [reloadLoggers]); return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react2.default.Fragment, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXERDRIY3js.FilteredTable, { rows: loggers, highlightSearch: true, tableColumns: [ { name: "Log Level", key: "configuredLevel", percentageWidth: 20, renderer: (logger) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SetLogDropdown, { loggerName: logger.name, currentLevel: logger.configuredLevel, logLevels, setIsDropdownOpen, isDropdownOpen, reloadLoggers: () => { setReloadLoggers(!reloadLoggers); } } ) }, { name: "Logger Name", key: "name", percentageWidth: 80 } ], searchCategories: [{ key: "name", name: "Logger Name" }], fixedSearchCategories: [ { name: "Log Level", key: "configuredLevel", ariaLabel: "Log Level", values: logLevels, renderer: (val) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LogLevel, { level: val }) } ] } ) }); }; // src/plugins/springboot/SpringBoot.tsx var _reactrouterdom = require('react-router-dom'); // src/plugins/springboot/TraceView.tsx var HttpStatusIcon = ({ code }) => { if (code < 400) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Icon, { status: "success", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _checkcircleicon.CheckCircleIcon, {}) }); else return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Icon, { status: "danger", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _exclamationcircleicon.ExclamationCircleIcon, {}) }); }; var HttpMethodLabel = ({ method }) => { switch (method) { case "GET": case "HEAD": return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Label, { color: "blue", children: method }); case "POST": return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Label, { color: "orange", children: method }); case "DELETE": return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Label, { color: "red", children: method }); case "PUT": case "PATCH": return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Label, { color: "green", children: method }); default: return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Label, { color: "grey", children: method }); } }; var TraceDetails = ({ isOpen, setIsOpen, traceInfo }) => { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Modal, { bodyAriaLabel: "Trace detail", tabIndex: 0, isOpen, variant: "large", title: "Trace", onClose: () => setIsOpen(false), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CodeBlock, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CodeBlockCode, { children: traceInfo }) }) } ); }; var TraceView = () => { const [traces, setTraces] = _react.useState.call(void 0, []); const [isTraceDetailsOpen, setIsTraceDetailsOpen] = _react.useState.call(void 0, false); const [traceDetails, setTraceDetails] = _react.useState.call(void 0, ""); _react.useEffect.call(void 0, () => { _chunkS4RWX7OXjs.springbootService.loadTraces().then((traces2) => { setTraces(traces2); }); }, []); return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react2.default.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TraceDetails, { isOpen: isTraceDetailsOpen, setIsOpen: setIsTraceDetailsOpen, traceInfo: traceDetails }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXERDRIY3js.FilteredTable, { rows: traces, highlightSearch: true, tableColumns: [ { name: "Timestamp", key: "timestamp", percentageWidth: 20 }, { name: "HTTP Status", key: "httpStatusCode", percentageWidth: 10, renderer: (val) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Flex, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, HttpStatusIcon, { code: val.httpStatusCode }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: val.httpStatusCode }) ] }) }, { name: "HTTP Method", key: "method", renderer: (val) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, HttpMethodLabel, { method: val.method }), percentageWidth: 10 }, { name: "Path", key: "path", percentageWidth: 30 }, { name: "Time Taken", key: "timeTaken", percentageWidth: 20 }, { isAction: true, percentageWidth: 10, renderer: (val) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Button, { onClick: (_event) => { setIsTraceDetailsOpen(true); setTraceDetails(val.info); }, size: "sm", children: "Show" } ) } ], fixedSearchCategories: [ { name: "HTTP Method", key: "method", ariaLabel: "HTTP Method", values: ["GET", "POST", "DELETE", "HEAD", "OPTIONS", "PATCH", "PUT", "TRACE"], renderer: (val) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, HttpMethodLabel, { method: val }) } ], searchCategories: [ { key: "timestamp", name: "Timestamp" }, { key: "httpStatusCode", name: "HTTP Status" }, { key: "path", name: "Path" }, { key: "timeTaken", name: "Time Taken" } ] } ) ] }); }; // src/plugins/springboot/SpringBoot.tsx var SpringBoot = () => { const location = _reactrouterdom.useLocation.call(void 0, ); const [navItems, setNavItems] = _react.useState.call(void 0, []); _react.useEffect.call(void 0, () => { const initNavItems = async () => { const nav = []; if (await _chunkS4RWX7OXjs.springbootService.hasEndpoint("Health")) { nav.push({ id: "health", title: "Health", component: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Health, {}) }); } if (await _chunkS4RWX7OXjs.springbootService.hasEndpoint("Info")) { nav.push({ id: "info", title: "Info", component: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Info, {}) }); } if (await _chunkS4RWX7OXjs.springbootService.hasEndpoint("Loggers")) { nav.push({ id: "loggers", title: "Loggers", component: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Loggers, {}) }); } if (await _chunkS4RWX7OXjs.springbootService.hasEndpoint("Httptrace")) { _chunkS4RWX7OXjs.springbootService.setIsSpringBoot3(false); nav.push({ id: "trace", title: "Trace", component: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TraceView, {}) }); } if (await _chunkS4RWX7OXjs.springbootService.hasEndpoint("Httpexchanges")) { _chunkS4RWX7OXjs.springbootService.setIsSpringBoot3(true); nav.push({ id: "trace", title: "Trace", component: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TraceView, {}) }); } setNavItems([...nav]); }; initNavItems(); }, []); return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react2.default.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { variant: "light", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Title, { headingLevel: "h1", children: "Spring Boot" }) }), /* @__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": "Spring-boot Nav", variant: "tertiary", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.NavList, { children: navItems.map((navItem) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.NavItem, { isActive: location.pathname === `/springboot/${navItem.id}`, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.NavLink, { to: navItem.id, children: navItem.title }) }, navItem.id)) }) }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Divider, {}), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { "aria-label": "Spring-boot Content", variant: _reactcore.PageSectionVariants.light, padding: { default: "noPadding" }, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactrouterdom.Routes, { children: [ navItems.map((navItem) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Route, { path: navItem.id, element: navItem.component }, navItem.id)), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Route, { path: "/", element: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Navigate, { to: "health" }) }) ] }) } ) ] }); }; exports.Health = Health; exports.Info = Info; exports.Loggers = Loggers; exports.SpringBoot = SpringBoot; exports.TraceView = TraceView; //# sourceMappingURL=ui-VS7PAYUC.js.map