Skip to content

Commit

Permalink
chore(SchedulersAndAgents): fix some React-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ma-efremoff committed Nov 17, 2023
1 parent 76fe005 commit c33a208
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';

import hammer from '../../../../common/hammer';
import block from 'bem-cn-lite';
Expand All @@ -13,14 +12,21 @@ import '../Schedulers.scss';

const b = block('system');

export default function Scheduler({host, state, maintenanceMessage}) {
const theme = {
active: 'online',
connected: 'online',
standby: 'banned',
disconnected: 'banned',
offline: 'offline',
}[state];
export type SchedulerProps = {
host?: string;
state: 'active' | 'connected' | 'standby' | 'disconnected' | 'offline';
maintenanceMessage?: React.ReactNode;
};
export default function Scheduler({host, state, maintenanceMessage}: SchedulerProps) {
const theme = (
{
active: 'online',
connected: 'online',
standby: 'banned',
disconnected: 'banned',
offline: 'offline',
} as const
)[state];

const address = hammer.format['Address'](host);

Expand All @@ -38,15 +44,9 @@ export default function Scheduler({host, state, maintenanceMessage}) {
<div title={address} className={b('scheduler-host')}>
<div className={b('scheduler-host-address')}>{address}</div>
<div className={b('scheduler-host-copy-btn')}>
<ClipboardButton view="flat-secondary" text={host} />
{host && <ClipboardButton view="flat-secondary" text={host} />}
</div>
</div>
</div>
);
}

Scheduler.propTypes = {
host: PropTypes.string.isRequired,
state: PropTypes.oneOf(['offline', 'active', 'connected', 'standby', 'disconnected']),
maintenanceMessage: PropTypes.string,
};
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ class SchedulersAndAgents extends Component {
};

renderHosts(connectedHosts) {
return _.map(connectedHosts, ({host, state, maintenanceMessage}) => (
<Scheduler
key={host}
host={host}
state={state}
maintenanceMessage={maintenanceMessage}
/>
));
return _.map(connectedHosts, ({host, state, maintenanceMessage}, index) => {
return (
<Scheduler
key={host ?? index}
host={host}
state={state}
maintenanceMessage={maintenanceMessage}
/>
);
});
}

renderSection(name, heading, showHostTypeButton) {
Expand Down Expand Up @@ -134,8 +136,8 @@ class SchedulersAndAgents extends Component {
{_.map(alerts.schedulers, (alert) => (
<Alert key={alert.attributes.host} error={alert} />
))}
{_.map(alerts.agents, (alert) => (
<Alert error={alert} />
{_.map(alerts.agents, (alert, index) => (
<Alert key={index} error={alert} />
))}

<div className={b('schedulers-agents')}>
Expand Down

0 comments on commit c33a208

Please sign in to comment.