import React, { ReactNode, PureComponent } from 'react'; import type { ShouldExpandNodeInitially } from 'react-json-tree'; import { ApiStats, QueryPreviewTabs, RtkQueryApiState } from '../types'; import { TreeView, TreeViewProps } from './TreeView'; import { renderTabPanelId, renderTabPanelButtonId } from '../utils/a11y'; export interface QueryPreviewApiProps { apiStats: ApiStats | null; apiState: RtkQueryApiState | null; isWideLayout: boolean; } const rootProps: TreeViewProps['rootProps'] = { 'aria-labelledby': renderTabPanelButtonId(QueryPreviewTabs.apiConfig), id: renderTabPanelId(QueryPreviewTabs.apiConfig), role: 'tabpanel', }; export class QueryPreviewApi extends PureComponent { shouldExpandApiStateNode: ShouldExpandNodeInitially = ( keyPath, value, layer, ) => { const lastKey = keyPath[keyPath.length - 1]; return layer <= 1 && lastKey !== 'config'; }; render(): ReactNode { const { apiStats, isWideLayout, apiState } = this.props; if (!apiState) { return null; } const hasMutations = Object.keys(apiState.mutations).length > 0; const hasQueries = Object.keys(apiState.queries).length > 0; return (
({ display: 'block', overflowY: 'auto', padding: '0.5em 0', color: theme.TAB_CONTENT_COLOR, '& h2': { color: theme.ULIST_STRONG_COLOR, padding: '0.5em 1em', fontWeight: 700, }, '& h3': { color: theme.ULIST_STRONG_COLOR, }, })} >

{apiState.config.reducerPath}

State} data={apiState} shouldExpandNodeInitially={this.shouldExpandApiStateNode} isWideLayout={isWideLayout} /> {apiStats && ( <> Tally} data={apiStats.tally} isWideLayout={isWideLayout} /> {hasQueries && ( Queries Timings} data={apiStats.timings.queries} isWideLayout={isWideLayout} /> )} {hasMutations && ( Mutations Timings} data={apiStats.timings.mutations} isWideLayout={isWideLayout} /> )} )}
); } }