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: use groups handler for storage #1225

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 12 additions & 3 deletions src/containers/PDiskPage/PDiskGroups/PDiskGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import React from 'react';

import {ResizeableDataTable} from '../../../components/ResizeableDataTable/ResizeableDataTable';
import {TableSkeleton} from '../../../components/TableSkeleton/TableSkeleton';
import {
useCapabilitiesLoaded,
useStorageGroupsHandlerAvailable,
} from '../../../store/reducers/capabilities/hooks';
import {storageApi} from '../../../store/reducers/storage/storage';
import {DEFAULT_TABLE_SETTINGS} from '../../../utils/constants';
import {useAutoRefreshInterval} from '../../../utils/hooks';
Expand All @@ -16,11 +20,16 @@ interface PDiskGroupsProps {
}

export function PDiskGroups({pDiskId, nodeId}: PDiskGroupsProps) {
const capabilitiesLoaded = useCapabilitiesLoaded();
const groupsHandlerAvailable = useStorageGroupsHandlerAvailable();
const [autoRefreshInterval] = useAutoRefreshInterval();

const {currentData, isFetching} = storageApi.useGetStorageGroupsInfoQuery(
{pDiskId, nodeId},
{pollingInterval: autoRefreshInterval},
{pDiskId, nodeId, useGroupsHandler: groupsHandlerAvailable},
{
pollingInterval: autoRefreshInterval,
skip: !capabilitiesLoaded,
},
);
const loading = isFetching && currentData === undefined;

Expand All @@ -30,7 +39,7 @@ export function PDiskGroups({pDiskId, nodeId}: PDiskGroupsProps) {

const pDiskStorageColumns = useGetDiskStorageColumns();

if (loading) {
if (loading || !capabilitiesLoaded) {
return <TableSkeleton />;
}

Expand Down
16 changes: 13 additions & 3 deletions src/containers/Storage/Storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {AccessDenied} from '../../components/Errors/403';
import {isAccessError} from '../../components/Errors/PageError/PageError';
import {ResponseError} from '../../components/Errors/ResponseError';
import {TableWithControlsLayout} from '../../components/TableWithControlsLayout/TableWithControlsLayout';
import {
useCapabilitiesLoaded,
useStorageGroupsHandlerAvailable,
} from '../../store/reducers/capabilities/hooks';
import type {NodesSortParams} from '../../store/reducers/nodes/types';
import {STORAGE_TYPES, VISIBLE_ENTITIES} from '../../store/reducers/storage/constants';
import {
Expand Down Expand Up @@ -57,7 +61,10 @@ interface StorageProps {
}

export const Storage = ({additionalNodesProps, database, nodeId}: StorageProps) => {
const capabilitiesLoaded = useCapabilitiesLoaded();
const groupsHandlerAvailable = useStorageGroupsHandlerAvailable();
const [autoRefreshInterval] = useAutoRefreshInterval();

const [queryParams, setQueryParams] = useQueryParams({
type: StringParam,
visible: StringParam,
Expand Down Expand Up @@ -95,9 +102,9 @@ export const Storage = ({additionalNodesProps, database, nodeId}: StorageProps)
},
);
const groupsQuery = storageApi.useGetStorageGroupsInfoQuery(
{database, with: visibleEntities, nodeId},
{database, with: visibleEntities, nodeId, useGroupsHandler: groupsHandlerAvailable},
{
skip: storageType !== STORAGE_TYPES.groups,
skip: storageType !== STORAGE_TYPES.groups || !capabilitiesLoaded,
pollingInterval: autoRefreshInterval,
},
);
Expand Down Expand Up @@ -220,7 +227,10 @@ export const Storage = ({additionalNodesProps, database, nodeId}: StorageProps)
<TableWithControlsLayout>
<TableWithControlsLayout.Controls>{renderControls()}</TableWithControlsLayout.Controls>
{error ? <ResponseError error={error} /> : null}
<TableWithControlsLayout.Table loading={isLoading} className={b('table')}>
<TableWithControlsLayout.Table
loading={isLoading || !capabilitiesLoaded}
className={b('table')}
>
{currentData ? renderDataTable() : null}
</TableWithControlsLayout.Table>
</TableWithControlsLayout>
Expand Down
38 changes: 25 additions & 13 deletions src/containers/Storage/StorageGroups/PaginatedStorageGroups.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React from 'react';

import {LoaderWrapper} from '../../../components/LoaderWrapper/LoaderWrapper';
import type {RenderControls, RenderErrorMessage} from '../../../components/PaginatedTable';
import {ResizeablePaginatedTable} from '../../../components/PaginatedTable';
import {
useCapabilitiesLoaded,
useStorageGroupsHandlerAvailable,
} from '../../../store/reducers/capabilities/hooks';
import {VISIBLE_ENTITIES} from '../../../store/reducers/storage/constants';
import type {VisibleEntities} from '../../../store/reducers/storage/types';

import {StorageGroupsEmptyDataMessage} from './StorageGroupsEmptyDataMessage';
import {STORAGE_GROUPS_COLUMNS_WIDTH_LS_KEY} from './columns/getStorageGroupsColumns';
import {useGetStorageGroupsColumns} from './columns/hooks';
import {getStorageGroups} from './getGroups';
import {useGroupsGetter} from './getGroups';
import i18n from './i18n';

interface PaginatedStorageGroupsProps {
Expand Down Expand Up @@ -36,6 +41,11 @@ export const PaginatedStorageGroups = ({
}: PaginatedStorageGroupsProps) => {
const columns = useGetStorageGroupsColumns(visibleEntities);

const capabilitiesLoaded = useCapabilitiesLoaded();
const groupsHandlerAvailable = useStorageGroupsHandlerAvailable();

const fetchData = useGroupsGetter(groupsHandlerAvailable);

const tableFilters = React.useMemo(() => {
return {searchValue, visibleEntities, database, nodeId};
}, [searchValue, visibleEntities, database, nodeId]);
Expand All @@ -54,17 +64,19 @@ export const PaginatedStorageGroups = ({
};

return (
<ResizeablePaginatedTable
columnsWidthLSKey={STORAGE_GROUPS_COLUMNS_WIDTH_LS_KEY}
parentContainer={parentContainer}
columns={columns}
fetchData={getStorageGroups}
limit={50}
renderControls={renderControls}
renderErrorMessage={renderErrorMessage}
renderEmptyDataMessage={renderEmptyDataMessage}
filters={tableFilters}
tableName="storage-groups"
/>
<LoaderWrapper loading={!capabilitiesLoaded}>
<ResizeablePaginatedTable
columnsWidthLSKey={STORAGE_GROUPS_COLUMNS_WIDTH_LS_KEY}
parentContainer={parentContainer}
columns={columns}
fetchData={fetchData}
limit={50}
renderControls={renderControls}
renderErrorMessage={renderErrorMessage}
renderEmptyDataMessage={renderEmptyDataMessage}
filters={tableFilters}
tableName="storage-groups"
/>
</LoaderWrapper>
);
};
65 changes: 36 additions & 29 deletions src/containers/Storage/StorageGroups/getGroups.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,51 @@
import React from 'react';

import type {FetchData} from '../../../components/PaginatedTable';
import {requestStorageData} from '../../../store/reducers/storage/requestStorageData';
import type {
PreparedStorageGroup,
PreparedStorageGroupFilters,
} from '../../../store/reducers/storage/types';
import {prepareStorageResponse} from '../../../store/reducers/storage/utils';
import type {StorageV2Sort} from '../../../types/api/storage';
import {prepareSortValue} from '../../../utils/filters';

const getConcurrentId = (limit?: number, offset?: number) => {
return `getStorageGroups|offset${offset}|limit${limit}`;
};

export const getStorageGroups: FetchData<
PreparedStorageGroup,
PreparedStorageGroupFilters
> = async (params) => {
const {limit, offset, sortParams, filters} = params;
const {sortOrder, columnId} = sortParams ?? {};
const {searchValue, visibleEntities, database, nodeId} = filters ?? {};

const sort = prepareSortValue(columnId, sortOrder) as StorageV2Sort;

const response = await window.api.getStorageInfo(
{
version: 'v2',
limit,
offset,
sort,
filter: searchValue,
with: visibleEntities,
database,
nodeId,
type GetStorageGroups = FetchData<PreparedStorageGroup, PreparedStorageGroupFilters>;

export function useGroupsGetter(useGroupsHandler: boolean) {
const fetchData: GetStorageGroups = React.useCallback(
async (params) => {
const {limit, offset, sortParams, filters} = params;
const {sortOrder, columnId} = sortParams ?? {};
const {searchValue, visibleEntities, database, nodeId} = filters ?? {};

const sort = prepareSortValue(columnId, sortOrder) as StorageV2Sort;

const {groups, found, total} = await requestStorageData(
{
limit,
offset,
sort,
filter: searchValue,
with: visibleEntities,
database,
nodeId,
useGroupsHandler,
},
{concurrentId: getConcurrentId(limit, offset)},
);

return {
data: groups || [],
found: found || 0,
total: total || 0,
};
},
{concurrentId: getConcurrentId(limit, offset)},
[useGroupsHandler],
);
const preparedResponse = prepareStorageResponse(response);

return {
data: preparedResponse.groups || [],
found: preparedResponse.found || 0,
total: preparedResponse.total || 0,
};
};
return fetchData;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from 'react';

import {
useCapabilitiesLoaded,
useStorageGroupsHandlerAvailable,
} from '../../../../../store/reducers/capabilities/hooks';
import {storageApi} from '../../../../../store/reducers/storage/storage';
import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../../../store/reducers/tenant/constants';
import {TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../../utils/constants';
Expand All @@ -22,6 +26,8 @@ interface TopGroupsProps {
export function TopGroups({tenant}: TopGroupsProps) {
const query = useSearchQuery();

const capabilitiesLoaded = useCapabilitiesLoaded();
const groupsHandlerAvailable = useStorageGroupsHandlerAvailable();
const [autoRefreshInterval] = useAutoRefreshInterval();

const columns = getStorageTopGroupsColumns();
Expand All @@ -32,8 +38,12 @@ export function TopGroups({tenant}: TopGroupsProps) {
sort: '-Usage',
with: 'all',
limit: TENANT_OVERVIEW_TABLES_LIMIT,
useGroupsHandler: groupsHandlerAvailable,
},
{
pollingInterval: autoRefreshInterval,
skip: !capabilitiesLoaded,
},
{pollingInterval: autoRefreshInterval},
);

const loading = isFetching && currentData === undefined;
Expand All @@ -57,7 +67,7 @@ export function TopGroups({tenant}: TopGroupsProps) {
data={preparedGroups}
columns={columns}
title={title}
loading={loading}
loading={loading || !capabilitiesLoaded}
error={error}
/>
);
Expand Down
35 changes: 21 additions & 14 deletions src/containers/VDiskPage/VDiskPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import {ResizeableDataTable} from '../../components/ResizeableDataTable/Resizeab
import {VDiskInfo} from '../../components/VDiskInfo/VDiskInfo';
import {api} from '../../store/reducers/api';
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
import {
useCapabilitiesLoaded,
useStorageGroupsHandlerAvailable,
} from '../../store/reducers/capabilities/hooks';
import {setHeaderBreadcrumbs} from '../../store/reducers/header/header';
import {storageApi} from '../../store/reducers/storage/storage';
import {vDiskApi} from '../../store/reducers/vdisk/vdisk';
Expand Down Expand Up @@ -180,12 +184,7 @@ export function VDiskPage() {

const renderGroupInfo = () => {
if (valueIsDefined(GroupID)) {
return (
<React.Fragment>
<div className={vDiskPageCn('group-title')}>{vDiskPageKeyset('group')}</div>
<VDiskGroup groupId={GroupID} />
</React.Fragment>
);
return <VDiskGroup groupId={GroupID} />;
}

return null;
Expand Down Expand Up @@ -217,11 +216,16 @@ export function VDiskPage() {
}

export function VDiskGroup({groupId}: {groupId: string | number}) {
const capabilitiesLoaded = useCapabilitiesLoaded();
const groupsHandlerAvailable = useStorageGroupsHandlerAvailable();
const [autoRefreshInterval] = useAutoRefreshInterval();

const {currentData} = storageApi.useGetStorageGroupsInfoQuery(
{groupId},
{pollingInterval: autoRefreshInterval},
{groupId, useGroupsHandler: groupsHandlerAvailable},
{
pollingInterval: autoRefreshInterval,
skip: !capabilitiesLoaded,
},
);

const preparedGroups = React.useMemo(() => {
Expand All @@ -237,11 +241,14 @@ export function VDiskGroup({groupId}: {groupId: string | number}) {
}

return (
<ResizeableDataTable
columnsWidthLSKey={STORAGE_GROUPS_COLUMNS_WIDTH_LS_KEY}
data={preparedGroups}
columns={vDiskStorageColumns}
settings={DEFAULT_TABLE_SETTINGS}
/>
<React.Fragment>
<div className={vDiskPageCn('group-title')}>{vDiskPageKeyset('group')}</div>
<ResizeableDataTable
columnsWidthLSKey={STORAGE_GROUPS_COLUMNS_WIDTH_LS_KEY}
data={preparedGroups}
columns={vDiskStorageColumns}
settings={DEFAULT_TABLE_SETTINGS}
/>
</React.Fragment>
);
}
2 changes: 1 addition & 1 deletion src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const TRACE_CHECK_TIMEOUT = 2 * SECOND_IN_MS;
const TRACE_API_ERROR_TIMEOUT = 10 * SECOND_IN_MS;
const MAX_TRACE_CHECK_RETRIES = 30;

type AxiosOptions = {
export type AxiosOptions = {
concurrentId?: string;
signal?: AbortSignal;
withRetries?: boolean;
Expand Down
12 changes: 11 additions & 1 deletion src/store/reducers/capabilities/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import type {Capability} from '../../../types/api/capabilities';
import {useTypedSelector} from '../../../utils/hooks';

import {selectCapabilityVersion} from './capabilities';
import {capabilitiesApi, selectCapabilityVersion} from './capabilities';

export function useCapabilitiesLoaded() {
const {data, error} = capabilitiesApi.useGetClusterCapabilitiesQuery(undefined);

return Boolean(data || error);
}

const useGetFeatureVersion = (feature: Capability) => {
return useTypedSelector((state) => selectCapabilityVersion(state, feature) || 0);
Expand All @@ -20,3 +26,7 @@ export const useDiskPagesAvailable = () => {
export const useTracingLevelOptionAvailable = () => {
return useGetFeatureVersion('/viewer/query') > 2;
};

export const useStorageGroupsHandlerAvailable = () => {
return useGetFeatureVersion('/storage/groups') > 2;
};
21 changes: 21 additions & 0 deletions src/store/reducers/storage/requestStorageData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type {AxiosOptions} from '../../../services/api';
import type {StorageRequestParams} from '../../../types/api/storage';

import {prepareGroupsResponse, prepareStorageResponse} from './utils';

export async function requestStorageData(
{
version = 'v2',
useGroupsHandler,
...params
}: StorageRequestParams & {useGroupsHandler?: boolean},
options: AxiosOptions,
) {
if (useGroupsHandler && version !== 'v1') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useGroupsHandler really looks like name of react hook

was really confused why we pass hooks to api =)

Please change useGroupsHandler to something else >_<

const result = await window.api.getStorageGroups({...params}, options);
return prepareGroupsResponse(result);
} else {
const result = await window.api.getStorageInfo({version, ...params}, options);
return prepareStorageResponse(result);
}
}
Loading
Loading