Skip to content

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

chore: set default project as filter in workspace databases page (#13817)

boojackc69d193d0baf
diff --git a/frontend/src/components/AdvancedSearch/AdvancedSearch.vue b/frontend/src/components/AdvancedSearch/AdvancedSearch.vue
index 1d6ca95e41..2bdc497dcc 100644
--- a/frontend/src/components/AdvancedSearch/AdvancedSearch.vue
+++ b/frontend/src/components/AdvancedSearch/AdvancedSearch.vue
@@ -1,13 +1,9 @@
<template>
- <div
- ref="containerRef"
- class="bb-advanced-audit-log-search-box w-full relative"
- >
+ <div ref="containerRef" class="w-full relative">
<NInput
ref="inputRef"
v-model:value="inputText"
:placeholder="placeholder ?? $t('issue.advanced-search.self')"
- class="bb-advanced-audit-log-search-box__input"
style="--n-padding-left: 8px; --n-padding-right: 4px"
@click="handleInputClick"
@blur="hideMenu"
@@ -547,11 +543,3 @@ watch(
}
);
</script>
-
-<style lang="postcss" scoped>
-.bb-advanced-audit-log-search-box
- .bb-advanced-audit-log-search-box__input
- :deep(.n-input__input) {
- @apply flex flex-row items-center;
-}
-</style>
diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vue
index 601970bd64..89c8c94ee5 100644
--- a/frontend/src/components/ProjectDatabasesPanel.vue
+++ b/frontend/src/components/ProjectDatabasesPanel.vue
@@ -1,7 +1,7 @@
<template>
<div class="space-y-4">
<div
- class="w-full text-lg font-medium leading-7 text-main flex flex-col sm:flex-row items-start sm:items-end justify-between gap-2"
+ class="w-full flex flex-col sm:flex-row items-start sm:items-end justify-between gap-2"
>
<AdvancedSearch
v-model:params="state.params"
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index fdb0bf7d01..a16563d953 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -21,7 +21,7 @@
<DatabaseV1Table
mode="ALL"
- :loading="!ready"
+ :loading="loading"
:bordered="false"
:database-list="filteredDatabaseList"
:custom-click="true"
@@ -33,7 +33,7 @@
</template>
<script lang="ts" setup>
-import { computed, onMounted, reactive, watch } from "vue";
+import { computed, onMounted, reactive, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import AdvancedSearch from "@/components/AdvancedSearch";
import { useCommonSearchScopeOptions } from "@/components/AdvancedSearch/useCommonSearchScopeOptions";
@@ -41,10 +41,16 @@ import DatabaseV1Table, {
DatabaseLabelFilter,
DatabaseOperations,
} from "@/components/v2/Model/DatabaseV1Table";
-import { useAppFeature, useProjectV1List, useUIStateStore } from "@/store";
+import {
+ useAppFeature,
+ useDatabaseV1Store,
+ useProjectV1List,
+ useUIStateStore,
+} from "@/store";
+import { projectNamePrefix } from "@/store/modules/v1/common";
import { useDatabaseV1List } from "@/store/modules/v1/databaseList";
import type { ComposedDatabase } from "@/types";
-import { UNKNOWN_ID, DEFAULT_PROJECT_NAME } from "@/types";
+import { DEFAULT_PROJECT_NAME } from "@/types";
import type { SearchParams } from "@/utils";
import {
filterDatabaseV1ByKeyword,
@@ -68,22 +74,30 @@ interface LocalState {
const props = defineProps<{
onClickDatabase?: (db: ComposedDatabase, event: MouseEvent) => void;
}>();
+
const emit = defineEmits<{
(event: "ready"): void;
}>();
+const route = useRoute();
+const router = useRouter();
const uiStateStore = useUIStateStore();
const { projectList } = useProjectV1List();
const hideUnassignedDatabases = useAppFeature(
"bb.feature.databases.hide-unassigned"
);
-const route = useRoute();
-const router = useRouter();
+const loading = ref(false);
const defaultSearchParams = () => {
const params: SearchParams = {
query: "",
- scopes: [],
+ scopes: [
+ // Default to show unassigned database from default project.
+ {
+ id: "project",
+ value: extractProjectResourceName(DEFAULT_PROJECT_NAME),
+ },
+ ],
};
return params;
};
@@ -102,45 +116,21 @@ const state = reactive<LocalState>({
selectedLabels: [],
});
-watch(
- () => state.params,
- () => {
- // using custom advanced search query, sync the search query string
- // to URL
- router.replace({
- query: {
- ...route.query,
- qs: buildSearchTextBySearchParams(state.params),
- },
- });
- },
- { deep: true }
-);
-
const scopeOptions = useCommonSearchScopeOptions(
computed(() => state.params),
[...CommonFilterScopeIdList, "project"]
);
const selectedInstance = computed(() => {
- return (
- state.params.scopes.find((scope) => scope.id === "instance")?.value ??
- `${UNKNOWN_ID}`
- );
+ return state.params.scopes.find((scope) => scope.id === "instance")?.value;
});
const selectedEnvironment = computed(() => {
- return (
- state.params.scopes.find((scope) => scope.id === "environment")?.value ??
- `${UNKNOWN_ID}`
- );
+ return state.params.scopes.find((scope) => scope.id === "environment")?.value;
});
const selectedProject = computed(() => {
- return (
- state.params.scopes.find((scope) => scope.id === "project")?.value ??
- `${UNKNOWN_ID}`
- );
+ return state.params.scopes.find((scope) => scope.id === "project")?.value;
});
onMounted(() => {
@@ -152,31 +142,49 @@ onMounted(() => {
}
});
-const { databaseList, ready } = useDatabaseV1List();
+watch(
+ () => selectedProject.value,
+ async () => {
+ loading.value = true;
+ let parent = undefined;
+ if (selectedProject.value) {
+ parent = `${projectNamePrefix}${selectedProject.value}`;
+ }
+ await wrapRefAsPromise(
+ useDatabaseV1List(parent).ready,
+ /* expected */ true
+ );
+ loading.value = false;
+ emit("ready");
+ },
+ {
+ immediate: true,
+ }
+);
const databaseV1List = computed(() => {
const projects = new Set(projectList.value.map((project) => project.name));
- return sortDatabaseV1List(databaseList.value).filter((db) =>
+ return sortDatabaseV1List(useDatabaseV1Store().databaseList).filter((db) =>
projects.has(db.project)
);
});
const filteredDatabaseList = computed(() => {
let list = databaseV1List.value;
- if (selectedEnvironment.value !== `${UNKNOWN_ID}`) {
+ if (selectedEnvironment.value) {
list = list.filter(
(db) =>
extractEnvironmentResourceName(db.effectiveEnvironment) ===
selectedEnvironment.value
);
}
- if (selectedInstance.value !== `${UNKNOWN_ID}`) {
+ if (selectedInstance.value) {
list = list.filter(
(db) =>
extractInstanceResourceName(db.instance) === selectedInstance.value
);
}
- if (selectedProject.value !== `${UNKNOWN_ID}`) {
+ if (selectedProject.value) {
list = list.filter(
(db) => extractProjectResourceName(db.project) === selectedProject.value
);
@@ -229,7 +237,16 @@ const handleDatabaseClick = (event: MouseEvent, database: ComposedDatabase) => {
}
};
-wrapRefAsPromise(ready, /* expected */ true).then(() => {
- emit("ready");
-});
+watch(
+ () => state.params,
+ () => {
+ router.replace({
+ query: {
+ ...route.query,
+ qs: buildSearchTextBySearchParams(state.params),
+ },
+ });
+ },
+ { deep: true }
+);
</script>