Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: valueIsDefined to isNil #2084

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
},
],
"curly": ["error", "all"],
"no-negated-condition": "off",
},
}
28 changes: 12 additions & 16 deletions src/components/PDiskInfo/PDiskInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Flex} from '@gravity-ui/uikit';
import {isNil} from 'lodash';

import {getPDiskPagePath} from '../../routes';
import {valueIsDefined} from '../../utils';
import {formatBytes} from '../../utils/bytesParsers';
import {formatStorageValuesToGb} from '../../utils/dataFormatters/dataFormatters';
import {createPDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
Expand Down Expand Up @@ -52,13 +52,13 @@ function getPDiskInfo<T extends PreparedPDisk>({

const generalInfo: InfoViewerItem[] = [];

if (valueIsDefined(Category)) {
if (!isNil(Category)) {
generalInfo.push({label: pDiskInfoKeyset('type'), value: Type});
}
if (valueIsDefined(Path)) {
if (!isNil(Path)) {
generalInfo.push({label: pDiskInfoKeyset('path'), value: Path});
}
if (valueIsDefined(Guid)) {
if (!isNil(Guid)) {
generalInfo.push({label: pDiskInfoKeyset('guid'), value: Guid});
}
// SerialNumber could be an empty string ""
Expand All @@ -77,19 +77,19 @@ function getPDiskInfo<T extends PreparedPDisk>({

const statusInfo: InfoViewerItem[] = [];

if (valueIsDefined(StatusV2)) {
if (!isNil(StatusV2)) {
statusInfo.push({label: pDiskInfoKeyset('drive-status'), value: StatusV2});
}
if (valueIsDefined(State)) {
if (!isNil(State)) {
statusInfo.push({label: pDiskInfoKeyset('state'), value: State});
}
if (valueIsDefined(Device)) {
if (!isNil(Device)) {
statusInfo.push({
label: pDiskInfoKeyset('device'),
value: <StatusIcon status={Device} />,
});
}
if (valueIsDefined(Realtime)) {
if (!isNil(Realtime)) {
statusInfo.push({
label: pDiskInfoKeyset('realtime'),
value: <StatusIcon status={Realtime} />,
Expand All @@ -109,13 +109,13 @@ function getPDiskInfo<T extends PreparedPDisk>({
/>
),
});
if (valueIsDefined(NumActiveSlots) && valueIsDefined(ExpectedSlotCount)) {
if (!isNil(NumActiveSlots) && !isNil(ExpectedSlotCount)) {
spaceInfo.push({
label: pDiskInfoKeyset('slots'),
value: <ProgressViewer value={NumActiveSlots} capacity={ExpectedSlotCount} />,
});
}
if (valueIsDefined(LogUsedSize) && valueIsDefined(LogTotalSize)) {
if (!isNil(LogUsedSize) && !isNil(LogTotalSize)) {
spaceInfo.push({
label: pDiskInfoKeyset('log-size'),
value: (
Expand All @@ -127,20 +127,16 @@ function getPDiskInfo<T extends PreparedPDisk>({
),
});
}
if (valueIsDefined(SystemSize)) {
if (!isNil(SystemSize)) {
spaceInfo.push({
label: pDiskInfoKeyset('system-size'),
value: formatBytes({value: SystemSize}),
});
}

const additionalInfo: InfoViewerItem[] = [];

const shouldDisplayLinks =
(withPDiskPageLink || isUserAllowedToMakeChanges) &&
valueIsDefined(PDiskId) &&
valueIsDefined(nodeId);

(withPDiskPageLink || isUserAllowedToMakeChanges) && !isNil(PDiskId) && !isNil(nodeId);
if (shouldDisplayLinks) {
const pDiskPagePath = getPDiskPagePath(PDiskId, nodeId);
const pDiskInternalViewerPath = createPDiskDeveloperUILink({
Expand Down
6 changes: 3 additions & 3 deletions src/components/PDiskPopup/PDiskPopup.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';

import {Flex} from '@gravity-ui/uikit';
import {isNil} from 'lodash';

import {getPDiskPagePath} from '../../routes';
import {selectNodesMap} from '../../store/reducers/nodesList';
import {EFlag} from '../../types/api/enums';
import {valueIsDefined} from '../../utils';
import {EMPTY_DATA_PLACEHOLDER} from '../../utils/constants';
import {createPDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
import type {PreparedPDisk} from '../../utils/disks/types';
Expand Down Expand Up @@ -76,7 +76,7 @@ export const preparePDiskData = (
pdiskData.push({label: 'Device', value: Device});
}

if (withDeveloperUILink && valueIsDefined(NodeId) && valueIsDefined(PDiskId)) {
if (withDeveloperUILink && !isNil(NodeId) && !isNil(PDiskId)) {
const pDiskInternalViewerPath = createPDiskDeveloperUILink({
nodeId: NodeId,
pDiskId: PDiskId,
Expand Down Expand Up @@ -111,7 +111,7 @@ interface PDiskPopupProps {
export const PDiskPopup = ({data}: PDiskPopupProps) => {
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
const nodesMap = useTypedSelector(selectNodesMap);
const nodeData = valueIsDefined(data.NodeId) ? nodesMap?.get(data.NodeId) : undefined;
const nodeData = !isNil(data.NodeId) ? nodesMap?.get(data.NodeId) : undefined;
const info = React.useMemo(
() => preparePDiskData(data, nodeData, isUserAllowedToMakeChanges),
[data, nodeData, isUserAllowedToMakeChanges],
Expand Down
38 changes: 19 additions & 19 deletions src/components/StorageGroupInfo/StorageGroupInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Flex} from '@gravity-ui/uikit';
import {isNil} from 'lodash';

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

const storageGroupInfoFirstColumn = [];

if (valueIsDefined(GroupGeneration)) {
if (!isNil(GroupGeneration)) {
storageGroupInfoFirstColumn.push({
label: storageGroupInfoKeyset('group-generation'),
value: GroupGeneration,
});
}
if (valueIsDefined(ErasureSpecies)) {
if (!isNil(ErasureSpecies)) {
storageGroupInfoFirstColumn.push({
label: storageGroupInfoKeyset('erasure-species'),
value: ErasureSpecies,
});
}
if (valueIsDefined(MediaType)) {
if (!isNil(MediaType)) {
storageGroupInfoFirstColumn.push({
label: storageGroupInfoKeyset('media-type'),
value: MediaType,
});
}
if (valueIsDefined(Encryption)) {
if (!isNil(Encryption)) {
storageGroupInfoFirstColumn.push({
label: storageGroupInfoKeyset('encryption'),
value: Encryption ? storageGroupInfoKeyset('yes') : storageGroupInfoKeyset('no'),
});
}
if (valueIsDefined(Overall)) {
if (!isNil(Overall)) {
storageGroupInfoFirstColumn.push({
label: storageGroupInfoKeyset('overall'),
value: <StatusIcon status={Overall} />,
});
}
if (valueIsDefined(State)) {
if (!isNil(State)) {
storageGroupInfoFirstColumn.push({label: storageGroupInfoKeyset('state'), value: State});
}
if (valueIsDefined(MissingDisks)) {
if (!isNil(MissingDisks)) {
storageGroupInfoFirstColumn.push({
label: storageGroupInfoKeyset('missing-disks'),
value: MissingDisks,
Expand All @@ -85,7 +85,7 @@ export function StorageGroupInfo({data, className, ...infoViewerProps}: StorageG

const storageGroupInfoSecondColumn = [];

if (valueIsDefined(Used) && valueIsDefined(Limit)) {
if (!isNil(Used) && !isNil(Limit)) {
storageGroupInfoSecondColumn.push({
label: storageGroupInfoKeyset('used-space'),
value: (
Expand All @@ -98,61 +98,61 @@ export function StorageGroupInfo({data, className, ...infoViewerProps}: StorageG
),
});
}
if (valueIsDefined(Available)) {
if (!isNil(Available)) {
storageGroupInfoSecondColumn.push({
label: storageGroupInfoKeyset('available'),
value: formatStorageValuesToGb(Number(Available)),
});
}
if (valueIsDefined(Usage)) {
if (!isNil(Usage)) {
storageGroupInfoSecondColumn.push({
label: storageGroupInfoKeyset('usage'),
value: `${Usage.toFixed(2)}%`,
});
}
if (valueIsDefined(DiskSpace)) {
if (!isNil(DiskSpace)) {
storageGroupInfoSecondColumn.push({
label: storageGroupInfoKeyset('disk-space'),
value: <StatusIcon status={DiskSpace} />,
});
}
if (valueIsDefined(Latency)) {
if (!isNil(Latency)) {
storageGroupInfoSecondColumn.push({
label: storageGroupInfoKeyset('latency'),
value: <StatusIcon status={Latency} />,
});
}
if (valueIsDefined(LatencyPutTabletLogMs)) {
if (!isNil(LatencyPutTabletLogMs)) {
storageGroupInfoSecondColumn.push({
label: storageGroupInfoKeyset('latency-put-tablet-log'),
value: formatToMs(LatencyPutTabletLogMs),
});
}
if (valueIsDefined(LatencyPutUserDataMs)) {
if (!isNil(LatencyPutUserDataMs)) {
storageGroupInfoSecondColumn.push({
label: storageGroupInfoKeyset('latency-put-user-data'),
value: formatToMs(LatencyPutUserDataMs),
});
}
if (valueIsDefined(LatencyGetFastMs)) {
if (!isNil(LatencyGetFastMs)) {
storageGroupInfoSecondColumn.push({
label: storageGroupInfoKeyset('latency-get-fast'),
value: formatToMs(LatencyGetFastMs),
});
}
if (valueIsDefined(AllocationUnits)) {
if (!isNil(AllocationUnits)) {
storageGroupInfoSecondColumn.push({
label: storageGroupInfoKeyset('allocation-units'),
value: AllocationUnits,
});
}
if (valueIsDefined(Read)) {
if (!isNil(Read)) {
storageGroupInfoSecondColumn.push({
label: storageGroupInfoKeyset('read-throughput'),
value: bytesToSpeed(Number(Read)),
});
}
if (valueIsDefined(Write)) {
if (!isNil(Write)) {
storageGroupInfoSecondColumn.push({
label: storageGroupInfoKeyset('write-throughput'),
value: bytesToSpeed(Number(Write)),
Expand Down
11 changes: 4 additions & 7 deletions src/components/VDisk/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {isNil} from 'lodash';

import {getDefaultNodePath} from '../../containers/Node/NodePages';
import {getVDiskPagePath} from '../../routes';
import type {TVDiskStateInfo, TVSlotId} from '../../types/api/vdisk';
import {valueIsDefined} from '../../utils';
import {stringifyVdiskId} from '../../utils/dataFormatters/dataFormatters';
import {isFullVDiskData} from '../../utils/disks/helpers';

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

if (
valueIsDefined(VDiskSlotId) &&
valueIsDefined(data.PDiskId) &&
valueIsDefined(data.NodeId)
) {
if (!isNil(VDiskSlotId) && !isNil(data.PDiskId) && !isNil(data.NodeId)) {
vDiskPath = getVDiskPagePath(VDiskSlotId, data.PDiskId, data.NodeId);
} else if (valueIsDefined(data.NodeId) && isFullVDiskData(data)) {
} else if (!isNil(data.NodeId) && isFullVDiskData(data)) {
vDiskPath = getDefaultNodePath(
data.NodeId,
{
Expand Down
Loading
Loading