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