Skip to content

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

refactor: environment selector component (#7714)

ecmadao7dfdf8f95b89
diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vue
index fc6f6d9495..c937399596 100644
--- a/frontend/src/components/ProjectDatabasesPanel.vue
+++ b/frontend/src/components/ProjectDatabasesPanel.vue
@@ -7,7 +7,7 @@
<EnvironmentTabFilter
:environment="state.environment"
:include-all="true"
- @update:environment="state.environment = $event ?? UNKNOWN_ID"
+ @update:environment="state.environment = $event"
/>
</div>
<NInputGroup style="width: auto">
@@ -15,7 +15,7 @@
:instance="state.instance"
:include-all="true"
:filter="filterInstance"
- :environment="state.environment"
+ :environment="environment?.uid"
@update:instance="
state.instance = $event ? String($event) : String(UNKNOWN_ID)
"
@@ -52,14 +52,23 @@
import { uniqBy } from "lodash-es";
import { NInputGroup } from "naive-ui";
import { reactive, PropType, computed, ref, watchEffect } from "vue";
-import { useCurrentUserV1, usePolicyV1Store } from "@/store";
+import {
+ useCurrentUserV1,
+ usePolicyV1Store,
+ useEnvironmentV1Store,
+} from "@/store";
import {
Policy,
PolicyResourceType,
PolicyType,
} from "@/types/proto/v1/org_policy_service";
import { filterDatabaseV1ByKeyword, isDatabaseV1Accessible } from "@/utils";
-import { ComposedDatabase, ComposedInstance, UNKNOWN_ID } from "../types";
+import {
+ ComposedDatabase,
+ ComposedInstance,
+ UNKNOWN_ID,
+ UNKNOWN_ENVIRONMENT_NAME,
+} from "../types";
import { DatabaseV1Table } from "./v2";
import { EnvironmentTabFilter, InstanceSelect, SearchBox } from "./v2";
@@ -77,8 +86,10 @@ const props = defineProps({
});
const currentUserV1 = useCurrentUserV1();
+const environmentV1Store = useEnvironmentV1Store();
+
const state = reactive<LocalState>({
- environment: String(UNKNOWN_ID),
+ environment: UNKNOWN_ENVIRONMENT_NAME,
instance: String(UNKNOWN_ID),
keyword: "",
});
@@ -99,9 +110,9 @@ const filteredDatabaseList = computed(() => {
let list = [...props.databaseList].filter((database) =>
isDatabaseV1Accessible(database, currentUserV1.value)
);
- if (state.environment !== String(UNKNOWN_ID)) {
+ if (state.environment !== UNKNOWN_ENVIRONMENT_NAME) {
list = list.filter(
- (db) => db.effectiveEnvironmentEntity.uid === state.environment
+ (db) => db.effectiveEnvironmentEntity.name === state.environment
);
}
if (state.instance !== String(UNKNOWN_ID)) {
@@ -130,4 +141,8 @@ const instanceList = computed(() => {
const filterInstance = (instance: ComposedInstance) => {
return instanceList.value.findIndex((inst) => inst.uid === instance.uid) >= 0;
};
+
+const environment = computed(() => {
+ return environmentV1Store.getEnvironmentByName(state.environment);
+});
</script>
diff --git a/frontend/src/components/SlowQuery/Panel/LogFilter.vue b/frontend/src/components/SlowQuery/Panel/LogFilter.vue
index c87905d330..6388655ce0 100644
--- a/frontend/src/components/SlowQuery/Panel/LogFilter.vue
+++ b/frontend/src/components/SlowQuery/Panel/LogFilter.vue
@@ -10,10 +10,10 @@
<EnvironmentTabFilter
v-if="filterTypes.includes('environment')"
class="flex-1"
- :environment="params.environment?.uid ?? String(UNKNOWN_ID)"
+ :environment="params.environment?.name"
:include-all="true"
:disabled="loading"
- @update:environment="changeEnvironmentId"
+ @update:environment="changeEnvironment"
/>
</div>
@@ -134,8 +134,8 @@ const canVisitDefaultProject = computed(() => {
);
});
-const changeEnvironmentId = (id: string) => {
- const environment = useEnvironmentV1Store().getEnvironmentByUID(id);
+const changeEnvironment = (name: string) => {
+ const environment = useEnvironmentV1Store().getEnvironmentByName(name);
update({ environment });
};
const changeInstanceId = (uid: string | undefined) => {
diff --git a/frontend/src/components/SlowQuery/Settings/SlowQuerySettings.vue b/frontend/src/components/SlowQuery/Settings/SlowQuerySettings.vue
index 87ac0ccc90..107dcbc360 100644
--- a/frontend/src/components/SlowQuery/Settings/SlowQuerySettings.vue
+++ b/frontend/src/components/SlowQuery/Settings/SlowQuerySettings.vue
@@ -13,7 +13,7 @@
</div>
<div class="flex items-center justify-between">
<EnvironmentTabFilter
- :environment="state.filter.environment?.uid ?? String(UNKNOWN_ID)"
+ :environment="state.filter.environment?.name"
:include-all="true"
@update:environment="changeEnvironment"
/>
@@ -132,9 +132,9 @@ const prepare = async () => {
}
};
-const changeEnvironment = (id: string | undefined) => {
+const changeEnvironment = (name: string | undefined) => {
state.filter.environment = environmentList.value.find(
- (env) => env.uid === id
+ (env) => env.name === name
);
};
diff --git a/frontend/src/components/v2/TabFilter/EnvironmentTabFilter.vue b/frontend/src/components/v2/TabFilter/EnvironmentTabFilter.vue
index 5b07bc9c05..1ab97b109e 100644
--- a/frontend/src/components/v2/TabFilter/EnvironmentTabFilter.vue
+++ b/frontend/src/components/v2/TabFilter/EnvironmentTabFilter.vue
@@ -5,7 +5,9 @@
@update:value="$emit('update:environment', $event)"
>
<template #label="{ item }">
- <template v-if="item.value === UNKNOWN_ID">{{ item.label }}</template>
+ <template v-if="item.value === UNKNOWN_ENVIRONMENT_NAME">{{
+ item.label
+ }}</template>
<EnvironmentV1Name v-else :environment="item.environment" :link="false" />
</template>
</TabFilter>
@@ -15,7 +17,7 @@
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useEnvironmentV1List } from "@/store";
-import { UNKNOWN_ID, unknownEnvironment } from "@/types";
+import { UNKNOWN_ENVIRONMENT_NAME, unknownEnvironment } from "@/types";
import { Environment } from "@/types/proto/v1/environment_service";
import { EnvironmentV1Name } from "../Model";
import { TabFilterItem } from "./types";
@@ -26,10 +28,11 @@ interface EnvironmentTabFilterItem extends TabFilterItem<string> {
const props = withDefaults(
defineProps<{
- environment: string; // UNKNOWN_ID(-1) to "ALL"
+ environment?: string; // UNKNOWN_ENVIRONMENT_NAME to "ALL"
includeAll?: boolean;
}>(),
{
+ environment: UNKNOWN_ENVIRONMENT_NAME,
includeAll: false,
}
);
@@ -45,17 +48,17 @@ const items = computed(() => {
const reversedEnvironmentList = [...environmentList.value].reverse();
const environmentItems =
reversedEnvironmentList.map<EnvironmentTabFilterItem>((env) => ({
- value: env.uid,
+ value: env.name,
label: env.title,
environment: env,
}));
- if (props.environment === String(UNKNOWN_ID) || props.includeAll) {
+ if (props.environment === UNKNOWN_ENVIRONMENT_NAME || props.includeAll) {
const dummyAll = {
...unknownEnvironment(),
title: t("common.all"),
};
environmentItems.unshift({
- value: dummyAll.uid,
+ value: dummyAll.name,
label: dummyAll.title,
environment: dummyAll,
});
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index e0df66a970..ad7047a68d 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -3,8 +3,8 @@
<div class="px-4 py-2 flex justify-between items-center">
<EnvironmentTabFilter
:include-all="true"
- :environment="selectedEnvironment?.uid ?? String(UNKNOWN_ID)"
- @update:environment="changeEnvironmentId"
+ :environment="selectedEnvironment?.name"
+ @update:environment="changeEnvironment"
/>
<div class="flex items-center space-x-4">
@@ -96,6 +96,7 @@ import {
} from "@/utils";
import {
UNKNOWN_ID,
+ UNKNOWN_ENVIRONMENT_NAME,
DEFAULT_PROJECT_ID,
UNKNOWN_USER_NAME,
ComposedDatabase,
@@ -144,7 +145,7 @@ watchEffect(preparePolicyList);
const selectedEnvironment = computed(() => {
const { environment } = route.query;
return environment
- ? environmentV1Store.getEnvironmentByUID(environment as string)
+ ? environmentV1Store.getEnvironmentByName(environment as string)
: undefined;
});
@@ -197,8 +198,8 @@ watchEffect(async () => {
state.loading = false;
});
-const changeEnvironmentId = (environment: string | undefined) => {
- if (environment && environment !== String(UNKNOWN_ID)) {
+const changeEnvironment = (environment: string | undefined) => {
+ if (environment && environment !== UNKNOWN_ENVIRONMENT_NAME) {
router.replace({
name: "workspace.database",
query: { environment },
@@ -219,7 +220,7 @@ const filteredDatabaseList = computed(() => {
isDatabaseV1Accessible(database, currentUserV1.value)
);
const environment = selectedEnvironment.value;
- if (environment && environment.name !== `environments/${UNKNOWN_ID}`) {
+ if (environment && environment.name !== UNKNOWN_ENVIRONMENT_NAME) {
list = list.filter((db) => db.effectiveEnvironment === environment.name);
}
if (state.instanceFilter !== String(UNKNOWN_ID)) {
@@ -244,7 +245,7 @@ const filteredDatabaseList = computed(() => {
const filteredDatabaseGroupList = computed(() => {
let list = [...state.databaseGroupList];
const environment = selectedEnvironment.value;
- if (environment && environment.name !== `environments/${UNKNOWN_ID}`) {
+ if (environment && environment.name !== UNKNOWN_ENVIRONMENT_NAME) {
list = list.filter(
(dbGroup) => dbGroup.environmentName === environment.name
);
diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue
index 76bd7eb6da..b344a39f7b 100644
--- a/frontend/src/views/Home.vue
+++ b/frontend/src/views/Home.vue
@@ -3,8 +3,8 @@
<div class="px-4 py-2 flex justify-between items-center">
<EnvironmentTabFilter
:include-all="true"
- :environment="selectedEnvironment?.uid ?? String(UNKNOWN_ID)"
- @update:environment="changeEnvironmentId"
+ :environment="selectedEnvironment?.name"
+ @update:environment="changeEnvironment"
/>
<SearchBox
:value="state.searchText"
@@ -206,7 +206,12 @@ import {
featureToRef,
useCurrentUserV1,
} from "@/store";
-import { UNKNOWN_ID, Issue, planTypeToString } from "../types";
+import {
+ UNKNOWN_ID,
+ UNKNOWN_ENVIRONMENT_NAME,
+ Issue,
+ planTypeToString,
+} from "../types";
import {
activeEnvironment,
extractUserUID,
@@ -253,7 +258,7 @@ const planImage = computed(() => {
const selectedEnvironment = computed(() => {
const { environment } = route.query;
return environment
- ? environmentV1Store.getEnvironmentByUID(environment as string)
+ ? environmentV1Store.getEnvironmentByName(environment as string)
: undefined;
});
@@ -281,8 +286,8 @@ const keywordAndEnvironmentFilter = (issue: Issue) => {
return true;
};
-const changeEnvironmentId = (environment: string | undefined) => {
- if (environment && environment !== String(UNKNOWN_ID)) {
+const changeEnvironment = (environment: string | undefined) => {
+ if (environment && environment !== UNKNOWN_ENVIRONMENT_NAME) {
router.replace({
name: "workspace.home",
query: {
diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vue
index 539ceb4d83..e585aa7f40 100644
--- a/frontend/src/views/InstanceDashboard.vue
+++ b/frontend/src/views/InstanceDashboard.vue
@@ -8,7 +8,7 @@
/>
<div class="px-4 py-2 flex justify-between items-center">
<EnvironmentTabFilter
- :environment="selectedEnvironment?.uid ?? String(UNKNOWN_ID)"
+ :environment="selectedEnvironment?.name"
:include-all="true"
@update:environment="selectEnvironment"
/>
@@ -43,7 +43,7 @@ import {
useInstanceV1Store,
} from "@/store";
import { PlanType } from "@/types/proto/v1/subscription_service";
-import { UNKNOWN_ID } from "../types";
+import { UNKNOWN_ENVIRONMENT_NAME } from "../types";
import { sortInstanceV1ListByEnvironmentV1 } from "../utils";
interface LocalState {
@@ -63,8 +63,9 @@ const state = reactive<LocalState>({
});
const selectedEnvironment = computed(() => {
- const uid = router.currentRoute.value.query.environment as string;
- if (uid) return useEnvironmentV1Store().getEnvironmentByUID(uid);
+ const environment = router.currentRoute.value.query.environment as string;
+ if (environment)
+ return useEnvironmentV1Store().getEnvironmentByName(environment);
return undefined;
});
@@ -77,11 +78,11 @@ onMounted(() => {
}
});
-const selectEnvironment = (uid: string | undefined) => {
- if (uid && uid !== String(UNKNOWN_ID)) {
+const selectEnvironment = (environment: string | undefined) => {
+ if (environment && environment !== UNKNOWN_ENVIRONMENT_NAME) {
router.replace({
name: "workspace.instance",
- query: { environment: uid },
+ query: { environment },
});
} else {
router.replace({ name: "workspace.instance" });
@@ -95,7 +96,7 @@ const { instanceList: rawInstanceV1List } = useInstanceV1List(
const filteredInstanceV1List = computed(() => {
let list = [...rawInstanceV1List.value];
const environment = selectedEnvironment.value;
- if (environment && environment.uid !== String(UNKNOWN_ID)) {
+ if (environment && environment.name !== UNKNOWN_ENVIRONMENT_NAME) {
list = list.filter((instance) => instance.environment === environment.name);
}
const keyword = state.searchText.trim().toLowerCase();
diff --git a/frontend/src/views/IssueDashboard.vue b/frontend/src/views/IssueDashboard.vue
index 4f0465a12f..a291d31494 100644
--- a/frontend/src/views/IssueDashboard.vue
+++ b/frontend/src/views/IssueDashboard.vue
@@ -3,8 +3,8 @@
<div class="px-4 py-2 flex justify-between items-center">
<EnvironmentTabFilter
:include-all="true"
- :environment="selectedEnvironment?.uid ?? String(UNKNOWN_ID)"
- @update:environment="changeEnvironmentId($event)"
+ :environment="selectedEnvironment?.name"
+ @update:environment="changeEnvironment($event)"
/>
<div class="flex flex-row space-x-4">
<NButton v-if="project" @click="goProject">
@@ -178,7 +178,7 @@ const selectedUserUID = computed((): string => {
const selectedEnvironment = computed((): Environment | undefined => {
const { environment } = route.query;
return environment
- ? environmentV1Store.getEnvironmentByUID(environment as string)
+ ? environmentV1Store.getEnvironmentByName(environment as string)
: undefined;
});
@@ -208,7 +208,7 @@ const filter = (issue: Issue) => {
return true;
};
-const changeEnvironmentId = (environment: string | undefined) => {
+const changeEnvironment = (environment: string | undefined) => {
if (environment && environment !== String(UNKNOWN_ID)) {
router.replace({
name: "workspace.issue",