Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: use advanced search for database and instance (#9723)
ecmadao043e638052c8
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue b/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vueindex c2f0940ca0..701cbf5716 100644--- a/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue+++ b/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue@@ -3,7 +3,7 @@<NInputref="inputRef"v-model:value="inputText"- :placeholder="$t('issue.advanced-search.self')"+ :placeholder="placeholder || $t('issue.advanced-search.self')"class="bb-advanced-issue-search-box__input"style="--n-padding-left: 8px; --n-padding-right: 4px"@click="handleInputClick"@@ -111,13 +111,17 @@ import { useSearchScopeOptions } from "./useSearchScopeOptions";const props = withDefaults(defineProps<{+ placeholder?: string;params: SearchParams;readonlyScopes?: SearchScope[];autofocus?: boolean;+ supportOptionIdList?: { id: SearchScopeId; includeAll: boolean }[];}>(),{readonlyScopes: () => [],+ supportOptionIdList: () => [],autofocus: false,+ placeholder: "",});@@ -190,7 +194,7 @@ const {currentScope,currentScopeOption,valueOptions,-} = useSearchScopeOptions(toRef(props, "params"));+} = useSearchScopeOptions(toRef(props, "params"), props.supportOptionIdList);const visibleScopeOptions = computed(() => {if (currentScopeOption.value) {diff --git a/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue b/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vueindex 68744944bf..0d9efd7e74 100644--- a/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue+++ b/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue@@ -8,6 +8,7 @@:params="params":autofocus="autofocus":readonly-scopes="readonlyScopes"+ :support-option-id-list="supportOptionIdList"class="flex-1"v-bind="componentProps?.searchbox"@update:params="$emit('update:params', $event)"@@ -44,8 +45,14 @@</template><script lang="ts" setup>-import { ref } from "vue";-import { SearchParams, SearchScope, SearchScopeId } from "@/utils";+import { ref, computed } from "vue";+import {+ SearchParams,+ SearchScope,+ SearchScopeId,+ UIIssueFilterScopeIdList,+ SearchScopeIdList,+} from "@/utils";import AdvancedSearchBox from "./AdvancedSearchBox.vue";import Status from "./Status.vue";import TimeRange from "./TimeRange.vue";@@ -88,4 +95,11 @@ const handleSelectScope = (id: SearchScopeId) => {showTimeRange.value = true;}};++const supportOptionIdList = computed(() =>+ [...UIIssueFilterScopeIdList, ...SearchScopeIdList].map((id) => ({+ id,+ includeAll: false,+ }))+);</script>diff --git a/frontend/src/components/IssueV1/components/IssueSearch/ScopeTags.vue b/frontend/src/components/IssueV1/components/IssueSearch/ScopeTags.vueindex 37a2f7b864..5981e28127 100644--- a/frontend/src/components/IssueV1/components/IssueSearch/ScopeTags.vue+++ b/frontend/src/components/IssueV1/components/IssueSearch/ScopeTags.vue@@ -21,6 +21,8 @@import dayjs from "dayjs";import { NTag, TagProps } from "naive-ui";import { computed, h } from "vue";+import { useI18n } from "vue-i18n";+import { UNKNOWN_ID } from "@/types";import {SearchParams,SearchScope,@@ -33,10 +35,14 @@ const props = defineProps<{focusedTagId?: SearchScopeId;readonlyScopes?: SearchScope[];}>();+defineEmits<{(event: "remove-scope", id: SearchScopeId, value: string): void;(event: "select-scope", id: SearchScopeId, value: string): void;}>();++const { t } = useI18n();+const readonlyScopeIds = computed(() => {return new Set((props.readonlyScopes ?? []).map((s) => s.id));});@@ -62,6 +68,9 @@ const renderValue = (scope: SearchScope, index: number) => {const [begin, end] = scope.value.split(",").map((ts) => parseInt(ts, 10));return [dayjs(begin).format("L"), dayjs(end).format("L")].join("-");}+ if (scope.value === `${UNKNOWN_ID}`) {+ return h("span", {}, t("common.all").toLocaleLowerCase());+ }return h("span", {}, scope.value);};</script>diff --git a/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts b/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.tsindex 340a457f9f..895dc4607a 100644--- a/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts+++ b/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts@@ -9,6 +9,7 @@ import {InstanceV1Name,ProjectV1Name,RichDatabaseName,+ EnvironmentV1Name,} from "@/components/v2";import {useCurrentUserV1,@@ -17,8 +18,14 @@ import {useProjectV1ListByCurrentUser,useSearchDatabaseV1List,useUserStore,+ useEnvironmentV1List,} from "@/store";-import { SYSTEM_BOT_EMAIL, UNKNOWN_ID } from "@/types";+import {+ SYSTEM_BOT_EMAIL,+ UNKNOWN_ID,+ unknownEnvironment,+ unknownInstance,+} from "@/types";import { engineToJSON } from "@/types/proto/v1/common";import { Workflow } from "@/types/proto/v1/project_service";import {@@ -44,11 +51,19 @@ export type ValueOption = {render: RenderFunction;};-export const useSearchScopeOptions = (params: Ref<SearchParams>) => {+interface LocalScopeOption extends ScopeOption {+ optionForAll?: ValueOption;+}++export const useSearchScopeOptions = (+ params: Ref<SearchParams>,+ supportOptionIdList: { id: SearchScopeId; includeAll: boolean }[]+) => {const { t } = useI18n();const me = useCurrentUserV1();const userStore = useUserStore();const databaseV1Store = useDatabaseV1Store();+ const environmentList = useEnvironmentV1List(false /* !showDeleted */);const { projectList } = useProjectV1ListByCurrentUser();const { instanceList } = useInstanceV1List(false /* !showDeleted */);const { databaseList } = useSearchDatabaseV1List({@@ -86,7 +101,7 @@ export const useSearchScopeOptions = (params: Ref<SearchParams>) => {// fullScopeOptions provides full search scopes and options.// we need this as the source of truth.const fullScopeOptions = computed((): ScopeOption[] => {- const scopes: ScopeOption[] = [+ const scopes: LocalScopeOption[] = [{id: "project",title: t("issue.advanced-search.scope.project.title"),@@ -178,6 +193,21 @@ export const useSearchScopeOptions = (params: Ref<SearchParams>) => {id: "instance",title: t("issue.advanced-search.scope.instance.title"),description: t("issue.advanced-search.scope.instance.description"),+ optionForAll: {+ value: `${UNKNOWN_ID}`,+ keywords: [],+ custom: true,+ render: () =>+ h(InstanceV1Name, {+ instance: {+ ...unknownInstance(),+ title: t("instance.all"),+ },+ icon: false,+ link: false,+ tooltip: false,+ }),+ },options: instanceList.value.map((ins) => {const name = extractInstanceResourceName(ins.name);return {@@ -231,6 +261,35 @@ export const useSearchScopeOptions = (params: Ref<SearchParams>) => {};}),},+ {+ id: "environment",+ title: "Environment",+ description: "xxxxxxxx",+ optionForAll: {+ value: `${UNKNOWN_ID}`,+ keywords: [],+ custom: true,+ render: () =>+ h(EnvironmentV1Name, {+ environment: {+ ...unknownEnvironment(),+ title: t("environment.all"),+ },+ link: false,+ }),+ },+ options: environmentList.value.map((env) => {+ return {+ value: extractEnvironmentResourceName(env.name),+ keywords: [env.name, env.title],+ render: () =>+ h(EnvironmentV1Name, {+ environment: env,+ link: false,+ }),+ };+ }),+ },{id: "type",title: t("issue.advanced-search.scope.type.title"),@@ -249,7 +308,20 @@ export const useSearchScopeOptions = (params: Ref<SearchParams>) => {],},];- return scopes;+ const supportOptionIdMap = new Map(+ supportOptionIdList.map((data) => [data.id, data.includeAll])+ );+ return scopes+ .filter((scope) => supportOptionIdMap.has(scope.id))+ .map((scope) => {+ if (supportOptionIdMap.get(scope.id) && scope.optionForAll) {+ return {+ ...scope,+ options: [scope.optionForAll, ...scope.options],+ };+ }+ return scope;+ });});// filteredScopeOptions will filter search options by chosen scope.@@ -266,31 +338,33 @@ export const useSearchScopeOptions = (params: Ref<SearchParams>) => {})),}));const index = clone.findIndex((scope) => scope.id === "database");- clone[index].options = clone[index].options.filter((option) => {- if (!existedScopes.has("project") && !existedScopes.has("instance")) {- return true;- }+ if (index >= 0) {+ clone[index].options = clone[index].options.filter((option) => {+ if (!existedScopes.has("project") && !existedScopes.has("instance")) {+ return true;+ }- const uid = option.value.split("-").slice(-1)[0];- const db = databaseV1Store.getDatabaseByUID(uid);- const project = db.project;- const instance = db.instance;+ const uid = option.value.split("-").slice(-1)[0];+ const db = databaseV1Store.getDatabaseByUID(uid);+ const project = db.project;+ const instance = db.instance;- const existedProject = `projects/${- existedScopes.get("project") ?? UNKNOWN_ID- }`;- if (project === existedProject) {- return true;- }- const existedInstance = `instances/${- existedScopes.get("instance") ?? UNKNOWN_ID- }`;- if (instance === existedInstance) {- return true;- }+ const existedProject = `projects/${+ existedScopes.get("project") ?? UNKNOWN_ID+ }`;+ if (project === existedProject) {+ return true;+ }+ const existedInstance = `instances/${+ existedScopes.get("instance") ?? UNKNOWN_ID+ }`;+ if (instance === existedInstance) {+ return true;+ }- return false;- });+ return false;+ });+ }return clone;});diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vueindex 23bf5d9626..e429a45956 100644--- a/frontend/src/components/ProjectDatabasesPanel.vue+++ b/frontend/src/components/ProjectDatabasesPanel.vue@@ -1,36 +1,19 @@<template><div class="space-y-4"><div- class="text-lg font-medium leading-7 text-main flex flex-col lg:flex-row items-start lg:items-end justify-between space-y-2"+ class="text-lg space-x-2 font-medium leading-7 text-main flex flex-col lg:flex-row items-start lg:items-end justify-between space-y-2">- <EnvironmentTabFilter- :environment="state.environment"- :include-all="true"- @update:environment="state.environment = $event"+ <AdvancedSearchBox+ v-model:params="state.params"+ class="flex-1"+ :autofocus="false"+ :placeholder="$t('database.filter-database')"+ :support-option-id-list="supportOptionIdList"+ />+ <DatabaseLabelFilter+ v-model:selected="state.selectedLabels"+ :database-list="databaseList"/>- <NInputGroup style="width: auto">- <DatabaseLabelFilter- v-model:selected="state.selectedLabels"- :database-list="databaseList"- />- <InstanceSelect- class="!w-48"- :instance="state.instance"- :include-all="true"- :filter="filterInstance"- :environment="environment?.uid"- @update:instance="- state.instance = $event ? String($event) : String(UNKNOWN_ID)- "- />- <div class="hidden md:block">- <SearchBox- :value="state.keyword"- :placeholder="$t('common.filter-by-name')"- @update:value="state.keyword = $event"- />- </div>- </NInputGroup></div><DatabaseOperations@@ -89,41 +72,28 @@</template><script lang="ts" setup>-import { uniqBy } from "lodash-es";-import { NInputGroup } from "naive-ui";import { reactive, PropType, computed, ref, watchEffect } from "vue";-import {- useCurrentUserV1,- usePolicyV1Store,- useEnvironmentV1Store,-} from "@/store";+import { useCurrentUserV1, usePolicyV1Store } from "@/store";+import { ComposedDatabase, UNKNOWN_ID } from "@/types";import {Policy,PolicyResourceType,PolicyType,} from "@/types/proto/v1/org_policy_service";-import { filterDatabaseV1ByKeyword, isDatabaseV1Accessible } from "@/utils";import {- ComposedDatabase,- ComposedInstance,- UNKNOWN_ID,- UNKNOWN_ENVIRONMENT_NAME,-} from "../types";-import {- DatabaseV1Table,- DatabaseOperations,- DatabaseLabelFilter,- EnvironmentTabFilter,- InstanceSelect,- SearchBox,-} from "./v2";+ filterDatabaseV1ByKeyword,+ isDatabaseV1Accessible,+ SearchParams,+ CommonFilterScopeIdList,+ extractEnvironmentResourceName,+ extractInstanceResourceName,+} from "@/utils";+import { DatabaseV1Table, DatabaseOperations, DatabaseLabelFilter } from "./v2";interface LocalState {- environment: string;- instance: string;- keyword: string;selectedDatabaseIds: Set<string>;selectedLabels: { key: string; value: string }[];+ params: SearchParams;}const props = defineProps({@@ -134,14 +104,23 @@ const props = defineProps({});const currentUserV1 = useCurrentUserV1();-const environmentV1Store = useEnvironmentV1Store();const state = reactive<LocalState>({- environment: UNKNOWN_ENVIRONMENT_NAME,- instance: String(UNKNOWN_ID),- keyword: "",selectedDatabaseIds: new Set(),selectedLabels: [],+ params: {+ query: "",+ scopes: [+ {+ id: "environment",+ value: String(UNKNOWN_ID),+ },+ {+ id: "instance",+ value: String(UNKNOWN_ID),+ },+ ],+ },});const policyList = ref<Policy[]>([]);@@ -156,19 +135,39 @@ const preparePolicyList = () => {watchEffect(preparePolicyList);+const selectedInstance = computed(() => {+ return (+ state.params.scopes.find((scope) => scope.id === "instance")?.value ??+ `${UNKNOWN_ID}`+ );+});++const selectedEnvironment = computed(() => {+ return (+ state.params.scopes.find((scope) => scope.id === "environment")?.value ??+ `${UNKNOWN_ID}`+ );+});+const filteredDatabaseList = computed(() => {let list = [...props.databaseList].filter((database) =>isDatabaseV1Accessible(database, currentUserV1.value));- if (state.environment !== UNKNOWN_ENVIRONMENT_NAME) {+ if (selectedEnvironment.value !== `${UNKNOWN_ID}`) {list = list.filter(- (db) => db.effectiveEnvironmentEntity.name === state.environment+ (db) =>+ extractEnvironmentResourceName(db.effectiveEnvironment) ===+ selectedEnvironment.value);}- if (state.instance !== String(UNKNOWN_ID)) {- list = list.filter((db) => db.instanceEntity.uid === state.instance);+ if (selectedInstance.value !== `${UNKNOWN_ID}`) {+ list = list.filter(+ (db) =>+ extractInstanceResourceName(db.instanceEntity.name) ===+ selectedInstance.value+ );}- const keyword = state.keyword.trim().toLowerCase();+ const keyword = state.params.query.trim().toLowerCase();if (keyword) {list = list.filter((db) =>filterDatabaseV1ByKeyword(db, keyword, [@@ -187,21 +186,6 @@ const filteredDatabaseList = computed(() => {return list;});-const instanceList = computed(() => {- return uniqBy(- props.databaseList.map((db) => db.instanceEntity),- (instance) => instance.uid- );-});--const filterInstance = (instance: ComposedInstance) => {- return instanceList.value.findIndex((inst) => inst.uid === instance.uid) >= 0;-};--const environment = computed(() => {- return environmentV1Store.getEnvironmentByName(state.environment);-});-const getAllSelectionState = (databaseList: ComposedDatabase[]): { checked: boolean; indeterminate: boolean } => {@@ -242,4 +226,8 @@ const selectedDatabases = computed((): ComposedDatabase[] => {state.selectedDatabaseIds.has(db.uid));});++const supportOptionIdList = computed(() =>+ [...CommonFilterScopeIdList].map((id) => ({ id, includeAll: true }))+);</script>diff --git a/frontend/src/components/SensitiveData/components/ClassificationExampleModal.vue b/frontend/src/components/SensitiveData/components/ClassificationExampleModal.vueindex 9b61cf310c..43f64a6393 100644--- a/frontend/src/components/SensitiveData/components/ClassificationExampleModal.vue+++ b/frontend/src/components/SensitiveData/components/ClassificationExampleModal.vue@@ -107,7 +107,6 @@ const { copy: copyTextToClipboard } = useClipboard();const { t } = useI18n();const handleCopy = () => {- console.log("handleCopy");copyTextToClipboard(JSON.stringify(example, null, 2));pushNotification({module: "bytebase",diff --git a/frontend/src/components/v2/Model/Instance/InstanceV1Name.vue b/frontend/src/components/v2/Model/Instance/InstanceV1Name.vueindex 785df60558..bbe50186ed 100644--- a/frontend/src/components/v2/Model/Instance/InstanceV1Name.vue+++ b/frontend/src/components/v2/Model/Instance/InstanceV1Name.vue@@ -12,7 +12,7 @@<slot name="prefix" />- <NEllipsis v-if="tooltip" :line-clamp="1" :class="textClass">+ <NEllipsis :disabled="!tooltip" :line-clamp="1" :class="textClass">{{ instanceV1Name(instance) }}</NEllipsis>diff --git a/frontend/src/layouts/BodyLayout.vue b/frontend/src/layouts/BodyLayout.vueindex c2d9c9d59e..62965153d9 100644--- a/frontend/src/layouts/BodyLayout.vue+++ b/frontend/src/layouts/BodyLayout.vue@@ -192,7 +192,7 @@<divclass="w-full flex flex-row justify-between items-center flex-wrap px-2 gap-x-4">- <div v-if="quickActionList.length > 0" class="flex-1 pt-3 pb-2">+ <div v-if="quickActionList.length > 0" class="flex-1 pt-3 pb-4"><QuickActionPanel :quick-action-list="quickActionList" /></div><divdiff --git a/frontend/src/layouts/ProjectLayout.vue b/frontend/src/layouts/ProjectLayout.vueindex 53f2467108..a65a798c9f 100644--- a/frontend/src/layouts/ProjectLayout.vue+++ b/frontend/src/layouts/ProjectLayout.vue@@ -1,20 +1,19 @@<template><ArchiveBanner v-if="project.state === State.DELETED" class="py-2" />- <HideInStandaloneMode>- <template v-if="isDefaultProject">- <h1 class="px-6 py-2 text-xl font-bold leading-6 text-main truncate">- {{ $t("database.unassigned-databases") }}- </h1>- </template>- <BBAttention- v-if="isDefaultProject"- class="mx-6 mb-4"- :style="'INFO'"- :title="$t('project.overview.info-slot-content')"- />- </HideInStandaloneMode>-<div class="p-6 h-full overflow-auto">+ <HideInStandaloneMode>+ <template v-if="isDefaultProject">+ <h1 class="mb-4 text-xl font-bold leading-6 text-main truncate">+ {{ $t("database.unassigned-databases") }}+ </h1>+ </template>+ <BBAttention+ v-if="isDefaultProject"+ class="mb-4"+ :style="'INFO'"+ :title="$t('project.overview.info-slot-content')"+ />+ </HideInStandaloneMode><router-view:project-slug="projectSlug":project-webhook-slug="projectWebhookSlug"diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex f337a79342..1f448d1000 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1351,6 +1351,7 @@}},"environment": {+ "all": "All environment","id": "Environment ID","id-description": "The Environment ID is the unique identifier for your environment. You cannot change it after created.","select": "Select environment",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex bb31791612..c1875ea79c 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1351,6 +1351,7 @@},"environment": {"id": "ID del Entorno",+ "all": "Todo el entorno","id-description": "El ID del entorno es el identificador único para su entorno. No puede cambiarlo después de creado.","select": "Seleccionar entorno","archive": "Archivar este entorno",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex d4a4ca71ac..83c6aeea58 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1349,6 +1349,7 @@},"environment": {"id": "环境 ID",+ "all": "所有环境","id-description": "环境 ID 是环境的唯一标识符。一旦创建不能修改。","select": "选择环境","archive": "归档此环境",diff --git a/frontend/src/utils/v1/instance.ts b/frontend/src/utils/v1/instance.tsindex 145ee5159f..2d731fa0f8 100644--- a/frontend/src/utils/v1/instance.ts+++ b/frontend/src/utils/v1/instance.ts@@ -2,7 +2,7 @@ import { keyBy, orderBy } from "lodash-es";import slug from "slug";import { useI18n } from "vue-i18n";import { useSubscriptionV1Store } from "@/store";-import { ComposedInstance } from "@/types";+import { ComposedInstance, UNKNOWN_ID } from "@/types";import { Engine, State } from "@/types/proto/v1/common";import { Environment } from "@/types/proto/v1/environment_service";import { DataSourceType, Instance } from "@/types/proto/v1/instance_service";@@ -19,7 +19,11 @@ export function instanceV1Name(instance: Instance) {// instance cannot be deleted and activated at the same time.if (instance.state === State.DELETED) {name += ` (${t("common.archived")})`;- } else if (!instance.activation && store.currentPlan !== PlanType.FREE) {+ } else if (+ instance.uid !== `${UNKNOWN_ID}` &&+ !instance.activation &&+ store.currentPlan !== PlanType.FREE+ ) {name += ` (${t("common.no-license")})`;}return name;diff --git a/frontend/src/utils/v1/issue/search/common.ts b/frontend/src/utils/v1/issue/search/common.tsindex aaf821278f..c53daf5bee 100644--- a/frontend/src/utils/v1/issue/search/common.ts+++ b/frontend/src/utils/v1/issue/search/common.ts@@ -7,7 +7,10 @@ export const UIIssueFilterScopeIdList = ["approval","releaser",] as const;-export type UIIssueFilterScopeId = typeof UIIssueFilterScopeIdList[number];+type UIIssueFilterScopeId = typeof UIIssueFilterScopeIdList[number];++export const CommonFilterScopeIdList = ["environment", "instance"] as const;+type CommonFilterScopeId = typeof CommonFilterScopeIdList[number];export const SearchScopeIdList = ["project",@@ -23,7 +26,8 @@ export const SearchScopeIdList = [export type SearchScopeId =| typeof SearchScopeIdList[number]- | UIIssueFilterScopeId;+ | UIIssueFilterScopeId+ | CommonFilterScopeId;export type SearchScope = {id: SearchScopeId;@@ -38,7 +42,8 @@ export interface SearchParams {export const isValidSearchScopeId = (id: string): id is SearchScopeId => {return (SearchScopeIdList.includes(id as any) ||- UIIssueFilterScopeIdList.includes(id as any)+ UIIssueFilterScopeIdList.includes(id as any) ||+ CommonFilterScopeIdList.includes(id as any));};diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vueindex f719a3695a..976ee4a4e6 100644--- a/frontend/src/views/DatabaseDashboard.vue+++ b/frontend/src/views/DatabaseDashboard.vue@@ -1,58 +1,12 @@<template><div class="flex flex-col relative space-y-4">- <div- class="px-4 flex flex-col lg:flex-row justify-between items-start lg:items-end"- >- <EnvironmentTabFilter- :include-all="true"- :environment="selectedEnvironment?.name"- @update:environment="changeEnvironment"- />-- <div- class="mt-2 lg:mt-0 flex flex-col sm:flex-row items-start sm:items-center"- >- <div class="mb-2 sm:mr-4 sm:mb-0">- <NTooltip v-if="canVisitUnassignedDatabases && !isStandaloneMode">- <template #trigger>- <router-link- :to="{- name: 'workspace.project.detail',- params: {- projectSlug: DEFAULT_PROJECT_ID,- },- hash: '#databases',- }"- class="normal-link text-sm"- >- {{ $t("database.view-unassigned-databases") }}- </router-link>- </template>-- <div class="whitespace-pre-wrap">- {{ $t("quick-action.unassigned-db-hint") }}- </div>- </NTooltip>- </div>-- <NInputGroup style="width: auto">- <InstanceSelect- class="!w-48"- :instance="state.instanceFilter"- :include-all="true"- :environment="selectedEnvironment?.uid"- @update:instance="- state.instanceFilter = $event ?? String(UNKNOWN_ID)- "- />- <SearchBox- v-model:value="state.searchText"- :placeholder="$t('database.filter-database')"- :autofocus="true"- />- </NInputGroup>- </div>- </div>+ <AdvancedSearchBox+ v-model:params="state.params"+ class="px-4"+ :autofocus="false"+ :placeholder="$t('database.filter-database')"+ :support-option-id-list="supportOptionIdList"+ /><DatabaseOperationsv-if="selectedDatabases.length > 0 || isStandaloneMode"@@ -115,68 +69,68 @@</template><script lang="ts" setup>-import { NInputGroup, NTooltip } from "naive-ui";import { computed, watchEffect, onMounted, reactive, ref } from "vue";-import { useRoute, useRouter } from "vue-router";-import {- EnvironmentTabFilter,- InstanceSelect,- DatabaseV1Table,- SearchBox,-} from "@/components/v2";+import { DatabaseV1Table } from "@/components/v2";import { isDatabase } from "@/components/v2/Model/DatabaseV1Table/utils";import {useCurrentUserV1,useDBGroupStore,useDatabaseV1Store,- useEnvironmentV1Store,usePageMode,usePolicyV1Store,useProjectV1ListByCurrentUser,useUIStateStore,} from "@/store";+import {+ UNKNOWN_ID,+ UNKNOWN_USER_NAME,+ ComposedDatabase,+ ComposedDatabaseGroup,+ DEFAULT_PROJECT_V1_NAME,+} from "@/types";import {Policy,PolicyResourceType,PolicyType,} from "@/types/proto/v1/org_policy_service";import {+ SearchParams,filterDatabaseV1ByKeyword,- hasWorkspacePermissionV1,sortDatabaseV1List,isDatabaseV1Accessible,+ CommonFilterScopeIdList,+ extractEnvironmentResourceName,+ extractInstanceResourceName,} from "@/utils";-import {- UNKNOWN_ID,- UNKNOWN_ENVIRONMENT_NAME,- DEFAULT_PROJECT_ID,- UNKNOWN_USER_NAME,- ComposedDatabase,- ComposedDatabaseGroup,- DEFAULT_PROJECT_V1_NAME,-} from "../types";interface LocalState {- instanceFilter: string;- searchText: string;databaseGroupList: ComposedDatabaseGroup[];loading: boolean;selectedDatabaseIds: Set<string>;+ params: SearchParams;}-const route = useRoute();-const router = useRouter();const uiStateStore = useUIStateStore();-const environmentV1Store = useEnvironmentV1Store();const { projectList } = useProjectV1ListByCurrentUser();const pageMode = usePageMode();const state = reactive<LocalState>({- instanceFilter: String(UNKNOWN_ID),- searchText: "",databaseGroupList: [],loading: false,selectedDatabaseIds: new Set(),+ params: {+ query: "",+ scopes: [+ {+ id: "environment",+ value: String(UNKNOWN_ID),+ },+ {+ id: "instance",+ value: String(UNKNOWN_ID),+ },+ ],+ },});const currentUserV1 = useCurrentUserV1();@@ -197,17 +151,17 @@ watchEffect(preparePolicyList);const isStandaloneMode = computed(() => pageMode.value === "STANDALONE");-const selectedEnvironment = computed(() => {- const { environment } = route.query;- return environment- ? environmentV1Store.getEnvironmentByName(environment as string)- : undefined;+const selectedInstance = computed(() => {+ return (+ state.params.scopes.find((scope) => scope.id === "instance")?.value ??+ `${UNKNOWN_ID}`+ );});-const canVisitUnassignedDatabases = computed(() => {- return hasWorkspacePermissionV1(- "bb.permission.workspace.manage-database",- currentUserV1.value.userRole+const selectedEnvironment = computed(() => {+ return (+ state.params.scopes.find((scope) => scope.id === "environment")?.value ??+ `${UNKNOWN_ID}`);});@@ -256,28 +210,22 @@ watchEffect(async () => {state.loading = false;});-const changeEnvironment = (environment: string | undefined) => {- if (environment && environment !== UNKNOWN_ENVIRONMENT_NAME) {- router.replace({- name: "workspace.database",- query: { environment },- });- } else {- router.replace({ name: "workspace.database" });- }-};-const filteredDatabaseList = computed(() => {let list = databaseV1List.value.filter((database) =>isDatabaseV1Accessible(database, currentUserV1.value));- const environment = selectedEnvironment.value;- if (environment && environment.name !== UNKNOWN_ENVIRONMENT_NAME) {- list = list.filter((db) => db.effectiveEnvironment === environment.name);+ if (selectedEnvironment.value !== `${UNKNOWN_ID}`) {+ list = list.filter(+ (db) =>+ extractEnvironmentResourceName(db.effectiveEnvironment) ===+ selectedEnvironment.value+ );}- if (state.instanceFilter !== String(UNKNOWN_ID)) {+ if (selectedInstance.value !== `${UNKNOWN_ID}`) {list = list.filter(- (db) => db.instanceEntity.uid === String(state.instanceFilter)+ (db) =>+ extractInstanceResourceName(db.instanceEntity.name) ===+ selectedInstance.value);}if (isStandaloneMode.value) {@@ -285,7 +233,7 @@ const filteredDatabaseList = computed(() => {(db) => db.projectEntity.name !== DEFAULT_PROJECT_V1_NAME);}- const keyword = state.searchText.trim().toLowerCase();+ const keyword = state.params.query.trim().toLowerCase();if (keyword) {list = list.filter((db) =>filterDatabaseV1ByKeyword(db, keyword, [@@ -301,13 +249,14 @@ const filteredDatabaseList = computed(() => {const filteredDatabaseGroupList = computed(() => {let list = [...state.databaseGroupList];- const environment = selectedEnvironment.value;- if (environment && environment.name !== UNKNOWN_ENVIRONMENT_NAME) {+ if (selectedEnvironment.value !== `${UNKNOWN_ID}`) {list = list.filter(- (dbGroup) => dbGroup.environmentName === environment.name+ (dbGroup) =>+ extractEnvironmentResourceName(dbGroup.environmentName) ===+ selectedEnvironment.value);}- const keyword = state.searchText.trim().toLowerCase();+ const keyword = state.params.query.trim().toLowerCase();if (keyword) {list = list.filter((dbGroup) =>@@ -366,4 +315,8 @@ const selectedDatabases = computed((): ComposedDatabase[] => {(db) => isDatabase(db) && state.selectedDatabaseIds.has(db.uid));});++const supportOptionIdList = computed(() =>+ [...CommonFilterScopeIdList].map((id) => ({ id, includeAll: true }))+);</script>diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vueindex e20b763068..e0a0b81742 100644--- a/frontend/src/views/InstanceDashboard.vue+++ b/frontend/src/views/InstanceDashboard.vue@@ -5,18 +5,13 @@feature="bb.feature.instance-count":description="instanceCountAttention"/>- <div class="px-4 flex flex-row justify-between items-end">- <EnvironmentTabFilter- :environment="selectedEnvironment?.name"- :include-all="true"- @update:environment="selectEnvironment"- />- <SearchBox- v-model:value="state.searchText"- :autofocus="true"- :placeholder="$t('instance.filter-instance-name')"- />- </div>+ <AdvancedSearchBox+ v-model:params="state.params"+ class="px-4"+ :autofocus="false"+ :placeholder="$t('instance.filter-instance-name')"+ :support-option-id-list="supportOptionIdList"+ /><InstanceV1Table:allow-selection="true":instance-list="filteredInstanceV1List"@@ -28,45 +23,51 @@<script lang="ts" setup>import { computed, onMounted, reactive } from "vue";import { useI18n } from "vue-i18n";-import { useRouter } from "vue-router";-import {- EnvironmentTabFilter,- InstanceV1Table,- SearchBox,-} from "@/components/v2";+import { InstanceV1Table } from "@/components/v2";import {useUIStateStore,useSubscriptionV1Store,- useEnvironmentV1Store,useEnvironmentV1List,useInstanceV1List,useInstanceV1Store,} from "@/store";+import { UNKNOWN_ID } from "@/types";import { PlanType } from "@/types/proto/v1/subscription_service";-import { UNKNOWN_ENVIRONMENT_NAME } from "../types";-import { sortInstanceV1ListByEnvironmentV1 } from "../utils";+import {+ sortInstanceV1ListByEnvironmentV1,+ extractEnvironmentResourceName,+ SearchParams,+ SearchScopeId,+} from "@/utils";interface LocalState {- searchText: string;+ params: SearchParams;}const subscriptionStore = useSubscriptionV1Store();const instanceV1Store = useInstanceV1Store();const uiStateStore = useUIStateStore();-const router = useRouter();const { t } = useI18n();const environmentList = useEnvironmentV1List(false /* !showDeleted */);const state = reactive<LocalState>({- searchText: "",+ params: {+ query: "",+ scopes: [+ {+ id: "environment",+ value: String(UNKNOWN_ID),+ },+ ],+ },});const selectedEnvironment = computed(() => {- const environment = router.currentRoute.value.query.environment as string;- if (environment)- return useEnvironmentV1Store().getEnvironmentByName(environment);- return undefined;+ return (+ state.params.scopes.find((scope) => scope.id === "environment")?.value ??+ `${UNKNOWN_ID}`+ );});onMounted(() => {@@ -78,28 +79,20 @@ onMounted(() => {}});-const selectEnvironment = (environment: string | undefined) => {- if (environment && environment !== UNKNOWN_ENVIRONMENT_NAME) {- router.replace({- name: "workspace.instance",- query: { environment },- });- } else {- router.replace({ name: "workspace.instance" });- }-};-const { instanceList: rawInstanceV1List } = useInstanceV1List(false /* !showDeleted */);const filteredInstanceV1List = computed(() => {let list = [...rawInstanceV1List.value];- const environment = selectedEnvironment.value;- if (environment && environment.name !== UNKNOWN_ENVIRONMENT_NAME) {- list = list.filter((instance) => instance.environment === environment.name);+ if (selectedEnvironment.value !== `${UNKNOWN_ID}`) {+ list = list.filter(+ (instance) =>+ extractEnvironmentResourceName(instance.environment) ===+ selectedEnvironment.value+ );}- const keyword = state.searchText.trim().toLowerCase();+ const keyword = state.params.query.trim().toLowerCase();if (keyword) {list = list.filter((instance) =>instance.title.toLowerCase().includes(keyword)@@ -134,4 +127,15 @@ const instanceCountAttention = computed((): string => {return `${status} ${upgrade}`;});++const supportOptionIdList = computed(+ (): { id: SearchScopeId; includeAll: boolean }[] => {+ return [+ {+ id: "environment",+ includeAll: true,+ },+ ];+ }+);</script>diff --git a/frontend/src/views/ProjectDetail.vue b/frontend/src/views/ProjectDetail.vueindex 9300ad6aca..7268759127 100644--- a/frontend/src/views/ProjectDetail.vue+++ b/frontend/src/views/ProjectDetail.vue@@ -1,5 +1,5 @@<template>- <div v-if="quickActionList.length > 0" class="flex-1 pb-2">+ <div v-if="quickActionList.length > 0" class="flex-1 pb-4"><QuickActionPanel :quick-action-list="quickActionList" /></div><template v-if="hash === 'issues'">