mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 23:53:57 +00:00
public cloud improvements
This commit is contained in:
@@ -11,32 +11,42 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { apiCall } from '../utility/api';
|
import { apiCall } from '../utility/api';
|
||||||
import newQuery from '../query/newQuery';
|
import newQuery from '../query/newQuery';
|
||||||
import { filterName } from 'dbgate-tools';
|
import { filterName, getSqlFrontMatter, setSqlFrontMatter } from 'dbgate-tools';
|
||||||
import { currentActiveCloudTags } from '../stores';
|
import { currentActiveCloudTags } from '../stores';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import yaml from 'js-yaml';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
async function handleOpenSqlFile() {
|
async function handleOpenSqlFile() {
|
||||||
const fileData = await apiCall('cloud/public-file-data', { path: data.path });
|
const fileData = await apiCall('cloud/public-file-data', { path: data.path });
|
||||||
|
let queryText = fileData.text;
|
||||||
|
if (!relatedToCurrentConnection) {
|
||||||
|
const frontMatter = getSqlFrontMatter(fileData.text, yaml);
|
||||||
|
if (frontMatter?.autoExecute) {
|
||||||
|
queryText = setSqlFrontMatter(fileData.text, _.omit(frontMatter, 'autoExecute'), yaml);
|
||||||
|
}
|
||||||
|
}
|
||||||
newQuery({
|
newQuery({
|
||||||
initialData: fileData.text,
|
initialData: queryText,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMenu() {
|
function createMenu() {
|
||||||
return [{ text: 'Open', onClick: handleOpenSqlFile }];
|
return [{ text: 'Open', onClick: handleOpenSqlFile }];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: relatedToCurrentConnection = _.intersection($currentActiveCloudTags, data.tags || []).length > 0;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<AppObjectCore
|
<AppObjectCore
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
{data}
|
{data}
|
||||||
icon={'img sql-file'}
|
icon={data.icon ?? 'img sql-file'}
|
||||||
title={data.title}
|
title={data.title}
|
||||||
menu={createMenu}
|
menu={createMenu}
|
||||||
on:click={handleOpenSqlFile}
|
on:click={handleOpenSqlFile}
|
||||||
isGrayed={_.intersection($currentActiveCloudTags, data.tags || []).length == 0}
|
isGrayed={!relatedToCurrentConnection}
|
||||||
data-testid={`public-cloud-file-${data.path}`}
|
data-testid={`public-cloud-file-${data.path}`}
|
||||||
>
|
>
|
||||||
{#if data.description}
|
{#if data.description}
|
||||||
|
|||||||
@@ -565,7 +565,7 @@
|
|||||||
|
|
||||||
onInitialData: value => {
|
onInitialData: value => {
|
||||||
const frontMatter = getSqlFrontMatter(value, yaml);
|
const frontMatter = getSqlFrontMatter(value, yaml);
|
||||||
if (frontMatter?.autoExecute) {
|
if (frontMatter?.autoExecute && hasConnection() && !isBusy()) {
|
||||||
executeCore(value, 0);
|
executeCore(value, 0);
|
||||||
}
|
}
|
||||||
if (frontMatter?.splitterInitialValue) {
|
if (frontMatter?.splitterInitialValue) {
|
||||||
|
|||||||
Reference in New Issue
Block a user