From a7d96f8758805f23df1690ee1ef74433d34c8958 Mon Sep 17 00:00:00 2001 From: mufazalov Date: Tue, 22 Oct 2024 17:46:52 +0300 Subject: [PATCH] fix: fields required in all storage and nodes requests --- src/containers/Storage/Storage.tsx | 1 + .../StorageGroupPage/StorageGroupPage.tsx | 4 +++- .../TenantCpu/TopNodesByCpu.tsx | 20 +++++++++++++---- .../TenantCpu/TopNodesByLoad.tsx | 22 +++++++++++++++---- .../TenantMemory/TopNodesByMemory.tsx | 21 ++++++++++++++---- .../TenantStorage/TopGroups.tsx | 20 +++++++++++++++-- src/services/api.ts | 2 +- src/utils/tableUtils/getRequiredDataFields.ts | 2 +- 8 files changed, 75 insertions(+), 17 deletions(-) diff --git a/src/containers/Storage/Storage.tsx b/src/containers/Storage/Storage.tsx index 19dc9d875..3d2014bb6 100644 --- a/src/containers/Storage/Storage.tsx +++ b/src/containers/Storage/Storage.tsx @@ -107,6 +107,7 @@ export const Storage = ({database, viewContext, nodeId, groupId, pDiskId}: Stora groupId, pDiskId, shouldUseGroupsHandler: groupsHandlerAvailable, + fieldsRequired: 'all', }, { skip: !isGroups || !capabilitiesLoaded, diff --git a/src/containers/StorageGroupPage/StorageGroupPage.tsx b/src/containers/StorageGroupPage/StorageGroupPage.tsx index fe4c6e530..752b5eb72 100644 --- a/src/containers/StorageGroupPage/StorageGroupPage.tsx +++ b/src/containers/StorageGroupPage/StorageGroupPage.tsx @@ -40,7 +40,9 @@ export function StorageGroupPage() { const shouldUseGroupsHandler = useStorageGroupsHandlerAvailable(); const capabilitiesLoaded = useCapabilitiesLoaded(); const groupQuery = storageApi.useGetStorageGroupsInfoQuery( - valueIsDefined(groupId) ? {groupId, shouldUseGroupsHandler, with: 'all'} : skipToken, + valueIsDefined(groupId) + ? {groupId, shouldUseGroupsHandler, with: 'all', fieldsRequired: 'all'} + : skipToken, { pollingInterval: autoRefreshInterval, skip: !capabilitiesLoaded, diff --git a/src/containers/Tenant/Diagnostics/TenantOverview/TenantCpu/TopNodesByCpu.tsx b/src/containers/Tenant/Diagnostics/TenantOverview/TenantCpu/TopNodesByCpu.tsx index 892a5cb6f..00b764624 100644 --- a/src/containers/Tenant/Diagnostics/TenantOverview/TenantCpu/TopNodesByCpu.tsx +++ b/src/containers/Tenant/Diagnostics/TenantOverview/TenantCpu/TopNodesByCpu.tsx @@ -5,14 +5,19 @@ import { getHostColumn, getNodeIdColumn, } from '../../../../../components/nodesColumns/columns'; -import {NODES_COLUMNS_WIDTH_LS_KEY} from '../../../../../components/nodesColumns/constants'; +import { + NODES_COLUMNS_TO_DATA_FIELDS, + NODES_COLUMNS_WIDTH_LS_KEY, +} from '../../../../../components/nodesColumns/constants'; import type {GetNodesColumnsParams} from '../../../../../components/nodesColumns/types'; import {nodesApi} from '../../../../../store/reducers/nodes/nodes'; import type {NodesPreparedEntity} from '../../../../../store/reducers/nodes/types'; import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../../../store/reducers/tenant/constants'; import type {AdditionalNodesProps} from '../../../../../types/additionalProps'; +import type {NodesRequiredField} from '../../../../../types/api/nodes'; import {TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../../utils/constants'; import {useAutoRefreshInterval, useSearchQuery} from '../../../../../utils/hooks'; +import {getRequiredDataFields} from '../../../../../utils/tableUtils/getRequiredDataFields'; import {TenantTabsGroups, getTenantPath} from '../../../TenantPages'; import {TenantOverviewTableLayout} from '../TenantOverviewTableLayout'; import {getSectionTitle} from '../getSectionTitle'; @@ -20,7 +25,7 @@ import i18n from '../i18n'; export function getTopNodesByCpuColumns( params: GetNodesColumnsParams, -): Column[] { +): [Column[], NodesRequiredField[]] { const hostColumn = {...getHostColumn(params), width: undefined}; const columns = [ @@ -29,10 +34,15 @@ export function getTopNodesByCpuColumns( hostColumn, ]; - return columns.map((column) => ({ + const preparedColumns = columns.map((column) => ({ ...column, sortable: false, })); + + const columnsIds = preparedColumns.map((column) => column.name); + const dataFieldsRequired = getRequiredDataFields(columnsIds, NODES_COLUMNS_TO_DATA_FIELDS); + + return [preparedColumns, dataFieldsRequired]; } interface TopNodesByCpuProps { @@ -44,7 +54,7 @@ export function TopNodesByCpu({tenantName, additionalNodesProps}: TopNodesByCpuP const query = useSearchQuery(); const [autoRefreshInterval] = useAutoRefreshInterval(); - const columns = getTopNodesByCpuColumns({ + const [columns, fieldsRequired] = getTopNodesByCpuColumns({ getNodeRef: additionalNodesProps?.getNodeRef, database: tenantName, }); @@ -55,6 +65,8 @@ export function TopNodesByCpu({tenantName, additionalNodesProps}: TopNodesByCpuP type: 'any', sort: '-CPU', limit: TENANT_OVERVIEW_TABLES_LIMIT, + tablets: false, + fieldsRequired, }, {pollingInterval: autoRefreshInterval}, ); diff --git a/src/containers/Tenant/Diagnostics/TenantOverview/TenantCpu/TopNodesByLoad.tsx b/src/containers/Tenant/Diagnostics/TenantOverview/TenantCpu/TopNodesByLoad.tsx index dafab258a..5d87f32f3 100644 --- a/src/containers/Tenant/Diagnostics/TenantOverview/TenantCpu/TopNodesByLoad.tsx +++ b/src/containers/Tenant/Diagnostics/TenantOverview/TenantCpu/TopNodesByLoad.tsx @@ -6,20 +6,27 @@ import { getNodeIdColumn, getVersionColumn, } from '../../../../../components/nodesColumns/columns'; -import {NODES_COLUMNS_WIDTH_LS_KEY} from '../../../../../components/nodesColumns/constants'; +import { + NODES_COLUMNS_TO_DATA_FIELDS, + NODES_COLUMNS_WIDTH_LS_KEY, +} from '../../../../../components/nodesColumns/constants'; import type {GetNodesColumnsParams} from '../../../../../components/nodesColumns/types'; import {nodesApi} from '../../../../../store/reducers/nodes/nodes'; import type {NodesPreparedEntity} from '../../../../../store/reducers/nodes/types'; import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../../../store/reducers/tenant/constants'; import type {AdditionalNodesProps} from '../../../../../types/additionalProps'; +import type {NodesRequiredField} from '../../../../../types/api/nodes'; import {TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../../utils/constants'; import {useAutoRefreshInterval, useSearchQuery} from '../../../../../utils/hooks'; +import {getRequiredDataFields} from '../../../../../utils/tableUtils/getRequiredDataFields'; import {TenantTabsGroups, getTenantPath} from '../../../TenantPages'; import {TenantOverviewTableLayout} from '../TenantOverviewTableLayout'; import {getSectionTitle} from '../getSectionTitle'; import i18n from '../i18n'; -function getTopNodesByLoadColumns(params: GetNodesColumnsParams): Column[] { +function getTopNodesByLoadColumns( + params: GetNodesColumnsParams, +): [Column[], NodesRequiredField[]] { const hostColumn = { ...getHostColumn(params), width: undefined, @@ -32,10 +39,15 @@ function getTopNodesByLoadColumns(params: GetNodesColumnsParams): Column(), ]; - return columns.map((column) => ({ + const preparedColumns = columns.map((column) => ({ ...column, sortable: false, })); + + const columnsIds = preparedColumns.map((column) => column.name); + const dataFieldsRequired = getRequiredDataFields(columnsIds, NODES_COLUMNS_TO_DATA_FIELDS); + + return [preparedColumns, dataFieldsRequired]; } interface TopNodesByLoadProps { @@ -47,7 +59,7 @@ export function TopNodesByLoad({tenantName, additionalNodesProps}: TopNodesByLoa const query = useSearchQuery(); const [autoRefreshInterval] = useAutoRefreshInterval(); - const columns = getTopNodesByLoadColumns({ + const [columns, fieldsRequired] = getTopNodesByLoadColumns({ getNodeRef: additionalNodesProps?.getNodeRef, database: tenantName, }); @@ -58,6 +70,8 @@ export function TopNodesByLoad({tenantName, additionalNodesProps}: TopNodesByLoa type: 'any', sort: '-LoadAverage', limit: TENANT_OVERVIEW_TABLES_LIMIT, + tablets: false, + fieldsRequired, }, {pollingInterval: autoRefreshInterval}, ); diff --git a/src/containers/Tenant/Diagnostics/TenantOverview/TenantMemory/TopNodesByMemory.tsx b/src/containers/Tenant/Diagnostics/TenantOverview/TenantMemory/TopNodesByMemory.tsx index c6fb6b691..0b52f213e 100644 --- a/src/containers/Tenant/Diagnostics/TenantOverview/TenantMemory/TopNodesByMemory.tsx +++ b/src/containers/Tenant/Diagnostics/TenantOverview/TenantMemory/TopNodesByMemory.tsx @@ -10,20 +10,27 @@ import { getTabletsColumn, getUptimeColumn, } from '../../../../../components/nodesColumns/columns'; -import {NODES_COLUMNS_WIDTH_LS_KEY} from '../../../../../components/nodesColumns/constants'; +import { + NODES_COLUMNS_TO_DATA_FIELDS, + NODES_COLUMNS_WIDTH_LS_KEY, +} from '../../../../../components/nodesColumns/constants'; import type {GetNodesColumnsParams} from '../../../../../components/nodesColumns/types'; import {nodesApi} from '../../../../../store/reducers/nodes/nodes'; import type {NodesPreparedEntity} from '../../../../../store/reducers/nodes/types'; import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../../../store/reducers/tenant/constants'; import type {AdditionalNodesProps} from '../../../../../types/additionalProps'; +import type {NodesRequiredField} from '../../../../../types/api/nodes'; import {TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../../utils/constants'; import {useAutoRefreshInterval, useSearchQuery} from '../../../../../utils/hooks'; +import {getRequiredDataFields} from '../../../../../utils/tableUtils/getRequiredDataFields'; import {TenantTabsGroups, getTenantPath} from '../../../TenantPages'; import {TenantOverviewTableLayout} from '../TenantOverviewTableLayout'; import {getSectionTitle} from '../getSectionTitle'; import i18n from '../i18n'; -function getTopNodesByMemoryColumns(params: GetNodesColumnsParams): Column[] { +function getTopNodesByMemoryColumns( + params: GetNodesColumnsParams, +): [Column[], NodesRequiredField[]] { const memoryColumn = { ...getMemoryColumn(), header: i18n('column-header.process'), @@ -40,10 +47,15 @@ function getTopNodesByMemoryColumns(params: GetNodesColumnsParams): Column(params), ]; - return columns.map((column) => ({ + const preparedColumns = columns.map((column) => ({ ...column, sortable: false, })); + + const columnsIds = preparedColumns.map((column) => column.name); + const dataFieldsRequired = getRequiredDataFields(columnsIds, NODES_COLUMNS_TO_DATA_FIELDS); + + return [preparedColumns, dataFieldsRequired]; } interface TopNodesByMemoryProps { @@ -55,7 +67,7 @@ export function TopNodesByMemory({tenantName, additionalNodesProps}: TopNodesByM const query = useSearchQuery(); const [autoRefreshInterval] = useAutoRefreshInterval(); - const columns = getTopNodesByMemoryColumns({ + const [columns, fieldsRequired] = getTopNodesByMemoryColumns({ getNodeRef: additionalNodesProps?.getNodeRef, database: tenantName, }); @@ -67,6 +79,7 @@ export function TopNodesByMemory({tenantName, additionalNodesProps}: TopNodesByM tablets: true, sort: '-Memory', limit: TENANT_OVERVIEW_TABLES_LIMIT, + fieldsRequired, }, {pollingInterval: autoRefreshInterval}, ); diff --git a/src/containers/Tenant/Diagnostics/TenantOverview/TenantStorage/TopGroups.tsx b/src/containers/Tenant/Diagnostics/TenantOverview/TenantStorage/TopGroups.tsx index 276ba51bd..db2ae13b9 100644 --- a/src/containers/Tenant/Diagnostics/TenantOverview/TenantStorage/TopGroups.tsx +++ b/src/containers/Tenant/Diagnostics/TenantOverview/TenantStorage/TopGroups.tsx @@ -4,15 +4,30 @@ import { } from '../../../../../store/reducers/capabilities/hooks'; import {storageApi} from '../../../../../store/reducers/storage/storage'; import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../../../store/reducers/tenant/constants'; +import type {GroupsRequiredField} from '../../../../../types/api/storage'; import {TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../../utils/constants'; import {useAutoRefreshInterval, useSearchQuery} from '../../../../../utils/hooks'; +import {getRequiredDataFields} from '../../../../../utils/tableUtils/getRequiredDataFields'; import {getStorageTopGroupsColumns} from '../../../../Storage/StorageGroups/columns/columns'; -import {STORAGE_GROUPS_COLUMNS_WIDTH_LS_KEY} from '../../../../Storage/StorageGroups/columns/constants'; +import { + GROUPS_COLUMNS_TO_DATA_FIELDS, + STORAGE_GROUPS_COLUMNS_WIDTH_LS_KEY, +} from '../../../../Storage/StorageGroups/columns/constants'; +import type {StorageGroupsColumn} from '../../../../Storage/StorageGroups/columns/types'; import {TenantTabsGroups, getTenantPath} from '../../../TenantPages'; import {TenantOverviewTableLayout} from '../TenantOverviewTableLayout'; import {getSectionTitle} from '../getSectionTitle'; import i18n from '../i18n'; +function getColumns(): [StorageGroupsColumn[], GroupsRequiredField[]] { + const preparedColumns = getStorageTopGroupsColumns(); + + const columnsIds = preparedColumns.map((column) => column.name); + const dataFieldsRequired = getRequiredDataFields(columnsIds, GROUPS_COLUMNS_TO_DATA_FIELDS); + + return [preparedColumns, dataFieldsRequired]; +} + interface TopGroupsProps { tenant?: string; } @@ -24,7 +39,7 @@ export function TopGroups({tenant}: TopGroupsProps) { const groupsHandlerAvailable = useStorageGroupsHandlerAvailable(); const [autoRefreshInterval] = useAutoRefreshInterval(); - const columns = getStorageTopGroupsColumns(); + const [columns, fieldsRequired] = getColumns(); const {currentData, isFetching, error} = storageApi.useGetStorageGroupsInfoQuery( { @@ -33,6 +48,7 @@ export function TopGroups({tenant}: TopGroupsProps) { with: 'all', limit: TENANT_OVERVIEW_TABLES_LIMIT, shouldUseGroupsHandler: groupsHandlerAvailable, + fieldsRequired, }, { pollingInterval: autoRefreshInterval, diff --git a/src/services/api.ts b/src/services/api.ts index f8bbffb5a..2a1d9b3e6 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -251,7 +251,7 @@ export class YdbEmbeddedAPI extends AxiosWrapper { ); } getStorageGroups( - {nodeId, pDiskId, groupId, fieldsRequired = 'all', filter, ...params}: GroupsRequestParams, + {nodeId, pDiskId, groupId, fieldsRequired, filter, ...params}: GroupsRequestParams, {concurrentId, signal}: AxiosOptions = {}, ) { const preparedNodeId = Array.isArray(nodeId) diff --git a/src/utils/tableUtils/getRequiredDataFields.ts b/src/utils/tableUtils/getRequiredDataFields.ts index 8659bba84..d51a21ab2 100644 --- a/src/utils/tableUtils/getRequiredDataFields.ts +++ b/src/utils/tableUtils/getRequiredDataFields.ts @@ -11,5 +11,5 @@ export function getRequiredDataFields()); - return Array.from(requiredFieldsSet); + return Array.from(requiredFieldsSet).sort(); }