import React from 'react'; import {ResponseError} from '../../../components/Errors/ResponseError/ResponseError'; import {PaginatedTableWithLayout} from '../../../components/PaginatedTable/PaginatedTableWithLayout'; import {TableColumnSetup} from '../../../components/TableColumnSetup/TableColumnSetup'; import {storageApi} from '../../../store/reducers/storage/storage'; import type {GroupsGroupByField} from '../../../types/api/storage'; import {useAutoRefreshInterval} from '../../../utils/hooks'; import {renderPaginatedTableErrorMessage} from '../../../utils/renderPaginatedTableErrorMessage'; import type {PaginatedStorageProps} from '../PaginatedStorage'; import {PaginatedStorageGroupsTable} from '../PaginatedStorageGroupsTable'; import {useStorageGroupsSelectedColumns} from '../PaginatedStorageGroupsTable/columns/hooks'; import type {StorageGroupsColumn} from '../PaginatedStorageGroupsTable/columns/types'; import {TableGroup} from '../TableGroup/TableGroup'; import {useExpandedGroups} from '../TableGroup/useExpandedTableGroups'; import i18n from '../i18n'; import {b} from '../shared'; import {useStorageQueryParams} from '../useStorageQueryParams'; import {StorageGroupsControls} from './StorageGroupsControls'; interface StorageGroupGroupProps { name: string; count: number; isExpanded: boolean; database?: string; nodeId?: string | number; groupId?: string | number; pDiskId?: string | number; searchValue: string; visibleEntities: 'all'; filterGroupBy?: GroupsGroupByField; columns: StorageGroupsColumn[]; scrollContainerRef: React.RefObject; onIsExpandedChange: (name: string, isExpanded: boolean) => void; handleShowAllGroups: VoidFunction; } export const StorageGroupGroup = React.memo(function StorageGroupGroup({ name, count, isExpanded, database, nodeId, groupId, pDiskId, searchValue, scrollContainerRef, filterGroupBy, columns, onIsExpandedChange, handleShowAllGroups, }: StorageGroupGroupProps) { return ( } tableWrapperProps={{ scrollContainerRef: scrollContainerRef, }} /> ); }); export function GroupedStorageGroupsComponent({ database, nodeId, groupId, pDiskId, scrollContainerRef, viewContext, }: PaginatedStorageProps) { const [autoRefreshInterval] = useAutoRefreshInterval(); const {groupsSearchValue, storageGroupsGroupByParam, visibleEntities, handleShowAllGroups} = useStorageQueryParams(); const {columnsToShow, columnsToSelect, setColumns} = useStorageGroupsSelectedColumns({ visibleEntities, viewContext, }); const {currentData, isFetching, error} = storageApi.useGetStorageGroupsInfoQuery( { database, with: 'all', nodeId, groupId, pDiskId, filter: groupsSearchValue.trim(), group: storageGroupsGroupByParam, }, { pollingInterval: autoRefreshInterval, }, ); const isLoading = currentData === undefined && isFetching; const {tableGroups, found = 0, total = 0} = currentData || {}; const {expandedGroups, setIsGroupExpanded} = useExpandedGroups(tableGroups); // Initialize the table state with the API data const initialState = React.useMemo( () => ({ foundEntities: found, totalEntities: total, isInitialLoad: isLoading, sortParams: undefined, }), [found, total, isLoading], ); const renderGroups = () => { if (tableGroups?.length) { return tableGroups.map(({name, count}) => { const isExpanded = expandedGroups[name]; return ( ); }); } return i18n('no-groups'); }; return ( } extraControls={ } error={error ? : null} table={renderGroups()} initialState={initialState} tableWrapperProps={{ scrollContainerRef, scrollDependencies: [groupsSearchValue, storageGroupsGroupByParam, tableGroups], loading: isLoading, className: b('groups-wrapper'), }} /> ); }