Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: Integrate state filtering into AdvancedSearch (#18951)
Danny Xu7a68eab9ed7c
diff --git a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.tsindex 2ed39b4554..d8f5c43498 100644--- a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts+++ b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts@@ -191,8 +191,13 @@ export const useCommonSearchScopeOptions = (},{value: "DELETED",- keywords: ["deleted", "DELETED"],- render: () => t("common.deleted"),+ keywords: ["archived", "ARCHIVED", "deleted", "DELETED"],+ render: () => t("common.archived"),+ },+ {+ value: "ALL",+ keywords: ["all", "ALL"],+ render: () => t("common.all"),},],allowMultiple: false,diff --git a/frontend/src/components/Instance/InstanceArchiveRestoreButton.vue b/frontend/src/components/Instance/InstanceArchiveRestoreButton.vueindex 05349b7e9e..f8a0152457 100644--- a/frontend/src/components/Instance/InstanceArchiveRestoreButton.vue+++ b/frontend/src/components/Instance/InstanceArchiveRestoreButton.vue@@ -58,7 +58,6 @@ import { useRouter } from "vue-router";import { BBButtonConfirm } from "@/bbkit";import ResourceHardDeleteButton from "@/components/v2/Button/ResourceHardDeleteButton.vue";import { INSTANCE_ROUTE_DASHBOARD } from "@/router/dashboard/workspaceRoutes";-import { SETTING_ROUTE_WORKSPACE_ARCHIVE } from "@/router/dashboard/workspaceSetting";import { pushNotification, useInstanceV1Store } from "@/store";import { State } from "@/types/proto-es/v1/common_pb";import type { Instance } from "@/types/proto-es/v1/instance_service_pb";@@ -112,8 +111,8 @@ const archiveOrRestoreInstance = async (archive: boolean) => {const hardDeleteInstance = async (resource: string) => {await instanceStore.deleteInstance(resource);router.replace({- name: SETTING_ROUTE_WORKSPACE_ARCHIVE,- hash: "#INSTANCE",+ name: INSTANCE_ROUTE_DASHBOARD,+ query: { q: "state:DELETED" },});};</script>diff --git a/frontend/src/components/Project/ProjectArchiveRestoreButton.vue b/frontend/src/components/Project/ProjectArchiveRestoreButton.vueindex d25c15838d..fd0c898be0 100644--- a/frontend/src/components/Project/ProjectArchiveRestoreButton.vue+++ b/frontend/src/components/Project/ProjectArchiveRestoreButton.vue@@ -39,7 +39,6 @@ import { useRouter } from "vue-router";import { BBButtonConfirm } from "@/bbkit";import ResourceHardDeleteButton from "@/components/v2/Button/ResourceHardDeleteButton.vue";import { PROJECT_V1_ROUTE_DASHBOARD } from "@/router/dashboard/workspaceRoutes";-import { SETTING_ROUTE_WORKSPACE_ARCHIVE } from "@/router/dashboard/workspaceSetting";import { useProjectV1Store } from "@/store";import { State } from "@/types/proto-es/v1/common_pb";import type { Project } from "@/types/proto-es/v1/project_service_pb";@@ -76,8 +75,8 @@ const archiveOrRestoreProject = async (archive: boolean) => {const hardDeleteProject = async (resource: string) => {await projectV1Store.deleteProject(resource);router.replace({- name: SETTING_ROUTE_WORKSPACE_ARCHIVE,- hash: "#PROJECT",+ name: PROJECT_V1_ROUTE_DASHBOARD,+ query: { q: "state:DELETED" },});};</script>diff --git a/frontend/src/router/dashboard/workspaceSetting.ts b/frontend/src/router/dashboard/workspaceSetting.tsindex 68711bf62e..c6fb147fb4 100644--- a/frontend/src/router/dashboard/workspaceSetting.ts+++ b/frontend/src/router/dashboard/workspaceSetting.ts@@ -7,7 +7,6 @@ export const SETTING_ROUTE_PROFILE = `${SETTING_ROUTE}.profile`;export const SETTING_ROUTE_PROFILE_TWO_FACTOR = `${SETTING_ROUTE_PROFILE}.two-factor`;export const SETTING_ROUTE_WORKSPACE_GENERAL = `${SETTING_ROUTE_WORKSPACE}.general`;export const SETTING_ROUTE_WORKSPACE_SUBSCRIPTION = `${SETTING_ROUTE_WORKSPACE}.subscription`;-export const SETTING_ROUTE_WORKSPACE_ARCHIVE = `${SETTING_ROUTE_WORKSPACE}.archive`;const workspaceSettingRoutes: RouteRecordRaw[] = [{@@ -57,19 +56,6 @@ const workspaceSettingRoutes: RouteRecordRaw[] = [component: () => import("@/views/SettingWorkspaceSubscription.vue"),props: true,},- {- path: "archive",- name: SETTING_ROUTE_WORKSPACE_ARCHIVE,- meta: {- title: () => t("common.archived"),- requiredPermissionList: () => [- "bb.projects.list",- "bb.instances.list",- ],- },- component: () => import("@/views/Archive.vue"),- props: true,- },],},];diff --git a/frontend/src/store/modules/v1/instance.ts b/frontend/src/store/modules/v1/instance.tsindex 5918af2e65..c879a9508c 100644--- a/frontend/src/store/modules/v1/instance.ts+++ b/frontend/src/store/modules/v1/instance.ts@@ -311,7 +311,7 @@ export const useInstanceV1Store = defineStore("instance_v1", () => {pageToken: params.pageToken,orderBy: params.orderBy,filter: getListInstanceFilter(params.filter ?? {}),- showDeleted: params.filter?.state === State.DELETED ? true : false,+ showDeleted: params.filter?.state !== State.ACTIVE,});const response = await instanceServiceClientConnect.listInstances(request, {contextValues: createContextValues().set(silentContextKey, params.silent),diff --git a/frontend/src/store/modules/v1/project.ts b/frontend/src/store/modules/v1/project.tsindex 17eec09dd3..0e9478056b 100644--- a/frontend/src/store/modules/v1/project.ts+++ b/frontend/src/store/modules/v1/project.ts@@ -143,7 +143,7 @@ export const useProjectV1Store = defineStore("project_v1", () => {pageToken,filter: getListProjectFilter(params.filter ?? {}),orderBy: params.orderBy,- showDeleted: params.filter?.state === State.DELETED ? true : false,+ showDeleted: params.filter?.state !== State.ACTIVE,});const connectResponse = await projectServiceClientConnect.listProjects(request,@@ -159,7 +159,7 @@ export const useProjectV1Store = defineStore("project_v1", () => {pageToken,filter: getListProjectFilter(params.filter ?? {}),orderBy: params.orderBy,- showDeleted: params.filter?.state === State.DELETED ? true : false,+ showDeleted: params.filter?.state !== State.ACTIVE,});const connectResponse =await projectServiceClientConnect.searchProjects(request, {diff --git a/frontend/src/utils/useDashboardSidebar.ts b/frontend/src/utils/useDashboardSidebar.tsindex ebfeb51642..ce08213041 100644--- a/frontend/src/utils/useDashboardSidebar.ts+++ b/frontend/src/utils/useDashboardSidebar.ts@@ -36,7 +36,6 @@ import {WORKSPACE_ROUTE_USERS,} from "@/router/dashboard/workspaceRoutes";import {- SETTING_ROUTE_WORKSPACE_ARCHIVE,SETTING_ROUTE_WORKSPACE_GENERAL,SETTING_ROUTE_WORKSPACE_SUBSCRIPTION,} from "@/router/dashboard/workspaceSetting";@@ -225,11 +224,6 @@ export const useDashboardSidebar = () => {name: SETTING_ROUTE_WORKSPACE_SUBSCRIPTION,type: "route",},- {- title: t("common.archived"),- name: SETTING_ROUTE_WORKSPACE_ARCHIVE,- type: "route",- },],},];diff --git a/frontend/src/views/Archive.vue b/frontend/src/views/Archive.vuedeleted file mode 100644index baa92b7ba1..0000000000--- a/frontend/src/views/Archive.vue+++ /dev/null@@ -1,106 +0,0 @@-<template>- <div class="flex flex-col gap-y-4">- <div class="flex justify-between items-end">- <TabFilter- :value="state.selectedTab"- :items="tabItemList"- @update:value="(val) => (state.selectedTab = val as LocalTabType)"- />-- <SearchBox- v-model:value="state.searchText"- :placeholder="$t('common.filter-by-name')"- />- </div>- <div class="">- <PagedProjectTable- v-if="state.selectedTab == 'PROJECT'"- session-key="bb.project-table.archived"- :filter="{- query: state.searchText,- state: State.DELETED,- excludeDefault: true,- }"- :bordered="true"- :show-selection="false"- />- <PagedInstanceTable- v-else-if="state.selectedTab == 'INSTANCE'"- session-key="bb.instance-table.archived"- :bordered="true"- :show-selection="false"- :filter="{- query: state.searchText,- state: State.DELETED,- }"- />- </div>- </div>-</template>--<script lang="ts" setup>-import { computed, reactive, watch } from "vue";-import { useI18n } from "vue-i18n";-import { useRoute, useRouter } from "vue-router";-import {- PagedInstanceTable,- PagedProjectTable,- SearchBox,- TabFilter,-} from "@/components/v2";-import { State } from "@/types/proto-es/v1/common_pb";-import { hasWorkspacePermissionV2 } from "@/utils";--const hashList = ["PROJECT", "INSTANCE"] as const;-export type TabHash = (typeof hashList)[number];-const isTabHash = (x: unknown): x is TabHash => hashList.includes(x as TabHash);--type LocalTabType = "PROJECT" | "INSTANCE";--interface LocalState {- selectedTab: LocalTabType;- searchText: string;-}--const router = useRouter();-const route = useRoute();-const { t } = useI18n();-const state = reactive<LocalState>({- selectedTab: "PROJECT",- searchText: "",-});--watch(- () => route.hash,- (hash) => {- const targetHash = hash.replace(/^#?/g, "") as TabHash;- if (isTabHash(targetHash)) {- state.selectedTab = targetHash;- }- },- { immediate: true }-);--watch(- () => state.selectedTab,- (tab) => {- router.replace({- hash: `#${tab}`,- query: route.query,- });- },- { immediate: true }-);--const tabItemList = computed(() => {- const list: { value: LocalTabType; label: string }[] = [- { value: "PROJECT", label: t("common.project") },- ];-- if (hasWorkspacePermissionV2("bb.instances.undelete")) {- list.push({ value: "INSTANCE", label: t("common.instance") });- }-- return list;-});-</script>diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vueindex 495066451e..3fb0f87ed8 100644--- a/frontend/src/views/InstanceDashboard.vue+++ b/frontend/src/views/InstanceDashboard.vue@@ -75,9 +75,9 @@<script lang="tsx" setup>import { PlusIcon } from "lucide-vue-next";import { NButton } from "naive-ui";-import { computed, onMounted, reactive, ref } from "vue";+import { computed, onMounted, reactive, ref, watch } from "vue";import { useI18n } from "vue-i18n";-import { useRouter } from "vue-router";+import { useRoute, useRouter } from "vue-router";import { BBAttention } from "@/bbkit";import AdvancedSearch from "@/components/AdvancedSearch";import type { ScopeOption } from "@/components/AdvancedSearch/types";@@ -102,11 +102,14 @@ import {} from "@/store";import { environmentNamePrefix } from "@/store/modules/v1/common";import { isValidInstanceName } from "@/types";-import { Engine } from "@/types/proto-es/v1/common_pb";+import { Engine, State } from "@/types/proto-es/v1/common_pb";import type { Instance } from "@/types/proto-es/v1/instance_service_pb";import {+ buildSearchParamsBySearchText,+ buildSearchTextBySearchParams,getValueFromSearchParams,getValuesFromSearchParams,+ hasWorkspacePermissionV2,type SearchParams,} from "@/utils";@@ -126,6 +129,7 @@ const subscriptionStore = useSubscriptionV1Store();const instanceV1Store = useInstanceV1Store();const uiStateStore = useUIStateStore();const actuatorStore = useActuatorV1Store();+const route = useRoute();const router = useRouter();const pagedInstanceTableRef = ref<InstanceType<typeof PagedInstanceTable>>();@@ -173,6 +177,13 @@ const selectedLabels = computed(() => {return getValuesFromSearchParams(state.params, "label");});+const selectedState = computed(() => {+ const stateValue = getValueFromSearchParams(state.params, "state");+ if (stateValue === "DELETED") return State.DELETED;+ if (stateValue === "ALL") return undefined; // undefined = show all+ return State.ACTIVE; // default+});+const filter = computed(() => ({environment: selectedEnvironment.value,host: selectedHost.value,@@ -180,6 +191,7 @@ const filter = computed(() => ({query: state.params.query,engines: selectedEngines.value,labels: selectedLabels.value,+ state: selectedState.value,}));const showCreateInstanceDrawer = () => {@@ -193,8 +205,9 @@ const showCreateInstanceDrawer = () => {};const scopeOptions = computed((): ScopeOption[] => {- return [- ...useCommonSearchScopeOptions(["environment", "engine", "label"]).value,+ const baseOptions = [+ ...useCommonSearchScopeOptions(["environment", "engine", "label", "state"])+ .value,{id: "host",title: t("instance.advanced-search.scope.host.title"),@@ -208,9 +221,39 @@ const scopeOptions = computed((): ScopeOption[] => {options: [],},];++ // If user doesn't have undelete permission, remove DELETED and ALL from state scope+ if (!hasWorkspacePermissionV2("bb.instances.undelete")) {+ return baseOptions.map((scope) => {+ if (scope.id === "state" && scope.options) {+ return {+ ...scope,+ options: scope.options.filter((opt) => opt.value === "ACTIVE"),+ };+ }+ return scope;+ });+ }++ return baseOptions;});onMounted(() => {+ // Migrate old URL format (?state=archived) to new format (?q=state:archived)+ const queryState = router.currentRoute.value.query.state as string;+ if (queryState === "archived" || queryState === "all") {+ const stateValue = queryState === "archived" ? "DELETED" : "ALL";+ router.replace({+ query: { q: `state:${stateValue}` },+ });+ }++ // Initialize params from URL query+ const queryString = route.query.q as string;+ if (queryString) {+ state.params = buildSearchParamsBySearchText(queryString);+ }+if (!uiStateStore.getIntroStateByKey("instance.visit")) {uiStateStore.saveIntroStateByKey({key: "instance.visit",@@ -219,6 +262,23 @@ onMounted(() => {}});+// Sync params to URL query when params change+watch(+ () => state.params,+ (params) => {+ const queryString = buildSearchTextBySearchParams(params);+ const currentQuery = route.query.q as string;++ // Only update URL if query string has actually changed+ if (queryString !== currentQuery) {+ router.replace({+ query: queryString ? { q: queryString } : {},+ });+ }+ },+ { deep: true }+);+const remainingInstanceCount = computed((): number => {return Math.max(0,diff --git a/frontend/src/views/ProjectDashboard.vue b/frontend/src/views/ProjectDashboard.vueindex c20b0f65c0..405deab295 100644--- a/frontend/src/views/ProjectDashboard.vue+++ b/frontend/src/views/ProjectDashboard.vue@@ -59,9 +59,9 @@<script lang="ts" setup>import { PlusIcon } from "lucide-vue-next";import { NButton } from "naive-ui";-import { computed, onMounted, reactive, ref } from "vue";+import { computed, onMounted, reactive, ref, watch } from "vue";import type { ComponentExposed } from "vue-component-type-helpers";-import { useRouter } from "vue-router";+import { useRoute, useRouter } from "vue-router";import AdvancedSearch, {useCommonSearchScopeOptions,} from "@/components/AdvancedSearch";@@ -70,8 +70,12 @@ import ProjectCreatePanel from "@/components/Project/ProjectCreatePanel.vue";import { Drawer, PagedProjectTable } from "@/components/v2";import ProjectOperations from "@/components/v2/Model/Project/ProjectOperations.vue";import { useProjectV1Store, useUIStateStore } from "@/store";+import { State } from "@/types/proto-es/v1/common_pb";import type { Project } from "@/types/proto-es/v1/project_service_pb";import {+ buildSearchParamsBySearchText,+ buildSearchTextBySearchParams,+ getValueFromSearchParams,getValuesFromSearchParams,hasWorkspacePermissionV2,type SearchParams,@@ -96,23 +100,50 @@ const state = reactive<LocalState>({selectedProjects: new Set(),});+const route = useRoute();const router = useRouter();const projectStore = useProjectV1Store();const pagedProjectTableRef = ref<ComponentExposed<typeof PagedProjectTable>>();-// Add label to the available scopes for filtering projects-const scopeOptions = useCommonSearchScopeOptions(["label"]);+// Add label and state to the available scopes for filtering projects+// Filter state options based on permissions+const scopeOptions = computed(() => {+ const baseOptions = useCommonSearchScopeOptions(["label", "state"]).value;++ // If user doesn't have undelete permission, remove DELETED and ALL from state scope+ if (!hasWorkspacePermissionV2("bb.projects.undelete")) {+ return baseOptions.map((scope) => {+ if (scope.id === "state" && scope.options) {+ return {+ ...scope,+ options: scope.options.filter((opt) => opt.value === "ACTIVE"),+ };+ }+ return scope;+ });+ }++ return baseOptions;+});// Extract labels from the search scopesconst selectedLabels = computed(() => {return getValuesFromSearchParams(state.params, "label");});+const selectedState = computed(() => {+ const stateValue = getValueFromSearchParams(state.params, "state");+ if (stateValue === "DELETED") return State.DELETED;+ if (stateValue === "ALL") return undefined; // undefined = show all+ return State.ACTIVE; // default+});+const filter = computed(() => ({query: state.params.query,excludeDefault: true,labels: selectedLabels.value,+ state: selectedState.value,}));const selectedProjectNames = computed(() => {@@ -138,6 +169,21 @@ const handleBatchOperation = () => {};onMounted(() => {+ // Migrate old URL format (?state=archived) to new format (?q=state:archived)+ const queryState = router.currentRoute.value.query.state as string;+ if (queryState === "archived" || queryState === "all") {+ const stateValue = queryState === "archived" ? "DELETED" : "ALL";+ router.replace({+ query: { q: `state:${stateValue}` },+ });+ }++ // Initialize params from URL query+ const queryString = route.query.q as string;+ if (queryString) {+ state.params = buildSearchParamsBySearchText(queryString);+ }+const uiStateStore = useUIStateStore();if (!uiStateStore.getIntroStateByKey("project.visit")) {uiStateStore.saveIntroStateByKey({@@ -147,6 +193,23 @@ onMounted(() => {}});+// Sync params to URL query when params change+watch(+ () => state.params,+ (params) => {+ const queryString = buildSearchTextBySearchParams(params);+ const currentQuery = route.query.q as string;++ // Only update URL if query string has actually changed+ if (queryString !== currentQuery) {+ router.replace({+ query: queryString ? { q: queryString } : {},+ });+ }+ },+ { deep: true }+);+const handleCreated = async (project: Project) => {if (props.onRowClick) {return props.onRowClick(project);