import { useMemo } from 'react'; import React from 'react'; import { Body, Subtitle, css, Icon, KeylineCard, IndexKeysBadge, palette, spacing, useDarkMode, } from '@mongodb-js/compass-components'; interface IndexModel { fields: { serialize: () => { field: string; value: unknown; }[]; }; } type IndexType = 'COLLSCAN' | 'COVERED' | 'MULTIPLE' | 'INDEX' | 'UNAVAILABLE'; interface ExplainSummaryProps { nReturned: number; totalKeysExamined: number; totalDocsExamined: number; executionTimeMillis: number; inMemorySort: boolean; indexType: IndexType; index?: IndexModel; } const SummaryIndexStat: React.FC<{ indexType: IndexType; index?: IndexModel; className?: string; }> = ({ indexType, index, className }) => { const darkMode = useDarkMode(); const warningColor = darkMode ? palette.yellow.base : palette.yellow.dark2; const successColor = darkMode ? palette.green.base : palette.green.dark2; const indexMessageText = useMemo(() => { const typeToMessage = { COLLSCAN: 'No index available for this query.', COVERED: 'Query covered by index:', MULTIPLE: 'Shard results differ (see details below)', INDEX: 'Query used the following index:', UNAVAILABLE: '', }; return typeToMessage[indexType]; }, [indexType]); const indexMessageIcon = useMemo(() => { const checkMarkIcon = ; const warningIcon = ; const typeToIcon = { COLLSCAN: warningIcon, COVERED: checkMarkIcon, MULTIPLE: warningIcon, INDEX: null, UNAVAILABLE: null, }; return typeToIcon[indexType]; }, [indexType]); const typeToColor = { COLLSCAN: warningColor, COVERED: successColor, MULTIPLE: warningColor, INDEX: undefined, UNAVAILABLE: undefined, }; return (
{indexMessageIcon}{' '} {indexMessageText}{' '} {index ? ( ) : null}
); }; const SummaryStat: React.FunctionComponent<{ 'data-testid'?: string; label: string; value: unknown; className?: string; }> = ({ 'data-testid': dataTestId, label, value, className }) => ( {label}{' '} {value} ); const explainSummaryStyles = css({ padding: spacing[3] }); const columnStyles = css({ display: 'grid', gridTemplateColumns: '1fr 1fr', gridGap: spacing[2], marginTop: spacing[2], }); const rowStyles = css({ marginTop: spacing[2] }); const ExplainSummary: React.FC = ({ nReturned, totalKeysExamined, totalDocsExamined, executionTimeMillis, inMemorySort, indexType, index, }) => { const inMemorySortValue = inMemorySort ? 'yes' : 'no'; return ( Query Performance Summary
); }; export default ExplainSummary;