Skip to content

Commit

Permalink
feat(configuration): hide Settings button on Statistics application d…
Browse files Browse the repository at this point in the history
…epending on if the configuration can editable through UI
  • Loading branch information
Desvelao committed Apr 26, 2024
1 parent 79cf82d commit c97bd92
Showing 1 changed file with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
} from '../../../../../components/common/hocs';
import { PromptStatisticsDisabled } from './prompt-statistics-disabled';
import { PromptStatisticsNoIndices } from './prompt-statistics-no-indices';
import { WazuhConfig } from '../../../../../react-services/wazuh-config';
import { WzRequest } from '../../../../../react-services/wz-request';
import { UI_ERROR_SEVERITIES } from '../../../../../react-services/error-orchestrator/types';
import { UI_LOGGER_LEVELS } from '../../../../../../common/constants';
Expand All @@ -43,8 +42,7 @@ import { getCore } from '../../../../../kibana-services';
import { appSettings, statistics } from '../../../../../utils/applications';
import { RedirectAppLinks } from '../../../../../../../../src/plugins/opensearch_dashboards_react/public';
import { DashboardTabsPanels } from '../../../../../components/overview/server-management-statistics/dashboards/dashboardTabsPanels';

const wzConfig = new WazuhConfig();
import { connect } from 'react-redux';

export class WzStatisticsOverview extends Component {
_isMounted = false;
Expand Down Expand Up @@ -174,19 +172,21 @@ export class WzStatisticsOverview extends Component {
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<RedirectAppLinks application={getCore().application}>
<EuiButtonEmpty
href={getCore().application.getUrlForApp(appSettings.id, {
path: '#/settings?tab=configuration&category=Task:Statistics',
})}
iconType='gear'
iconSide='left'
>
Settings
</EuiButtonEmpty>
</RedirectAppLinks>
</EuiFlexItem>
{this.props.configurationUIEditable && (
<EuiFlexItem grow={false}>
<RedirectAppLinks application={getCore().application}>
<EuiButtonEmpty
href={getCore().application.getUrlForApp(appSettings.id, {
path: '#/settings?tab=configuration&category=Task:Statistics',
})}
iconType='gear'
iconSide='left'
>
Settings
</EuiButtonEmpty>
</RedirectAppLinks>
</EuiFlexItem>
)}
</EuiFlexGroup>
<EuiFlexGroup>
<EuiFlexItem>
Expand Down Expand Up @@ -215,14 +215,21 @@ export class WzStatisticsOverview extends Component {
}
}

const mapStateToProps = state => ({
statisticsEnabled: state.appConfig.data?.['cron.statistics.status'],
configurationUIEditable:
state.appConfig.data?.['configuration.ui_api_editable'],
});

export default compose(
withGlobalBreadcrumb([{ text: statistics.breadcrumbLabel }]),
withUserAuthorizationPrompt([
{ action: 'cluster:status', resource: '*:*:*' },
{ action: 'cluster:read', resource: 'node:id:*' },
]),
connect(mapStateToProps),
withGuard(props => {
return !(wzConfig.getConfig() || {})['cron.statistics.status']; // if 'cron.statistics.status' is false, then it renders PromptStatisticsDisabled component
return !props.statisticsEnabled;
}, PromptStatisticsDisabled),
)(props => {
const [loading, setLoading] = useState(false);
Expand Down

0 comments on commit c97bd92

Please sign in to comment.