UNPKG

@hawtio/react

Version:

A Hawtio reimplementation based on TypeScript + React.

306 lines (270 loc) 18.7 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 _chunkWYFZRJ4Cjs = require('./chunk-WYFZRJ4C.js'); var _chunkBJ6TSPQKjs = require('./chunk-BJ6TSPQK.js'); require('./chunk-BHIEXRGK.js'); // src/plugins/diagnostics/Diagnostics.tsx var _reactcore = require('@patternfly/react-core'); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _reactrouterdom = require('react-router-dom'); // src/plugins/diagnostics/FlightRecorder.tsx var _deprecated = require('@patternfly/react-core/deprecated'); var _reacticons = require('@patternfly/react-icons'); var _reacttable = require('@patternfly/react-table'); var _jsxruntime = require('react/jsx-runtime'); var FlightRecorder = () => { const [initialized, setInitialized] = _react.useState.call(void 0, false); const [recordings, setRecordings] = _react.useState.call(void 0, []); const [currentRecording, setCurrentRecording] = _react.useState.call(void 0, ); const [configurations, setConfigurations] = _react.useState.call(void 0, []); const [userJfrSettings, setUserJfrSettings] = _react.useState.call(void 0, ); const [jolokiaUrl, setJolokiaUrl] = _react.useState.call(void 0, ); const [alerts, setAlerts] = _react.useState.call(void 0, []); const [isModalOpen, setIsModalOpen] = _react.useState.call(void 0, false); const [isConfigurationsDropdownOpen, setIsConfigurationsDropdownOpen] = _react.useState.call(void 0, false); const [isLimitTypeOpen, setIsLimitTypeOpen] = _react.useState.call(void 0, false); const LIMIT_TYPE = [ { label: "Unlimited", value: "unlimited" }, { label: "Duration", value: "duration" }, { label: "Size", value: "maxSize" } ]; _react.useEffect.call(void 0, () => { if (!initialized) _chunkBJ6TSPQKjs.jolokiaService.getFullJolokiaUrl().then((url) => { setJolokiaUrl(url); }); _chunkWYFZRJ4Cjs.flightRecorderService.setUp().then(() => { setInitialized(true); setRecordings(_chunkWYFZRJ4Cjs.flightRecorderService.recordings); setCurrentRecording(_chunkWYFZRJ4Cjs.flightRecorderService.currentRecording); setConfigurations(_chunkWYFZRJ4Cjs.flightRecorderService.jfrConfigs || []); setUserJfrSettings(_chunkWYFZRJ4Cjs.flightRecorderService.userJfrSettings); }); }, [initialized]); if (!initialized) { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { hasBodyWrapper: false, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Spinner, { "aria-label": "Loading Flight Recorder" }) }); } if (!(initialized && jolokiaUrl && ["localhost", "127.0.0.1", "::1", "192.168.", "10.0"].filter((localUrl) => jolokiaUrl.includes(localUrl)).length >= 1)) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { hasBodyWrapper: false, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.EmptyState, { headingLevel: "h1", icon: _reacticons.CubesIcon, titleText: "Tech preview only allows for local connections", variant: _reactcore.EmptyStateVariant.full } ) }); if (initialized && !_chunkWYFZRJ4Cjs.flightRecorderService.hasFlightRecorderMBean()) { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { hasBodyWrapper: false, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.EmptyState, { headingLevel: "h1", icon: _reacticons.CubesIcon, titleText: "No MBean found for Java Flight Recorder", variant: _reactcore.EmptyStateVariant.full } ) }); } const recordingAlert = (text, downloadId, recordingName, timeout) => { setAlerts((prevAlerts) => { let recordingNameForDownload = recordingName || _optionalChain([downloadId, 'optionalAccess', _ => _.toString, 'call', _2 => _2()]) || "recording"; if (!_optionalChain([recordingNameForDownload, 'optionalAccess', _3 => _3.endsWith, 'call', _4 => _4(".jfr")])) recordingNameForDownload += ".jfr"; return [ ...prevAlerts, /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Alert, { title: text, timeout: timeout ? timeout : 2e3, actionLinks: downloadId && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Fragment, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.AlertActionLink, { component: "a", onClick: async () => { await _chunkWYFZRJ4Cjs.flightRecorderService.downloadRecording(Number(downloadId), recordingNameForDownload); saveRecordingAlert(recordingNameForDownload); }, children: "Download" } ) }) } ) ]; }); }; const startRecordingAlert = () => recordingAlert("Starting recording."); const stopRecordingAlert = (recordingId, recordingName) => recordingAlert(`Recording ${recordingName} stored`, recordingId); const saveRecordingAlert = (recordingName) => recordingAlert(`Downloading recording ${recordingName}`); const SettingsModal = () => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _deprecated.Modal, { title: `Settings for recording ${_optionalChain([currentRecording, 'optionalAccess', _5 => _5.number])}`, isOpen: isModalOpen, onClose: () => setIsModalOpen(false), children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Form, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.FormGroup, { label: "Recording configuration", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Dropdown, { isOpen: isConfigurationsDropdownOpen, onSelect: (_event, value) => { setUserJfrSettings({ ...userJfrSettings, configuration: value }); setIsConfigurationsDropdownOpen(false); }, toggle: (toggleRef) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.MenuToggle, { ref: toggleRef, onClick: () => setIsConfigurationsDropdownOpen(true), isExpanded: isConfigurationsDropdownOpen, children: _nullishCoalesce(_optionalChain([configurations, 'optionalAccess', _6 => _6.find, 'call', _7 => _7((config) => config.name === _optionalChain([userJfrSettings, 'optionalAccess', _8 => _8.configuration])), 'optionalAccess', _9 => _9.label]), () => ( "Select configuration")) } ), onOpenChange: (isOpen) => setIsConfigurationsDropdownOpen(isOpen), shouldFocusToggleOnSelect: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DropdownList, { children: _optionalChain([configurations, 'optionalAccess', _10 => _10.map, 'call', _11 => _11(({ name, description, label }, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DropdownItem, { value: name, description, children: label }, index))]) }) } ) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.FormGroup, { label: "Recording name", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.TextInput, { "aria-label": "Recording name", value: _optionalChain([userJfrSettings, 'optionalAccess', _12 => _12.name]), onChange: (_event, value) => setUserJfrSettings({ ...userJfrSettings, name: value, isUserSelectedName: true }) } ) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.FormGroup, { label: "Limit", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Stack, { hasGutter: true, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DropdownGroup, { label: "Type", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Dropdown, { isOpen: isLimitTypeOpen, onSelect: (_event, value) => { setUserJfrSettings({ ...userJfrSettings, limitType: value, limitValue: value === "unlimited" ? 0 : _optionalChain([userJfrSettings, 'optionalAccess', _13 => _13.limitValue]) }); setIsLimitTypeOpen(false); }, toggle: (toggleRef) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.MenuToggle, { ref: toggleRef, onClick: () => setIsLimitTypeOpen(true), isExpanded: isLimitTypeOpen, children: _optionalChain([LIMIT_TYPE, 'access', _14 => _14.find, 'call', _15 => _15((limitType) => limitType.value === _optionalChain([userJfrSettings, 'optionalAccess', _16 => _16.limitType])), 'optionalAccess', _17 => _17.label]) || `Select limit type` }), onOpenChange: (isOpen) => setIsLimitTypeOpen(isOpen), shouldFocusToggleOnSelect: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DropdownList, { children: LIMIT_TYPE.map(({ label, value }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DropdownItem, { value, children: label }, value)) }) } ) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.TextInput, { type: "number", label: "Value", "aria-label": "Value", value: _optionalChain([userJfrSettings, 'optionalAccess', _18 => _18.limitValue]) || 0, isDisabled: _optionalChain([userJfrSettings, 'optionalAccess', _19 => _19.limitType]) === "unlimited", onChange: (_event, value) => setUserJfrSettings({ ...userJfrSettings, limitValue: Number(value) }) } ) ] }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Checkbox, { id: "dump-on-exit-checkbox", label: "Dump on exit", isChecked: _optionalChain([userJfrSettings, 'optionalAccess', _20 => _20.dumpOnExit]), onChange: (_event, value) => setUserJfrSettings({ ...userJfrSettings, dumpOnExit: value }) } ) ] }) } ); return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.PageSection, { className: "java-flight-recorder", hasBodyWrapper: false, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SettingsModal, {}), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.AlertGroup, { isToast: true, isLiveRegion: true, children: alerts }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Stack, { hasGutter: true, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Card, { className: "flight-recorder-button-divider", isPlain: true, isCompact: true, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Flex, { direction: { md: "column" }, alignContent: { md: "alignContentCenter" }, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CardHeader, { className: "flight-recorder-recording-text", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Title, { headingLevel: "h3", children: _optionalChain([currentRecording, 'optionalAccess', _21 => _21.state]) == 2 /* RECORDING */ ? "Currently recording..." : "Ready to record" }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.ActionList, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Flex, { alignContent: { md: "alignContentCenter" }, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Button, { icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacticons.RecordVinylIcon, {}), isDisabled: _optionalChain([currentRecording, 'optionalAccess', _22 => _22.state]) == 2 /* RECORDING */, onClick: () => _chunkWYFZRJ4Cjs.flightRecorderService.startRecording(userJfrSettings).then(() => { startRecordingAlert(); }), children: "Start" } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Button, { icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacticons.StopIcon, {}), isDisabled: _optionalChain([currentRecording, 'optionalAccess', _23 => _23.state]) != 2 /* RECORDING */, onClick: () => { _chunkWYFZRJ4Cjs.flightRecorderService.stopRecording().then(() => { stopRecordingAlert( _optionalChain([currentRecording, 'optionalAccess', _24 => _24.number]), _optionalChain([userJfrSettings, 'optionalAccess', _25 => _25.name]) || _optionalChain([currentRecording, 'optionalAccess', _26 => _26.number, 'optionalAccess', _27 => _27.toString, 'call', _28 => _28()]) || "" ); setRecordings(_chunkWYFZRJ4Cjs.flightRecorderService.recordings); setCurrentRecording(_chunkWYFZRJ4Cjs.flightRecorderService.currentRecording); setUserJfrSettings(_chunkWYFZRJ4Cjs.flightRecorderService.userJfrSettings); }); }, children: "Stop" } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Divider, { orientation: { md: "vertical" } }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Button, { icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacticons.CogIcon, {}), variant: "secondary", isDisabled: _optionalChain([currentRecording, 'optionalAccess', _29 => _29.state]) == 2 /* RECORDING */, onClick: () => setIsModalOpen(true), children: "Settings" } ) ] }) }) ] }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Card, { isCompact: true, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reacttable.Table, { variant: "compact", 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, { children: "Record number" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Th, { children: "Name" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Th, { children: "Size" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Th, { children: "Date" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Th, { children: "Download" }) ] }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Tbody, { children: recordings.sort((recordA, recordB) => Number(recordB.number) - Number(recordA.number)).map(({ number, file, size, time }) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reacttable.Tr, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Td, { children: number }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Td, { children: file }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Td, { children: size }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Td, { children: new Date(time).toUTCString() }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacttable.Td, { modifier: "fitContent", hasAction: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Button, { icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reacticons.DownloadIcon, {}), variant: "secondary", onClick: async () => { await _chunkWYFZRJ4Cjs.flightRecorderService.downloadRecording(Number(number), file); saveRecordingAlert(file); } } ) }) ] }, number)) }) ] }) }) ] }) ] }); }; // src/plugins/diagnostics/Diagnostics.tsx var Diagnostics = () => { const location = _reactrouterdom.useLocation.call(void 0, ); const navItems = [{ id: "jfr", title: "Flight Recorder", component: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, FlightRecorder, {}) }]; return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react2.default.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { hasBodyWrapper: false, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Title, { headingLevel: "h1", children: "Diagnostics" }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageGroup, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { type: "tabs", hasBodyWrapper: false, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Nav, { "aria-label": "Diagnostics Nav", variant: "horizontal-subnav", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.NavList, { children: navItems.map(({ id, title }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.NavItem, { isActive: location.pathname === `/diagnostics/${id}`, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.NavLink, { to: id, children: title }) }, id)) }) }) }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { hasBodyWrapper: false, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactrouterdom.Routes, { children: [ navItems.map(({ id, component }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Route, { path: id, element: component }, id)), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Route, { path: "/", element: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Navigate, { to: "jfr" }) }) ] }) }) ] }); }; exports.Diagnostics = Diagnostics; //# sourceMappingURL=ui-FYCSZ5BD.js.map