@hawtio/react
Version:
A Hawtio reimplementation based on TypeScript + React.
101 lines (91 loc) • 5.14 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); 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 _chunkZYPGXT7Qjs = require('./chunk-ZYPGXT7Q.js');
// src/ui/init/HawtioInitialization.tsx
var _react = require('react');
var _jsxruntime = require('react/jsx-runtime');
var HawtioInitialization = ({ verbose = false }) => {
const silentLogin = localStorage.getItem("core.auth.silentLogin") === "1";
const [tasks, setTasks] = _react.useState.call(void 0, silentLogin ? {} : _chunkZYPGXT7Qjs.configManager.getInitializationTasks());
_react.useEffect.call(void 0, () => {
const listener = (tasks2) => {
setTasks({ ...tasks2 });
for (const item in tasks2) {
if (_optionalChain([tasks2, 'access', _ => _[item], 'optionalAccess', _2 => _2.group]) === "finish") {
_chunkZYPGXT7Qjs.configManager.initItem("Finish", 2 /* finished */, "finish");
break;
}
}
};
_chunkZYPGXT7Qjs.configManager.addInitListener(listener);
return () => {
_chunkZYPGXT7Qjs.configManager.removeInitListener(listener);
};
}, []);
if (silentLogin) {
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "hwt-loading", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h4", { className: "not-ready", children: "Verifying user..." }) });
}
const items = [];
const plugins = [];
const dots = [];
let finish = false;
for (const item in tasks) {
if (_optionalChain([tasks, 'access', _3 => _3[item], 'optionalAccess', _4 => _4.group]) === "plugins") {
plugins.push({ item, ready: tasks[item] ? tasks[item].ready : 0 /* started */ });
dots.push(tasks[item] ? tasks[item].ready : 0 /* started */);
} else if (_optionalChain([tasks, 'access', _5 => _5[item], 'optionalAccess', _6 => _6.group]) === "finish") {
finish = true;
} else {
items.push({ item, ready: tasks[item] ? tasks[item].ready : 0 /* started */ });
dots.push(tasks[item] ? tasks[item].ready : 0 /* started */);
}
}
if (!verbose) {
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "hwt-loading", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h4", { children: dots.map((el) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: tickClass(el), children: "\u25CF" })) }) }) });
} else {
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "hwt-loading", children: [
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h4", { className: finish ? "ready" : "not-ready", children: "Hawtio initialization ..." }),
items.length > 0 ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "ul", { children: items.map((el, idx) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "li", { className: el.ready == 0 /* started */ ? "not-ready" : "ready", children: [
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: icon(el.ready) }),
el.item
] }, idx)) }) : null,
plugins.length > 0 ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h4", { className: finish ? "ready" : "not-ready", children: "Hawtio plugins ..." }),
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "ul", { children: plugins.map((el, idx) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "li", { className: el.ready == 0 /* started */ ? "not-ready" : "ready", children: [
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: icon(el.ready) }),
el.item
] }, idx)) })
] }) : null
] }) });
}
};
function icon(state) {
switch (state) {
case 1 /* skipped */:
return "\u2796";
case 2 /* finished */:
return "\u2705";
case 3 /* error */:
return "\u274C";
case 0 /* started */:
default:
return "\u2754";
}
}
function tickClass(state) {
switch (state) {
case 1 /* skipped */:
return "tick tick-skipped";
case 2 /* finished */:
return "tick tick-finished";
case 3 /* error */:
return "tick tick-error";
case 0 /* started */:
default:
return "tick tick-started";
}
}
// src/init.ts
var configManager2 = _chunkZYPGXT7Qjs.configManager;
var hawtio2 = _chunkZYPGXT7Qjs.hawtio;
exports.HawtioInitialization = HawtioInitialization; exports.TaskState = _chunkZYPGXT7Qjs.TaskState; exports.configManager = configManager2; exports.hawtio = hawtio2;
//# sourceMappingURL=init.js.map