Skip to content

Commit a55068d

Browse files
authored
fixing sonar code smells (#1826)
* fixing sonar code smells * removing unnecessary change * fixing some sonar code smell issues * making requested changes
1 parent 9acef94 commit a55068d

File tree

5 files changed

+37
-41
lines changed

5 files changed

+37
-41
lines changed

kafka-ui-react-app/src/components/Brokers/Brokers.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Brokers: React.FC = () => {
3232

3333
const replicas = inSyncReplicasCount ?? 0 + (outOfSyncReplicasCount ?? 0);
3434
const areAllInSync = inSyncReplicasCount && replicas === inSyncReplicasCount;
35-
35+
const partitionIsOffline = offlinePartitionCount && offlinePartitionCount > 0;
3636
React.useEffect(() => {
3737
dispatch(fetchClusterStats(clusterName));
3838
dispatch(fetchBrokers(clusterName));
@@ -60,13 +60,9 @@ const Brokers: React.FC = () => {
6060
<Metrics.Indicator
6161
label="Online"
6262
isAlert
63-
alertType={
64-
offlinePartitionCount && offlinePartitionCount > 0
65-
? 'error'
66-
: 'success'
67-
}
63+
alertType={partitionIsOffline ? 'error' : 'success'}
6864
>
69-
{offlinePartitionCount && offlinePartitionCount > 0 ? (
65+
{partitionIsOffline ? (
7066
<Metrics.RedText>{onlinePartitionCount}</Metrics.RedText>
7167
) : (
7268
onlinePartitionCount
@@ -80,11 +76,9 @@ const Brokers: React.FC = () => {
8076
label="URP"
8177
title="Under replicated partitions"
8278
isAlert
83-
alertType={
84-
underReplicatedPartitionCount === 0 ? 'success' : 'error'
85-
}
79+
alertType={!underReplicatedPartitionCount ? 'success' : 'error'}
8680
>
87-
{underReplicatedPartitionCount === 0 ? (
81+
{!underReplicatedPartitionCount ? (
8882
<Metrics.LightText>
8983
{underReplicatedPartitionCount}
9084
</Metrics.LightText>

kafka-ui-react-app/src/components/Connect/Details/Tasks/ListItem/ListItemContainer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface OwnProps extends RouteComponentProps {
1010
task: Task;
1111
}
1212

13-
const mapStateToProps = (state: RootState, { task }: OwnProps) => ({
13+
const mapStateToProps = (_state: RootState, { task }: OwnProps) => ({
1414
task,
1515
});
1616

kafka-ui-react-app/src/components/Topics/List/List.tsx

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ const List: React.FC<TopicsListProps> = ({
149149
'' | 'deleteTopics' | 'purgeMessages'
150150
>('');
151151

152+
const [confirmationModalText, setConfirmationModalText] =
153+
React.useState<string>('');
152154
const closeConfirmationModal = () => {
153155
setConfirmationModal('');
154156
};
@@ -157,22 +159,6 @@ const List: React.FC<TopicsListProps> = ({
157159
tableState.toggleSelection(false);
158160
}, [tableState]);
159161

160-
const deleteTopicsHandler = React.useCallback(() => {
161-
deleteTopics(clusterName, Array.from(tableState.selectedIds));
162-
closeConfirmationModal();
163-
clearSelectedTopics();
164-
}, [clearSelectedTopics, clusterName, deleteTopics, tableState.selectedIds]);
165-
const purgeMessagesHandler = React.useCallback(() => {
166-
clearTopicsMessages(clusterName, Array.from(tableState.selectedIds));
167-
closeConfirmationModal();
168-
clearSelectedTopics();
169-
}, [
170-
clearSelectedTopics,
171-
clearTopicsMessages,
172-
clusterName,
173-
tableState.selectedIds,
174-
]);
175-
176162
const searchHandler = React.useCallback(
177163
(searchString: string) => {
178164
setTopicsSearch(searchString);
@@ -187,6 +173,23 @@ const List: React.FC<TopicsListProps> = ({
187173
},
188174
[setTopicsSearch, history, pathname, perPage, page]
189175
);
176+
const deleteOrPurgeConfirmationHandler = React.useCallback(() => {
177+
const selectedIds = Array.from(tableState.selectedIds);
178+
if (confirmationModal === 'deleteTopics') {
179+
deleteTopics(clusterName, selectedIds);
180+
} else {
181+
clearTopicsMessages(clusterName, selectedIds);
182+
}
183+
closeConfirmationModal();
184+
clearSelectedTopics();
185+
}, [
186+
confirmationModal,
187+
clearSelectedTopics,
188+
clusterName,
189+
deleteTopics,
190+
clearTopicsMessages,
191+
tableState.selectedIds,
192+
]);
190193

191194
const ActionsCell = React.memo<TableCellProps<TopicWithDetailedInfo, string>>(
192195
({ hovered, dataItem: { internal, cleanUpPolicy, name } }) => {
@@ -306,6 +309,9 @@ const List: React.FC<TopicsListProps> = ({
306309
buttonType="secondary"
307310
onClick={() => {
308311
setConfirmationModal('deleteTopics');
312+
setConfirmationModalText(
313+
'Are you sure you want to remove selected topics?'
314+
);
309315
}}
310316
>
311317
Delete selected topics
@@ -329,6 +335,9 @@ const List: React.FC<TopicsListProps> = ({
329335
buttonType="secondary"
330336
onClick={() => {
331337
setConfirmationModal('purgeMessages');
338+
setConfirmationModalText(
339+
'Are you sure you want to purge messages of selected topics?'
340+
);
332341
}}
333342
>
334343
Purge messages of selected topics
@@ -337,15 +346,9 @@ const List: React.FC<TopicsListProps> = ({
337346
<ConfirmationModal
338347
isOpen={confirmationModal !== ''}
339348
onCancel={closeConfirmationModal}
340-
onConfirm={
341-
confirmationModal === 'deleteTopics'
342-
? deleteTopicsHandler
343-
: purgeMessagesHandler
344-
}
349+
onConfirm={deleteOrPurgeConfirmationHandler}
345350
>
346-
{confirmationModal === 'deleteTopics'
347-
? 'Are you sure you want to remove selected topics?'
348-
: 'Are you sure you want to purge messages of selected topics?'}
351+
{confirmationModalText}
349352
</ConfirmationModal>
350353
</>
351354
)}

kafka-ui-react-app/src/components/Topics/shared/Form/CustomParams/CustomParamsContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface OwnProps extends RouteComponentProps {
1010
}
1111

1212
const mapStateToProps = (
13-
state: RootState,
13+
_state: RootState,
1414
{ isSubmitting, config }: OwnProps
1515
) => ({
1616
isSubmitting,

kafka-ui-react-app/src/components/common/SmartTable/SmartTable.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ export const SmartTable = <T, TId extends IdType, OT = never>({
4848

4949
const { headerCell, title, orderValue } = child.props;
5050

51-
const HeaderCell = headerCell as
52-
| React.FC<TableHeaderCellProps<T, TId, OT>>
53-
| undefined;
54-
51+
const HeaderCell = headerCell as React.FC<
52+
TableHeaderCellProps<T, TId, OT>
53+
>;
5554
return HeaderCell ? (
5655
<S.TableHeaderCell>
5756
<HeaderCell

0 commit comments

Comments
 (0)