import React from 'react'; import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; class StatusTable extends React.PureComponent { renderPreInitializedLabel() { return ――; } renderConnectionStatusLabels() { const { t } = this.props; const { isErrorOccuredOnSearchService, isConnected, isConfigured, } = this.props; const errorOccuredLabel = isErrorOccuredOnSearchService ? { t('full_text_search_management.connection_status_label_erroroccured') } : null; let connectionStatusLabel = null; if (!isConfigured) { connectionStatusLabel = { t('full_text_search_management.connection_status_label_unconfigured') }; } else { connectionStatusLabel = isConnected // eslint-disable-next-line max-len ? { t('full_text_search_management.connection_status_label_connected') } : { t('full_text_search_management.connection_status_label_disconnected') }; } return ( <> {connectionStatusLabel}{errorOccuredLabel} ); } renderIndicesStatusLabel() { const { t, isNormalized } = this.props; return isNormalized ? { t('full_text_search_management.indices_status_label_normalized') } : { t('full_text_search_management.indices_status_label_unnormalized') }; } renderIndexInfoPanel(indexName, body = {}, aliases = []) { const collapseId = `collapse-${indexName}`; const aliasLabels = aliases.map((aliasName) => { return ( {aliasName} ); }); return (
{indexName} {aliasLabels}
              {JSON.stringify(body, null, 2)}
            
); } renderIndexInfoPanels() { const { indicesData, aliasesData, } = this.props; // data is null if (indicesData == null) { return null; } /* "indices": { "growi": { ... } }, */ const indexNameToDataMap = {}; for (const [indexName, indexData] of Object.entries(indicesData)) { indexNameToDataMap[indexName] = indexData; } // no indices if (indexNameToDataMap.length === 0) { return null; } /* "aliases": { "growi": { "aliases": { "growi-alias": {} } } }, */ const indexNameToAliasMap = {}; for (const [indexName, aliasData] of Object.entries(aliasesData)) { indexNameToAliasMap[indexName] = Object.keys(aliasData.aliases); } return (
{ Object.keys(indexNameToDataMap).map((indexName) => { return (
{ this.renderIndexInfoPanel(indexName, indexNameToDataMap[indexName], indexNameToAliasMap[indexName]) }
); }) }
); } render() { const { t } = this.props; const { isInitialized, } = this.props; return (
{t('full_text_search_management.connection_status')} { isInitialized ? this.renderConnectionStatusLabels() : this.renderPreInitializedLabel() }
{t('full_text_search_management.indices_status')} { isInitialized ? this.renderIndicesStatusLabel() : this.renderPreInitializedLabel() }
{t('full_text_search_management.indices_summary')} { isInitialized && this.renderIndexInfoPanels() }
); } } const StatusTableWrapperFC = (props) => { const { t } = useTranslation(); return ; }; StatusTable.propTypes = { t: PropTypes.func.isRequired, // i18next isInitialized: PropTypes.bool, isErrorOccuredOnSearchService: PropTypes.bool, isConnected: PropTypes.bool, isConfigured: PropTypes.bool, isNormalized: PropTypes.bool, indicesData: PropTypes.object, aliasesData: PropTypes.object, }; export default StatusTableWrapperFC;