Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: optimize (#16056)

ecmadao14afdb2b3950
diff --git a/backend/api/v1/instance_service.go b/backend/api/v1/instance_service.go
index 5bc5cd902b..aa0adddbf0 100644
--- a/backend/api/v1/instance_service.go
+++ b/backend/api/v1/instance_service.go
@@ -155,12 +155,17 @@ func parseListInstanceFilter(filter string) (*store.ListResourceFilter, error) {
if !ok {
return "", status.Errorf(codes.InvalidArgument, "expect string, got %T, hint: filter literals should be string", value)
}
+ if strValue == "" {
+ return "", status.Errorf(codes.InvalidArgument, `empty value for %q`, variable)
+ }
switch variable {
case "name":
return "LOWER(instance.metadata->>'title') LIKE '%" + strings.ToLower(strValue) + "%'", nil
case "resource_id":
return "LOWER(instance.resource_id) LIKE '%" + strings.ToLower(strValue) + "%'", nil
+ case "host", "port":
+ return "ds ->> '" + variable + "' LIKE '%" + strValue + "%'", nil
default:
return "", status.Errorf(codes.InvalidArgument, "unsupport variable %q", variable)
}
diff --git a/frontend/src/components/v2/Model/DatabaseV1Name.vue b/frontend/src/components/v2/Model/DatabaseV1Name.vue
index bd13577b8d..fda970e6df 100644
--- a/frontend/src/components/v2/Model/DatabaseV1Name.vue
+++ b/frontend/src/components/v2/Model/DatabaseV1Name.vue
@@ -8,8 +8,7 @@
shouldShowLink && 'hover:underline',
]"
>
- <!-- eslint-disable-next-line vue/no-v-html -->
- <span v-html="renderedDatabaseName" />
+ <HighlightLabelText :text="database.databaseName" :keyword="keyword" />
<span
v-if="showNotFound && database.state === State.DELETED"
class="text-control-placeholder"
@@ -25,7 +24,8 @@ import { computed } from "vue";
import { useRouter } from "vue-router";
import type { ComposedDatabase } from "@/types";
import { State } from "@/types/proto/v1/common";
-import { autoDatabaseRoute, getHighlightHTMLByRegExp } from "@/utils";
+import { autoDatabaseRoute } from "@/utils";
+import HighlightLabelText from "./HighlightLabelText.vue";
const props = withDefaults(
defineProps<{
@@ -61,8 +61,4 @@ const bindings = computed(() => {
}
return {};
});
-
-const renderedDatabaseName = computed(() => {
- return getHighlightHTMLByRegExp(props.database.databaseName, props.keyword);
-});
</script>
diff --git a/frontend/src/components/v2/Model/EnvironmentV1Name.vue b/frontend/src/components/v2/Model/EnvironmentV1Name.vue
index fe3013d517..a7287072dc 100644
--- a/frontend/src/components/v2/Model/EnvironmentV1Name.vue
+++ b/frontend/src/components/v2/Model/EnvironmentV1Name.vue
@@ -7,8 +7,10 @@
>
<span class="line-clamp-1 select-none" :class="textClass">
{{ prefix }}
- <!-- eslint-disable-next-line vue/no-v-html -->
- <span v-html="renderedEnvironmentName" />
+ <HighlightLabelText
+ :text="environmentV1Name(environment)"
+ :keyword="keyword"
+ />
<slot name="suffix">
{{ suffix }}
</slot>
@@ -27,11 +29,8 @@ import { computed } from "vue";
import { useRouter } from "vue-router";
import type { Environment } from "@/types/v1/environment";
import type { VueClass } from "@/utils";
-import {
- autoEnvironmentRoute,
- environmentV1Name,
- getHighlightHTMLByRegExp,
-} from "@/utils";
+import { autoEnvironmentRoute, environmentV1Name } from "@/utils";
+import HighlightLabelText from "./HighlightLabelText.vue";
import ProductionEnvironmentV1Icon from "./ProductionEnvironmentV1Icon.vue";
const props = withDefaults(
@@ -79,11 +78,4 @@ const bindings = computed(() => {
}
return {};
});
-
-const renderedEnvironmentName = computed(() => {
- return getHighlightHTMLByRegExp(
- environmentV1Name(props.environment),
- props.keyword
- );
-});
</script>
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/HighlightLabelText.vue b/frontend/src/components/v2/Model/HighlightLabelText.vue
similarity index 100%
rename from frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/HighlightLabelText.vue
rename to frontend/src/components/v2/Model/HighlightLabelText.vue
diff --git a/frontend/src/components/v2/Model/Instance/InstanceV1Name.vue b/frontend/src/components/v2/Model/Instance/InstanceV1Name.vue
index c8edd060d5..998904b751 100644
--- a/frontend/src/components/v2/Model/Instance/InstanceV1Name.vue
+++ b/frontend/src/components/v2/Model/Instance/InstanceV1Name.vue
@@ -16,7 +16,7 @@
<slot name="prefix" />
<NEllipsis :disabled="!tooltip" :line-clamp="1" :class="textClass">
- {{ instanceV1Name(instance) }}
+ <HighlightLabelText :text="instanceV1Name(instance)" :keyword="keyword" />
</NEllipsis>
<InstanceV1EngineIcon
@@ -39,6 +39,7 @@ import {
hasWorkspacePermissionV2,
instanceV1Name,
} from "@/utils";
+import HighlightLabelText from "../HighlightLabelText.vue";
import InstanceV1EngineIcon from "./InstanceV1EngineIcon.vue";
const props = withDefaults(
@@ -51,6 +52,7 @@ const props = withDefaults(
tooltip?: boolean;
iconPosition?: "prefix" | "suffix";
textClass?: string;
+ keyword?: string;
}>(),
{
tag: "span",
@@ -60,6 +62,7 @@ const props = withDefaults(
tooltip: true,
iconPosition: "prefix",
textClass: "",
+ keyword: "",
}
);
const router = useRouter();
diff --git a/frontend/src/components/v2/Model/ProjectV1Name.vue b/frontend/src/components/v2/Model/ProjectV1Name.vue
index bde929ce8b..87bdcf4c9f 100644
--- a/frontend/src/components/v2/Model/ProjectV1Name.vue
+++ b/frontend/src/components/v2/Model/ProjectV1Name.vue
@@ -6,8 +6,7 @@
:class="link && !plain && 'normal-link'"
>
<NPerformantEllipsis>
- <!-- eslint-disable-next-line vue/no-v-html -->
- <span v-html="renderedProjectName" />
+ <HighlightLabelText :text="projectV1Name(project)" :keyword="keyword" />
</NPerformantEllipsis>
</component>
</template>
@@ -17,11 +16,8 @@ import { NPerformantEllipsis } from "naive-ui";
import { computed } from "vue";
import { useRouter } from "vue-router";
import type { Project } from "@/types/proto/v1/project_service";
-import {
- autoProjectRoute,
- getHighlightHTMLByRegExp,
- projectV1Name,
-} from "@/utils";
+import { autoProjectRoute, projectV1Name } from "@/utils";
+import HighlightLabelText from "./HighlightLabelText.vue";
const props = withDefaults(
defineProps<{
@@ -55,8 +51,4 @@ const bindings = computed(() => {
}
return {};
});
-
-const renderedProjectName = computed(() => {
- return getHighlightHTMLByRegExp(projectV1Name(props.project), props.keyword);
-});
</script>
diff --git a/frontend/src/components/v2/Model/ProjectV1Table.vue b/frontend/src/components/v2/Model/ProjectV1Table.vue
index dea2af0140..a98a5266f3 100644
--- a/frontend/src/components/v2/Model/ProjectV1Table.vue
+++ b/frontend/src/components/v2/Model/ProjectV1Table.vue
@@ -29,7 +29,8 @@ import { PROJECT_V1_ROUTE_DASHBOARD } from "@/router/dashboard/workspaceRoutes";
import { getProjectName } from "@/store/modules/v1/common";
import type { ComposedProject } from "@/types";
import type { Project } from "@/types/proto/v1/project_service";
-import { extractProjectResourceName, getHighlightHTMLByRegExp } from "@/utils";
+import { extractProjectResourceName } from "@/utils";
+import HighlightLabelText from "./HighlightLabelText.vue";
type ProjectDataTableColumn = DataTableColumn<ComposedProject> & {
hide?: boolean;
@@ -91,12 +92,10 @@ const columnList = computed((): ProjectDataTableColumn[] => {
ellipsis: true,
render: (project) => {
return (
- <span
- innerHTML={getHighlightHTMLByRegExp(
- extractProjectResourceName(project.name),
- props.keyword ?? ""
- )}
- ></span>
+ <HighlightLabelText
+ text={extractProjectResourceName(project.name)}
+ keyword={props.keyword ?? ""}
+ />
);
},
},
diff --git a/frontend/src/components/v2/Model/RichDatabaseName.vue b/frontend/src/components/v2/Model/RichDatabaseName.vue
index 1602ea4e62..35a2eca61a 100644
--- a/frontend/src/components/v2/Model/RichDatabaseName.vue
+++ b/frontend/src/components/v2/Model/RichDatabaseName.vue
@@ -1,7 +1,7 @@
<template>
<NPopover :disabled="!tooltip">
<template #trigger>
- <div class="flex flex-row justify-start items-center gap-x-1">
+ <div class="flex flex-row justify-start items-center">
<div v-if="showProject">
<ProjectV1Name :project="database.projectEntity" :link="false" />
</div>
@@ -44,6 +44,7 @@
:database="database"
:link="false"
:show-icon="false"
+ :keyword="keyword"
/>
</div>
</div>
@@ -76,6 +77,7 @@ withDefaults(
showEnvironment?: boolean;
showProductionEnvironmentIcon?: boolean;
tooltip?: "instance" | undefined;
+ keyword?: string;
}>(),
{
showProject: false,
@@ -85,6 +87,7 @@ withDefaults(
showEnvironment: true,
showProductionEnvironmentIcon: true,
tooltip: undefined,
+ keyword: "",
}
);
</script>
diff --git a/frontend/src/components/v2/Model/index.ts b/frontend/src/components/v2/Model/index.ts
index 1d6221a0f5..570a1a581d 100644
--- a/frontend/src/components/v2/Model/index.ts
+++ b/frontend/src/components/v2/Model/index.ts
@@ -2,6 +2,7 @@ import DatabaseV1Name from "./DatabaseV1Name.vue";
import DatabaseView from "./DatabaseView.vue";
import EnvironmentV1Name from "./EnvironmentV1Name.vue";
import EnvironmentV1Table from "./EnvironmentV1Table.vue";
+import HighlightLabelText from "./HighlightLabelText.vue";
import RichEngineName from "./Instance/RichEngineName.vue";
import PagedProjectTable from "./PagedProjectTable.vue";
import ProductionEnvironmentV1Icon from "./ProductionEnvironmentV1Icon.vue";
@@ -23,4 +24,5 @@ export {
PagedProjectTable,
DatabaseView,
RichEngineName,
+ HighlightLabelText,
};
diff --git a/frontend/src/store/modules/v1/instance.ts b/frontend/src/store/modules/v1/instance.ts
index 7d826a5ef9..53c4b0fdfc 100644
--- a/frontend/src/store/modules/v1/instance.ts
+++ b/frontend/src/store/modules/v1/instance.ts
@@ -40,10 +40,10 @@ const getListInstanceFilter = (params: InstanceFilter) => {
list.push(`environment == "${params.environment}"`);
}
if (params.host) {
- list.push(`host == "${params.host}"`);
+ list.push(`host.matches("${params.host}")`);
}
if (params.port) {
- list.push(`port == "${params.port}"`);
+ list.push(`port.matches("${params.port}")`);
}
if (params.engines && params.engines.length > 0) {
// engine filter should be:
diff --git a/frontend/src/types/proto/v1/instance_service.ts b/frontend/src/types/proto/v1/instance_service.ts
index 89cc0860ff..c97577e6a8 100644
--- a/frontend/src/types/proto/v1/instance_service.ts
+++ b/frontend/src/types/proto/v1/instance_service.ts
@@ -113,8 +113,8 @@ export interface ListInstancesRequest {
* - environment: the environment full name in "environments/{id}" format, support "==" operator.
* - state: the instance state, check State enum for values, support "==" operator.
* - engine: the instance engine, check Engine enum for values. Support "==", "in [xx]", "!(in [xx])" operator.
- * - host: the instance host, support "==" operator.
- * - port: the instance port, support "==" operator.
+ * - host: the instance host, support "==" and ".matches()" operator.
+ * - port: the instance port, support "==" and ".matches()" operator.
* - project: the project full name in "projects/{id}" format, support "==" operator.
*
* For example:
@@ -128,7 +128,9 @@ export interface ListInstancesRequest {
* engine in ["MYSQL", "POSTGRES"]
* !(engine in ["MYSQL", "POSTGRES"])
* host == "127.0.0.1"
+ * host.matches("127.0")
* port == "54321"
+ * port.matches("543")
* project == "projects/sample-project"
* You can combine filter conditions like:
* name.matches("sample") && environment == "environments/test"
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/CommonNode.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/CommonNode.vue
index ffab53f294..8e995ab044 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/CommonNode.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/CommonNode.vue
@@ -29,7 +29,7 @@
</template>
<script setup lang="ts">
-import HighlightLabelText from "./HighlightLabelText.vue";
+import { HighlightLabelText } from "@/components/v2";
defineProps<{
text: string;
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
index 3b3b05dbd3..c5e0923a47 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
@@ -8,7 +8,7 @@
{{
$t("sql-editor.batch-query.description", {
count: state.selectedDatabases.size,
- project: editorStore.project,
+ project: project.title,
})
}}
</div>
@@ -57,7 +57,7 @@
>
<div
v-if="treeStore.state === 'READY'"
- class="flex flex-col space-y-2 pb-4"
+ class="flex flex-col space-y-2 pt-2 pb-4"
>
<NTree
ref="treeRef"
@@ -65,7 +65,6 @@
:data="treeStore.tree"
:show-irrelevant-nodes="false"
:selected-keys="selectedKeys"
- :pattern="mounted ? state.params.query : ''"
:default-expand-all="true"
:expand-on-click="true"
:node-props="nodeProps"
@@ -122,7 +121,7 @@
</template>
<script lang="ts" setup>
-import { useElementSize, useMounted } from "@vueuse/core";
+import { useElementSize } from "@vueuse/core";
import { head } from "lodash-es";
import {
NTag,
@@ -143,6 +142,8 @@ import { RichDatabaseName } from "@/components/v2";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import {
hasFeature,
+ batchGetOrFetchDatabases,
+ useProjectV1Store,
useDatabaseV1Store,
useSQLEditorTabStore,
resolveOpeningDatabaseListFromSQLEditorTabList,
@@ -191,6 +192,7 @@ const treeStore = useSQLEditorTreeStore();
const tabStore = useSQLEditorTabStore();
const editorStore = useSQLEditorStore();
const databaseStore = useDatabaseV1Store();
+const projectStore = useProjectV1Store();
const hasBatchQueryFeature = computed(() =>
hasFeature("bb.feature.batch-query")
@@ -207,12 +209,13 @@ const state = reactive<LocalState>({
watch(
() => tabStore.currentTab?.id,
- () => {
+ async () => {
if (!tabStore.currentTab) {
return;
}
const databases = tabStore.currentTab.batchQueryContext?.databases ?? [];
databases.push(tabStore.currentTab.connection.database);
+ await batchGetOrFetchDatabases(databases);
state.selectedDatabases = new Set(databases);
},
{
@@ -254,6 +257,10 @@ const scopeOptions = useCommonSearchScopeOptions([
"engine",
]);
+const project = computed(() =>
+ projectStore.getProjectByName(editorStore.project)
+);
+
const editorContext = useSQLEditorContext();
const { events: editorEvents, showConnectionPanel } = editorContext;
const {
@@ -270,7 +277,6 @@ const {
handleClickoutside: handleDropdownClickoutside,
} = useDropdown();
-const mounted = useMounted();
const treeContainerElRef = ref<HTMLElement>();
const { height: treeContainerHeight } = useElementSize(
treeContainerElRef,
@@ -314,31 +320,30 @@ const { hasMissingQueryDatabases, showMissingQueryDatabases } =
// dynamic render the highlight keywords
const renderLabel = ({ option }: { option: TreeOption }) => {
const node = option as SQLEditorTreeNode;
- let checked = false;
+ let databaseName = "";
if (node.meta.type === "database") {
- checked = state.selectedDatabases.has(
- (node as SQLEditorTreeNode<"database">).meta.target.name
- );
+ databaseName = (node as SQLEditorTreeNode<"database">).meta.target.name;
}
+
return h(Label, {
node,
- checked,
+ checked: state.selectedDatabases.has(databaseName),
factors: treeStore.filteredFactorList,
keyword: state.params.query,
+ connected: connectedDatabases.value.has(databaseName),
connectedDatabases: connectedDatabases.value,
"onUpdate:checked": (checked: boolean) => {
if (node.meta.type !== "database") {
return;
}
- const dbName = (node as SQLEditorTreeNode<"database">).meta.target.name;
if (checked) {
if (!hasBatchQueryFeature.value) {
state.showFeatureModal = true;
return;
}
- state.selectedDatabases.add(dbName);
+ state.selectedDatabases.add(databaseName);
} else {
- state.selectedDatabases.delete(dbName);
+ state.selectedDatabases.delete(databaseName);
}
},
});
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/DatabaseNode.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/DatabaseNode.vue
index 09083b6eab..b2f7b43c8a 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/DatabaseNode.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/DatabaseNode.vue
@@ -8,28 +8,17 @@
@update:checked="$emit('update:checked', $event)"
/>
- <InstanceV1EngineIcon
- v-if="!hasInstanceContext"
- :instance="database.instanceResource"
+ <RichDatabaseName
+ :database="database"
+ :show-instance="!hasInstanceContext"
+ :show-engine-icon="!hasInstanceContext"
+ :show-environment="showEnvironment"
+ :show-arrow="true"
+ :keyword="keyword"
/>
- <EnvironmentV1Name
- v-if="showEnvironment"
- :environment="database.effectiveEnvironmentEntity"
- :link="false"
- class="text-control-light"
- />
-
- <DatabaseIcon />
-
- <span class="flex-1 truncate">
- <HighlightLabelText :text="database.databaseName" :keyword="keyword" />
- <span v-if="!hasInstanceContext" class="text-control-light">
- ({{ database.instanceResource.title }})
- </span>
- <span v-if="connected" class="textinfolabel">
- ({{ $t("sql-editor.connected") }})
- </span>
+ <span v-if="connected" class="truncate textinfolabel">
+ ({{ $t("sql-editor.connected") }})
</span>
<RequestQueryButton
v-if="showRequestQueryButton"
@@ -44,8 +33,7 @@
<script setup lang="ts">
import { NCheckbox } from "naive-ui";
import { computed } from "vue";
-import DatabaseIcon from "~icons/heroicons-outline/circle-stack";
-import { EnvironmentV1Name, InstanceV1EngineIcon } from "@/components/v2";
+import { RichDatabaseName } from "@/components/v2";
import { hasFeature, useAppFeature, useSQLEditorTabStore } from "@/store";
import type {
SQLEditorTreeNode as TreeNode,
@@ -53,13 +41,12 @@ import type {
} from "@/types";
import { isDatabaseV1Queryable } from "@/utils";
import RequestQueryButton from "../../../EditorCommon/ResultView/RequestQueryButton.vue";
-import HighlightLabelText from "./HighlightLabelText.vue";
const props = defineProps<{
node: TreeNode;
factors: Factor[];
keyword: string;
- connected: boolean;
+ connected?: boolean;
checked?: boolean;
}>();
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/EnvironmentNode.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/EnvironmentNode.vue
deleted file mode 100644
index 9262d52cf2..0000000000
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/EnvironmentNode.vue
+++ /dev/null
@@ -1,26 +0,0 @@
-<template>
- <div class="truncate leading-5">
- <HighlightLabelText :text="environment.title" :keyword="keyword" />
- <ProductionEnvironmentV1Icon :environment="environment" class="ml-1" />
- </div>
-</template>
-
-<script setup lang="ts">
-import { computed } from "vue";
-import { ProductionEnvironmentV1Icon } from "@/components/v2";
-import type {
- SQLEditorTreeNode as TreeNode,
- SQLEditorTreeFactor as Factor,
-} from "@/types";
-import HighlightLabelText from "./HighlightLabelText.vue";
-
-const props = defineProps<{
- node: TreeNode;
- factors: Factor[];
- keyword: string;
-}>();
-
-const environment = computed(
- () => (props.node as TreeNode<"environment">).meta.target
-);
-</script>
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/HighlightLabelText.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/HighlightLabelText.vue
deleted file mode 100644
index 31fb8fa6af..0000000000
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/HighlightLabelText.vue
+++ /dev/null
@@ -1,24 +0,0 @@
-<template>
- <span v-if="!keyword.trim()" v-bind="$attrs">{{ text }}</span>
- <!-- eslint-disable-next-line vue/no-v-html -->
- <span v-else v-bind="$attrs" v-html="html" />
-</template>
-
-<script lang="ts" setup>
-import { escape } from "lodash-es";
-import { computed } from "vue";
-import { getHighlightHTMLByRegExp } from "@/utils";
-
-const props = defineProps<{
- text: string;
- keyword: string;
-}>();
-
-const html = computed(() => {
- return getHighlightHTMLByRegExp(
- escape(props.text),
- escape(props.keyword.trim()),
- false /* !caseSensitive */
- );
-});
-</script>
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/InstanceNode.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/InstanceNode.vue
index afc34b85f9..eb2247fcf8 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/InstanceNode.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/InstanceNode.vue
@@ -1,29 +1,23 @@
<template>
<div class="flex items-center max-w-full overflow-hidden gap-x-1">
- <InstanceV1EngineIcon :instance="instance" />
<EnvironmentV1Name
v-if="!hasEnvironmentContext"
:environment="environment"
:link="false"
class="text-control-light"
/>
- <HighlightLabelText
- :text="instance.title"
- :keyword="keyword"
- class="flex-1 truncate"
- />
+ <InstanceV1Name :link="false" :instance="instance" :keyword="keyword" />
</div>
</template>
<script setup lang="ts">
import { computed } from "vue";
-import { EnvironmentV1Name, InstanceV1EngineIcon } from "@/components/v2";
+import { EnvironmentV1Name, InstanceV1Name } from "@/components/v2";
import { useEnvironmentV1Store } from "@/store";
import type {
SQLEditorTreeNode as TreeNode,
SQLEditorTreeFactor as Factor,
} from "@/types";
-import HighlightLabelText from "./HighlightLabelText.vue";
const props = defineProps<{
node: TreeNode;
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/Label.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/Label.vue
index 0a332195bf..1306a86909 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/Label.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/Label.vue
@@ -3,7 +3,11 @@
<InstanceNode :node="node" :factors="factors" :keyword="keyword" />
</template>
<template v-if="type === 'environment'">
- <EnvironmentNode :node="node" :factors="factors" :keyword="keyword" />
+ <EnvironmentV1Name
+ :environment="(node as TreeNode<'environment'>).meta.target"
+ :keyword="keyword"
+ :link="false"
+ />
</template>
<template v-if="type === 'database'">
<DatabaseNode
@@ -11,24 +15,21 @@
:node="node"
:factors="factors"
:keyword="keyword"
- :connected="
- connectedDatabases.has((node as TreeNode<'database'>).meta.target.name)
- "
/>
</template>
<template v-if="type === 'label'">
- <LabelNode :node="node" :factors="factors" :keyword="keyword" />
+ <LabelNode :node="node" :keyword="keyword" />
</template>
</template>
<script lang="ts" setup>
import { computed } from "vue";
+import { EnvironmentV1Name } from "@/components/v2";
import type {
SQLEditorTreeNode as TreeNode,
SQLEditorTreeFactor as Factor,
} from "@/types";
import DatabaseNode from "./DatabaseNode.vue";
-import EnvironmentNode from "./EnvironmentNode.vue";
import InstanceNode from "./InstanceNode.vue";
import LabelNode from "./LabelNode.vue";
@@ -36,7 +37,6 @@ const props = defineProps<{
node: TreeNode;
factors: Factor[];
keyword: string;
- connectedDatabases: Set<string>;
}>();
const type = computed(() => props.node.meta.type);
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/LabelNode.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/LabelNode.vue
index 92d09a8976..83d4f7d6d1 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/LabelNode.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/LabelNode.vue
@@ -15,15 +15,11 @@
<script setup lang="ts">
import { computed } from "vue";
-import type {
- SQLEditorTreeNode as TreeNode,
- SQLEditorTreeFactor as Factor,
-} from "@/types";
-import HighlightLabelText from "./HighlightLabelText.vue";
+import { HighlightLabelText } from "@/components/v2";
+import type { SQLEditorTreeNode as TreeNode } from "@/types";
const props = defineProps<{
node: TreeNode;
- factors: Factor[];
keyword: string;
}>();
diff --git a/frontend/src/views/sql-editor/EditorPanel/ResultPanel/BatchQuerySelect.vue b/frontend/src/views/sql-editor/EditorPanel/ResultPanel/BatchQuerySelect.vue
index c6b00a0456..598682cc81 100644
--- a/frontend/src/views/sql-editor/EditorPanel/ResultPanel/BatchQuerySelect.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/ResultPanel/BatchQuerySelect.vue
@@ -21,45 +21,35 @@
</template>
</NTooltip>
- <NTooltip
+ <NButton
v-for="item in filteredItems"
:key="item.database.name"
- trigger="hover"
+ secondary
+ strong
+ size="small"
+ :type="'default'"
+ :style="{
+ ...getBackgroundColorRgb(item.database),
+ borderTop: selectedDatabase === item.database ? '3px solid' : '',
+ }"
+ @click="$emit('update:selected-database', item.database)"
>
- <template #trigger>
- <NButton
- secondary
- strong
- size="small"
- :type="selectedDatabase === item.database ? 'primary' : 'default'"
- @click="$emit('update:selected-database', item.database)"
- >
- <InstanceV1EngineIcon
- :instance="item.database.instanceResource"
- :tooltip="false"
- />
- <span class="mx-2 opacity-60">{{
- item.database.effectiveEnvironmentEntity.title
- }}</span>
- <span>{{ item.database.databaseName }}</span>
- <InfoIcon
- v-if="isDatabaseQueryFailed(item.database)"
- class="ml-1 text-yellow-600 w-4 h-auto"
- />
- <span
- v-if="isEmptyQueryItem(item)"
- class="text-control-placeholder italic ml-1"
- >
- ({{ $t("common.empty") }})
- </span>
- <XIcon
- class="ml-1 text-gray-400 w-4 h-auto hover:text-gray-600"
- @click.stop="handleCloseSingleResultView(item.database)"
- />
- </NButton>
- </template>
- {{ item.database.instanceResource.title }}
- </NTooltip>
+ <RichDatabaseName :database="item.database" />
+ <InfoIcon
+ v-if="isDatabaseQueryFailed(item.database)"
+ class="ml-1 text-yellow-600 w-4 h-auto"
+ />
+ <span
+ v-if="isEmptyQueryItem(item)"
+ class="text-control-placeholder italic ml-1"
+ >
+ ({{ $t("common.empty") }})
+ </span>
+ <XIcon
+ class="ml-1 text-gray-400 w-4 h-auto hover:text-gray-600"
+ @click.stop="handleCloseSingleResultView(item.database)"
+ />
+ </NButton>
</div>
</template>
@@ -70,9 +60,10 @@ import { EyeIcon, EyeOffIcon, InfoIcon, XIcon } from "lucide-vue-next";
import { NButton, NTooltip } from "naive-ui";
import { storeToRefs } from "pinia";
import { computed, watch } from "vue";
-import { InstanceV1EngineIcon } from "@/components/v2";
+import { RichDatabaseName } from "@/components/v2";
import { useDatabaseV1Store, useSQLEditorTabStore } from "@/store";
import type { ComposedDatabase, SQLResultSetV1 } from "@/types";
+import { hexToRgb } from "@/utils";
type BatchQueryItem = {
database: ComposedDatabase;
@@ -157,4 +148,16 @@ watch(
immediate: true,
}
);
+
+const getBackgroundColorRgb = (database: ComposedDatabase) => {
+ const color = hexToRgb(
+ database.effectiveEnvironmentEntity.color || "#4f46e5"
+ ).join(", ");
+ return {
+ backgroundColor: `rgba(${color}, 0.1)`,
+ borderTopColor: `rgb(${color})`,
+ color: `rgb(${color})`,
+ borderTop: "3px solid",
+ };
+};
</script>
diff --git a/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue b/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue
index 7690375851..b048f15cbf 100644
--- a/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue
+++ b/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue
@@ -18,11 +18,11 @@
<div
class="body"
:style="
- backgroundColorRgb.length > 0
+ backgroundColorRgb
? {
- backgroundColor: `rgba(${backgroundColorRgb[0]}, ${backgroundColorRgb[1]}, ${backgroundColorRgb[2]}, 0.1)`,
- borderTopColor: `rgb(${backgroundColorRgb[0]}, ${backgroundColorRgb[1]}, ${backgroundColorRgb[2]})`,
- color: `rgb(${backgroundColorRgb[0]}, ${backgroundColorRgb[1]}, ${backgroundColorRgb[2]})`,
+ backgroundColor: `rgba(${backgroundColorRgb}, 0.1)`,
+ borderTopColor: `rgb(${backgroundColorRgb})`,
+ color: `rgb(${backgroundColorRgb})`,
}
: {}
"
@@ -38,10 +38,7 @@
<script lang="ts" setup>
import { computed, reactive } from "vue";
import { useSQLEditorTabStore } from "@/store";
-import {
- type SQLEditorTab,
- UNKNOWN_ID,
-} from "@/types";
+import { type SQLEditorTab, UNKNOWN_ID } from "@/types";
import { connectionForSQLEditorTab, hexToRgb } from "@/utils";
import AdminLabel from "./AdminLabel.vue";
import Label from "./Label.vue";
@@ -81,12 +78,12 @@ const environment = computed(() => {
const backgroundColorRgb = computed(() => {
if (!isCurrentTab.value) {
- return [];
+ return "";
}
if (!environment.value || !environment.value.color) {
- return hexToRgb("#4f46e5");
+ return hexToRgb("#4f46e5").join(", ");
}
- return hexToRgb(environment.value.color);
+ return hexToRgb(environment.value.color).join(", ");
});
</script>
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index ebec5e81e9..ccffe1dda4 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -907,8 +907,8 @@ paths:
- environment: the environment full name in "environments/{id}" format, support "==" operator.
- state: the instance state, check State enum for values, support "==" operator.
- engine: the instance engine, check Engine enum for values. Support "==", "in [xx]", "!(in [xx])" operator.
- - host: the instance host, support "==" operator.
- - port: the instance port, support "==" operator.
+ - host: the instance host, support "==" and ".matches()" operator.
+ - port: the instance port, support "==" and ".matches()" operator.
- project: the project full name in "projects/{id}" format, support "==" operator.
For example:
@@ -922,7 +922,9 @@ paths:
engine in ["MYSQL", "POSTGRES"]
!(engine in ["MYSQL", "POSTGRES"])
host == "127.0.0.1"
+ host.matches("127.0")
port == "54321"
+ port.matches("543")
project == "projects/sample-project"
You can combine filter conditions like:
name.matches("sample") && environment == "environments/test"
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index 569323609d..593f9bc285 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -1563,9 +1563,9 @@ When paginating, all other parameters provided to `ListInstances` must match the
| show_deleted | [bool](#bool) | | Show deleted instances if specified. |
| filter | [string](#string) | | Filter the instance. The syntax and semantics of CEL are documented at https://github.com/google/cel-spec
-Supported filters: - name: the instance name, support &#34;==&#34; and &#34;.matches()&#34; operator. - resource_id: the instance id, support &#34;==&#34; and &#34;.matches()&#34; operator. - environment: the environment full name in &#34;environments/{id}&#34; format, support &#34;==&#34; operator. - state: the instance state, check State enum for values, support &#34;==&#34; operator. - engine: the instance engine, check Engine enum for values. Support &#34;==&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34; operator. - host: the instance host, support &#34;==&#34; operator. - port: the instance port, support &#34;==&#34; operator. - project: the project full name in &#34;projects/{id}&#34; format, support &#34;==&#34; operator.
+Supported filters: - name: the instance name, support &#34;==&#34; and &#34;.matches()&#34; operator. - resource_id: the instance id, support &#34;==&#34; and &#34;.matches()&#34; operator. - environment: the environment full name in &#34;environments/{id}&#34; format, support &#34;==&#34; operator. - state: the instance state, check State enum for values, support &#34;==&#34; operator. - engine: the instance engine, check Engine enum for values. Support &#34;==&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34; operator. - host: the instance host, support &#34;==&#34; and &#34;.matches()&#34; operator. - port: the instance port, support &#34;==&#34; and &#34;.matches()&#34; operator. - project: the project full name in &#34;projects/{id}&#34; format, support &#34;==&#34; operator.
-For example: name == &#34;sample instance&#34; name.matches(&#34;sample&#34;) resource_id = &#34;sample-instance&#34; resource_id.matches(&#34;sample&#34;) state == &#34;DELETED&#34; environment == &#34;environments/test&#34; engine == &#34;MYSQL&#34; engine in [&#34;MYSQL&#34;, &#34;POSTGRES&#34;] !(engine in [&#34;MYSQL&#34;, &#34;POSTGRES&#34;]) host == &#34;127.0.0.1&#34; port == &#34;54321&#34; project == &#34;projects/sample-project&#34; You can combine filter conditions like: name.matches(&#34;sample&#34;) &amp;&amp; environment == &#34;environments/test&#34; host == &#34;127.0.0.1&#34; &amp;&amp; port == &#34;54321&#34; |
+For example: name == &#34;sample instance&#34; name.matches(&#34;sample&#34;) resource_id = &#34;sample-instance&#34; resource_id.matches(&#34;sample&#34;) state == &#34;DELETED&#34; environment == &#34;environments/test&#34; engine == &#34;MYSQL&#34; engine in [&#34;MYSQL&#34;, &#34;POSTGRES&#34;] !(engine in [&#34;MYSQL&#34;, &#34;POSTGRES&#34;]) host == &#34;127.0.0.1&#34; host.matches(&#34;127.0&#34;) port == &#34;54321&#34; port.matches(&#34;543&#34;) project == &#34;projects/sample-project&#34; You can combine filter conditions like: name.matches(&#34;sample&#34;) &amp;&amp; environment == &#34;environments/test&#34; host == &#34;127.0.0.1&#34; &amp;&amp; port == &#34;54321&#34; |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index bb1e5752c0..b1dcc7db7b 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -5099,8 +5099,8 @@ Supported filters:
- environment: the environment full name in &#34;environments/{id}&#34; format, support &#34;==&#34; operator.
- state: the instance state, check State enum for values, support &#34;==&#34; operator.
- engine: the instance engine, check Engine enum for values. Support &#34;==&#34;, &#34;in [xx]&#34;, &#34;!(in [xx])&#34; operator.
-- host: the instance host, support &#34;==&#34; operator.
-- port: the instance port, support &#34;==&#34; operator.
+- host: the instance host, support &#34;==&#34; and &#34;.matches()&#34; operator.
+- port: the instance port, support &#34;==&#34; and &#34;.matches()&#34; operator.
- project: the project full name in &#34;projects/{id}&#34; format, support &#34;==&#34; operator.
For example:
@@ -5114,7 +5114,9 @@ engine == &#34;MYSQL&#34;
engine in [&#34;MYSQL&#34;, &#34;POSTGRES&#34;]
!(engine in [&#34;MYSQL&#34;, &#34;POSTGRES&#34;])
host == &#34;127.0.0.1&#34;
+host.matches(&#34;127.0&#34;)
port == &#34;54321&#34;
+port.matches(&#34;543&#34;)
project == &#34;projects/sample-project&#34;
You can combine filter conditions like:
name.matches(&#34;sample&#34;) &amp;&amp; environment == &#34;environments/test&#34;
diff --git a/proto/generated-go/v1/instance_service.pb.go b/proto/generated-go/v1/instance_service.pb.go
index 66a0d84c52..fdcf288bee 100644
--- a/proto/generated-go/v1/instance_service.pb.go
+++ b/proto/generated-go/v1/instance_service.pb.go
@@ -406,8 +406,8 @@ type ListInstancesRequest struct {
// - environment: the environment full name in "environments/{id}" format, support "==" operator.
// - state: the instance state, check State enum for values, support "==" operator.
// - engine: the instance engine, check Engine enum for values. Support "==", "in [xx]", "!(in [xx])" operator.
- // - host: the instance host, support "==" operator.
- // - port: the instance port, support "==" operator.
+ // - host: the instance host, support "==" and ".matches()" operator.
+ // - port: the instance port, support "==" and ".matches()" operator.
// - project: the project full name in "projects/{id}" format, support "==" operator.
//
// For example:
@@ -421,7 +421,9 @@ type ListInstancesRequest struct {
// engine in ["MYSQL", "POSTGRES"]
// !(engine in ["MYSQL", "POSTGRES"])
// host == "127.0.0.1"
+ // host.matches("127.0")
// port == "54321"
+ // port.matches("543")
// project == "projects/sample-project"
// You can combine filter conditions like:
// name.matches("sample") && environment == "environments/test"
diff --git a/proto/v1/v1/instance_service.proto b/proto/v1/v1/instance_service.proto
index a2d0b08a15..f25e5184b3 100644
--- a/proto/v1/v1/instance_service.proto
+++ b/proto/v1/v1/instance_service.proto
@@ -163,8 +163,8 @@ message ListInstancesRequest {
// - environment: the environment full name in "environments/{id}" format, support "==" operator.
// - state: the instance state, check State enum for values, support "==" operator.
// - engine: the instance engine, check Engine enum for values. Support "==", "in [xx]", "!(in [xx])" operator.
- // - host: the instance host, support "==" operator.
- // - port: the instance port, support "==" operator.
+ // - host: the instance host, support "==" and ".matches()" operator.
+ // - port: the instance port, support "==" and ".matches()" operator.
// - project: the project full name in "projects/{id}" format, support "==" operator.
//
// For example:
@@ -178,7 +178,9 @@ message ListInstancesRequest {
// engine in ["MYSQL", "POSTGRES"]
// !(engine in ["MYSQL", "POSTGRES"])
// host == "127.0.0.1"
+ // host.matches("127.0")
// port == "54321"
+ // port.matches("543")
// project == "projects/sample-project"
// You can combine filter conditions like:
// name.matches("sample") && environment == "environments/test"