fixing sonar code smells (#1826)
* fixing sonar code smells * removing unnecessary change * fixing some sonar code smell issues * making requested changes
This commit is contained in:
parent
9acef94234
commit
a55068d122
5 changed files with 37 additions and 41 deletions
|
@ -32,7 +32,7 @@ const Brokers: React.FC = () => {
|
||||||
|
|
||||||
const replicas = inSyncReplicasCount ?? 0 + (outOfSyncReplicasCount ?? 0);
|
const replicas = inSyncReplicasCount ?? 0 + (outOfSyncReplicasCount ?? 0);
|
||||||
const areAllInSync = inSyncReplicasCount && replicas === inSyncReplicasCount;
|
const areAllInSync = inSyncReplicasCount && replicas === inSyncReplicasCount;
|
||||||
|
const partitionIsOffline = offlinePartitionCount && offlinePartitionCount > 0;
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
dispatch(fetchClusterStats(clusterName));
|
dispatch(fetchClusterStats(clusterName));
|
||||||
dispatch(fetchBrokers(clusterName));
|
dispatch(fetchBrokers(clusterName));
|
||||||
|
@ -60,13 +60,9 @@ const Brokers: React.FC = () => {
|
||||||
<Metrics.Indicator
|
<Metrics.Indicator
|
||||||
label="Online"
|
label="Online"
|
||||||
isAlert
|
isAlert
|
||||||
alertType={
|
alertType={partitionIsOffline ? 'error' : 'success'}
|
||||||
offlinePartitionCount && offlinePartitionCount > 0
|
|
||||||
? 'error'
|
|
||||||
: 'success'
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{offlinePartitionCount && offlinePartitionCount > 0 ? (
|
{partitionIsOffline ? (
|
||||||
<Metrics.RedText>{onlinePartitionCount}</Metrics.RedText>
|
<Metrics.RedText>{onlinePartitionCount}</Metrics.RedText>
|
||||||
) : (
|
) : (
|
||||||
onlinePartitionCount
|
onlinePartitionCount
|
||||||
|
@ -80,11 +76,9 @@ const Brokers: React.FC = () => {
|
||||||
label="URP"
|
label="URP"
|
||||||
title="Under replicated partitions"
|
title="Under replicated partitions"
|
||||||
isAlert
|
isAlert
|
||||||
alertType={
|
alertType={!underReplicatedPartitionCount ? 'success' : 'error'}
|
||||||
underReplicatedPartitionCount === 0 ? 'success' : 'error'
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{underReplicatedPartitionCount === 0 ? (
|
{!underReplicatedPartitionCount ? (
|
||||||
<Metrics.LightText>
|
<Metrics.LightText>
|
||||||
{underReplicatedPartitionCount}
|
{underReplicatedPartitionCount}
|
||||||
</Metrics.LightText>
|
</Metrics.LightText>
|
||||||
|
|
|
@ -10,7 +10,7 @@ interface OwnProps extends RouteComponentProps {
|
||||||
task: Task;
|
task: Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state: RootState, { task }: OwnProps) => ({
|
const mapStateToProps = (_state: RootState, { task }: OwnProps) => ({
|
||||||
task,
|
task,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -149,6 +149,8 @@ const List: React.FC<TopicsListProps> = ({
|
||||||
'' | 'deleteTopics' | 'purgeMessages'
|
'' | 'deleteTopics' | 'purgeMessages'
|
||||||
>('');
|
>('');
|
||||||
|
|
||||||
|
const [confirmationModalText, setConfirmationModalText] =
|
||||||
|
React.useState<string>('');
|
||||||
const closeConfirmationModal = () => {
|
const closeConfirmationModal = () => {
|
||||||
setConfirmationModal('');
|
setConfirmationModal('');
|
||||||
};
|
};
|
||||||
|
@ -157,22 +159,6 @@ const List: React.FC<TopicsListProps> = ({
|
||||||
tableState.toggleSelection(false);
|
tableState.toggleSelection(false);
|
||||||
}, [tableState]);
|
}, [tableState]);
|
||||||
|
|
||||||
const deleteTopicsHandler = React.useCallback(() => {
|
|
||||||
deleteTopics(clusterName, Array.from(tableState.selectedIds));
|
|
||||||
closeConfirmationModal();
|
|
||||||
clearSelectedTopics();
|
|
||||||
}, [clearSelectedTopics, clusterName, deleteTopics, tableState.selectedIds]);
|
|
||||||
const purgeMessagesHandler = React.useCallback(() => {
|
|
||||||
clearTopicsMessages(clusterName, Array.from(tableState.selectedIds));
|
|
||||||
closeConfirmationModal();
|
|
||||||
clearSelectedTopics();
|
|
||||||
}, [
|
|
||||||
clearSelectedTopics,
|
|
||||||
clearTopicsMessages,
|
|
||||||
clusterName,
|
|
||||||
tableState.selectedIds,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const searchHandler = React.useCallback(
|
const searchHandler = React.useCallback(
|
||||||
(searchString: string) => {
|
(searchString: string) => {
|
||||||
setTopicsSearch(searchString);
|
setTopicsSearch(searchString);
|
||||||
|
@ -187,6 +173,23 @@ const List: React.FC<TopicsListProps> = ({
|
||||||
},
|
},
|
||||||
[setTopicsSearch, history, pathname, perPage, page]
|
[setTopicsSearch, history, pathname, perPage, page]
|
||||||
);
|
);
|
||||||
|
const deleteOrPurgeConfirmationHandler = React.useCallback(() => {
|
||||||
|
const selectedIds = Array.from(tableState.selectedIds);
|
||||||
|
if (confirmationModal === 'deleteTopics') {
|
||||||
|
deleteTopics(clusterName, selectedIds);
|
||||||
|
} else {
|
||||||
|
clearTopicsMessages(clusterName, selectedIds);
|
||||||
|
}
|
||||||
|
closeConfirmationModal();
|
||||||
|
clearSelectedTopics();
|
||||||
|
}, [
|
||||||
|
confirmationModal,
|
||||||
|
clearSelectedTopics,
|
||||||
|
clusterName,
|
||||||
|
deleteTopics,
|
||||||
|
clearTopicsMessages,
|
||||||
|
tableState.selectedIds,
|
||||||
|
]);
|
||||||
|
|
||||||
const ActionsCell = React.memo<TableCellProps<TopicWithDetailedInfo, string>>(
|
const ActionsCell = React.memo<TableCellProps<TopicWithDetailedInfo, string>>(
|
||||||
({ hovered, dataItem: { internal, cleanUpPolicy, name } }) => {
|
({ hovered, dataItem: { internal, cleanUpPolicy, name } }) => {
|
||||||
|
@ -306,6 +309,9 @@ const List: React.FC<TopicsListProps> = ({
|
||||||
buttonType="secondary"
|
buttonType="secondary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setConfirmationModal('deleteTopics');
|
setConfirmationModal('deleteTopics');
|
||||||
|
setConfirmationModalText(
|
||||||
|
'Are you sure you want to remove selected topics?'
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Delete selected topics
|
Delete selected topics
|
||||||
|
@ -329,6 +335,9 @@ const List: React.FC<TopicsListProps> = ({
|
||||||
buttonType="secondary"
|
buttonType="secondary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setConfirmationModal('purgeMessages');
|
setConfirmationModal('purgeMessages');
|
||||||
|
setConfirmationModalText(
|
||||||
|
'Are you sure you want to purge messages of selected topics?'
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Purge messages of selected topics
|
Purge messages of selected topics
|
||||||
|
@ -337,15 +346,9 @@ const List: React.FC<TopicsListProps> = ({
|
||||||
<ConfirmationModal
|
<ConfirmationModal
|
||||||
isOpen={confirmationModal !== ''}
|
isOpen={confirmationModal !== ''}
|
||||||
onCancel={closeConfirmationModal}
|
onCancel={closeConfirmationModal}
|
||||||
onConfirm={
|
onConfirm={deleteOrPurgeConfirmationHandler}
|
||||||
confirmationModal === 'deleteTopics'
|
|
||||||
? deleteTopicsHandler
|
|
||||||
: purgeMessagesHandler
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{confirmationModal === 'deleteTopics'
|
{confirmationModalText}
|
||||||
? 'Are you sure you want to remove selected topics?'
|
|
||||||
: 'Are you sure you want to purge messages of selected topics?'}
|
|
||||||
</ConfirmationModal>
|
</ConfirmationModal>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -10,7 +10,7 @@ interface OwnProps extends RouteComponentProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (
|
const mapStateToProps = (
|
||||||
state: RootState,
|
_state: RootState,
|
||||||
{ isSubmitting, config }: OwnProps
|
{ isSubmitting, config }: OwnProps
|
||||||
) => ({
|
) => ({
|
||||||
isSubmitting,
|
isSubmitting,
|
||||||
|
|
|
@ -48,10 +48,9 @@ export const SmartTable = <T, TId extends IdType, OT = never>({
|
||||||
|
|
||||||
const { headerCell, title, orderValue } = child.props;
|
const { headerCell, title, orderValue } = child.props;
|
||||||
|
|
||||||
const HeaderCell = headerCell as
|
const HeaderCell = headerCell as React.FC<
|
||||||
| React.FC<TableHeaderCellProps<T, TId, OT>>
|
TableHeaderCellProps<T, TId, OT>
|
||||||
| undefined;
|
>;
|
||||||
|
|
||||||
return HeaderCell ? (
|
return HeaderCell ? (
|
||||||
<S.TableHeaderCell>
|
<S.TableHeaderCell>
|
||||||
<HeaderCell
|
<HeaderCell
|
||||||
|
|
Loading…
Add table
Reference in a new issue