UNPKG

@openshift-assisted/ui-lib

Version:

React component library for the Assisted Installer UI

418 lines 19.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hostActionResolver = exports.macAddressColumn = exports.ipv6Column = exports.ipv4Column = exports.activeNICColumn = exports.countColumn = exports.disksColumn = exports.memoryColumn = exports.cpuCoresColumn = exports.cpuArchitectureColumn = exports.discoveredAtColumn = exports.statusColumn = exports.roleColumn = exports.hostnameColumn = exports.getSelectedNic = void 0; const tslib_1 = require("tslib"); const React = tslib_1.__importStar(require("react")); const ip_address_1 = require("ip-address"); const clusterConfiguration_1 = require("../clusterConfiguration"); const constants_1 = require("../constants"); const ui_1 = require("../ui"); const hardwareInfo_1 = require("./hardwareInfo"); const Hostname_1 = tslib_1.__importDefault(require("./Hostname")); const HostPropertyValidationPopover_1 = tslib_1.__importDefault(require("./HostPropertyValidationPopover")); const HostsCount_1 = tslib_1.__importDefault(require("./HostsCount")); const HostStatus_1 = tslib_1.__importDefault(require("./HostStatus")); const RoleCell_1 = tslib_1.__importDefault(require("./RoleCell")); const utils_1 = require("./utils"); const clusterSelectors_1 = require("../../selectors/clusterSelectors"); const status_1 = require("./status"); const utils_2 = require("../../utils"); const getSelectedNic = (nics, currentSubnet) => { return nics.find((nic) => { const ipv4Addresses = (nic.ipv4Addresses || []).reduce((addresses, address) => { if (ip_address_1.Address4.isValid(address)) { addresses.push(new ip_address_1.Address4(address)); } return addresses; }, []); if (ipv4Addresses.find((address) => address.isInSubnet(currentSubnet))) { return true; } const ipv6Addresses = (nic.ipv6Addresses || []).reduce((addresses, address) => { if (ip_address_1.Address6.isValid(address)) { addresses.push(new ip_address_1.Address6(address)); } return addresses; }, []); return ipv6Addresses.find((address) => address.isInSubnet(currentSubnet)); }); }; exports.getSelectedNic = getSelectedNic; const hostnameColumn = (t, onEditHostname, hosts, canEditHostname) => { return { header: { title: t('ai:Hostname'), props: { id: 'col-header-hostname', modifier: 'breakWord', }, sort: true, }, cell: (host) => { const inventory = (0, utils_1.getInventory)(host); const editHostname = onEditHostname ? () => onEditHostname(host) : undefined; const computedHostname = (0, utils_1.getHostname)(host, inventory); return { title: (React.createElement(Hostname_1.default, { host: host, inventory: inventory, onEditHostname: editHostname, hosts: hosts, readonly: canEditHostname ? !canEditHostname(host) : false })), props: { 'data-testid': 'host-name' }, sortableValue: computedHostname || '', }; }, }; }; exports.hostnameColumn = hostnameColumn; const roleColumn = (t, canEditRole, onEditRole, schedulableMasters, clusterKind) => { return { header: { title: t('ai:Role'), props: { id: 'col-header-role', }, sort: true, }, cell: (host) => { const editRole = onEditRole ? (role) => onEditRole(host, role) : undefined; const isRoleEditable = canEditRole === null || canEditRole === void 0 ? void 0 : canEditRole(host); const hostRole = (0, utils_1.getHostRole)(host, t, schedulableMasters, clusterKind); return { title: (React.createElement(RoleCell_1.default, { host: host, readonly: !isRoleEditable, role: hostRole, onEditRole: editRole })), props: { 'data-testid': 'host-role' }, sortableValue: hostRole, }; }, }; }; exports.roleColumn = roleColumn; const statusColumn = (t, clusterStatus, AdditionalNTPSourcesDialogToggleComponent, onEditHostname, UpdateDay2ApiVipDialogToggleComponent) => { return { header: { title: t('ai:Status'), props: { id: 'col-header-status', }, sort: true, }, cell: (host) => { const validationsInfo = (0, utils_2.stringToJSON)(host.validationsInfo) || {}; const editHostname = onEditHostname ? () => onEditHostname(host) : undefined; const sublabel = (0, utils_1.areOnlySoftValidationsFailing)(validationsInfo) && ['known', 'known-unbound'].includes(host.status) ? t('ai:Some validations failed') : undefined; const actualHostStatus = (0, utils_1.getHostStatus)(host.status, clusterStatus); return { title: (React.createElement(HostStatus_1.default, { host: host, status: Object.assign(Object.assign({}, (0, status_1.hostStatus)(t)[actualHostStatus]), { sublabel }), onEditHostname: editHostname, validationsInfo: validationsInfo, AdditionalNTPSourcesDialogToggleComponent: AdditionalNTPSourcesDialogToggleComponent, UpdateDay2ApiVipDialogToggleComponent: UpdateDay2ApiVipDialogToggleComponent })), props: { 'data-testid': 'host-status' }, sortableValue: host.status, }; }, }; }; exports.statusColumn = statusColumn; const discoveredAtColumn = (t) => ({ header: { title: t('ai:Discovered on'), props: { id: 'col-header-discoveredat', }, sort: true, }, cell: (host) => { const { createdAt } = host; const dateTimeCell = (0, ui_1.getDateTimeCell)(createdAt); return { title: dateTimeCell.title, props: { 'data-testid': 'host-discovered-time' }, sortableValue: dateTimeCell.sortableValue, }; }, }); exports.discoveredAtColumn = discoveredAtColumn; const cpuArchitectureColumn = (t) => ({ header: { title: t('ai:CPU Architecture'), props: { id: 'col-header-cpuarchitecture', }, sort: true, }, cell: (host) => { var _a, _b; const inventory = (0, utils_1.getInventory)(host); return { title: (_a = inventory.cpu) === null || _a === void 0 ? void 0 : _a.architecture, props: { 'data-testid': 'host-cpu-architecture' }, sortableValue: (_b = inventory.cpu) === null || _b === void 0 ? void 0 : _b.architecture, }; }, }); exports.cpuArchitectureColumn = cpuArchitectureColumn; const cpuCoresColumn = (t) => ({ header: { title: t('ai:CPU Cores'), props: { id: 'col-header-cpucores', }, sort: true, }, cell: (host) => { var _a; const inventory = (0, utils_1.getInventory)(host); const { cores } = (0, hardwareInfo_1.getHostRowHardwareInfo)(inventory); const validationsInfo = (0, utils_2.stringToJSON)(host.validationsInfo) || {}; const cpuCoresValidation = (_a = validationsInfo === null || validationsInfo === void 0 ? void 0 : validationsInfo.hardware) === null || _a === void 0 ? void 0 : _a.find((v) => v.id === 'has-cpu-cores-for-role'); return { title: (React.createElement(HostPropertyValidationPopover_1.default, { validation: cpuCoresValidation }, cores.title)), props: { 'data-testid': 'host-cpu-cores' }, sortableValue: cores.sortableValue, }; }, }); exports.cpuCoresColumn = cpuCoresColumn; const memoryColumn = (t) => ({ header: { title: t('ai:Memory'), props: { id: 'col-header-memory', }, sort: true, }, cell: (host) => { var _a; const inventory = (0, utils_1.getInventory)(host); const { memory } = (0, hardwareInfo_1.getHostRowHardwareInfo)(inventory); const validationsInfo = (0, utils_2.stringToJSON)(host.validationsInfo) || {}; const memoryValidation = (_a = validationsInfo === null || validationsInfo === void 0 ? void 0 : validationsInfo.hardware) === null || _a === void 0 ? void 0 : _a.find((v) => v.id === 'has-memory-for-role'); return { title: (React.createElement(HostPropertyValidationPopover_1.default, { validation: memoryValidation }, memory.title)), props: { 'data-testid': 'host-memory' }, sortableValue: memory.sortableValue, }; }, }); exports.memoryColumn = memoryColumn; const disksColumn = (t) => ({ header: { title: t('ai:Total storage'), props: { id: 'col-header-disk', }, sort: true, }, cell: (host) => { var _a; const inventory = (0, utils_1.getInventory)(host); const { disk } = (0, hardwareInfo_1.getHostRowHardwareInfo)(inventory); const validationsInfo = (0, utils_2.stringToJSON)(host.validationsInfo) || {}; const diskValidation = (_a = validationsInfo === null || validationsInfo === void 0 ? void 0 : validationsInfo.hardware) === null || _a === void 0 ? void 0 : _a.find((v) => v.id === 'has-min-valid-disks'); return { title: (React.createElement(HostPropertyValidationPopover_1.default, { validation: diskValidation }, disk.title)), props: { 'data-testid': 'host-disks' }, sortableValue: disk.sortableValue, }; }, }); exports.disksColumn = disksColumn; const countColumn = (cluster) => ({ header: { title: React.createElement(HostsCount_1.default, { cluster: cluster, inParenthesis: true }) }, }); exports.countColumn = countColumn; const activeNICColumn = (cluster, t) => ({ header: { title: t('ai:Active NIC'), sort: true, }, cell: (host) => { const inventory = (0, utils_1.getInventory)(host); const nics = inventory.interfaces || []; const machineNetworkCidr = (0, clusterSelectors_1.selectMachineNetworkCIDR)(cluster); const currentSubnet = machineNetworkCidr ? (0, clusterConfiguration_1.getSubnet)(machineNetworkCidr) : null; const selectedNic = currentSubnet ? (0, exports.getSelectedNic)(nics, currentSubnet) : null; return { title: (selectedNic === null || selectedNic === void 0 ? void 0 : selectedNic.name) || constants_1.DASH, props: { 'data-testid': 'nic-name' }, sortableValue: (selectedNic === null || selectedNic === void 0 ? void 0 : selectedNic.name) || constants_1.DASH, }; }, }); exports.activeNICColumn = activeNICColumn; const ipv4Column = (cluster) => ({ header: { title: 'IPv4 address', sort: true, }, cell: (host) => { const inventory = (0, utils_1.getInventory)(host); const nics = inventory.interfaces || []; const machineNetworkCidr = (0, clusterSelectors_1.selectMachineNetworkCIDR)(cluster); const currentSubnet = machineNetworkCidr ? (0, clusterConfiguration_1.getSubnet)(machineNetworkCidr) : null; const selectedNic = currentSubnet ? (0, exports.getSelectedNic)(nics, currentSubnet) : null; return { title: ((selectedNic === null || selectedNic === void 0 ? void 0 : selectedNic.ipv4Addresses) || []).join(', ') || constants_1.DASH, props: { 'data-testid': 'nic-ipv4' }, sortableValue: ((selectedNic === null || selectedNic === void 0 ? void 0 : selectedNic.ipv4Addresses) || []).join(', ') || constants_1.DASH, }; }, }); exports.ipv4Column = ipv4Column; const ipv6Column = (cluster) => ({ header: { title: 'IPv6 address', sort: true, }, cell: (host) => { const inventory = (0, utils_1.getInventory)(host); const nics = inventory.interfaces || []; const machineNetworkCidr = (0, clusterSelectors_1.selectMachineNetworkCIDR)(cluster); const currentSubnet = machineNetworkCidr ? (0, clusterConfiguration_1.getSubnet)(machineNetworkCidr) : null; const selectedNic = currentSubnet ? (0, exports.getSelectedNic)(nics, currentSubnet) : null; return { title: ((selectedNic === null || selectedNic === void 0 ? void 0 : selectedNic.ipv6Addresses) || []).join(', ') || constants_1.DASH, props: { 'data-testid': 'nic-ipv6' }, sortableValue: ((selectedNic === null || selectedNic === void 0 ? void 0 : selectedNic.ipv6Addresses) || []).join(', ') || constants_1.DASH, }; }, }); exports.ipv6Column = ipv6Column; const macAddressColumn = (cluster) => ({ header: { title: 'MAC address', sort: true, }, cell: (host) => { const inventory = (0, utils_1.getInventory)(host); const nics = inventory.interfaces || []; const machineNetworkCidr = (0, clusterSelectors_1.selectMachineNetworkCIDR)(cluster); const currentSubnet = machineNetworkCidr ? (0, clusterConfiguration_1.getSubnet)(machineNetworkCidr) : null; const selectedNic = currentSubnet ? (0, exports.getSelectedNic)(nics, currentSubnet) : null; return { title: (selectedNic === null || selectedNic === void 0 ? void 0 : selectedNic.macAddress) || constants_1.DASH, props: { 'data-testid': 'nic-mac-address' }, sortableValue: (selectedNic === null || selectedNic === void 0 ? void 0 : selectedNic.macAddress) || constants_1.DASH, }; }, }); exports.macAddressColumn = macAddressColumn; const ActionTitle = ({ title, description, disabled, }) => (React.createElement(React.Fragment, null, title, disabled && (React.createElement(React.Fragment, null, React.createElement("br", null), description)))); const hostActionResolver = ({ t, onInstallHost, canInstallHost, onEditHost, canEditHost, onHostEnable, canEnable, onHostDisable, canDisable, onHostReset, canReset, onViewHostEvents, onDownloadHostLogs, canDownloadHostLogs, onDeleteHost, canDelete, onEditBMH, canEditBMH, canUnbindHost, onUnbindHost, }) => (host) => { const actions = []; if (host) { const inventory = (0, utils_1.getInventory)(host); const hostname = (0, utils_1.getHostname)(host, inventory); if (onInstallHost && (canInstallHost === null || canInstallHost === void 0 ? void 0 : canInstallHost(host))) { actions.push({ title: 'Install host', id: `button-install-host-${hostname}`, onClick: () => onInstallHost(host), }); } if (onEditHost) { if (canEditHost) { const canEdit = canEditHost(host); if (typeof canEdit === 'boolean') { canEdit && actions.push({ title: t('ai:Change hostname'), id: `button-edit-host-${hostname}`, onClick: () => onEditHost(host), }); } else { const [enabled, reason] = canEdit; actions.push({ title: (React.createElement(ActionTitle, { disabled: !enabled, description: reason, title: t('ai:Change hostname') })), id: `button-edit-host-${hostname}`, onClick: () => onEditHost(host), isDisabled: !enabled, }); } } } if (onHostEnable && (canEnable === null || canEnable === void 0 ? void 0 : canEnable(host))) { actions.push({ title: t('ai:Enable in cluster'), id: `button-enable-in-cluster-${hostname}`, onClick: () => onHostEnable(host), }); } if (onHostDisable && (canDisable === null || canDisable === void 0 ? void 0 : canDisable(host))) { actions.push({ title: t('ai:Disable in cluster'), id: `button-disable-in-cluster-${hostname}`, onClick: () => onHostDisable(host), }); } if (onHostReset && (canReset === null || canReset === void 0 ? void 0 : canReset(host))) { actions.push({ title: t('ai:Reset host'), id: `button-reset-host-${hostname}`, onClick: () => onHostReset(host), }); } if (onViewHostEvents) { actions.push({ title: t('ai:View host events'), id: `button-view-host-events-${hostname}`, onClick: () => onViewHostEvents(host), }); } if (onDownloadHostLogs && (canDownloadHostLogs === null || canDownloadHostLogs === void 0 ? void 0 : canDownloadHostLogs(host))) { actions.push({ title: t('ai:Download host logs'), id: `button-download-host-installation-logs-${hostname}`, onClick: () => onDownloadHostLogs(host), }); } if (onDeleteHost) { if (canDelete) { const canDeleteHost = canDelete(host); if (typeof canDeleteHost === 'boolean') { canDeleteHost && actions.push({ title: t('ai:Remove host'), id: `button-delete-host-${hostname}`, onClick: () => onDeleteHost(host), }); } else { const [enabled, reason] = canDeleteHost; actions.push({ title: (React.createElement(ActionTitle, { disabled: !enabled, description: reason, title: t('ai:Remove host') })), id: `button-delete-host-${hostname}`, onClick: () => onDeleteHost(host), isDisabled: !enabled, }); } } } if (onEditBMH && host.href === 'bmc') { if (canEditBMH) { const [enabled, reason] = canEditBMH(host); actions.push({ title: (React.createElement(ActionTitle, { disabled: !enabled, description: reason, title: t('ai:Edit BMC') })), id: `button-edit-bmh-host-${hostname}`, onClick: () => onEditBMH(host), isDisabled: !enabled, }); } } if (onUnbindHost && canUnbindHost) { const [enabled, reason] = canUnbindHost(host); actions.push({ title: (React.createElement(ActionTitle, { disabled: !enabled, description: reason, title: t('ai:Remove from the cluster') })), id: `button-unbind-host-${hostname}`, onClick: () => onUnbindHost(host), isDisabled: !enabled, }); } } return actions; }; exports.hostActionResolver = hostActionResolver; //# sourceMappingURL=tableUtils.js.map