diff --git a/src/containers/Tenant/Tenant.tsx b/src/containers/Tenant/Tenant.tsx index a40b9be6b4..1722996727 100644 --- a/src/containers/Tenant/Tenant.tsx +++ b/src/containers/Tenant/Tenant.tsx @@ -8,10 +8,11 @@ import {LoaderWrapper} from '../../components/LoaderWrapper/LoaderWrapper'; import SplitPane from '../../components/SplitPane'; import {setHeaderBreadcrumbs} from '../../store/reducers/header/header'; import {overviewApi} from '../../store/reducers/overview/overview'; +import {selectSchemaObjectData} from '../../store/reducers/schema/schema'; import type {AdditionalNodesProps, AdditionalTenantsProps} from '../../types/additionalProps'; import {cn} from '../../utils/cn'; import {DEFAULT_IS_TENANT_SUMMARY_COLLAPSED, DEFAULT_SIZE_TENANT_KEY} from '../../utils/constants'; -import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks'; +import {useAutoRefreshInterval, useTypedDispatch, useTypedSelector} from '../../utils/hooks'; import {isAccessError} from '../../utils/response'; import ObjectGeneral from './ObjectGeneral/ObjectGeneral'; @@ -100,8 +101,18 @@ export function Tenant(props: TenantProps) { pollingInterval: autoRefreshInterval, }, ); - const {PathType: currentPathType, PathSubType: currentPathSubType} = - currentItem?.PathDescription?.Self || {}; + + const preloadedData = useTypedSelector((state) => + selectSchemaObjectData(state, path, tenantName), + ); + + // Use preloaded data if there is no current item data yet + const currentPathType = + currentItem?.PathDescription?.Self?.PathType ?? + preloadedData?.PathDescription?.Self?.PathType; + const currentPathSubType = + currentItem?.PathDescription?.Self?.PathSubType ?? + preloadedData?.PathDescription?.Self?.PathSubType; const showBlockingError = isAccessError(error); diff --git a/src/store/reducers/schema/schema.ts b/src/store/reducers/schema/schema.ts index 0368c24da0..a9f8ca473d 100644 --- a/src/store/reducers/schema/schema.ts +++ b/src/store/reducers/schema/schema.ts @@ -1,9 +1,10 @@ import React from 'react'; -import {createSlice} from '@reduxjs/toolkit'; +import {createSelector, createSlice} from '@reduxjs/toolkit'; import type {PayloadAction} from '@reduxjs/toolkit'; import type {TEvDescribeSchemeResult} from '../../../types/api/schema'; +import type {RootState} from '../../defaultStore'; import {api} from '../api'; const initialState = { @@ -110,3 +111,18 @@ export function useGetSchemaQuery({path, database}: {path: string; database: str return {data, isLoading, error: currentPathError}; } + +const getSchemaSelector = createSelector( + (path: string) => path, + (_path: string, database: string) => database, + (path, database) => schemaApi.endpoints.getSchema.select({path, database}), +); + +export const selectSchemaObjectData = createSelector( + (state: RootState) => state, + (_state: RootState, path: string) => path, + (_state: RootState, path: string, database: string) => getSchemaSelector(path, database), + (state, path, selectSchemaData) => { + return selectSchemaData(state).data?.[path]; + }, +);