mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-10-12 23:37:00 +08:00
* CB-2867 dataset plugin * CB-2867 - add original sql query to resultset * CB-2867 move originalQuery to execute info * CB-2867 feat: read originalQuery for query results * CB-2867 refactor: rename scripts plugin & resources tree type filter * CB-2867 fix: import * CB-2867 fix: file extensions type * CB-2867 fix: file extensions type * CB-2867 refactor: data tools bar styles * CB-2867 send query with all filters to gql * CB-2867 chore: implement getKeyRef for CachedMapResource * CB-2867 refactor: ProjectNavNodeService * CB-2867 chore: update go-split * CB-2867 refactor: rename originalQuery to fullQuery * CB-2867 refactor: add resource onUse data * CB-2867 refactor: add sql data source script feature * CB-2867 refactor: add metadata to sql datasource * CB-2867 refactor: add datasource outdate * CB-2867 feat: provided database models for SqlDataSource * CB-2867 fix invalid resource parent node * CB-2867 fix: styles * CB-2867 do not return extra nodes in root navigator model * CB-2867 fix: nav tree project hide for TE single project * CB-2867 fix: pass schema & catalog info to data source * CB-2867 chore: code review --------- Co-authored-by: Aleksey Potsetsuev <wrouds@gmail.com> Co-authored-by: Wroud <wroud@yandex.ru>
65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
/*
|
|
* CloudBeaver - Cloud Database Manager
|
|
* Copyright (C) 2020-2022 DBeaver Corp and others
|
|
*
|
|
* Licensed under the Apache License, Version 2.0.
|
|
* you may not use this file except in compliance with the License.
|
|
*/
|
|
|
|
import { observer } from 'mobx-react-lite';
|
|
import { useContext } from 'react';
|
|
import styled from 'reshadow';
|
|
|
|
import { useStyles } from '@cloudbeaver/core-blocks';
|
|
import { Connection, ConnectionInfoResource } from '@cloudbeaver/core-connections';
|
|
import { useService } from '@cloudbeaver/core-di';
|
|
import { TabIcon, Tab, TabTitle, ITabData } from '@cloudbeaver/core-ui';
|
|
import { CaptureViewContext, useDataContext } from '@cloudbeaver/core-view';
|
|
import type { TabHandlerTabComponent } from '@cloudbeaver/plugin-navigation-tabs';
|
|
import { DATA_CONTEXT_SQL_EDITOR_STATE, getSqlEditorName, ISqlEditorTabState, SqlDataSourceService } from '@cloudbeaver/plugin-sql-editor';
|
|
|
|
import { DATA_CONTEXT_SQL_EDITOR_TAB } from './DATA_CONTEXT_SQL_EDITOR_TAB';
|
|
|
|
export const SqlEditorTab: TabHandlerTabComponent<ISqlEditorTabState> = observer(function SqlEditorTab({
|
|
tab, onSelect, onClose, style,
|
|
}) {
|
|
const viewContext = useContext(CaptureViewContext);
|
|
const tabMenuContext = useDataContext(viewContext);
|
|
|
|
tabMenuContext.set(DATA_CONTEXT_SQL_EDITOR_TAB, true);
|
|
tabMenuContext.set(DATA_CONTEXT_SQL_EDITOR_STATE, tab.handlerState);
|
|
|
|
const sqlDataSourceService = useService(SqlDataSourceService);
|
|
const connectionInfo = useService(ConnectionInfoResource);
|
|
|
|
const dataSource = sqlDataSourceService.get(tab.handlerState.editorId);
|
|
let connection: Connection | undefined;
|
|
|
|
if (dataSource?.executionContext) {
|
|
connection = connectionInfo.get({
|
|
projectId: dataSource.executionContext.projectId,
|
|
connectionId: dataSource.executionContext.connectionId,
|
|
});
|
|
}
|
|
|
|
const name = getSqlEditorName(tab.handlerState, dataSource, connection);
|
|
const icon = dataSource?.icon ?? '/icons/sql_script_m.svg';
|
|
|
|
const handleSelect = ({ tabId }: ITabData<any>) => onSelect(tabId);
|
|
const handleClose = onClose ? ({ tabId }: ITabData<any>) => onClose(tabId) : undefined;
|
|
|
|
return styled(useStyles(style))(
|
|
<Tab
|
|
tabId={tab.id}
|
|
style={style}
|
|
title={name}
|
|
menuContext={tabMenuContext}
|
|
onOpen={handleSelect}
|
|
onClose={handleClose}
|
|
>
|
|
<TabIcon icon={icon} />
|
|
<TabTitle>{name}</TabTitle>
|
|
</Tab>
|
|
);
|
|
});
|