import React, { useCallback } from 'react'; import { useSelector } from 'react-redux'; import { translate as __ } from 'foremanReact/common/I18n'; import { Skeleton, Label, Hint, HintBody, Button } from '@patternfly/react-core'; import PropTypes from 'prop-types'; import { upperFirst } from 'lodash'; import { TableText, TableVariant, Thead, Tbody, Tr, Th, Td } from '@patternfly/react-table'; import { LongArrowAltUpIcon, CheckIcon, } from '@patternfly/react-icons'; import { urlBuilder } from 'foremanReact/common/urlHelpers'; import { selectModuleStreamStatus, selectModuleStream } from './ModuleStreamsSelectors'; import { useBulkSelect, useUrlParams } from '../../../../Table/TableHooks'; import { getHostModuleStreams } from './ModuleStreamsActions'; import InactiveText from '../../../../../scenes/ContentViews/components/InactiveText'; import TableWrapper from '../../../../../components/Table/TableWrapper'; import hostIdNotReady from '../../HostDetailsActions'; import { selectHostDetails } from '../../HostDetailsSelectors'; export const ModuleStreamsTab = () => { const { id: hostId, name: hostName } = useSelector(selectHostDetails); const emptyContentTitle = __('This host does not have any Module streams.'); const emptyContentBody = __('Module streams will appear here when available.'); const emptySearchTitle = __('Your search returned no matching Module streams.'); const emptySearchBody = __('Try changing your search criteria.'); const { searchParam } = useUrlParams(); const columnHeaders = [ __('Name'), __('State'), __('Stream'), __('Installation status'), __('Installed profile'), ]; const fetchItems = useCallback( (params) => { if (!hostId) return hostIdNotReady; return getHostModuleStreams( hostId, params, ); }, [hostId], ); const response = useSelector(selectModuleStream); const { results, ...metadata } = response; const status = useSelector(state => selectModuleStreamStatus(state)); /* eslint-disable no-unused-vars */ const { selectOne, isSelected, searchQuery, selectedCount, isSelectable, updateSearchQuery, selectNone, fetchBulkParams, ...selectAll } = useBulkSelect({ results, metadata, isSelectable: _result => false, initialSearchQuery: searchParam || '', }); /* eslint-enable no-unused-vars */ if (!hostId) return ; const rowActions = [ { title: __('Install'), disabled: true, }, { title: __('Update'), disabled: true, }, { title: __('Enable'), disabled: true, }, { title: __('Disable'), disabled: true, }, { title: __('Reset'), disabled: true, }, { title: __('Remove'), disabled: true, }, ]; const EnabledIcon = ({ streamText, streamInstallStatus, upgradable }) => { const INSTALLED_STATE = { INSTALLED: __('Installed'), UPGRADEABLE: __('Upgradable'), UPTODATE: __('Up-to-date'), NOTINSTALLED: __('Not installed'), }; switch (true) { case (streamInstallStatus?.length > 0 && streamText === 'disabled'): return {INSTALLED_STATE.INSTALLED}; case (streamInstallStatus?.length > 0 && streamText === 'enabled' && upgradable !== true): return <> {INSTALLED_STATE.UPTODATE}; case (streamInstallStatus?.length > 0 && streamText === 'enabled' && upgradable): return <> {INSTALLED_STATE.UPGRADEABLE}; default: return ; } }; EnabledIcon.propTypes = { streamText: PropTypes.string.isRequired, streamInstallStatus: PropTypes.arrayOf(PropTypes.string).isRequired, upgradable: PropTypes.bool.isRequired, }; const StreamState = ({ moduleStreamStatus }) => { let streamText = moduleStreamStatus?.charAt(0)?.toUpperCase() + moduleStreamStatus?.slice(1); streamText = streamText?.replace('Unknown', 'Default'); switch (true) { case (streamText === 'Default'): return ; case (streamText === 'Disabled'): return ; case (streamText === 'Enabled'): return ; default: return null; } }; StreamState.propTypes = { moduleStreamStatus: PropTypes.string.isRequired, }; const HostInstalledProfiles = ({ moduleStreamStatus, installedProfiles }) => { let installedProfile; if (installedProfiles?.length > 0) { installedProfile = installedProfiles?.map(profile => upperFirst(profile)).join(', '); } else { installedProfile = 'No profile installed'; } const disabledText = moduleStreamStatus === 'disabled' || moduleStreamStatus === 'unknown'; return disabledText ? : installedProfile; }; HostInstalledProfiles.propTypes = { moduleStreamStatus: PropTypes.string.isRequired, installedProfiles: PropTypes.arrayOf(PropTypes.string).isRequired, }; return (
{__('Module stream management functionality on this page is incomplete')}.
{columnHeaders.map(col => {col})} {results?.map(({ id, status: moduleStreamStatus, name, stream, installed_profiles: installedProfiles, upgradable, module_spec: moduleSpec, }, index) => /* eslint-disable react/no-array-index-key */ ( {name} {stream} )) }
); }; export default ModuleStreamsTab;