LCOV - code coverage report
Current view: top level - dashql-app/src/connections - connection_engine_facts.tsx Coverage Total Hit
Test: DashQL 915828b Lines: 17.5 % 40 7
Test Date: 2026-11-06 19:30:32

            Line data    Source code
       1              : import * as React from 'react';
       2              : 
       3              : import { useEmbeddedDatabaseSetup } from '../platform/database/embedded_database_provider.js';
       4              : import type { ConnectionState } from './connection_state.js';
       5              : 
       6              : /// The version of the embedded Hyper, null until it is read or for a remote Hyper
       7            0 : function useEmbeddedHyperVersion(embedded: boolean): string | null {
       8            0 :     const setupDatabase = useEmbeddedDatabaseSetup();
       9            0 :     const [version, setVersion] = React.useState<string | null>(null);
      10            0 :     React.useEffect(() => {
      11            0 :         if (!embedded) {
      12            0 :             setVersion(null);
      13            0 :             return;
      14            0 :         }
      15            0 :         let cancelled = false;
      16            0 :         setupDatabase('connection_overview')
      17            0 :             .then(database => database.getVersion())
      18            0 :             .then(v => { if (!cancelled) setVersion(v); })
      19            0 :             .catch(() => { if (!cancelled) setVersion(null); });
      20            0 :         return () => { cancelled = true; };
      21            0 :     }, [setupDatabase, embedded]);
      22            0 :     return version;
      23            0 : }
      24              : 
      25              : /// The names of the protocols of the Hyper connections
      26            1 : const HYPER_PROTOCOL_NAMES: Record<string, string> = {
      27            1 :     WASM: 'embedded (WebAssembly)',
      28            1 :     V3_GRPC: 'gRPC',
      29            1 :     V3_HTTP: 'HTTP',
      30            1 :     V3_HTTP_LINK: 'HTTP link',
      31            1 : };
      32              : 
      33              : interface Props {
      34              :     /// The connection
      35              :     connection: ConnectionState;
      36              : }
      37              : 
      38              : /// The facts about the Hyper of a connection: its version or endpoint and the protocol
      39            1 : export const ConnectionEngineFacts: React.FC<Props> = ({ connection }) => {
      40            0 :     const params = 'hyper' in connection.params ? connection.params.hyper : null;
      41            0 :     const embedded = params?.protocol === 'WASM';
      42            0 :     const version = useEmbeddedHyperVersion(embedded);
      43            0 :     const protocol = HYPER_PROTOCOL_NAMES[params?.protocol ?? 'WASM'] ?? params?.protocol;
      44            0 :     return (
      45            0 :         <span data-testid="connection-engine">
      46            0 :             <span data-testid="detail-version">{version == null ? 'Hyper' : `Hyper ${version}`}</span>
      47            0 :             {' · '}
      48            0 :             <span data-testid="detail-engine">{protocol}</span>
      49            0 :             {!embedded && params?.endpoint && (
      50            0 :                 <>
      51            0 :                     {' · '}
      52            0 :                     <span title={params.endpoint} data-testid="detail-endpoint">{params.endpoint}</span>
      53            0 :                 </>
      54              :             )}
      55            0 :         </span>
      56              :     );
      57            0 : };
        

Generated by: LCOV version 2.0-1