import React from 'react';
import {ResponseError} from '../../../../components/Errors/ResponseError';
import {TableIndexInfo} from '../../../../components/InfoViewer/schemaInfo';
import {Loader} from '../../../../components/Loader';
import {useClusterWithProxy} from '../../../../store/reducers/cluster/cluster';
import {overviewApi} from '../../../../store/reducers/overview/overview';
import {EPathType} from '../../../../types/api/schema';
import {cn} from '../../../../utils/cn';
import {useAutoRefreshInterval} from '../../../../utils/hooks';
import {ViewInfo} from '../../Info/View/View';
import {isDomain} from '../../ObjectSummary/transformPath';
import {useNavigationV2Enabled} from '../../utils/useNavigationV2Enabled';
import {AsyncReplicationInfo} from './AsyncReplicationInfo';
import {ChangefeedInfo} from './ChangefeedInfo';
import {DatabaseInfo} from './DatabaseInfo/DatabaseInfo';
import {DefaultEntityInfo} from './DefaultEntityInfo';
import {ResourcePoolInfo} from './ResourcePoolInfo';
import {ResourcePoolUsage} from './ResourcePoolInfo/ResourcePoolUsage';
import {SchemaObjectInfoContainer} from './SchemaObjectInfo/SchemaObjectInfoContainer';
import {StreamingQueryInfo} from './StreamingQueryInfo';
import {TableInfo} from './TableInfo';
import {TopicInfo} from './TopicInfo';
import {TransferInfo} from './TransferInfo';
interface OverviewProps {
type?: EPathType;
path: string;
database: string;
databaseFullPath: string;
}
const b = cn('ydb-diagnostics-resource-pool-info');
function Overview({type, path, database, databaseFullPath}: OverviewProps) {
const [autoRefreshInterval] = useAutoRefreshInterval();
const useMetaProxy = useClusterWithProxy();
const isV2Navigation = useNavigationV2Enabled();
const {currentData, isFetching, error} = overviewApi.useGetOverviewQuery(
{path, database, databaseFullPath, useMetaProxy},
{pollingInterval: autoRefreshInterval},
);
const isStreamingQuery = type === EPathType.EPathTypeStreamingQuery;
const loading =
isFetching && currentData === undefined && (!isStreamingQuery || error === undefined);
const renderContent = () => {
const data = currentData ?? undefined;
// verbose mapping to guarantee a correct render for new path types
// TS will error when a new type is added but not mapped here
const renderTableInfo = () => (
);
const pathTypeToComponent: Record React.ReactNode) | undefined> = {
[EPathType.EPathTypeInvalid]: undefined,
[EPathType.EPathTypeDir]: undefined,
[EPathType.EPathTypeResourcePool]: () => (
),
[EPathType.EPathTypeSecret]: undefined,
[EPathType.EPathTypeTable]: renderTableInfo,
[EPathType.EPathTypeSysView]: undefined,
[EPathType.EPathTypeSubDomain]: undefined,
[EPathType.EPathTypeTableIndex]: () => ,
[EPathType.EPathTypeExtSubDomain]: undefined,
[EPathType.EPathTypeColumnStore]: renderTableInfo,
[EPathType.EPathTypeColumnTable]: renderTableInfo,
[EPathType.EPathTypeCdcStream]: () => (
),
[EPathType.EPathTypePersQueueGroup]: () => (
),
[EPathType.EPathTypeExternalTable]: undefined,
[EPathType.EPathTypeExternalDataSource]: undefined,
[EPathType.EPathTypeView]: () => ,
[EPathType.EPathTypeReplication]: () => ,
[EPathType.EPathTypeTransfer]: () => (
),
[EPathType.EPathTypeStreamingQuery]: () => (
),
};
const isDatabase =
type === EPathType.EPathTypeSubDomain ||
type === EPathType.EPathTypeExtSubDomain ||
isDomain(path, type);
if (isV2Navigation && isDatabase) {
return ;
}
if (!type || type === EPathType.EPathTypeInvalid) {
return ;
}
const content = pathTypeToComponent[type]?.();
if (isStreamingQuery) {
return content;
}
const commonInfo = (
);
if (!content) {
return commonInfo;
}
return (
{commonInfo}
{content}
);
};
if (loading) {
return ;
}
if (error && !currentData && isStreamingQuery) {
return renderContent();
}
return (
{error ? : null}
{error && !currentData ? null : renderContent()}
);
}
export default Overview;