Skip to content

Commit f1add4a

Browse files
fix: do not display Developer UI link for viewers
1 parent be57439 commit f1add4a

File tree

2 files changed

+45
-23
lines changed

2 files changed

+45
-23
lines changed

src/components/PDiskInfo/PDiskInfo.tsx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {cn} from '../../utils/cn';
55
import {formatStorageValuesToGb} from '../../utils/dataFormatters/dataFormatters';
66
import {createPDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
77
import type {PreparedPDisk} from '../../utils/disks/types';
8+
import {useTypedSelector} from '../../utils/hooks';
89
import {EntityStatus} from '../EntityStatus/EntityStatus';
910
import type {InfoViewerItem} from '../InfoViewer';
1011
import {InfoViewer} from '../InfoViewer/InfoViewer';
@@ -21,12 +22,15 @@ interface GetPDiskInfoOptions<T extends PreparedPDisk> {
2122
pDisk?: T;
2223
nodeId?: number | string | null;
2324
isPDiskPage?: boolean;
25+
isUserAllowedToMakeChanges?: boolean;
2426
}
2527

28+
// eslint-disable-next-line complexity
2629
function getPDiskInfo<T extends PreparedPDisk>({
2730
pDisk,
2831
nodeId,
2932
isPDiskPage = false,
33+
isUserAllowedToMakeChanges,
3034
}: GetPDiskInfoOptions<T>) {
3135
const {
3236
PDiskId,
@@ -142,7 +146,12 @@ function getPDiskInfo<T extends PreparedPDisk>({
142146

143147
const additionalInfo: InfoViewerItem[] = [];
144148

145-
if (valueIsDefined(PDiskId) && valueIsDefined(nodeId)) {
149+
const shouldDisplayLinks =
150+
(!isPDiskPage || isUserAllowedToMakeChanges) &&
151+
valueIsDefined(PDiskId) &&
152+
valueIsDefined(nodeId);
153+
154+
if (shouldDisplayLinks) {
146155
const pDiskPagePath = getPDiskPagePath(PDiskId, nodeId);
147156
const pDiskInternalViewerPath = createPDiskDeveloperUILink({
148157
nodeId,
@@ -160,10 +169,12 @@ function getPDiskInfo<T extends PreparedPDisk>({
160169
external={false}
161170
/>
162171
)}
163-
<LinkWithIcon
164-
title={pDiskInfoKeyset('developer-ui')}
165-
url={pDiskInternalViewerPath}
166-
/>
172+
{isUserAllowedToMakeChanges && (
173+
<LinkWithIcon
174+
title={pDiskInfoKeyset('developer-ui')}
175+
url={pDiskInternalViewerPath}
176+
/>
177+
)}
167178
</span>
168179
),
169180
});
@@ -182,21 +193,24 @@ export function PDiskInfo<T extends PreparedPDisk>({
182193
isPDiskPage = false,
183194
className,
184195
}: PDiskInfoProps<T>) {
196+
const {isUserAllowedToMakeChanges} = useTypedSelector((state) => state.authentication);
197+
185198
const [generalInfo, statusInfo, spaceInfo, additionalInfo] = getPDiskInfo({
186199
pDisk,
187200
nodeId,
188201
isPDiskPage,
202+
isUserAllowedToMakeChanges,
189203
});
190204

191205
return (
192206
<div className={b('wrapper', className)}>
193207
<div className={b('col')}>
194-
<InfoViewer info={generalInfo} />
195-
<InfoViewer info={spaceInfo} />
208+
<InfoViewer info={generalInfo} renderEmptyState={() => null} />
209+
<InfoViewer info={spaceInfo} renderEmptyState={() => null} />
196210
</div>
197211
<div className={b('col')}>
198-
<InfoViewer info={statusInfo} />
199-
<InfoViewer info={additionalInfo} />
212+
<InfoViewer info={statusInfo} renderEmptyState={() => null} />
213+
<InfoViewer info={additionalInfo} renderEmptyState={() => null} />
200214
</div>
201215
</div>
202216
);

src/store/reducers/pdisk/utils.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {TPDiskInfoResponse} from '../../../types/api/pdisk';
22
import type {TStorageInfo} from '../../../types/api/storage';
33
import type {TEvSystemStateResponse} from '../../../types/api/systemState';
4-
import {getArray} from '../../../utils';
4+
import {getArray, valueIsDefined} from '../../../utils';
55
import {preparePDiskData, prepareVDiskData} from '../../../utils/disks/prepareDisks';
66
import {prepareNodeSystemState} from '../../../utils/nodes';
77
import type {PreparedStorageGroup} from '../storage/types';
@@ -29,18 +29,22 @@ export function preparePDiskDataResponse([pdiskResponse = {}, nodeResponse]: [
2929
EnforcedDynamicSlotSize,
3030
} = preparedPDisk;
3131

32-
const logSlot: SlotItem<'log'> = {
33-
SlotType: 'log',
34-
Used: Number(LogUsedSize),
35-
Total: Number(LogTotalSize),
36-
UsagePercent: (Number(LogUsedSize) * 100) / Number(LogTotalSize),
37-
Severity: 1,
38-
SlotData: {
39-
LogUsedSize,
40-
LogTotalSize,
41-
SystemSize,
42-
},
43-
};
32+
let logSlot: SlotItem<'log'> | undefined;
33+
34+
if (valueIsDefined(LogTotalSize)) {
35+
logSlot = {
36+
SlotType: 'log',
37+
Used: Number(LogUsedSize),
38+
Total: Number(LogTotalSize),
39+
UsagePercent: (Number(LogUsedSize) * 100) / Number(LogTotalSize),
40+
Severity: 1,
41+
SlotData: {
42+
LogUsedSize,
43+
LogTotalSize,
44+
SystemSize,
45+
},
46+
};
47+
}
4448

4549
const preparedVDisks = WhiteboardVDisksData.map(prepareVDiskData).sort(
4650
(disk1, disk2) => Number(disk2.VDiskSlotId) - Number(disk1.VDiskSlotId),
@@ -87,7 +91,11 @@ export function preparePDiskDataResponse([pdiskResponse = {}, nodeResponse]: [
8791
});
8892
}
8993

90-
const diskSlots = [logSlot, ...vdisksSlots, ...emptySlots];
94+
const diskSlots: PDiskData['SlotItems'] = [...vdisksSlots, ...emptySlots];
95+
96+
if (logSlot) {
97+
diskSlots.unshift(logSlot);
98+
}
9199

92100
const rawNode = nodeResponse.SystemStateInfo?.[0];
93101
const preparedNode = prepareNodeSystemState(rawNode);

0 commit comments

Comments
 (0)