Skip to content

Commit 8649a5c

Browse files
feat: hide some columns and storage nodes for users-viewers
1 parent d02a62a commit 8649a5c

File tree

23 files changed

+98
-52
lines changed

23 files changed

+98
-52
lines changed

src/components/PDiskInfo/PDiskInfo.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import {Flex} from '@gravity-ui/uikit';
22

33
import {getPDiskPagePath} from '../../routes';
4-
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
54
import {valueIsDefined} from '../../utils';
65
import {formatBytes} from '../../utils/bytesParsers';
76
import {cn} from '../../utils/cn';
87
import {formatStorageValuesToGb} from '../../utils/dataFormatters/dataFormatters';
98
import {createPDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
109
import type {PreparedPDisk} from '../../utils/disks/types';
11-
import {useTypedSelector} from '../../utils/hooks';
10+
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
1211
import type {InfoViewerItem} from '../InfoViewer';
1312
import {InfoViewer} from '../InfoViewer/InfoViewer';
1413
import {LinkWithIcon} from '../LinkWithIcon/LinkWithIcon';
@@ -189,7 +188,7 @@ export function PDiskInfo<T extends PreparedPDisk>({
189188
withPDiskPageLink,
190189
className,
191190
}: PDiskInfoProps<T>) {
192-
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
191+
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
193192

194193
const [generalInfo, statusInfo, spaceInfo, additionalInfo] = getPDiskInfo({
195194
pDisk,

src/components/PDiskPopup/PDiskPopup.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React from 'react';
22

3-
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
43
import {selectNodesMap} from '../../store/reducers/nodesList';
54
import {EFlag} from '../../types/api/enums';
65
import {valueIsDefined} from '../../utils';
76
import {EMPTY_DATA_PLACEHOLDER} from '../../utils/constants';
87
import {createPDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
98
import type {PreparedPDisk} from '../../utils/disks/types';
109
import {useTypedSelector} from '../../utils/hooks';
10+
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
1111
import {bytesToGB, isNumeric} from '../../utils/utils';
1212
import {InfoViewer} from '../InfoViewer';
1313
import type {InfoViewerItem} from '../InfoViewer';
@@ -92,7 +92,7 @@ interface PDiskPopupProps {
9292
}
9393

9494
export const PDiskPopup = ({data}: PDiskPopupProps) => {
95-
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
95+
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
9696
const nodesMap = useTypedSelector(selectNodesMap);
9797
const nodeData = valueIsDefined(data.NodeId) ? nodesMap?.get(data.NodeId) : undefined;
9898
const info = React.useMemo(

src/components/TabletNameWrapper/TabletNameWrapper.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import {DefinitionList, PopoverBehavior} from '@gravity-ui/uikit';
22

33
import {getTabletPagePath} from '../../routes';
4-
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
54
import {createTabletDeveloperUIHref} from '../../utils/developerUI/developerUI';
6-
import {useTypedSelector} from '../../utils/hooks';
5+
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
76
import {CellWithPopover} from '../CellWithPopover/CellWithPopover';
87
import {EntityStatus} from '../EntityStatus/EntityStatus';
98
import {LinkWithIcon} from '../LinkWithIcon/LinkWithIcon';
@@ -16,7 +15,7 @@ interface TabletNameWrapperProps {
1615
}
1716

1817
export function TabletNameWrapper({tabletId, database}: TabletNameWrapperProps) {
19-
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
18+
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
2019

2120
const tabletPath = getTabletPagePath(tabletId, {database});
2221

src/components/TenantNameWrapper/TenantNameWrapper.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import {DefinitionList, PopoverBehavior} from '@gravity-ui/uikit';
22

33
import {getTenantPath} from '../../containers/Tenant/TenantPages';
4-
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
54
import type {PreparedTenant} from '../../store/reducers/tenants/types';
65
import type {AdditionalTenantsProps, NodeAddress} from '../../types/additionalProps';
7-
import {useTypedSelector} from '../../utils/hooks';
6+
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
87
import {CellWithPopover} from '../CellWithPopover/CellWithPopover';
98
import {EntityStatus} from '../EntityStatus/EntityStatus';
109
import {LinkWithIcon} from '../LinkWithIcon/LinkWithIcon';
@@ -34,7 +33,7 @@ const getTenantBackend = (
3433
};
3534

3635
export function TenantNameWrapper({tenant, additionalTenantsProps}: TenantNameWrapperProps) {
37-
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
36+
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
3837

3938
const backend = getTenantBackend(tenant, additionalTenantsProps);
4039
const isExternalLink = Boolean(backend);

src/components/TooltipsContent/NodeEndpointsTooltipContent/NodeEndpointsTooltipContent.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import type {DefinitionListItemProps} from '@gravity-ui/uikit';
22
import {DefinitionList} from '@gravity-ui/uikit';
33

4-
import {selectIsUserAllowedToMakeChanges} from '../../../store/reducers/authentication/authentication';
54
import type {TSystemStateInfo} from '../../../types/api/nodes';
65
import {cn} from '../../../utils/cn';
7-
import {useTypedSelector} from '../../../utils/hooks';
6+
import {useIsUserAllowedToMakeChanges} from '../../../utils/hooks/useIsUserAllowedToMakeChanges';
87
import {LinkWithIcon} from '../../LinkWithIcon/LinkWithIcon';
98

109
import i18n from './i18n';
@@ -19,7 +18,7 @@ interface NodeEdpointsTooltipProps {
1918
}
2019

2120
export const NodeEndpointsTooltipContent = ({data, nodeHref}: NodeEdpointsTooltipProps) => {
22-
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
21+
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
2322
const info: (DefinitionListItemProps & {key: string})[] = [];
2423

2524
if (data?.Roles?.length) {

src/components/VDiskInfo/VDiskInfo.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import React from 'react';
22

33
import {getVDiskPagePath} from '../../routes';
4-
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
54
import {valueIsDefined} from '../../utils';
65
import {cn} from '../../utils/cn';
76
import {formatStorageValuesToGb} from '../../utils/dataFormatters/dataFormatters';
87
import {createVDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
98
import {getSeverityColor} from '../../utils/disks/helpers';
109
import type {PreparedVDisk} from '../../utils/disks/types';
11-
import {useTypedSelector} from '../../utils/hooks';
10+
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
1211
import {bytesToSpeed} from '../../utils/utils';
1312
import {InfoViewer} from '../InfoViewer';
1413
import type {InfoViewerProps} from '../InfoViewer/InfoViewer';
@@ -35,7 +34,7 @@ export function VDiskInfo<T extends PreparedVDisk>({
3534
withTitle,
3635
...infoViewerProps
3736
}: VDiskInfoProps<T>) {
38-
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
37+
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
3938

4039
const {
4140
AllocatedSize,

src/components/VDiskPopup/VDiskPopup.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22

33
import {Label} from '@gravity-ui/uikit';
44

5-
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
65
import {selectNodesMap} from '../../store/reducers/nodesList';
76
import {EFlag} from '../../types/api/enums';
87
import {valueIsDefined} from '../../utils';
@@ -12,6 +11,7 @@ import {createVDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
1211
import {isFullVDiskData} from '../../utils/disks/helpers';
1312
import type {PreparedVDisk, UnavailableDonor} from '../../utils/disks/types';
1413
import {useTypedSelector} from '../../utils/hooks';
14+
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
1515
import {bytesToGB, bytesToSpeed} from '../../utils/utils';
1616
import type {InfoViewerItem} from '../InfoViewer';
1717
import {InfoViewer} from '../InfoViewer';
@@ -178,7 +178,7 @@ interface VDiskPopupProps {
178178
export const VDiskPopup = ({data}: VDiskPopupProps) => {
179179
const isFullData = isFullVDiskData(data);
180180

181-
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
181+
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
182182

183183
const vdiskInfo = React.useMemo(
184184
() =>

src/components/nodesColumns/constants.ts

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ export const NODES_COLUMNS_IDS = {
3535

3636
export type NodesColumnId = ValueOf<typeof NODES_COLUMNS_IDS>;
3737

38+
// Columns, that should displayed only for users with isMonitoringAllowed:true
39+
const MONITORING_USER_COLUMNS_IDS: NodesColumnId[] = ['Pools', 'Memory'];
40+
41+
export function isMonitoringUserNodesColumn(columnId: string): boolean {
42+
return MONITORING_USER_COLUMNS_IDS.includes(columnId as NodesColumnId);
43+
}
44+
3845
// This code is running when module is initialized and correct language may not be set yet
3946
// get functions guarantee that i18n fields will be inited on render with current render language
4047
export const NODES_COLUMNS_TITLES = {

src/containers/Header/Header.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import {useLocation} from 'react-router-dom';
66

77
import {getConnectToDBDialog} from '../../components/ConnectToDB/ConnectToDBDialog';
88
import {InternalLink} from '../../components/InternalLink';
9-
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
109
import {useClusterBaseInfo} from '../../store/reducers/cluster/cluster';
1110
import {cn} from '../../utils/cn';
1211
import {DEVELOPER_UI_TITLE} from '../../utils/constants';
1312
import {createDeveloperUIInternalPageHref} from '../../utils/developerUI/developerUI';
1413
import {useTypedSelector} from '../../utils/hooks';
1514
import {useDatabaseFromQuery} from '../../utils/hooks/useDatabaseFromQuery';
15+
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
1616

1717
import type {RawBreadcrumbItem} from './breadcrumbs';
1818
import {getBreadcrumbs} from './breadcrumbs';
@@ -28,7 +28,7 @@ interface HeaderProps {
2828

2929
function Header({mainPage}: HeaderProps) {
3030
const {page, pageBreadcrumbsOptions} = useTypedSelector((state) => state.header);
31-
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
31+
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
3232

3333
const clusterInfo = useClusterBaseInfo();
3434

src/containers/Node/NodeStructure/Pdisk.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {PDiskInfo} from '../../../components/PDiskInfo/PDiskInfo';
1010
import {ProgressViewer} from '../../../components/ProgressViewer/ProgressViewer';
1111
import {StatusIcon} from '../../../components/StatusIcon/StatusIcon';
1212
import {VDiskInfo} from '../../../components/VDiskInfo/VDiskInfo';
13-
import {selectIsUserAllowedToMakeChanges} from '../../../store/reducers/authentication/authentication';
1413
import type {
1514
PreparedStructurePDisk,
1615
PreparedStructureVDisk,
@@ -23,7 +22,7 @@ import {cn} from '../../../utils/cn';
2322
import {DEFAULT_TABLE_SETTINGS} from '../../../utils/constants';
2423
import {formatStorageValuesToGb} from '../../../utils/dataFormatters/dataFormatters';
2524
import {createVDiskDeveloperUILink} from '../../../utils/developerUI/developerUI';
26-
import {useTypedSelector} from '../../../utils/hooks';
25+
import {useIsUserAllowedToMakeChanges} from '../../../utils/hooks/useIsUserAllowedToMakeChanges';
2726
import i18n from '../i18n';
2827

2928
import {PDiskTitleBadge} from './PDiskTitleBadge';
@@ -171,7 +170,7 @@ export function PDisk({
171170
nodeId,
172171
unfolded: unfoldedFromProps,
173172
}: PDiskProps) {
174-
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
173+
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
175174

176175
const [unfolded, setUnfolded] = React.useState(unfoldedFromProps ?? false);
177176

src/containers/Nodes/Nodes.tsx

+15-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import {ResponseError} from '../../components/Errors/ResponseError';
44
import {LoaderWrapper} from '../../components/LoaderWrapper/LoaderWrapper';
55
import type {Column, RenderControls} from '../../components/PaginatedTable';
66
import {TableWithControlsLayout} from '../../components/TableWithControlsLayout/TableWithControlsLayout';
7-
import {NODES_COLUMNS_TITLES} from '../../components/nodesColumns/constants';
7+
import {
8+
NODES_COLUMNS_TITLES,
9+
isMonitoringUserNodesColumn,
10+
} from '../../components/nodesColumns/constants';
811
import type {NodesColumnId} from '../../components/nodesColumns/constants';
912
import {
1013
useCapabilitiesLoaded,
@@ -16,6 +19,7 @@ import {useProblemFilter} from '../../store/reducers/settings/hooks';
1619
import type {AdditionalNodesProps} from '../../types/additionalProps';
1720
import type {NodesGroupByField} from '../../types/api/nodes';
1821
import {useAutoRefreshInterval} from '../../utils/hooks';
22+
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
1923
import {useSelectedColumns} from '../../utils/hooks/useSelectedColumns';
2024
import {NodesUptimeFilterValues} from '../../utils/nodes';
2125
import {TableGroup} from '../Storage/TableGroup/TableGroup';
@@ -69,6 +73,14 @@ export function Nodes({
6973

7074
const capabilitiesLoaded = useCapabilitiesLoaded();
7175
const viewerNodesHandlerHasGrouping = useViewerNodesHandlerHasGrouping();
76+
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
77+
78+
const preparedColumns = React.useMemo(() => {
79+
if (isUserAllowedToMakeChanges) {
80+
return columns;
81+
}
82+
return columns.filter((column) => !isMonitoringUserNodesColumn(column.name));
83+
}, [columns, isUserAllowedToMakeChanges]);
7284

7385
// Other filters do not fit with grouping
7486
// Reset them if grouping available
@@ -96,7 +108,7 @@ export function Nodes({
96108
database={database}
97109
parentRef={parentRef}
98110
withPeerRoleFilter={withPeerRoleFilter}
99-
columns={columns}
111+
columns={preparedColumns}
100112
defaultColumnsIds={defaultColumnsIds}
101113
requiredColumnsIds={requiredColumnsIds}
102114
selectedColumnsKey={selectedColumnsKey}
@@ -111,7 +123,7 @@ export function Nodes({
111123
database={database}
112124
parentRef={parentRef}
113125
withPeerRoleFilter={withPeerRoleFilter}
114-
columns={columns}
126+
columns={preparedColumns}
115127
defaultColumnsIds={defaultColumnsIds}
116128
requiredColumnsIds={requiredColumnsIds}
117129
selectedColumnsKey={selectedColumnsKey}

src/containers/PDiskPage/PDiskPage.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import {PDiskInfo} from '../../components/PDiskInfo/PDiskInfo';
1616
import {PageMetaWithAutorefresh} from '../../components/PageMeta/PageMeta';
1717
import {getPDiskPagePath} from '../../routes';
1818
import {api} from '../../store/reducers/api';
19-
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
2019
import {useDiskPagesAvailable} from '../../store/reducers/capabilities/hooks';
2120
import {setHeaderBreadcrumbs} from '../../store/reducers/header/header';
2221
import {pDiskApi} from '../../store/reducers/pdisk/pdisk';
2322
import type {EDecommitStatus} from '../../types/api/pdisk';
2423
import {valueIsDefined} from '../../utils';
2524
import {cn} from '../../utils/cn';
2625
import {getPDiskId, getSeverityColor} from '../../utils/disks/helpers';
27-
import {useAutoRefreshInterval, useTypedDispatch, useTypedSelector} from '../../utils/hooks';
26+
import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks';
27+
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
2828
import {PaginatedStorage} from '../Storage/PaginatedStorage';
2929

3030
import {DecommissionButton} from './DecommissionButton/DecommissionButton';
@@ -61,7 +61,7 @@ const pDiskTabSchema = z.nativeEnum(PDISK_TABS_IDS).catch(PDISK_TABS_IDS.spaceDi
6161
export function PDiskPage() {
6262
const dispatch = useTypedDispatch();
6363

64-
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
64+
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
6565
const newDiskApiAvailable = useDiskPagesAvailable();
6666
const containerRef = React.useRef<HTMLDivElement>(null);
6767

src/containers/Storage/PaginatedStorage.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
2+
13
import {PaginatedStorageGroups} from './PaginatedStorageGroups';
24
import {PaginatedStorageNodes} from './PaginatedStorageNodes';
35
import type {StorageViewContext} from './types';
@@ -19,10 +21,12 @@ export interface PaginatedStorageProps {
1921

2022
export const PaginatedStorage = (props: PaginatedStorageProps) => {
2123
const {storageType} = useStorageQueryParams();
24+
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
2225

2326
const isNodes = storageType === 'nodes';
2427

25-
if (isNodes) {
28+
// Hide storage details for users with only viewer rights
29+
if (isNodes && isUserAllowedToMakeChanges) {
2630
return (
2731
<PaginatedStorageNodes
2832
initialEntitiesCount={getStorageNodesInitialEntitiesCount(props.viewContext)}

src/containers/Storage/StorageControls/StorageControls.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Select, TableColumnSetup, Text} from '@gravity-ui/uikit';
66
import {EntitiesCount} from '../../../components/EntitiesCount/EntitiesCount';
77
import {Search} from '../../../components/Search/Search';
88
import {UptimeFilter} from '../../../components/UptimeFIlter';
9+
import {useIsUserAllowedToMakeChanges} from '../../../utils/hooks/useIsUserAllowedToMakeChanges';
910
import {STORAGE_GROUPS_GROUP_BY_OPTIONS} from '../StorageGroups/columns/constants';
1011
import {STORAGE_NODES_GROUP_BY_OPTIONS} from '../StorageNodes/columns/constants';
1112
import {StorageTypeFilter} from '../StorageTypeFilter/StorageTypeFilter';
@@ -48,10 +49,14 @@ export function StorageGroupsControls({
4849
handleStorageGroupsGroupByParamChange,
4950
} = useStorageQueryParams();
5051

52+
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
53+
5154
const handleGroupBySelectUpdate = (value: string[]) => {
5255
handleStorageGroupsGroupByParamChange(value[0]);
5356
};
5457

58+
const displayTypeSelector = withTypeSelector && isUserAllowedToMakeChanges;
59+
5560
return (
5661
<React.Fragment>
5762
<Search
@@ -60,7 +65,7 @@ export function StorageGroupsControls({
6065
placeholder={i18n('controls_groups-search-placeholder')}
6166
className={b('search')}
6267
/>
63-
{withTypeSelector && (
68+
{displayTypeSelector && (
6469
<StorageTypeFilter value={storageType} onChange={handleStorageTypeChange} />
6570
)}
6671
{withGroupBySelect ? null : (

src/containers/Storage/StorageGroups/columns/constants.ts

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ export const STORAGE_GROUPS_COLUMNS_IDS = {
3535

3636
export type StorageGroupsColumnId = ValueOf<typeof STORAGE_GROUPS_COLUMNS_IDS>;
3737

38+
// Columns, that should displayed only for users with isMonitoringAllowed:true
39+
const MONITORING_USER_COLUMNS_IDS: StorageGroupsColumnId[] = [
40+
'DiskSpaceUsage',
41+
'Latency',
42+
'AllocationUnits',
43+
'VDisksPDisks',
44+
];
45+
46+
export function isMonitoringUserGroupsColumn(columnId: string): boolean {
47+
return MONITORING_USER_COLUMNS_IDS.includes(columnId as StorageGroupsColumnId);
48+
}
49+
3850
export const DEFAULT_STORAGE_GROUPS_COLUMNS: StorageGroupsColumnId[] = [
3951
'GroupId',
4052
'PoolName',

0 commit comments

Comments
 (0)