Skip to content

Commit 44269fa

Browse files
fix(Partitions): fix error on wrong consumer in query string
1 parent 95e4462 commit 44269fa

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

src/containers/Tenant/Diagnostics/Partitions/Partitions.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import block from 'bem-cn-lite';
2-
import {useCallback, useEffect, useMemo, useRef, useState} from 'react';
2+
import {useCallback, useEffect, useMemo, useState} from 'react';
33
import {useDispatch} from 'react-redux';
44
import {escapeRegExp} from 'lodash/fp';
55

@@ -53,8 +53,6 @@ export const Partitions = ({path, type, nodes, consumers}: PartitionsProps) => {
5353

5454
const dispatch = useDispatch();
5555

56-
const isFirstRenderRef = useRef(true);
57-
5856
const [generalSearchValue, setGeneralSearchValue] = useState('');
5957
const [partitionIdSearchValue, setPartitionIdSearchValue] = useState('');
6058

@@ -74,14 +72,6 @@ export const Partitions = ({path, type, nodes, consumers}: PartitionsProps) => {
7472
useEffect(() => {
7573
// Manual path control to ensure it updates with other values so no request with wrong params will be sent
7674
setComponentCurrentPath(path);
77-
78-
// Do not reset selected consumer on first effect call
79-
// To enable navigating to specific consumer
80-
if (isFirstRenderRef.current) {
81-
isFirstRenderRef.current = false;
82-
} else {
83-
dispatch(setSelectedConsumer(undefined));
84-
}
8575
}, [dispatch, path]);
8676

8777
const fetchConsumerData = useCallback(
@@ -90,11 +80,11 @@ export const Partitions = ({path, type, nodes, consumers}: PartitionsProps) => {
9080
dispatch(setDataWasNotLoaded());
9181
}
9282

93-
if (selectedConsumer) {
83+
if (selectedConsumer && consumers && consumers.includes(selectedConsumer)) {
9484
dispatch(getConsumer(componentCurrentPath, selectedConsumer));
9585
}
9686
},
97-
[dispatch, selectedConsumer, componentCurrentPath],
87+
[dispatch, selectedConsumer, componentCurrentPath, consumers],
9888
);
9989

10090
useAutofetcher(fetchConsumerData, [fetchConsumerData], autorefresh);
@@ -111,10 +101,13 @@ export const Partitions = ({path, type, nodes, consumers}: PartitionsProps) => {
111101
);
112102

113103
useEffect(() => {
114-
if (consumersToSelect && consumersToSelect.length && !selectedConsumer) {
104+
const shouldUpdateSelectedConsumer =
105+
!selectedConsumer || (consumers && !consumers.includes(selectedConsumer));
106+
107+
if (consumersToSelect && consumersToSelect.length && shouldUpdateSelectedConsumer) {
115108
dispatch(setSelectedConsumer(consumersToSelect[0].value));
116109
}
117-
}, [dispatch, consumersToSelect, selectedConsumer]);
110+
}, [dispatch, consumersToSelect, selectedConsumer, consumers]);
118111

119112
const selectedColumns: string[] = useMemo(
120113
() =>

src/containers/Tenant/Diagnostics/Partitions/PartitionsWrapper.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {EPathType} from '../../../../types/api/schema';
66
import {useTypedSelector} from '../../../../utils/hooks';
77

88
import {
9+
cleanTopicData,
910
getTopic,
1011
setDataWasNotLoaded as setTopicDataWasNotLoaded,
1112
} from '../../../../store/reducers/topic';
@@ -61,6 +62,7 @@ export const PartitionsWrapper = ({path, type}: PartitionsWrapperProps) => {
6162

6263
useEffect(() => {
6364
dispatch(setTopicDataWasNotLoaded());
65+
dispatch(cleanTopicData());
6466
dispatch(setNodesDataWasNotLoaded());
6567

6668
dispatch(getTopic(path));

src/store/reducers/topic.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {convertBytesObjectToSpeed} from '../../utils/bytesParsers';
1818
export const FETCH_TOPIC = createRequestActionTypes('topic', 'FETCH_TOPIC');
1919

2020
const SET_DATA_WAS_NOT_LOADED = 'topic/SET_DATA_WAS_NOT_LOADED';
21+
const CLEAN_TOPIC_DATA = 'topic/CLEAN_TOPIC_DATA';
2122

2223
const initialState = {
2324
loading: true,
@@ -64,6 +65,12 @@ const topic: Reducer<ITopicState, ITopicAction> = (state = initialState, action)
6465
wasLoaded: false,
6566
};
6667
}
68+
case CLEAN_TOPIC_DATA: {
69+
return {
70+
...state,
71+
data: undefined,
72+
};
73+
}
6774
default:
6875
return state;
6976
}
@@ -75,6 +82,12 @@ export const setDataWasNotLoaded = () => {
7582
} as const;
7683
};
7784

85+
export const cleanTopicData = () => {
86+
return {
87+
type: CLEAN_TOPIC_DATA,
88+
} as const;
89+
};
90+
7891
export function getTopic(path?: string) {
7992
return createApiRequest({
8093
request: window.api.getTopic({path}),

src/types/store/topic.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {FETCH_TOPIC, setDataWasNotLoaded} from '../../store/reducers/topic';
1+
import {FETCH_TOPIC, cleanTopicData, setDataWasNotLoaded} from '../../store/reducers/topic';
22
import type {ApiRequestAction} from '../../store/utils';
33
import type {IProcessSpeedStats} from '../../utils/bytesParsers';
44
import type {IResponseError} from '../api/error';
@@ -31,7 +31,8 @@ export interface ITopicState {
3131

3232
export type ITopicAction =
3333
| ApiRequestAction<typeof FETCH_TOPIC, DescribeTopicResult, IResponseError>
34-
| ReturnType<typeof setDataWasNotLoaded>;
34+
| ReturnType<typeof setDataWasNotLoaded>
35+
| ReturnType<typeof cleanTopicData>;
3536

3637
export interface ITopicRootStateSlice {
3738
topic: ITopicState;

0 commit comments

Comments
 (0)