Skip to content

Commit d7fde7f

Browse files
committed
fix: review
1 parent d3579cb commit d7fde7f

File tree

5 files changed

+55
-73
lines changed

5 files changed

+55
-73
lines changed

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export default [
4646
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
4747
curly: ['error', 'all'],
4848
'react-hooks/exhaustive-deps': 'warn',
49+
'react-hooks/rules-of-hooks': 'error',
4950
},
5051
},
5152
// TypeScript-specific rules that require type information

src/components/VDisk/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import {getVDiskPagePath} from '../../routes';
22
import type {PreparedVDisk} from '../../utils/disks/types';
33

44
export function getVDiskLink(data: PreparedVDisk, query: {database: string | undefined}) {
5+
if (!data.StringifiedId) {
6+
return undefined;
7+
}
58
return getVDiskPagePath(
69
{
7-
pDiskId: data.PDiskId,
810
nodeId: data.NodeId,
911
vDiskId: data.StringifiedId,
1012
},

src/components/VDiskInfo/VDiskInfo.tsx

Lines changed: 48 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22

33
import {Flex} from '@gravity-ui/uikit';
4+
import {isNil} from 'lodash';
45

56
import {getPDiskPagePath, getVDiskPagePath} from '../../routes';
67
import {EVDiskState} from '../../types/api/vdisk';
7-
import {valueIsDefined} from '../../utils';
88
import {cn} from '../../utils/cn';
99
import {
1010
formatStorageValuesToGb,
@@ -74,10 +74,10 @@ export function VDiskInfo<T extends PreparedVDisk>({
7474

7575
const leftColumn = [];
7676

77-
if (valueIsDefined(StoragePoolName)) {
77+
if (!isNil(StoragePoolName)) {
7878
leftColumn.push({label: vDiskInfoKeyset('pool-name'), value: StoragePoolName});
7979
}
80-
if (valueIsDefined(VDiskState)) {
80+
if (!isNil(VDiskState)) {
8181
leftColumn.push({
8282
label: vDiskInfoKeyset('state-status'),
8383
value: VDiskState,
@@ -96,37 +96,37 @@ export function VDiskInfo<T extends PreparedVDisk>({
9696
),
9797
});
9898
}
99-
if (valueIsDefined(DiskSpace)) {
99+
if (!isNil(DiskSpace)) {
100100
leftColumn.push({
101101
label: vDiskInfoKeyset('space-status'),
102102
value: <StatusIcon status={DiskSpace} />,
103103
});
104104
}
105-
if (valueIsDefined(FrontQueues)) {
105+
if (!isNil(FrontQueues)) {
106106
leftColumn.push({
107107
label: vDiskInfoKeyset('front-queues'),
108108
value: <StatusIcon status={FrontQueues} />,
109109
});
110110
}
111-
if (valueIsDefined(SatisfactionRank?.FreshRank?.Flag)) {
111+
if (!isNil(SatisfactionRank?.FreshRank?.Flag)) {
112112
leftColumn.push({
113113
label: vDiskInfoKeyset('fresh-rank-satisfaction'),
114114
value: <StatusIcon status={SatisfactionRank?.FreshRank?.Flag} />,
115115
});
116116
}
117-
if (valueIsDefined(SatisfactionRank?.LevelRank?.Flag)) {
117+
if (!isNil(SatisfactionRank?.LevelRank?.Flag)) {
118118
leftColumn.push({
119119
label: vDiskInfoKeyset('level-rank-satisfaction'),
120120
value: <StatusIcon status={SatisfactionRank?.LevelRank?.Flag} />,
121121
});
122122
}
123-
if (valueIsDefined(ReadThroughput)) {
123+
if (!isNil(ReadThroughput)) {
124124
leftColumn.push({
125125
label: vDiskInfoKeyset('read-throughput'),
126126
value: bytesToSpeed(ReadThroughput),
127127
});
128128
}
129-
if (valueIsDefined(WriteThroughput)) {
129+
if (!isNil(WriteThroughput)) {
130130
leftColumn.push({
131131
label: vDiskInfoKeyset('write-throughput'),
132132
value: bytesToSpeed(WriteThroughput),
@@ -135,15 +135,15 @@ export function VDiskInfo<T extends PreparedVDisk>({
135135

136136
const rightColumn = [];
137137

138-
if (valueIsDefined(Replicated)) {
138+
if (!isNil(Replicated)) {
139139
rightColumn.push({
140140
label: vDiskInfoKeyset('replication-status'),
141141
value: Replicated ? vDiskInfoKeyset('yes') : vDiskInfoKeyset('no'),
142142
});
143143
}
144144
// Only show replication progress and time remaining when disk is not replicated and state is OK
145145
if (Replicated === false && VDiskState === EVDiskState.OK) {
146-
if (valueIsDefined(ReplicationProgress)) {
146+
if (!isNil(ReplicationProgress)) {
147147
rightColumn.push({
148148
label: vDiskInfoKeyset('replication-progress'),
149149
value: (
@@ -156,7 +156,7 @@ export function VDiskInfo<T extends PreparedVDisk>({
156156
),
157157
});
158158
}
159-
if (valueIsDefined(ReplicationSecondsRemaining)) {
159+
if (!isNil(ReplicationSecondsRemaining)) {
160160
const timeRemaining = formatUptimeInSeconds(ReplicationSecondsRemaining);
161161
if (timeRemaining) {
162162
rightColumn.push({
@@ -166,11 +166,11 @@ export function VDiskInfo<T extends PreparedVDisk>({
166166
}
167167
}
168168
}
169-
if (valueIsDefined(VDiskSlotId)) {
169+
if (!isNil(VDiskSlotId)) {
170170
rightColumn.push({label: vDiskInfoKeyset('slot-id'), value: VDiskSlotId});
171171
}
172-
if (valueIsDefined(PDiskId)) {
173-
const pDiskPath = valueIsDefined(NodeId) ? getPDiskPagePath(PDiskId, NodeId) : undefined;
172+
if (!isNil(PDiskId)) {
173+
const pDiskPath = !isNil(NodeId) ? getPDiskPagePath(PDiskId, NodeId) : undefined;
174174

175175
const value = pDiskPath ? <InternalLink to={pDiskPath}>{PDiskId}</InternalLink> : PDiskId;
176176

@@ -180,19 +180,19 @@ export function VDiskInfo<T extends PreparedVDisk>({
180180
});
181181
}
182182

183-
if (valueIsDefined(Kind)) {
183+
if (!isNil(Kind)) {
184184
rightColumn.push({label: vDiskInfoKeyset('kind'), value: Kind});
185185
}
186-
if (valueIsDefined(Guid)) {
186+
if (!isNil(Guid)) {
187187
rightColumn.push({label: vDiskInfoKeyset('guid'), value: Guid});
188188
}
189-
if (valueIsDefined(IncarnationGuid)) {
189+
if (!isNil(IncarnationGuid)) {
190190
rightColumn.push({label: vDiskInfoKeyset('incarnation-guid'), value: IncarnationGuid});
191191
}
192-
if (valueIsDefined(InstanceGuid)) {
192+
if (!isNil(InstanceGuid)) {
193193
rightColumn.push({label: vDiskInfoKeyset('instance-guid'), value: InstanceGuid});
194194
}
195-
if (valueIsDefined(HasUnreadableBlobs)) {
195+
if (!isNil(HasUnreadableBlobs)) {
196196
rightColumn.push({
197197
label: vDiskInfoKeyset('has-unreadable-blobs'),
198198
value: HasUnreadableBlobs ? vDiskInfoKeyset('yes') : vDiskInfoKeyset('no'),
@@ -202,16 +202,15 @@ export function VDiskInfo<T extends PreparedVDisk>({
202202
// Show donors list when replication is in progress
203203
if (Replicated === false && VDiskState === EVDiskState.OK && Donors?.length) {
204204
const donorLinks = Donors.map((donor, index) => {
205-
const {StringifiedId: id, NodeId: dNodeId, PDiskId: dPDiskId} = donor;
205+
const {StringifiedId: id, NodeId: dNodeId} = donor;
206206

207-
if (!id || !dNodeId || !dPDiskId) {
207+
if (!id || !dNodeId) {
208208
return null;
209209
}
210210

211211
const vDiskPath = getVDiskPagePath(
212212
{
213213
nodeId: dNodeId,
214-
pDiskId: dPDiskId,
215214
vDiskId: id,
216215
},
217216
{database},
@@ -235,17 +234,11 @@ export function VDiskInfo<T extends PreparedVDisk>({
235234
});
236235
}
237236
}
238-
239-
const diskParamsDefined =
240-
valueIsDefined(PDiskId) && valueIsDefined(NodeId) && valueIsDefined(VDiskSlotId);
241-
242-
if (diskParamsDefined) {
243-
const links: React.ReactNode[] = [];
244-
237+
const links: React.ReactNode[] = [];
238+
if (!isNil(StringifiedId)) {
245239
if (withVDiskPageLink) {
246240
const vDiskPagePath = getVDiskPagePath(
247241
{
248-
pDiskId: PDiskId,
249242
nodeId: NodeId,
250243
vDiskId: StringifiedId,
251244
},
@@ -260,33 +253,33 @@ export function VDiskInfo<T extends PreparedVDisk>({
260253
/>,
261254
);
262255
}
256+
}
263257

264-
if (isUserAllowedToMakeChanges) {
265-
const vDiskInternalViewerPath = createVDiskDeveloperUILink({
266-
nodeId: NodeId,
267-
pDiskId: PDiskId,
268-
vDiskSlotId: VDiskSlotId,
269-
});
258+
if (isUserAllowedToMakeChanges && !isNil(NodeId) && !isNil(VDiskSlotId) && !isNil(PDiskId)) {
259+
const vDiskInternalViewerPath = createVDiskDeveloperUILink({
260+
nodeId: NodeId,
261+
pDiskId: PDiskId,
262+
vDiskSlotId: VDiskSlotId,
263+
});
270264

271-
links.push(
272-
<LinkWithIcon
273-
key={vDiskInternalViewerPath}
274-
title={vDiskInfoKeyset('developer-ui')}
275-
url={vDiskInternalViewerPath}
276-
/>,
277-
);
278-
}
265+
links.push(
266+
<LinkWithIcon
267+
key={vDiskInternalViewerPath}
268+
title={vDiskInfoKeyset('developer-ui')}
269+
url={vDiskInternalViewerPath}
270+
/>,
271+
);
272+
}
279273

280-
if (links.length) {
281-
rightColumn.push({
282-
label: vDiskInfoKeyset('links'),
283-
value: (
284-
<Flex wrap="wrap" gap={2}>
285-
{links}
286-
</Flex>
287-
),
288-
});
289-
}
274+
if (links.length) {
275+
rightColumn.push({
276+
label: vDiskInfoKeyset('links'),
277+
value: (
278+
<Flex wrap="wrap" gap={2}>
279+
{links}
280+
</Flex>
281+
),
282+
});
290283
}
291284

292285
const title = data && withTitle ? <VDiskTitle data={data} /> : null;

src/containers/VDiskPage/VDiskPage.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,7 @@ export function VDiskPage() {
104104
vDiskId: vDiskData?.StringifiedId,
105105
}),
106106
);
107-
}, [
108-
dispatch,
109-
nodeId,
110-
pDiskId,
111-
database,
112-
vDiskData?.VDiskId?.GroupID,
113-
vDiskData?.StringifiedId,
114-
]);
107+
}, [dispatch, database, vDiskData?.VDiskId?.GroupID, vDiskData?.StringifiedId]);
115108

116109
const loading = isFetching && vDiskData === undefined;
117110
const {NodeHost, NodeId, NodeType, NodeDC, PDiskId, PDiskType, Severity, VDiskId} =
@@ -242,21 +235,16 @@ export function VDiskPage() {
242235
};
243236

244237
const renderTabs = () => {
245-
const vDiskExtendedParamsDefined = !isNil(nodeId) && !isNil(pDiskId) && !isNil(vDiskSlotId);
246-
247-
const vDiskBasicParamsDefined = !isNil(vDiskId);
248-
249238
return (
250239
<div className={vDiskPageCn('tabs')}>
251240
<TabProvider value={vDiskTab}>
252241
<TabList size="l">
253242
{VDISK_PAGE_TABS.map(({id, title}) => {
254243
let path: string | undefined;
255-
if (vDiskExtendedParamsDefined || vDiskBasicParamsDefined) {
244+
if (!isNil(vDiskId)) {
256245
path = getVDiskPagePath(
257246
{
258247
nodeId: nodeId?.toString(),
259-
pDiskId: pDiskId?.toString(),
260248
vDiskId: vDiskId?.toString(),
261249
},
262250
{activeTab: id, database},

src/routes.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,9 @@ export function getPDiskPagePath(
121121
}
122122

123123
export function getVDiskPagePath(
124-
// provide all of the params to functions to ensure nothing was forgotten
125124
params: {
126-
pDiskId: string | number | undefined;
127125
nodeId: string | number | undefined;
128-
vDiskId: string | undefined;
126+
vDiskId: string;
129127
},
130128
query: {database: string | undefined; activeTab?: string} = {database: undefined},
131129
) {

0 commit comments

Comments
 (0)