UNPKG

@hawtio/react

Version:

A Hawtio reimplementation based on TypeScript + React.

428 lines (381 loc) 18.9 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var _chunkUB6QWSAJjs = require('./chunk-UB6QWSAJ.js'); var _chunkXERDRIY3js = require('./chunk-XERDRIY3.js'); var _chunkS4RWX7OXjs = require('./chunk-S4RWX7OX.js'); require('./chunk-URJD3F2K.js'); require('./chunk-TM6OCU7K.js'); require('./chunk-ZYPGXT7Q.js'); // src/plugins/logs/Logs.tsx var _reactcore = require('@patternfly/react-core'); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _jsxruntime = require('react/jsx-runtime'); var Logs = () => { return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react2.default.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { id: "logs-header", hasShadowBottom: true, variant: "light", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Title, { headingLevel: "h1", children: "Logs" }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Divider, {}), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.PageSection, { id: "logs-table", variant: "light", isFilled: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LogsTable, {}) }) ] }); }; var LogRowData = class { constructor(entry) { this.timestamp = entry.getTimestamp(); this.level = entry.event.level; this.logger = entry.event.logger; this.message = entry.event.message; this.logEntry = entry; } }; var LogsTable = () => { const [, setLogs] = _react.useState.call(void 0, []); const [rows, setRows] = _react.useState.call(void 0, []); const timestamp = _react.useRef.call(void 0, 0); const [loaded, setLoaded] = _react.useState.call(void 0, false); const [isModalOpen, setIsModalOpen] = _react.useState.call(void 0, false); const [selected, setSelected] = _react.useState.call(void 0, null); _react.useEffect.call(void 0, () => { const loadLogs = async () => { const result = await _chunkS4RWX7OXjs.logsService.loadLogs(); setLogs(result.logs); setRows(result.logs.map((log2) => new LogRowData(log2))); timestamp.current = result.timestamp; setLoaded(true); _chunkS4RWX7OXjs.log2.debug("Load logs:", timestamp.current); }; loadLogs(); let timeoutHandle; const updateLogs = async () => { _chunkS4RWX7OXjs.log2.debug("Update logs:", timestamp.current); if (timeoutHandle && timestamp.current > 0) { const result = await _chunkS4RWX7OXjs.logsService.loadLogsAfter(timestamp.current); if (result.logs.length > 0) { setLogs((prev) => { const logsAppended = _chunkS4RWX7OXjs.logsService.append(prev, result.logs); setRows(logsAppended.map((log2) => new LogRowData(log2))); return logsAppended; }); } timestamp.current = result.timestamp; } timeoutHandle = setTimeout(() => updateLogs(), _chunkS4RWX7OXjs.LOGS_UPDATE_INTERVAL); }; updateLogs(); return () => timeoutHandle && clearTimeout(timeoutHandle); }, []); if (!loaded) { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Skeleton, { "data-testid": "loading-logs", screenreaderText: "Loading..." }); } const logLevels = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR"]; const handleModalToggle = () => { setIsModalOpen(!isModalOpen); }; return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LogModal, { isOpen: isModalOpen, onClose: handleModalToggle, log: selected }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXERDRIY3js.FilteredTable, { rows, highlightSearch: true, tableColumns: [ { name: "Timestamp", key: "timestamp", percentageWidth: 10 }, { name: "Level", key: "level", renderer: (val) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LogLevel, { level: val.level }), percentageWidth: 10 }, { name: "Logger", key: "logger", percentageWidth: 40 }, { name: "Message", key: "message", percentageWidth: 40 } ], fixedSearchCategories: [ { name: "Level", key: "level", id: "logs-table-toolbar-level", ariaLabel: "Filter level", values: logLevels, renderer: (val) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LogLevel, { level: val }) } ], searchCategories: [ { name: "Logger", key: "logger" }, { name: "Message", key: "message" } ], onClick: (row) => { setSelected(row.logEntry); setIsModalOpen(true); } } ) ] }); }; var LogModal = ({ isOpen, onClose, log: log2 }) => { if (!log2) { return null; } const { event } = log2; const logDetails = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Card, { isCompact: true, isPlain: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CardBody, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionList, { isCompact: true, isHorizontal: true, children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionListGroup, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListTerm, { children: "Timestamp" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListDescription, { children: log2.getTimestamp() }) ] }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionListGroup, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListTerm, { children: "Level" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListDescription, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LogLevel, { level: event.level }) }) ] }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionListGroup, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListTerm, { children: "Logger" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListDescription, { children: event.logger }) ] }), log2.hasLogSourceLineHref && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react2.default.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionListGroup, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListTerm, { children: "Class" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListDescription, { children: event.className }) ] }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionListGroup, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListTerm, { children: "Method" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListDescription, { children: event.methodName }) ] }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionListGroup, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListTerm, { children: "File" }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionListDescription, { children: [ event.fileName, ":", event.lineNumber ] }) ] }) ] }), event.host && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionListGroup, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListTerm, { children: "Host" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListDescription, { children: event.host }) ] }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionListGroup, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListTerm, { children: "Thread" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListDescription, { children: event.thread }) ] }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionListGroup, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListTerm, { children: "Message" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListDescription, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CodeBlock, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CodeBlockCode, { children: event.message }) }) }) ] }), event.exception && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionListGroup, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListTerm, { children: "Stack Trace" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListDescription, { children: event.exception }) ] }) ] }) }) }); const osgiProperties = log2.hasOSGiProperties && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Card, { isCompact: true, isPlain: true, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CardTitle, { children: "OSGi Properties" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CardBody, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionList, { isCompact: true, isHorizontal: true, children: [ { key: "bundle.name", name: "Bundle Name" }, { key: "bundle.id", name: "Bundle ID" }, { key: "bundle.version", name: "Bundle Version" } ].filter(({ key }) => event.properties[key] !== void 0).map(({ key, name }) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionListGroup, { children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionListTerm, { children: [ "$", name ] }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListDescription, { children: event.properties[key] }) ] }, key)) }) }) ] }); const mdcProperties = log2.hasMDCProperties && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Card, { isCompact: true, isPlain: true, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CardTitle, { children: "MDC Properties" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CardBody, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionList, { isCompact: true, isHorizontal: true, children: Object.entries(log2.mdcProperties).map(([key, value]) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.DescriptionListGroup, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListTerm, { children: key }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.DescriptionListDescription, { children: value }) ] }, key)) }) }) ] }); return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.Modal, { id: "logs-log-modal", variant: "large", title: "Log", isOpen, onClose, actions: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Button, { onClick: onClose, children: "Close" }, "close") ], children: [ logDetails, osgiProperties, mdcProperties ] } ); }; var LogLevel = ({ level }) => { switch (level) { case "TRACE": 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 }); } }; // src/plugins/logs/LogsPreferences.tsx var _exclamationcircleicon = require('@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon'); var LogsPreferences = () => { const [options, setOptions] = _react.useState.call(void 0, _chunkS4RWX7OXjs.logsService.loadOptions()); const [logCacheSizeValidated, setLogCacheSizeValidated] = _react.useState.call(void 0, "default" ); const [logCacheSizeInvalidText, setLogCacheSizeInvalidText] = _react.useState.call(void 0, ""); const [logBatchSizeValidated, setLogBatchSizeValidated] = _react.useState.call(void 0, "default" ); const [logBatchSizeInvalidText, setLogBatchSizeInvalidText] = _react.useState.call(void 0, ""); const updateOptions = (updated) => { _chunkS4RWX7OXjs.logsService.saveOptions(updated); setOptions({ ...options, ...updated }); }; const onSortAscendingChanged = (sortAscending) => { updateOptions({ sortAscending }); }; const onAutoScrollChanged = (autoScroll) => { updateOptions({ autoScroll }); }; const onLogCacheSizeChanged = (cacheSize) => { const intValue = parseInt(cacheSize); if (!intValue) { setLogCacheSizeValidated("error"); setLogCacheSizeInvalidText("Must be a number"); return; } if (intValue <= 0) { setLogCacheSizeValidated("error"); setLogCacheSizeInvalidText("Must be greater than 0"); return; } updateOptions({ cacheSize: intValue }); setLogCacheSizeValidated("success"); }; const onLogBatchSizeChanged = (batchSize) => { const intValue = parseInt(batchSize); if (!intValue) { setLogBatchSizeValidated("error"); setLogBatchSizeInvalidText("Must be a number"); return; } if (intValue <= 0) { setLogBatchSizeValidated("error"); setLogBatchSizeInvalidText("Must be greater than 0"); return; } updateOptions({ batchSize: intValue }); setLogBatchSizeValidated("success"); }; return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.CardBody, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Form, { isHorizontal: true, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.FormSection, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.FormGroup, { label: "Sort ascending", fieldId: "logs-form-sort-ascending", labelIcon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkUB6QWSAJjs.TooltipHelpIcon, { tooltip: "Sort log entries by timestamp ascending" }), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Checkbox, { id: "logs-form-sort-ascending-input", isChecked: options.sortAscending, onChange: (_event, sortAscending) => onSortAscendingChanged(sortAscending) } ) } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.FormGroup, { label: "Auto scroll", fieldId: "logs-form-auto-scroll", labelIcon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkUB6QWSAJjs.TooltipHelpIcon, { tooltip: "Automatically scroll when new log entries are added" }), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.Checkbox, { id: "logs-form-auto-scroll-input", isChecked: options.autoScroll, onChange: (_event, autoScroll) => onAutoScrollChanged(autoScroll) } ) } ), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.FormGroup, { label: "Log cache size", fieldId: "logs-form-log-cache-size", labelIcon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkUB6QWSAJjs.TooltipHelpIcon, { tooltip: "The number of log messages to keep in the browser" }), children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.TextInput, { id: "logs-form-log-cache-size-input", type: "number", value: options.cacheSize, validated: logCacheSizeValidated, onChange: (_event, cacheSize) => onLogCacheSizeChanged(cacheSize) } ), /* @__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, { variant: logCacheSizeValidated, ...logCacheSizeValidated === "error" && { icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _exclamationcircleicon.ExclamationCircleIcon, {}) }, children: logCacheSizeValidated === "error" && logCacheSizeInvalidText } ) }) }) ] } ), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactcore.FormGroup, { label: "Log batch size", fieldId: "logs-form-log-batch-size", labelIcon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkUB6QWSAJjs.TooltipHelpIcon, { tooltip: "The maximum number of log messages to retrieve when loading new log lines" }), children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactcore.TextInput, { id: "logs-form-log-batch-size-input", type: "number", value: options.batchSize, validated: logBatchSizeValidated, onChange: (_event, batchSize) => onLogBatchSizeChanged(batchSize) } ), /* @__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, { variant: logBatchSizeValidated, ...logBatchSizeValidated === "error" && { icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _exclamationcircleicon.ExclamationCircleIcon, {}) }, children: logBatchSizeValidated === "error" && logBatchSizeInvalidText } ) }) }) ] } ) ] }) }) }); }; exports.Logs = Logs; exports.LogsPreferences = LogsPreferences; //# sourceMappingURL=ui-RMBU6VJX.js.map