mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 05:26:00 +00:00
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
import _ from 'lodash';
|
|
import { useSetOpenedTabs, useCurrentDatabase } from '../utility/globalState';
|
|
import useOpenNewTab from '../utility/useOpenNewTab';
|
|
|
|
export default function useNewQuery() {
|
|
const openNewTab = useOpenNewTab();
|
|
const currentDatabase = useCurrentDatabase();
|
|
|
|
const connection = _.get(currentDatabase, 'connection') || {};
|
|
const database = _.get(currentDatabase, 'name');
|
|
|
|
const tooltip = `${connection.displayName || connection.server}\n${database}`;
|
|
|
|
return ({ title = undefined, initialData = undefined, ...props } = {}) =>
|
|
openNewTab(
|
|
{
|
|
title: title || 'Query',
|
|
icon: 'img sql-file',
|
|
tooltip,
|
|
tabComponent: 'QueryTab',
|
|
props: {
|
|
...props,
|
|
conid: connection._id,
|
|
database,
|
|
},
|
|
},
|
|
{ editor: initialData }
|
|
);
|
|
}
|
|
|
|
export function useNewQueryDesign() {
|
|
const openNewTab = useOpenNewTab();
|
|
const currentDatabase = useCurrentDatabase();
|
|
|
|
const connection = _.get(currentDatabase, 'connection') || {};
|
|
const database = _.get(currentDatabase, 'name');
|
|
|
|
const tooltip = `${connection.displayName || connection.server}\n${database}`;
|
|
|
|
return ({ title = undefined, initialData = undefined, ...props } = {}) =>
|
|
openNewTab(
|
|
{
|
|
title: title || 'Query',
|
|
icon: 'img query-design',
|
|
tooltip,
|
|
tabComponent: 'QueryDesignTab',
|
|
props: {
|
|
...props,
|
|
conid: connection._id,
|
|
database,
|
|
},
|
|
},
|
|
{ editor: initialData }
|
|
);
|
|
}
|