Line data Source code
1 : import * as React from 'react';
2 : import * as dashql from '@ankoh/dashql-core';
3 :
4 : import type { ConnectionState } from './connection_state.js';
5 : import { useConnectionAllocator } from './connection_registry.js';
6 : import { createAttachedConnectionParamsForConnector, createConnectionStateFromParams } from './connection_params.js';
7 : import { CONNECTOR_INFOS, ConnectorType } from './connector_info.js';
8 :
9 : /// The connectors of the connections that the user attaches next to the embedded Hyper
10 1 : export const ATTACHABLE_CONNECTORS = [ConnectorType.HYPER, ConnectorType.TRINO, ConnectorType.SALESFORCE_DATA_CLOUD, ConnectorType.SIDB] as const;
11 :
12 : /// Allocate a new connection that the user attaches, the user configures it in its settings
13 1 : export function useConnectionAttach(): (dql: dashql.DashQL, connector: ConnectorType) => ConnectionState {
14 1 : const allocate = useConnectionAllocator();
15 1 : return React.useCallback((dql: dashql.DashQL, connector: ConnectorType) => {
16 0 : const params = createAttachedConnectionParamsForConnector(CONNECTOR_INFOS[connector]);
17 0 : return allocate({ ...createConnectionStateFromParams(dql, params), active: true });
18 1 : }, [allocate]);
19 1 : }
|