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

feat: hide some columns and storage nodes for users-viewers #1967

Merged
merged 1 commit into from
Feb 19, 2025
Merged
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
5 changes: 2 additions & 3 deletions src/components/PDiskInfo/PDiskInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {Flex} from '@gravity-ui/uikit';

import {getPDiskPagePath} from '../../routes';
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
import {valueIsDefined} from '../../utils';
import {formatBytes} from '../../utils/bytesParsers';
import {cn} from '../../utils/cn';
import {formatStorageValuesToGb} from '../../utils/dataFormatters/dataFormatters';
import {createPDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
import type {PreparedPDisk} from '../../utils/disks/types';
import {useTypedSelector} from '../../utils/hooks';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import type {InfoViewerItem} from '../InfoViewer';
import {InfoViewer} from '../InfoViewer/InfoViewer';
import {LinkWithIcon} from '../LinkWithIcon/LinkWithIcon';
Expand Down Expand Up @@ -189,7 +188,7 @@ export function PDiskInfo<T extends PreparedPDisk>({
withPDiskPageLink,
className,
}: PDiskInfoProps<T>) {
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();

const [generalInfo, statusInfo, spaceInfo, additionalInfo] = getPDiskInfo({
pDisk,
Expand Down
4 changes: 2 additions & 2 deletions src/components/PDiskPopup/PDiskPopup.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';

import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
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';
import {useTypedSelector} from '../../utils/hooks';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {bytesToGB, isNumeric} from '../../utils/utils';
import {InfoViewer} from '../InfoViewer';
import type {InfoViewerItem} from '../InfoViewer';
Expand Down Expand Up @@ -92,7 +92,7 @@ interface PDiskPopupProps {
}

export const PDiskPopup = ({data}: PDiskPopupProps) => {
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
const nodesMap = useTypedSelector(selectNodesMap);
const nodeData = valueIsDefined(data.NodeId) ? nodesMap?.get(data.NodeId) : undefined;
const info = React.useMemo(
Expand Down
5 changes: 2 additions & 3 deletions src/components/TabletNameWrapper/TabletNameWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {DefinitionList, PopoverBehavior} from '@gravity-ui/uikit';

import {getTabletPagePath} from '../../routes';
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
import {createTabletDeveloperUIHref} from '../../utils/developerUI/developerUI';
import {useTypedSelector} from '../../utils/hooks';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {CellWithPopover} from '../CellWithPopover/CellWithPopover';
import {EntityStatus} from '../EntityStatus/EntityStatus';
import {LinkWithIcon} from '../LinkWithIcon/LinkWithIcon';
Expand All @@ -16,7 +15,7 @@ interface TabletNameWrapperProps {
}

export function TabletNameWrapper({tabletId, database}: TabletNameWrapperProps) {
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();

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

Expand Down
5 changes: 2 additions & 3 deletions src/components/TenantNameWrapper/TenantNameWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {DefinitionList, PopoverBehavior} from '@gravity-ui/uikit';

import {getTenantPath} from '../../containers/Tenant/TenantPages';
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
import type {PreparedTenant} from '../../store/reducers/tenants/types';
import type {AdditionalTenantsProps, NodeAddress} from '../../types/additionalProps';
import {useTypedSelector} from '../../utils/hooks';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {CellWithPopover} from '../CellWithPopover/CellWithPopover';
import {EntityStatus} from '../EntityStatus/EntityStatus';
import {LinkWithIcon} from '../LinkWithIcon/LinkWithIcon';
Expand Down Expand Up @@ -34,7 +33,7 @@ const getTenantBackend = (
};

export function TenantNameWrapper({tenant, additionalTenantsProps}: TenantNameWrapperProps) {
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();

const backend = getTenantBackend(tenant, additionalTenantsProps);
const isExternalLink = Boolean(backend);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type {DefinitionListItemProps} from '@gravity-ui/uikit';
import {DefinitionList} from '@gravity-ui/uikit';

import {selectIsUserAllowedToMakeChanges} from '../../../store/reducers/authentication/authentication';
import type {TSystemStateInfo} from '../../../types/api/nodes';
import {cn} from '../../../utils/cn';
import {useTypedSelector} from '../../../utils/hooks';
import {useIsUserAllowedToMakeChanges} from '../../../utils/hooks/useIsUserAllowedToMakeChanges';
import {LinkWithIcon} from '../../LinkWithIcon/LinkWithIcon';

import i18n from './i18n';
Expand All @@ -19,7 +18,7 @@ interface NodeEdpointsTooltipProps {
}

export const NodeEndpointsTooltipContent = ({data, nodeHref}: NodeEdpointsTooltipProps) => {
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
const info: (DefinitionListItemProps & {key: string})[] = [];

if (data?.Roles?.length) {
Expand Down
5 changes: 2 additions & 3 deletions src/components/VDiskInfo/VDiskInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React from 'react';

import {getVDiskPagePath} from '../../routes';
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
import {valueIsDefined} from '../../utils';
import {cn} from '../../utils/cn';
import {formatStorageValuesToGb} from '../../utils/dataFormatters/dataFormatters';
import {createVDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
import {getSeverityColor} from '../../utils/disks/helpers';
import type {PreparedVDisk} from '../../utils/disks/types';
import {useTypedSelector} from '../../utils/hooks';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {bytesToSpeed} from '../../utils/utils';
import {InfoViewer} from '../InfoViewer';
import type {InfoViewerProps} from '../InfoViewer/InfoViewer';
Expand All @@ -35,7 +34,7 @@ export function VDiskInfo<T extends PreparedVDisk>({
withTitle,
...infoViewerProps
}: VDiskInfoProps<T>) {
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();

const {
AllocatedSize,
Expand Down
4 changes: 2 additions & 2 deletions src/components/VDiskPopup/VDiskPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';

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

import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
import {selectNodesMap} from '../../store/reducers/nodesList';
import {EFlag} from '../../types/api/enums';
import {valueIsDefined} from '../../utils';
Expand All @@ -12,6 +11,7 @@ import {createVDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
import {isFullVDiskData} from '../../utils/disks/helpers';
import type {PreparedVDisk, UnavailableDonor} from '../../utils/disks/types';
import {useTypedSelector} from '../../utils/hooks';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {bytesToGB, bytesToSpeed} from '../../utils/utils';
import type {InfoViewerItem} from '../InfoViewer';
import {InfoViewer} from '../InfoViewer';
Expand Down Expand Up @@ -178,7 +178,7 @@ interface VDiskPopupProps {
export const VDiskPopup = ({data}: VDiskPopupProps) => {
const isFullData = isFullVDiskData(data);

const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();

const vdiskInfo = React.useMemo(
() =>
Expand Down
7 changes: 7 additions & 0 deletions src/components/nodesColumns/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export const NODES_COLUMNS_IDS = {

export type NodesColumnId = ValueOf<typeof NODES_COLUMNS_IDS>;

// Columns, that should displayed only for users with isMonitoringAllowed:true
const MONITORING_USER_COLUMNS_IDS: NodesColumnId[] = ['Pools', 'Memory'];

export function isMonitoringUserNodesColumn(columnId: string): boolean {
return MONITORING_USER_COLUMNS_IDS.includes(columnId as NodesColumnId);
}

// This code is running when module is initialized and correct language may not be set yet
// get functions guarantee that i18n fields will be inited on render with current render language
export const NODES_COLUMNS_TITLES = {
Expand Down
4 changes: 2 additions & 2 deletions src/containers/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {useLocation} from 'react-router-dom';

import {getConnectToDBDialog} from '../../components/ConnectToDB/ConnectToDBDialog';
import {InternalLink} from '../../components/InternalLink';
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
import {useClusterBaseInfo} from '../../store/reducers/cluster/cluster';
import {cn} from '../../utils/cn';
import {DEVELOPER_UI_TITLE} from '../../utils/constants';
import {createDeveloperUIInternalPageHref} from '../../utils/developerUI/developerUI';
import {useTypedSelector} from '../../utils/hooks';
import {useDatabaseFromQuery} from '../../utils/hooks/useDatabaseFromQuery';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';

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

function Header({mainPage}: HeaderProps) {
const {page, pageBreadcrumbsOptions} = useTypedSelector((state) => state.header);
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();

const clusterInfo = useClusterBaseInfo();

Expand Down
5 changes: 2 additions & 3 deletions src/containers/Node/NodeStructure/Pdisk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {PDiskInfo} from '../../../components/PDiskInfo/PDiskInfo';
import {ProgressViewer} from '../../../components/ProgressViewer/ProgressViewer';
import {StatusIcon} from '../../../components/StatusIcon/StatusIcon';
import {VDiskInfo} from '../../../components/VDiskInfo/VDiskInfo';
import {selectIsUserAllowedToMakeChanges} from '../../../store/reducers/authentication/authentication';
import type {
PreparedStructurePDisk,
PreparedStructureVDisk,
Expand All @@ -23,7 +22,7 @@ import {cn} from '../../../utils/cn';
import {DEFAULT_TABLE_SETTINGS} from '../../../utils/constants';
import {formatStorageValuesToGb} from '../../../utils/dataFormatters/dataFormatters';
import {createVDiskDeveloperUILink} from '../../../utils/developerUI/developerUI';
import {useTypedSelector} from '../../../utils/hooks';
import {useIsUserAllowedToMakeChanges} from '../../../utils/hooks/useIsUserAllowedToMakeChanges';
import i18n from '../i18n';

import {PDiskTitleBadge} from './PDiskTitleBadge';
Expand Down Expand Up @@ -171,7 +170,7 @@ export function PDisk({
nodeId,
unfolded: unfoldedFromProps,
}: PDiskProps) {
const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();

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

Expand Down
18 changes: 15 additions & 3 deletions src/containers/Nodes/Nodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {ResponseError} from '../../components/Errors/ResponseError';
import {LoaderWrapper} from '../../components/LoaderWrapper/LoaderWrapper';
import type {Column, RenderControls} from '../../components/PaginatedTable';
import {TableWithControlsLayout} from '../../components/TableWithControlsLayout/TableWithControlsLayout';
import {NODES_COLUMNS_TITLES} from '../../components/nodesColumns/constants';
import {
NODES_COLUMNS_TITLES,
isMonitoringUserNodesColumn,
} from '../../components/nodesColumns/constants';
import type {NodesColumnId} from '../../components/nodesColumns/constants';
import {
useCapabilitiesLoaded,
Expand All @@ -16,6 +19,7 @@ import {useProblemFilter} from '../../store/reducers/settings/hooks';
import type {AdditionalNodesProps} from '../../types/additionalProps';
import type {NodesGroupByField} from '../../types/api/nodes';
import {useAutoRefreshInterval} from '../../utils/hooks';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {useSelectedColumns} from '../../utils/hooks/useSelectedColumns';
import {NodesUptimeFilterValues} from '../../utils/nodes';
import {TableGroup} from '../Storage/TableGroup/TableGroup';
Expand Down Expand Up @@ -69,6 +73,14 @@ export function Nodes({

const capabilitiesLoaded = useCapabilitiesLoaded();
const viewerNodesHandlerHasGrouping = useViewerNodesHandlerHasGrouping();
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();

const preparedColumns = React.useMemo(() => {
if (isUserAllowedToMakeChanges) {
return columns;
}
return columns.filter((column) => !isMonitoringUserNodesColumn(column.name));
}, [columns, isUserAllowedToMakeChanges]);

// Other filters do not fit with grouping
// Reset them if grouping available
Expand Down Expand Up @@ -96,7 +108,7 @@ export function Nodes({
database={database}
parentRef={parentRef}
withPeerRoleFilter={withPeerRoleFilter}
columns={columns}
columns={preparedColumns}
defaultColumnsIds={defaultColumnsIds}
requiredColumnsIds={requiredColumnsIds}
selectedColumnsKey={selectedColumnsKey}
Expand All @@ -111,7 +123,7 @@ export function Nodes({
database={database}
parentRef={parentRef}
withPeerRoleFilter={withPeerRoleFilter}
columns={columns}
columns={preparedColumns}
defaultColumnsIds={defaultColumnsIds}
requiredColumnsIds={requiredColumnsIds}
selectedColumnsKey={selectedColumnsKey}
Expand Down
6 changes: 3 additions & 3 deletions src/containers/PDiskPage/PDiskPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import {PDiskInfo} from '../../components/PDiskInfo/PDiskInfo';
import {PageMetaWithAutorefresh} from '../../components/PageMeta/PageMeta';
import {getPDiskPagePath} from '../../routes';
import {api} from '../../store/reducers/api';
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
import {useDiskPagesAvailable} from '../../store/reducers/capabilities/hooks';
import {setHeaderBreadcrumbs} from '../../store/reducers/header/header';
import {pDiskApi} from '../../store/reducers/pdisk/pdisk';
import type {EDecommitStatus} from '../../types/api/pdisk';
import {valueIsDefined} from '../../utils';
import {cn} from '../../utils/cn';
import {getPDiskId, getSeverityColor} from '../../utils/disks/helpers';
import {useAutoRefreshInterval, useTypedDispatch, useTypedSelector} from '../../utils/hooks';
import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {PaginatedStorage} from '../Storage/PaginatedStorage';

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

const isUserAllowedToMakeChanges = useTypedSelector(selectIsUserAllowedToMakeChanges);
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
const newDiskApiAvailable = useDiskPagesAvailable();
const containerRef = React.useRef<HTMLDivElement>(null);

Expand Down
6 changes: 5 additions & 1 deletion src/containers/Storage/PaginatedStorage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';

import {PaginatedStorageGroups} from './PaginatedStorageGroups';
import {PaginatedStorageNodes} from './PaginatedStorageNodes';
import type {StorageViewContext} from './types';
Expand All @@ -19,10 +21,12 @@ export interface PaginatedStorageProps {

export const PaginatedStorage = (props: PaginatedStorageProps) => {
const {storageType} = useStorageQueryParams();
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();

const isNodes = storageType === 'nodes';

if (isNodes) {
// Hide storage node details for users with only viewer rights
if (isNodes && isUserAllowedToMakeChanges) {
return (
<PaginatedStorageNodes
initialEntitiesCount={getStorageNodesInitialEntitiesCount(props.viewContext)}
Expand Down
7 changes: 6 additions & 1 deletion src/containers/Storage/StorageControls/StorageControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Select, TableColumnSetup, Text} from '@gravity-ui/uikit';
import {EntitiesCount} from '../../../components/EntitiesCount/EntitiesCount';
import {Search} from '../../../components/Search/Search';
import {UptimeFilter} from '../../../components/UptimeFIlter';
import {useIsUserAllowedToMakeChanges} from '../../../utils/hooks/useIsUserAllowedToMakeChanges';
import {STORAGE_GROUPS_GROUP_BY_OPTIONS} from '../StorageGroups/columns/constants';
import {STORAGE_NODES_GROUP_BY_OPTIONS} from '../StorageNodes/columns/constants';
import {StorageTypeFilter} from '../StorageTypeFilter/StorageTypeFilter';
Expand Down Expand Up @@ -48,10 +49,14 @@ export function StorageGroupsControls({
handleStorageGroupsGroupByParamChange,
} = useStorageQueryParams();

const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();

const handleGroupBySelectUpdate = (value: string[]) => {
handleStorageGroupsGroupByParamChange(value[0]);
};

const displayTypeSelector = withTypeSelector && isUserAllowedToMakeChanges;

return (
<React.Fragment>
<Search
Expand All @@ -60,7 +65,7 @@ export function StorageGroupsControls({
placeholder={i18n('controls_groups-search-placeholder')}
className={b('search')}
/>
{withTypeSelector && (
{displayTypeSelector && (
<StorageTypeFilter value={storageType} onChange={handleStorageTypeChange} />
)}
{withGroupBySelect ? null : (
Expand Down
12 changes: 12 additions & 0 deletions src/containers/Storage/StorageGroups/columns/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ export const STORAGE_GROUPS_COLUMNS_IDS = {

export type StorageGroupsColumnId = ValueOf<typeof STORAGE_GROUPS_COLUMNS_IDS>;

// Columns, that should displayed only for users with isMonitoringAllowed:true
const MONITORING_USER_COLUMNS_IDS: StorageGroupsColumnId[] = [
'DiskSpaceUsage',
'Latency',
'AllocationUnits',
'VDisksPDisks',
];

export function isMonitoringUserGroupsColumn(columnId: string): boolean {
return MONITORING_USER_COLUMNS_IDS.includes(columnId as StorageGroupsColumnId);
}

export const DEFAULT_STORAGE_GROUPS_COLUMNS: StorageGroupsColumnId[] = [
'GroupId',
'PoolName',
Expand Down
Loading
Loading