Skip to content

Commit

Permalink
Fixed configuration_cards itemsList, the code is improved and unneces…
Browse files Browse the repository at this point in the history
…sary code is removed
  • Loading branch information
jbiset committed Apr 16, 2024
1 parent 7b25db2 commit 8a40b5a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 98 deletions.
Expand Up @@ -37,6 +37,41 @@ export const ConfigurationCards = ({
indexPatternId,
filters,
}: ConfigurationCardsProps) => {
const configurationItemsList = [
{
title: 'Disabled',
description: String(configuration?.disabled),
},
{
title: 'Hidden',
description: String(configuration?.hidden),
},
{
title: 'Name',
description: configuration?.name,
},
{
title: 'Node name',
description: configuration?.node_name,
},
{
title: 'Node type',
description: configuration?.node_type,
},
{
title: 'Bind address',
description: configuration?.bind_addr,
},
{
title: 'IP',
description: configuration?.nodes[0] || '-',
},
{
title: 'Port',
description: configuration?.port,
},
];

return (
<EuiFlexGroup direction='column' gutterSize='s'>
<EuiFlexItem>
Expand Down Expand Up @@ -114,72 +149,14 @@ export const ConfigurationCards = ({
type='column'
compressed={true}
align='left'
listItems={[
{
title: (
<span style={{ fontWeight: 400, fontSize: '1rem' }}>
Disabled
</span>
),
description: configuration?.disabled ? 'true' : 'false',
},
{
title: (
<span style={{ fontWeight: 400, fontSize: '1rem' }}>
Hidden
</span>
),
description: configuration?.hidden ? 'true' : 'false',
},
{
title: (
<span style={{ fontWeight: 400, fontSize: '1rem' }}>
Name
</span>
),
description: configuration?.name,
},
{
title: (
<span style={{ fontWeight: 400, fontSize: '1rem' }}>
Node name
</span>
),
description: configuration?.node_name,
},
{
title: (
<span style={{ fontWeight: 400, fontSize: '1rem' }}>
Node type
</span>
),
description: configuration?.node_type,
},
{
title: (
<span style={{ fontWeight: 400, fontSize: '1rem' }}>
Bind address
</span>
),
description: configuration?.bind_addr,
},
{
title: (
<span style={{ fontWeight: 400, fontSize: '1rem' }}>
IP
</span>
),
description: configuration?.nodes[0] || '-',
},
{
title: (
<span style={{ fontWeight: 400, fontSize: '1rem' }}>
Port
</span>
),
description: configuration?.port,
},
]}
listItems={configurationItemsList.map(item => ({
title: (
<span style={{ fontWeight: 400, fontSize: '1rem' }}>
{item.title}
</span>
),
description: item.description,
}))}
titleProps={{
className: 'cluster-descriptionList-title',
}}
Expand Down
Expand Up @@ -133,13 +133,13 @@ const DashboardCT: React.FC<DashboardCTProps> = ({ statusRunning }) => {
WzRequest.apiReq('GET', '/cluster/healthcheck', {}),
]);

const nodeList = ((data[0] || {}).data || {}).data || {} || false;
const clusterConfig = ((data[1] || {}).data || {}).data || {} || false;
const agents = ((data[3] || {}).data || {}).data || {} || false;
const nodeList = data[0]?.data?.data || {} || false;
const clusterConfig = data[1]?.data?.data || {} || false;
const agents = data[3]?.data?.data || {} || false;
setState({
...state,
configuration: clusterConfig.affected_items[0],
version: (((data[2] || {}).data || {}).data || {}).api_version || false,
version: data[2]?.data?.data?.api_version || false,
nodesCount: nodeList.total_affected_items,
agentsCount: agents.total_affected_items - 1,
nodeList: nodeList?.affected_items ?? [],
Expand All @@ -154,7 +154,7 @@ const DashboardCT: React.FC<DashboardCTProps> = ({ statusRunning }) => {
<EuiFlexItem style={{ padding: '0 16px' }}>
{isDataSourceLoading && !dataSource ? (
<LoadingSpinner />
) : (
) : !state.showNodes ? (
<div className='wz-search-bar'>
<SearchBar
appName='ct-searchbar'
Expand All @@ -164,7 +164,7 @@ const DashboardCT: React.FC<DashboardCTProps> = ({ statusRunning }) => {
showQueryBar={true}
/>
</div>
)}
) : null}
<EuiSpacer size='m' />
{!isDataSourceLoading &&
dataSource &&
Expand Down
Expand Up @@ -12,11 +12,9 @@ import { ClusterDisabled } from '../../../../../components/management/cluster/cl
import { ClusterDashboard } from '../../../../../components/management/cluster/dashboard/dashboard';

interface ClusterOverviewState {
authorized: boolean;
clusterEnabled: boolean;
isClusterRunning: boolean;
statusRunning: string;
permissions: any;
}

export const ClusterOverview = compose(
Expand All @@ -33,36 +31,19 @@ export const ClusterOverview = compose(
constructor(props) {
super(props);
this.state = {
authorized: true,
clusterEnabled: false,
isClusterRunning: false,
statusRunning: 'no',
permissions: undefined,
};
}

clusterStatus = async () => {
try {
const status = await WzRequest.apiReq('GET', '/cluster/status', {});
this.setState({
authorized: true,
});
return status;
} catch (error) {
if (error === '3013 - Permission denied: Resource type: *:*')
this.setState({
authorized: false,
});
}
};

async componentDidMount() {
this._isMount = true;
const clusterEnabled =
AppState.getClusterInfo() &&
AppState.getClusterInfo().status === 'enabled';

const status: any = await this.clusterStatus();
const status: any = await WzRequest.apiReq('GET', '/cluster/status', {});
const statusRunning = status?.data?.data?.running;
this.setState({
clusterEnabled: clusterEnabled,
Expand All @@ -79,18 +60,14 @@ export const ClusterOverview = compose(
return (
<>
<div style={{ padding: '16px' }}>
{!this.state?.clusterEnabled ||
!this.state?.isClusterRunning ||
!this.state?.authorized ? (
{!this.state?.clusterEnabled || !this.state?.isClusterRunning ? (
<ClusterDisabled
enabled={this.state?.clusterEnabled}
running={this.state?.isClusterRunning}
/>
) : null}
</div>
{this.state?.clusterEnabled &&
this.state?.isClusterRunning &&
this.state?.authorized ? (
{this.state?.clusterEnabled && this.state?.isClusterRunning ? (
<ClusterDashboard statusRunning={this.state?.statusRunning} />
) : null}
</>
Expand Down

0 comments on commit 8a40b5a

Please sign in to comment.