Skip to content

Commit be4b954

Browse files
committed
[FE] Use id field for keys
1 parent cba12d4 commit be4b954

File tree

8 files changed

+32
-17
lines changed

8 files changed

+32
-17
lines changed

kafka-ui-react-app/src/components/Dashboard/ClustersWidget/ClustersWidget.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,29 @@ interface Props {
1212
offlineClusters: Cluster[];
1313
}
1414

15+
interface ChunkItem {
16+
id: string;
17+
data: Cluster[];
18+
}
19+
1520
const ClustersWidget: React.FC<Props> = ({
1621
clusters,
1722
onlineClusters,
1823
offlineClusters,
1924
}) => {
2025
const [showOfflineOnly, setShowOfflineOnly] = React.useState<boolean>(false);
2126

22-
const clusterList: Array<Cluster[]> = React.useMemo(() => {
27+
const clusterList: ChunkItem[] = React.useMemo(() => {
2328
let list = clusters;
2429

2530
if (showOfflineOnly) {
2631
list = offlineClusters;
2732
}
2833

29-
return chunk(list, 2);
34+
return chunk(list, 2).map((data) => ({
35+
id: v4(),
36+
data,
37+
}));
3038
}, [clusters, offlineClusters, showOfflineOnly]);
3139

3240
const handleSwitch = () => setShowOfflineOnly(!showOfflineOnly);
@@ -56,8 +64,8 @@ const ClustersWidget: React.FC<Props> = ({
5664
</MetricsWrapper>
5765

5866
{clusterList.map((chunkItem) => (
59-
<div className="columns" key={v4()}>
60-
{chunkItem.map((cluster) => (
67+
<div className="columns" key={chunkItem.id}>
68+
{chunkItem.data.map((cluster) => (
6169
<ClusterWidget cluster={cluster} key={cluster.id} />
6270
))}
6371
</div>

kafka-ui-react-app/src/components/Topics/Details/Settings/Settings.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import { v4 } from 'uuid';
32
import { ClusterName, TopicName, TopicConfig } from 'redux/interfaces';
43

54
interface Props {
@@ -57,7 +56,7 @@ const Sertings: React.FC<Props> = ({
5756
</thead>
5857
<tbody>
5958
{config.map((item) => (
60-
<ConfigListItem key={v4()} config={item} />
59+
<ConfigListItem key={item.id} config={item} />
6160
))}
6261
</tbody>
6362
</table>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import { v4 } from 'uuid';
32
import { TopicWithDetailedInfo, ClusterName } from 'redux/interfaces';
43
import Breadcrumb from 'components/common/Breadcrumb/Breadcrumb';
54
import { NavLink } from 'react-router-dom';
@@ -60,7 +59,7 @@ const List: React.FC<Props> = ({ clusterName, topics, externalTopics }) => {
6059
</thead>
6160
<tbody>
6261
{items.map((topic) => (
63-
<ListItem key={v4()} topic={topic} />
62+
<ListItem key={topic.id} topic={topic} />
6463
))}
6564
</tbody>
6665
</table>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import { NavLink } from 'react-router-dom';
3-
import { v4 } from 'uuid';
43

54
interface Link {
65
label: string;
@@ -17,7 +16,7 @@ const Breadcrumb: React.FC<Props> = ({ links, children }) => {
1716
<ul>
1817
{links &&
1918
links.map(({ label, href }) => (
20-
<li key={v4()}>
19+
<li key={href}>
2120
<NavLink to={href}>{label}</NavLink>
2221
</li>
2322
))}

kafka-ui-react-app/src/redux/actions/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
BrokerMetrics,
66
Cluster,
77
Topic,
8-
TopicConfig,
8+
InputTopicConfig,
99
TopicDetails,
1010
TopicMessage,
1111
TopicName,
@@ -54,7 +54,7 @@ export const fetchTopicConfigAction = createAsyncAction(
5454
ActionType.GET_TOPIC_CONFIG__REQUEST,
5555
ActionType.GET_TOPIC_CONFIG__SUCCESS,
5656
ActionType.GET_TOPIC_CONFIG__FAILURE
57-
)<undefined, { topicName: TopicName; config: TopicConfig[] }, undefined>();
57+
)<undefined, { topicName: TopicName; config: InputTopicConfig[] }, undefined>();
5858

5959
export const createTopicAction = createAsyncAction(
6060
ActionType.POST_TOPIC__REQUEST,

kafka-ui-react-app/src/redux/api/topics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
Topic,
55
ClusterName,
66
TopicDetails,
7-
TopicConfig,
7+
InputTopicConfig,
88
TopicFormData,
99
TopicFormCustomParam,
1010
TopicFormFormattedParams,
@@ -30,7 +30,7 @@ const formatCustomParams = (
3030
export const getTopicConfig = (
3131
clusterName: ClusterName,
3232
topicName: TopicName
33-
): Promise<TopicConfig[]> =>
33+
): Promise<InputTopicConfig[]> =>
3434
fetch(`${BASE_URL}/clusters/${clusterName}/topics/${topicName}/config`, {
3535
...BASE_PARAMS,
3636
}).then((res) => res.json());

kafka-ui-react-app/src/redux/interfaces/topic.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ export enum CleanupPolicy {
55
Compact = 'compact',
66
}
77

8-
export interface TopicConfig {
8+
export interface InputTopicConfig {
99
name: string;
1010
value: string;
1111
defaultValue: string;
1212
}
1313

14+
export interface TopicConfig extends InputTopicConfig {
15+
id: string;
16+
}
17+
1418
export interface TopicConfigByName {
1519
byName: {
1620
[paramName: string]: TopicConfig;
@@ -89,6 +93,7 @@ export interface TopicFormCustomParams {
8993

9094
export interface TopicWithDetailedInfo extends Topic, TopicDetails {
9195
config?: TopicConfig[];
96+
id: string;
9297
}
9398

9499
export interface TopicsState {

kafka-ui-react-app/src/redux/reducers/topics/reducer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { v4 } from 'uuid';
12
import { Action, TopicsState, Topic } from 'redux/interfaces';
23
import ActionType from 'redux/actionType';
34

@@ -18,6 +19,7 @@ const updateTopicList = (state: TopicsState, payload: Topic[]): TopicsState => {
1819
memo.byName[name] = {
1920
...memo.byName[name],
2021
...topic,
22+
id: v4(),
2123
};
2224
memo.allNames.push(name);
2325

@@ -30,7 +32,7 @@ const addToTopicList = (state: TopicsState, payload: Topic): TopicsState => {
3032
...state,
3133
};
3234
newState.allNames.push(payload.name);
33-
newState.byName[payload.name] = payload;
35+
newState.byName[payload.name] = { ...payload, id: v4() };
3436
return newState;
3537
};
3638

@@ -61,7 +63,10 @@ const reducer = (state = initialState, action: Action): TopicsState => {
6163
...state.byName,
6264
[action.payload.topicName]: {
6365
...state.byName[action.payload.topicName],
64-
config: action.payload.config,
66+
config: action.payload.config.map((inputConfig) => ({
67+
...inputConfig,
68+
id: v4(),
69+
})),
6570
},
6671
},
6772
};

0 commit comments

Comments
 (0)