Skip to content

Commit 7e52974

Browse files
committed
chore: valueIsDefined to isNil
1 parent 4ea21a1 commit 7e52974

File tree

25 files changed

+123
-152
lines changed

25 files changed

+123
-152
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@
3232
},
3333
],
3434
"curly": ["error", "all"],
35+
"no-negated-condition": "off",
3536
},
3637
}

src/components/PDiskInfo/PDiskInfo.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Flex} from '@gravity-ui/uikit';
2+
import {isNil} from 'lodash';
23

34
import {getPDiskPagePath} from '../../routes';
4-
import {valueIsDefined} from '../../utils';
55
import {formatBytes} from '../../utils/bytesParsers';
66
import {formatStorageValuesToGb} from '../../utils/dataFormatters/dataFormatters';
77
import {createPDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
@@ -52,13 +52,13 @@ function getPDiskInfo<T extends PreparedPDisk>({
5252

5353
const generalInfo: InfoViewerItem[] = [];
5454

55-
if (valueIsDefined(Category)) {
55+
if (!isNil(Category)) {
5656
generalInfo.push({label: pDiskInfoKeyset('type'), value: Type});
5757
}
58-
if (valueIsDefined(Path)) {
58+
if (!isNil(Path)) {
5959
generalInfo.push({label: pDiskInfoKeyset('path'), value: Path});
6060
}
61-
if (valueIsDefined(Guid)) {
61+
if (!isNil(Guid)) {
6262
generalInfo.push({label: pDiskInfoKeyset('guid'), value: Guid});
6363
}
6464
// SerialNumber could be an empty string ""
@@ -77,19 +77,19 @@ function getPDiskInfo<T extends PreparedPDisk>({
7777

7878
const statusInfo: InfoViewerItem[] = [];
7979

80-
if (valueIsDefined(StatusV2)) {
80+
if (!isNil(StatusV2)) {
8181
statusInfo.push({label: pDiskInfoKeyset('drive-status'), value: StatusV2});
8282
}
83-
if (valueIsDefined(State)) {
83+
if (!isNil(State)) {
8484
statusInfo.push({label: pDiskInfoKeyset('state'), value: State});
8585
}
86-
if (valueIsDefined(Device)) {
86+
if (!isNil(Device)) {
8787
statusInfo.push({
8888
label: pDiskInfoKeyset('device'),
8989
value: <StatusIcon status={Device} />,
9090
});
9191
}
92-
if (valueIsDefined(Realtime)) {
92+
if (!isNil(Realtime)) {
9393
statusInfo.push({
9494
label: pDiskInfoKeyset('realtime'),
9595
value: <StatusIcon status={Realtime} />,
@@ -109,13 +109,13 @@ function getPDiskInfo<T extends PreparedPDisk>({
109109
/>
110110
),
111111
});
112-
if (valueIsDefined(NumActiveSlots) && valueIsDefined(ExpectedSlotCount)) {
112+
if (!isNil(NumActiveSlots) && !isNil(ExpectedSlotCount)) {
113113
spaceInfo.push({
114114
label: pDiskInfoKeyset('slots'),
115115
value: <ProgressViewer value={NumActiveSlots} capacity={ExpectedSlotCount} />,
116116
});
117117
}
118-
if (valueIsDefined(LogUsedSize) && valueIsDefined(LogTotalSize)) {
118+
if (!isNil(LogUsedSize) && !isNil(LogTotalSize)) {
119119
spaceInfo.push({
120120
label: pDiskInfoKeyset('log-size'),
121121
value: (
@@ -127,20 +127,16 @@ function getPDiskInfo<T extends PreparedPDisk>({
127127
),
128128
});
129129
}
130-
if (valueIsDefined(SystemSize)) {
130+
if (!isNil(SystemSize)) {
131131
spaceInfo.push({
132132
label: pDiskInfoKeyset('system-size'),
133133
value: formatBytes({value: SystemSize}),
134134
});
135135
}
136136

137137
const additionalInfo: InfoViewerItem[] = [];
138-
139138
const shouldDisplayLinks =
140-
(withPDiskPageLink || isUserAllowedToMakeChanges) &&
141-
valueIsDefined(PDiskId) &&
142-
valueIsDefined(nodeId);
143-
139+
(withPDiskPageLink || isUserAllowedToMakeChanges) && !isNil(PDiskId) && !isNil(nodeId);
144140
if (shouldDisplayLinks) {
145141
const pDiskPagePath = getPDiskPagePath(PDiskId, nodeId);
146142
const pDiskInternalViewerPath = createPDiskDeveloperUILink({

src/components/PDiskPopup/PDiskPopup.tsx

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

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

56
import {getPDiskPagePath} from '../../routes';
67
import {selectNodesMap} from '../../store/reducers/nodesList';
78
import {EFlag} from '../../types/api/enums';
8-
import {valueIsDefined} from '../../utils';
99
import {EMPTY_DATA_PLACEHOLDER} from '../../utils/constants';
1010
import {createPDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
1111
import type {PreparedPDisk} from '../../utils/disks/types';
@@ -76,7 +76,7 @@ export const preparePDiskData = (
7676
pdiskData.push({label: 'Device', value: Device});
7777
}
7878

79-
if (withDeveloperUILink && valueIsDefined(NodeId) && valueIsDefined(PDiskId)) {
79+
if (withDeveloperUILink && !isNil(NodeId) && !isNil(PDiskId)) {
8080
const pDiskInternalViewerPath = createPDiskDeveloperUILink({
8181
nodeId: NodeId,
8282
pDiskId: PDiskId,
@@ -111,7 +111,7 @@ interface PDiskPopupProps {
111111
export const PDiskPopup = ({data}: PDiskPopupProps) => {
112112
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
113113
const nodesMap = useTypedSelector(selectNodesMap);
114-
const nodeData = valueIsDefined(data.NodeId) ? nodesMap?.get(data.NodeId) : undefined;
114+
const nodeData = !isNil(data.NodeId) ? nodesMap?.get(data.NodeId) : undefined;
115115
const info = React.useMemo(
116116
() => preparePDiskData(data, nodeData, isUserAllowedToMakeChanges),
117117
[data, nodeData, isUserAllowedToMakeChanges],

src/components/StorageGroupInfo/StorageGroupInfo.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Flex} from '@gravity-ui/uikit';
2+
import {isNil} from 'lodash';
23

34
import type {PreparedStorageGroup} from '../../store/reducers/storage/types';
4-
import {valueIsDefined} from '../../utils';
55
import {formatStorageValuesToGb} from '../../utils/dataFormatters/dataFormatters';
66
import {formatToMs} from '../../utils/timeParsers';
77
import {bytesToSpeed} from '../../utils/utils';
@@ -43,40 +43,40 @@ export function StorageGroupInfo({data, className, ...infoViewerProps}: StorageG
4343

4444
const storageGroupInfoFirstColumn = [];
4545

46-
if (valueIsDefined(GroupGeneration)) {
46+
if (!isNil(GroupGeneration)) {
4747
storageGroupInfoFirstColumn.push({
4848
label: storageGroupInfoKeyset('group-generation'),
4949
value: GroupGeneration,
5050
});
5151
}
52-
if (valueIsDefined(ErasureSpecies)) {
52+
if (!isNil(ErasureSpecies)) {
5353
storageGroupInfoFirstColumn.push({
5454
label: storageGroupInfoKeyset('erasure-species'),
5555
value: ErasureSpecies,
5656
});
5757
}
58-
if (valueIsDefined(MediaType)) {
58+
if (!isNil(MediaType)) {
5959
storageGroupInfoFirstColumn.push({
6060
label: storageGroupInfoKeyset('media-type'),
6161
value: MediaType,
6262
});
6363
}
64-
if (valueIsDefined(Encryption)) {
64+
if (!isNil(Encryption)) {
6565
storageGroupInfoFirstColumn.push({
6666
label: storageGroupInfoKeyset('encryption'),
6767
value: Encryption ? storageGroupInfoKeyset('yes') : storageGroupInfoKeyset('no'),
6868
});
6969
}
70-
if (valueIsDefined(Overall)) {
70+
if (!isNil(Overall)) {
7171
storageGroupInfoFirstColumn.push({
7272
label: storageGroupInfoKeyset('overall'),
7373
value: <StatusIcon status={Overall} />,
7474
});
7575
}
76-
if (valueIsDefined(State)) {
76+
if (!isNil(State)) {
7777
storageGroupInfoFirstColumn.push({label: storageGroupInfoKeyset('state'), value: State});
7878
}
79-
if (valueIsDefined(MissingDisks)) {
79+
if (!isNil(MissingDisks)) {
8080
storageGroupInfoFirstColumn.push({
8181
label: storageGroupInfoKeyset('missing-disks'),
8282
value: MissingDisks,
@@ -85,7 +85,7 @@ export function StorageGroupInfo({data, className, ...infoViewerProps}: StorageG
8585

8686
const storageGroupInfoSecondColumn = [];
8787

88-
if (valueIsDefined(Used) && valueIsDefined(Limit)) {
88+
if (!isNil(Used) && !isNil(Limit)) {
8989
storageGroupInfoSecondColumn.push({
9090
label: storageGroupInfoKeyset('used-space'),
9191
value: (
@@ -98,61 +98,61 @@ export function StorageGroupInfo({data, className, ...infoViewerProps}: StorageG
9898
),
9999
});
100100
}
101-
if (valueIsDefined(Available)) {
101+
if (!isNil(Available)) {
102102
storageGroupInfoSecondColumn.push({
103103
label: storageGroupInfoKeyset('available'),
104104
value: formatStorageValuesToGb(Number(Available)),
105105
});
106106
}
107-
if (valueIsDefined(Usage)) {
107+
if (!isNil(Usage)) {
108108
storageGroupInfoSecondColumn.push({
109109
label: storageGroupInfoKeyset('usage'),
110110
value: `${Usage.toFixed(2)}%`,
111111
});
112112
}
113-
if (valueIsDefined(DiskSpace)) {
113+
if (!isNil(DiskSpace)) {
114114
storageGroupInfoSecondColumn.push({
115115
label: storageGroupInfoKeyset('disk-space'),
116116
value: <StatusIcon status={DiskSpace} />,
117117
});
118118
}
119-
if (valueIsDefined(Latency)) {
119+
if (!isNil(Latency)) {
120120
storageGroupInfoSecondColumn.push({
121121
label: storageGroupInfoKeyset('latency'),
122122
value: <StatusIcon status={Latency} />,
123123
});
124124
}
125-
if (valueIsDefined(LatencyPutTabletLogMs)) {
125+
if (!isNil(LatencyPutTabletLogMs)) {
126126
storageGroupInfoSecondColumn.push({
127127
label: storageGroupInfoKeyset('latency-put-tablet-log'),
128128
value: formatToMs(LatencyPutTabletLogMs),
129129
});
130130
}
131-
if (valueIsDefined(LatencyPutUserDataMs)) {
131+
if (!isNil(LatencyPutUserDataMs)) {
132132
storageGroupInfoSecondColumn.push({
133133
label: storageGroupInfoKeyset('latency-put-user-data'),
134134
value: formatToMs(LatencyPutUserDataMs),
135135
});
136136
}
137-
if (valueIsDefined(LatencyGetFastMs)) {
137+
if (!isNil(LatencyGetFastMs)) {
138138
storageGroupInfoSecondColumn.push({
139139
label: storageGroupInfoKeyset('latency-get-fast'),
140140
value: formatToMs(LatencyGetFastMs),
141141
});
142142
}
143-
if (valueIsDefined(AllocationUnits)) {
143+
if (!isNil(AllocationUnits)) {
144144
storageGroupInfoSecondColumn.push({
145145
label: storageGroupInfoKeyset('allocation-units'),
146146
value: AllocationUnits,
147147
});
148148
}
149-
if (valueIsDefined(Read)) {
149+
if (!isNil(Read)) {
150150
storageGroupInfoSecondColumn.push({
151151
label: storageGroupInfoKeyset('read-throughput'),
152152
value: bytesToSpeed(Number(Read)),
153153
});
154154
}
155-
if (valueIsDefined(Write)) {
155+
if (!isNil(Write)) {
156156
storageGroupInfoSecondColumn.push({
157157
label: storageGroupInfoKeyset('write-throughput'),
158158
value: bytesToSpeed(Number(Write)),

src/components/VDisk/utils.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import {isNil} from 'lodash';
2+
13
import {getDefaultNodePath} from '../../containers/Node/NodePages';
24
import {getVDiskPagePath} from '../../routes';
35
import type {TVDiskStateInfo, TVSlotId} from '../../types/api/vdisk';
4-
import {valueIsDefined} from '../../utils';
56
import {stringifyVdiskId} from '../../utils/dataFormatters/dataFormatters';
67
import {isFullVDiskData} from '../../utils/disks/helpers';
78

@@ -11,13 +12,9 @@ export function getVDiskLink(data: TVDiskStateInfo | TVSlotId) {
1112
const isFullData = isFullVDiskData(data);
1213
const VDiskSlotId = isFullData ? data.VDiskSlotId : data.VSlotId;
1314

14-
if (
15-
valueIsDefined(VDiskSlotId) &&
16-
valueIsDefined(data.PDiskId) &&
17-
valueIsDefined(data.NodeId)
18-
) {
15+
if (!isNil(VDiskSlotId) && !isNil(data.PDiskId) && !isNil(data.NodeId)) {
1916
vDiskPath = getVDiskPagePath(VDiskSlotId, data.PDiskId, data.NodeId);
20-
} else if (valueIsDefined(data.NodeId) && isFullVDiskData(data)) {
17+
} else if (!isNil(data.NodeId) && isFullVDiskData(data)) {
2118
vDiskPath = getDefaultNodePath(
2219
data.NodeId,
2320
{

0 commit comments

Comments
 (0)