UNPKG

@hawtio/react

Version:

A Hawtio reimplementation based on TypeScript + React.

111 lines (98 loc) 3.08 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _chunkTM6OCU7Kjs = require('./chunk-TM6OCU7K.js'); // src/plugins/connect/connections.ts var ADD = "ADD"; var UPDATE = "UPDATE"; var DELETE = "DELETE"; var IMPORT = "IMPORT"; var RESET = "RESET"; function addConnection(state, connection) { if (!connection.id) { _chunkTM6OCU7Kjs.connectService.generateId(connection, state); } return { ...state, [connection.id]: connection }; } function updateConnection(state, id, connection) { return { ...state, [id]: connection }; } function deleteConnection(state, id) { const newState = { ...state }; delete newState[id]; return newState; } function importConnections(state, imported) { return imported.reduce((newState, conn) => { if (!conn.id) { _chunkTM6OCU7Kjs.connectService.generateId(conn, state); } let exists = false; for (const c in state) { if (c === conn.id) { exists = true; break; } } if (exists) { return updateConnection(state, conn.id, conn); } else { return addConnection(newState, conn); } }, state); } function reducer(state, action) { switch (action.type) { case ADD: { const { connection } = action; return addConnection(state, connection); } case UPDATE: { const { id, connection } = action; return updateConnection(state, id, connection); } case DELETE: { const { id } = action; return deleteConnection(state, id); } case IMPORT: { const { connections } = action; return importConnections(state, connections); } case RESET: return {}; default: return state; } } // src/util/dates.ts function formatTimestamp(date, millis = false) { const padZero = (n, len = 2) => String(n).padStart(len, "0"); const year = date.getFullYear(); const month = padZero(date.getMonth() + 1); const day = padZero(date.getDate()); const hours = padZero(date.getHours()); const minutes = padZero(date.getMinutes()); const seconds = padZero(date.getSeconds()); if (!millis) { return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; } const milliseconds = padZero(date.getMilliseconds(), 3); return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`; } function humanizeSeconds(seconds) { const humanize = (n, unit) => { const fixed = Number.isInteger(n) ? n : n.toFixed(1); return `${fixed} ${unit}` + (n === 1 ? "" : "s"); }; if (seconds < 60) { return humanize(seconds, "second"); } if (seconds < 60 * 60) { return humanize(seconds / 60, "minute"); } if (seconds < 60 * 60 * 24) { return humanize(seconds / (60 * 60), "hour"); } return humanize(seconds / (60 * 60 * 24), "day"); } exports.ADD = ADD; exports.UPDATE = UPDATE; exports.DELETE = DELETE; exports.IMPORT = IMPORT; exports.RESET = RESET; exports.reducer = reducer; exports.formatTimestamp = formatTimestamp; exports.humanizeSeconds = humanizeSeconds; //# sourceMappingURL=chunk-URJD3F2K.js.map