Skip to content

Commit d2543a7

Browse files
yenienserranoasteriscoschantal-kelm
authored
Fix warning type error in status view (#6722)
Conditional render Co-authored-by: Federico Rodriguez <federico.rodriguez@wazuh.com> Co-authored-by: Chantal Belén kelm <99441266+chantal-kelm@users.noreply.github.com>
1 parent 33fddd7 commit d2543a7

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

plugins/main/public/controllers/management/components/management/status/actions-buttons-main.js

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
EuiFlexItem,
1616
EuiSelect,
1717
EuiOverlayMask,
18-
EuiConfirmModal
18+
EuiConfirmModal,
1919
} from '@elastic/eui';
2020

2121
import { connect } from 'react-redux';
@@ -30,7 +30,7 @@ import {
3030
} from '../../../../../redux/actions/statusActions';
3131

3232
import StatusHandler from './utils/status-handler';
33-
import { getToasts } from '../../../../../kibana-services';
33+
import { getToasts } from '../../../../../kibana-services';
3434
import { WzButtonPermissions } from '../../../../../components/common/permissions/button';
3535

3636
import { UI_ERROR_SEVERITIES } from '../../../../../react-services/error-orchestrator/types';
@@ -47,7 +47,7 @@ class WzStatusActionButtons extends Component {
4747
this.statusHandler = StatusHandler;
4848
this.state = {
4949
isModalVisible: false,
50-
isRestarting: false
50+
isRestarting: false,
5151
};
5252
}
5353

@@ -72,7 +72,7 @@ class WzStatusActionButtons extends Component {
7272
this.showToast(
7373
'success',
7474
'Restarting cluster, it will take up to 30 seconds.',
75-
3000
75+
3000,
7676
);
7777
} catch (error) {
7878
this.setState({ isRestarting: false });
@@ -131,9 +131,11 @@ class WzStatusActionButtons extends Component {
131131
this.props.updateLoadingStatus(true);
132132
this.props.updateSelectedNode(node);
133133

134-
const agentsCountByManagerNodes = await this.statusHandler.clusterAgentsCount();
134+
const agentsCountByManagerNodes =
135+
await this.statusHandler.clusterAgentsCount();
135136

136-
const { connection: agentsCount } = agentsCountByManagerNodes?.data?.data?.agent_status;
137+
const { connection: agentsCount } =
138+
agentsCountByManagerNodes?.data?.data?.agent_status;
137139

138140
const agentsActiveCoverage = (
139141
(agentsCount.active / agentsCount.total) *
@@ -168,7 +170,7 @@ class WzStatusActionButtons extends Component {
168170
error: {
169171
error: error,
170172
message: error.message || error,
171-
title: `${error.name}: Node ${node} is down`
173+
title: `${error.name}: Node ${node} is down`,
172174
},
173175
};
174176
getErrorOrchestrator().handleError(options);
@@ -192,7 +194,7 @@ class WzStatusActionButtons extends Component {
192194
getToasts().add({
193195
color: color,
194196
title: text,
195-
toastLifeTimeMs: time
197+
toastLifeTimeMs: time,
196198
});
197199
};
198200

@@ -201,7 +203,7 @@ class WzStatusActionButtons extends Component {
201203
for (const node of listNodes) {
202204
options.push({
203205
value: node.name,
204-
text: `${node.name} (${node.type})`
206+
text: `${node.name} (${node.type})`,
205207
});
206208
}
207209
return options;
@@ -212,33 +214,35 @@ class WzStatusActionButtons extends Component {
212214
};
213215

214216
render() {
215-
const {
216-
isLoading,
217-
listNodes,
218-
selectedNode,
219-
clusterEnabled,
220-
} = this.props.state;
217+
const { isLoading, listNodes, selectedNode, clusterEnabled } =
218+
this.props.state;
221219

222220
let options = this.transforToOptions(listNodes);
223221

224222
// Select node
225-
const selectNode = (
226-
<EuiSelect
227-
id="selectNode"
228-
options={options}
229-
value={selectedNode}
230-
onChange={this.changeNode}
231-
disabled={isLoading || this.state.isRestarting}
232-
aria-label="Select node"
233-
/>
234-
);
223+
const selectNode = selectedNode ? (
224+
<EuiFlexItem grow={false}>
225+
<EuiSelect
226+
id='selectNode'
227+
options={options}
228+
value={selectedNode}
229+
onChange={this.changeNode}
230+
disabled={isLoading || this.state.isRestarting}
231+
aria-label='Select node'
232+
/>
233+
</EuiFlexItem>
234+
) : null;
235235

236236
// Restart button
237237
const restartButton = (
238238
<WzButtonPermissions
239239
buttonType='empty'
240-
permissions={[clusterEnabled ? {action: 'cluster:restart', resource: 'node:id:*'} : {action: 'manager:restart', resource: '*:*:*'}]}
241-
iconType="refresh"
240+
permissions={[
241+
clusterEnabled
242+
? { action: 'cluster:restart', resource: 'node:id:*' }
243+
: { action: 'manager:restart', resource: '*:*:*' },
244+
]}
245+
iconType='refresh'
242246
onClick={async () => this.setState({ isModalVisible: true })}
243247
isDisabled={isLoading}
244248
isLoading={this.state.isRestarting}
@@ -268,9 +272,9 @@ class WzStatusActionButtons extends Component {
268272
}
269273
this.setState({ isModalVisible: false });
270274
}}
271-
cancelButtonText="Cancel"
272-
confirmButtonText="Confirm"
273-
defaultFocusedButton="cancel"
275+
cancelButtonText='Cancel'
276+
confirmButtonText='Confirm'
277+
defaultFocusedButton='cancel'
274278
></EuiConfirmModal>
275279
</EuiOverlayMask>
276280
);
@@ -281,7 +285,7 @@ class WzStatusActionButtons extends Component {
281285
{selectedNode !== null && (
282286
<EuiFlexItem grow={false}>{restartButton}</EuiFlexItem>
283287
)}
284-
{selectedNode && <EuiFlexItem grow={false}>{selectNode}</EuiFlexItem>}
288+
{selectNode}
285289
{modal}
286290
</Fragment>
287291
);
@@ -290,7 +294,7 @@ class WzStatusActionButtons extends Component {
290294

291295
const mapStateToProps = state => {
292296
return {
293-
state: state.statusReducers
297+
state: state.statusReducers,
294298
};
295299
};
296300

@@ -299,13 +303,14 @@ const mapDispatchToProps = dispatch => {
299303
updateLoadingStatus: status => dispatch(updateLoadingStatus(status)),
300304
updateListDaemons: listDaemons => dispatch(updateListDaemons(listDaemons)),
301305
updateNodeInfo: nodeInfo => dispatch(updateNodeInfo(nodeInfo)),
302-
updateSelectedNode: selectedNode => dispatch(updateSelectedNode(selectedNode)),
306+
updateSelectedNode: selectedNode =>
307+
dispatch(updateSelectedNode(selectedNode)),
303308
updateStats: stats => dispatch(updateStats(stats)),
304-
updateAgentInfo: agentInfo => dispatch(updateAgentInfo(agentInfo))
309+
updateAgentInfo: agentInfo => dispatch(updateAgentInfo(agentInfo)),
305310
};
306311
};
307312

308313
export default connect(
309314
mapStateToProps,
310-
mapDispatchToProps
315+
mapDispatchToProps,
311316
)(WzStatusActionButtons);

0 commit comments

Comments
 (0)