import React from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import { createSubscribedElement } from '../../UnstatedUtils'; import AppContainer from '../../../services/AppContainer'; import WebsocketContainer from '../../../services/WebsocketContainer'; import { toastSuccess, toastError } from '../../../util/apiNotification'; import ProgressBar from '../Common/ProgressBar'; class RebuildIndex extends React.Component { constructor(props) { super(props); this.state = { isNormalized: undefined, indicesData: null, aliasesData: null, isProcessing: false, isCompleted: false, total: 0, current: 0, skip: 0, }; this.normalizeIndices = this.normalizeIndices.bind(this); this.rebuildIndices = this.rebuildIndices.bind(this); } async componentWillMount() { this.retrieveIndicesStatus(); } componentDidMount() { this.initWebSockets(); } initWebSockets() { const socket = this.props.websocketContainer.getWebSocket(); socket.on('admin:addPageProgress', (data) => { this.setState({ isProcessing: true, ...data, }); }); socket.on('admin:finishAddPage', (data) => { this.setState({ isProcessing: false, isCompleted: true, ...data, }); }); } async retrieveIndicesStatus() { const { appContainer } = this.props; try { const { info } = await appContainer.apiv3Get('/search/indices'); this.setState({ indicesData: info.indices, aliasesData: info.aliases, isNormalized: info.isNormalized, }); } catch (e) { toastError(e); } } async normalizeIndices() { const { appContainer } = this.props; try { await appContainer.apiv3Put('/search/indices', { operation: 'normalize' }); } catch (e) { toastError(e); } await this.retrieveIndicesStatus(); toastSuccess('Normalizing has succeeded'); } async rebuildIndices() { const { appContainer } = this.props; try { await appContainer.apiv3Put('/search/indices', { operation: 'rebuild' }); this.setState({ isProcessing: true }); toastSuccess('Rebuilding is requested'); } catch (e) { toastError(e); } } renderIndexInfoPanel(indexName, body = {}, aliases = []) { const collapseId = `collapse-${indexName}`; const aliasLabels = aliases.map((aliasName) => { return ( {aliasName} ); }); return (
{JSON.stringify(body, null, 2)}
{ t('full_text_search_management.normalize_description') }
{ t('full_text_search_management.rebuild_description_1') }
{ t('full_text_search_management.rebuild_description_2') }
| { t('full_text_search_management.indices_status') } | {statusLabel} |
|---|---|
| { t('full_text_search_management.indices_summary') } | { this.renderIndexInfoPanels() } |