import React from 'react'; import {ChartTreemap} from '@gravity-ui/icons'; import {Button, Flex, Icon, Select, Text} from '@gravity-ui/uikit'; import {EntitiesCount} from '../../../components/EntitiesCount/EntitiesCount'; import {usePaginatedTableState} from '../../../components/PaginatedTable/PaginatedTableContext'; import {Search} from '../../../components/Search/Search'; import { useBlobStorageCapacityMetricsAvailable, useBlobStorageCapacityMetricsEnabled, useBridgeModeEnabled, } from '../../../store/reducers/capabilities/hooks'; import {SETTING_KEYS} from '../../../store/reducers/settings/constants'; import {useSetting} from '../../../utils/hooks'; import {useIsUserAllowedToMakeChanges} from '../../../utils/hooks/useIsUserAllowedToMakeChanges'; import { STORAGE_GROUPS_COLUMNS_IDS, getStorageGroupsGroupByOptions, } from '../PaginatedStorageGroupsTable/columns/constants'; import type {StorageGroupsColumn} from '../PaginatedStorageGroupsTable/columns/types'; import {StorageGroupsExpertModePanel} from '../StorageExpertModePanel/StorageGroupsExpertModePanel'; import {StorageTypeFilter} from '../StorageTypeFilter/StorageTypeFilter'; import {StorageVisibleEntitiesFilter} from '../StorageVisibleEntitiesFilter/StorageVisibleEntitiesFilter'; import i18n from '../i18n'; import {b} from '../shared'; import {useIsStorageExpertMode, useStorageQueryParams} from '../useStorageQueryParams'; interface StorageControlsProps { withTypeSelector?: boolean; withGroupBySelect?: boolean; columns?: StorageGroupsColumn[]; entitiesCountCurrent: number; entitiesCountTotal?: number; entitiesLoading: boolean; } export function StorageGroupsControls({ withTypeSelector, withGroupBySelect, columns = [], entitiesCountCurrent, entitiesCountTotal, entitiesLoading, }: StorageControlsProps) { const { groupsSearchValue, storageType, visibleEntities, storageGroupsGroupByParam, handleTextFilterGroupsChange, handleStorageTypeChange, handleVisibleEntitiesChange, handleStorageGroupsGroupByParamChange, handleStorageExpertModeChange, } = useStorageQueryParams(); const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges(); const [storageExpertModeSettingEnabled] = useSetting( SETTING_KEYS.ENABLE_STORAGE_EXPERT_MODE, ); const isStorageExpertMode = useIsStorageExpertMode(); const storageExpertModeAvailable = useBlobStorageCapacityMetricsAvailable(); const bridgeModeEnabled = useBridgeModeEnabled(); const blobMetricsEnabled = useBlobStorageCapacityMetricsEnabled(); const isVDisksPDisksColumnVisible = React.useMemo(() => { return columns.some((column) => column.name === STORAGE_GROUPS_COLUMNS_IDS.VDisksPDisks); }, [columns]); const groupByOptions = React.useMemo(() => { return getStorageGroupsGroupByOptions(blobMetricsEnabled, bridgeModeEnabled); }, [bridgeModeEnabled, blobMetricsEnabled]); const handleGroupBySelectUpdate = (value: string[]) => { handleStorageGroupsGroupByParamChange(value[0]); }; const displayTypeSelector = withTypeSelector && isUserAllowedToMakeChanges; const canUseStorageExpertMode = storageExpertModeAvailable && storageExpertModeSettingEnabled && Boolean(isUserAllowedToMakeChanges); return ( {displayTypeSelector && ( )} {withGroupBySelect ? null : ( )} {withGroupBySelect ? ( {i18n('controls_group-by-placeholder')}