import React, { useCallback, useState } from 'react'; import { Badge, Button, Code, css, KeylineCard, palette, rgba, spacing, Subtitle, HorizontalRule, } from '@mongodb-js/compass-components'; import { Clock } from './clock'; interface ExplainStageProps { name: string; nReturned: number; highlights: Record; curStageExecTimeMS: number; prevStageExecTimeMS: number; totalExecTimeMS: number; isShard: boolean; details: Record; x: number; y: number; xoffset: number; yoffset: number; } interface ShardViewProps { name: string; } interface StageViewProps { name: string; nReturned: number; highlights: Record; curStageExecTimeMS: number; prevStageExecTimeMS: number; totalExecTimeMS: number; toggleDetails: () => void; details: Record; detailsOpen: boolean; } interface ExecutionstatsProps { nReturned: number; prevStageExecTimeMS: number; curStageExecTimeMS: number; totalExecTimeMS: number; } let zIndexCounter = 100; function getNewZIndex() { return zIndexCounter++; } const cardStyles = css({ position: 'absolute', width: '276px', padding: spacing[2], }); const separatorStyles = css({ marginTop: spacing[2], marginBottom: spacing[2], }); const contentStyles = css({ position: 'relative' }); const clockStyles = css({ position: 'absolute', top: -(12 + spacing[2]), right: -(30 + spacing[2]), }); const codeStyles = css({ marginTop: spacing[2], }); const executionStatsStyle = css({ position: 'relative', display: 'grid', gridTemplateColumns: '1fr 1fr', }); const ShardView: React.FunctionComponent = (props) => { return {props.name}; }; const Highlights: React.FunctionComponent<{ highlights: Record; }> = ({ highlights }) => { return (
    {Object.entries(highlights).map(([key, value], index) => (
  • {key}: {typeof value === 'boolean' ? (value ? 'yes' : 'no') : value}
  • ))}
); }; const ExecutionStats: React.FunctionComponent = ({ nReturned, prevStageExecTimeMS, curStageExecTimeMS, totalExecTimeMS, }) => { return (
nReturned {nReturned}
Execution Time
); }; const StageView: React.FunctionComponent = (props) => { return ( <> {props.name} {Object.entries(props.highlights).length > 0 && (
)} {props.detailsOpen && (
{JSON.stringify(props.details, null, ' ') || '{}'}
)} ); }; const ExplainStage: React.FunctionComponent = ({ name = '', nReturned = 0, isShard = false, totalExecTimeMS = 1, curStageExecTimeMS = 0, prevStageExecTimeMS = 0, x = 0, y = 0, xoffset = 0, yoffset = 0, highlights = {}, details = {}, }) => { const [detailsOpen, setDetailsOpen] = useState(false); const detailsButtonClicked = useCallback(() => { setDetailsOpen(!detailsOpen); }, [detailsOpen]); return (
{isShard ? ( ) : ( )}
); }; export default ExplainStage;