Skip to content

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

chore(frontend): refactor do not use environment uid if not really needed (#12787)

Liu Jie4da331e8467
diff --git a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
index 32232068e4..94bf235904 100644
--- a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
+++ b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
@@ -55,8 +55,6 @@ export const useCommonSearchScopeOptions = (
// fullScopeOptions provides full search scopes and options.
// we need this as the source of truth.
const fullScopeOptions = computed((): ScopeOption[] => {
- console.time("evaluate fullScopeOptions");
-
const scopeCreators = {
project: () => ({
id: "project",
@@ -186,7 +184,6 @@ export const useCommonSearchScopeOptions = (
scopes.push(create());
}
});
- console.timeEnd("evaluate fullScopeOptions");
return scopes;
});
diff --git a/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue b/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue
index 97b00cbc32..0c544bad6a 100644
--- a/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue
@@ -15,7 +15,7 @@
<NCollapse
arrow-placement="left"
:default-expanded-names="
- databaseListGroupByEnvironment.map((group) => group.environment.uid)
+ databaseListGroupByEnvironment.map((group) => group.environment.name)
"
>
<NCollapseItem
@@ -23,8 +23,8 @@
environment,
databaseList: databaseListInEnvironment,
} in databaseListGroupByEnvironment"
- :key="environment.uid"
- :name="environment.uid"
+ :key="environment.name"
+ :name="environment.name"
>
<template #header>
<label class="flex items-center gap-x-2" @click.stop.prevent>
@@ -79,14 +79,14 @@
:checked="
isDatabaseSelectedForEnvironment(
database.uid,
- environment.uid
+ environment.name
)
"
@update:checked="
(checked) =>
toggleDatabaseUidForEnvironment(
database.uid,
- environment.uid,
+ environment.name,
checked
)
"
@@ -171,11 +171,11 @@ const databaseListGroupByEnvironment = computed(() => {
const toggleDatabaseUidForEnvironment = (
databaseId: string,
- environmentId: string,
+ environmentName: string,
selected: boolean
) => {
const map = state.selectedDatabaseUidListForEnvironment;
- const list = map.get(environmentId) || [];
+ const list = map.get(environmentName) || [];
const index = list.indexOf(databaseId);
if (selected) {
// push the databaseId in if needed
@@ -190,18 +190,18 @@ const toggleDatabaseUidForEnvironment = (
}
// Set or remove the list to the map
if (list.length > 0) {
- map.set(environmentId, list);
+ map.set(environmentName, list);
} else {
- map.delete(environmentId);
+ map.delete(environmentName);
}
};
const isDatabaseSelectedForEnvironment = (
databaseId: string,
- environmentId: string
+ environmentName: string
) => {
const map = state.selectedDatabaseUidListForEnvironment;
- const list = map.get(environmentId) || [];
+ const list = map.get(environmentName) || [];
return list.includes(databaseId);
};
@@ -210,7 +210,7 @@ const getAllSelectionStateForEnvironment = (
databaseList: ComposedDatabase[]
): { checked: boolean; indeterminate: boolean } => {
const set = new Set(
- state.selectedDatabaseUidListForEnvironment.get(environment.uid) ?? []
+ state.selectedDatabaseUidListForEnvironment.get(environment.name) ?? []
);
const checked = set.size > 0 && databaseList.every((db) => set.has(db.uid));
const indeterminate = !checked && databaseList.some((db) => set.has(db.uid));
@@ -227,7 +227,7 @@ const toggleAllDatabasesSelectionForEnvironment = (
on: boolean
) => {
databaseList.forEach((db) =>
- toggleDatabaseUidForEnvironment(db.uid, environment.uid, on)
+ toggleDatabaseUidForEnvironment(db.uid, environment.name, on)
);
};
@@ -236,7 +236,7 @@ const getSelectionStateSummaryForEnvironment = (
databaseList: ComposedDatabase[]
) => {
const set = new Set(
- state.selectedDatabaseUidListForEnvironment.get(environment.uid)
+ state.selectedDatabaseUidListForEnvironment.get(environment.name)
);
const selected = databaseList.filter((db) => set.has(db.uid)).length;
const total = databaseList.length;
diff --git a/frontend/src/components/AnomalyCenter/AnomalyCenterDashboard.vue b/frontend/src/components/AnomalyCenter/AnomalyCenterDashboard.vue
index 90e62719f5..13e527aaf3 100644
--- a/frontend/src/components/AnomalyCenter/AnomalyCenterDashboard.vue
+++ b/frontend/src/components/AnomalyCenter/AnomalyCenterDashboard.vue
@@ -290,13 +290,13 @@ const databaseAnomalySummaryList = computed((): Summary[] => {
break;
}
}
- const summary = envMap.get(database.effectiveEnvironmentEntity.uid);
+ const summary = envMap.get(database.effectiveEnvironment);
if (summary) {
summary.criticalCount += criticalCount;
summary.highCount += highCount;
summary.mediumCount += mediumCount;
} else {
- envMap.set(String(database.effectiveEnvironmentEntity.uid), {
+ envMap.set(database.effectiveEnvironment, {
environmentName: database.effectiveEnvironmentEntity.title,
criticalCount,
highCount,
@@ -307,7 +307,7 @@ const databaseAnomalySummaryList = computed((): Summary[] => {
const list: Summary[] = [];
for (const environment of environmentList.value) {
- const summary = envMap.get(environment.uid);
+ const summary = envMap.get(environment.name);
if (summary) {
list.push(summary);
}
@@ -338,13 +338,13 @@ const instanceAnomalySummaryList = computed((): Summary[] => {
break;
}
}
- const summary = envMap.get(instance.environmentEntity.uid);
+ const summary = envMap.get(instance.environment);
if (summary) {
summary.criticalCount += criticalCount;
summary.highCount += highCount;
summary.mediumCount += mediumCount;
} else {
- envMap.set(instance.environmentEntity.uid, {
+ envMap.set(instance.environment, {
environmentName: instance.environmentEntity.title,
criticalCount,
highCount,
@@ -355,7 +355,7 @@ const instanceAnomalySummaryList = computed((): Summary[] => {
const list: Summary[] = [];
for (const environment of environmentList.value) {
- const summary = envMap.get(environment.uid);
+ const summary = envMap.get(environment.name);
if (summary) {
list.push(summary);
}
diff --git a/frontend/src/components/Branch/BaselineSchemaSelector.vue b/frontend/src/components/Branch/BaselineSchemaSelector.vue
index 179190d89b..557ef9b2a3 100644
--- a/frontend/src/components/Branch/BaselineSchemaSelector.vue
+++ b/frontend/src/components/Branch/BaselineSchemaSelector.vue
@@ -3,15 +3,15 @@
<EnvironmentSelect
name="environment"
:disabled="readonly || props.loading"
- :environment="state.environmentId"
- @update:environment="handleEnvironmentSelect"
+ :environment-name="state.environmentName"
+ @update:environment-name="handleEnvironmentSelect"
/>
<DatabaseSelect
style="width: 100%"
:placeholder="$t('schema-designer.select-database-placeholder')"
:disabled="readonly || props.loading"
:allowed-engine-type-list="allowedEngineTypeList"
- :environment="state.environmentId"
+ :environment="shamefulEnvironmentUID"
:project="projectId"
:database="state.databaseId ?? String(UNKNOWN_ID)"
:fallback-option="false"
@@ -22,7 +22,7 @@
<script lang="ts" setup>
import { isNull, isUndefined } from "lodash-es";
-import { reactive, watch } from "vue";
+import { computed, reactive, watch } from "vue";
import { EnvironmentSelect, DatabaseSelect } from "@/components/v2";
import { useDatabaseV1Store, useEnvironmentV1Store } from "@/store";
import { UNKNOWN_ID } from "@/types";
@@ -40,13 +40,12 @@ const emit = defineEmits<{
}>();
interface LocalState {
- environmentId?: string;
+ environmentName?: string;
databaseId?: string;
}
const state = reactive<LocalState>({});
const databaseStore = useDatabaseV1Store();
-const environmentStore = useEnvironmentV1Store();
watch(
() => props.projectId,
@@ -58,7 +57,7 @@ watch(
return;
}
if (database.projectEntity.uid !== props.projectId) {
- state.environmentId = undefined;
+ state.environmentName = undefined;
state.databaseId = undefined;
}
}
@@ -73,7 +72,7 @@ watch(
try {
if (database) {
state.databaseId = database.uid;
- state.environmentId = database.effectiveEnvironmentEntity.uid;
+ state.environmentName = database.effectiveEnvironment;
}
} catch (error) {
// do nothing.
@@ -96,9 +95,9 @@ const isValidId = (id: any): id is string => {
return true;
};
-const handleEnvironmentSelect = (environmentId?: string) => {
- if (environmentId !== state.environmentId) {
- state.environmentId = environmentId;
+const handleEnvironmentSelect = (name?: string) => {
+ if (name !== state.environmentName) {
+ state.environmentName = name;
state.databaseId = undefined;
}
};
@@ -109,14 +108,17 @@ const handleDatabaseSelect = (databaseId?: string) => {
if (!database) {
return;
}
-
- const environment = environmentStore.getEnvironmentByName(
- database.effectiveEnvironment
- );
- state.environmentId = environment?.uid;
+ state.environmentName = database.effectiveEnvironment;
state.databaseId = databaseId;
}
};
+
+const shamefulEnvironmentUID = computed(() => {
+ // todo(jim): refactor me
+ const { environmentName } = state;
+ if (!environmentName) return undefined;
+ return useEnvironmentV1Store().getEnvironmentByName(environmentName).uid;
+});
</script>
<style lang="postcss">
diff --git a/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue b/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue
index edcfe3d6e4..ce769b1d43 100644
--- a/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue
+++ b/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue
@@ -11,9 +11,9 @@
<div class="flex flex-row items-center gap-x-2">
<div class="textlabel">{{ $t("common.environment") }}</div>
<EnvironmentSelect
- :environment="environment?.uid"
+ :environment-name="environment?.name"
style="width: 8rem"
- @update:environment="handleSelectEnvironment"
+ @update:environment-name="handleSelectEnvironment"
/>
</div>
<div class="flex flex-row items-center gap-x-2">
@@ -142,7 +142,7 @@ import {
useSheetV1Store,
} from "@/store";
import type { ComposedDatabase, ComposedProject } from "@/types";
-import { UNKNOWN_ID } from "@/types";
+import { UNKNOWN_ENVIRONMENT_NAME, UNKNOWN_ID } from "@/types";
import { Branch } from "@/types/proto/v1/branch_service";
import { DatabaseMetadata } from "@/types/proto/v1/database_service";
import type { Environment } from "@/types/proto/v1/environment_service";
@@ -193,14 +193,15 @@ const emptyBranch = Branch.fromJSON({});
const isGeneratingDDL = ref(false);
const $dialog = useDialog();
-const handleSelectEnvironment = (uid: string | undefined) => {
- if (!uid || uid === String(UNKNOWN_ID)) {
+const handleSelectEnvironment = (name: string | undefined) => {
+ if (!name || name === UNKNOWN_ENVIRONMENT_NAME) {
environment.value = undefined;
+ handleSelectDatabase(undefined);
return;
}
- environment.value = useEnvironmentV1Store().getEnvironmentByUID(uid);
+ environment.value = useEnvironmentV1Store().getEnvironmentByName(name);
if (database.value) {
- if (database.value.effectiveEnvironment !== environment.value.name) {
+ if (database.value.effectiveEnvironment !== name) {
// de-select database since environment changed
handleSelectDatabase(undefined);
}
diff --git a/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue b/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue
index 8950a11c71..0e49a5a0a2 100644
--- a/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue
+++ b/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue
@@ -78,7 +78,6 @@
required
:disabled="!allowEditInstance"
:instance-name="state.instanceName"
- :use-resource-id="true"
:filter="instanceV1HasCreateDatabase"
@update:instance-name="selectInstance"
/>
@@ -90,11 +89,10 @@
{{ $t("common.environment") }}
</label>
<EnvironmentSelect
- v-model:environment="state.environment"
+ v-model:environment-name="state.environmentName"
class="mt-1"
required
name="environment"
- :use-resource-id="true"
/>
</div>
@@ -201,7 +199,7 @@ import {
interface LocalState {
projectId?: string;
- environment?: string;
+ environmentName?: string;
instanceName?: string;
instanceRole?: string;
labels: Record<string, string>;
@@ -216,7 +214,7 @@ interface LocalState {
const props = defineProps<{
projectId?: string;
- environment?: string;
+ environmentName?: string;
instanceName?: string;
}>();
@@ -233,7 +231,7 @@ const projectV1Store = useProjectV1Store();
const state = reactive<LocalState>({
databaseName: "",
projectId: props.projectId,
- environment: props.environment,
+ environmentName: props.environmentName,
instanceName: props.instanceName,
labels: {},
tableName: "",
@@ -258,7 +256,7 @@ const allowCreate = computed(() => {
validDatabaseOwnerName.value &&
!isReservedName.value &&
state.projectId &&
- state.environment &&
+ state.environmentName &&
state.instanceName
);
});
@@ -304,7 +302,7 @@ const selectProject = (projectId: string | undefined) => {
const selectInstance = (instanceName: string | undefined) => {
state.instanceName = instanceName;
- state.environment = selectedInstance.value.environment;
+ state.environmentName = selectedInstance.value.environment;
};
const selectInstanceRole = (name?: string) => {
@@ -326,7 +324,7 @@ const createV1 = async () => {
if (!allowCreate.value) {
return;
}
- if (!state.environment || !state.instanceName) {
+ if (!state.environmentName || !state.instanceName) {
return;
}
@@ -347,7 +345,7 @@ const createV1 = async () => {
database: databaseName,
table: tableName,
labels: state.labels,
- environment: state.environment,
+ environment: state.environmentName,
characterSet:
state.characterSet ||
diff --git a/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepPanel.vue b/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepPanel.vue
index c9ea16cebe..e9c39aab0f 100644
--- a/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepPanel.vue
+++ b/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepPanel.vue
@@ -3,7 +3,7 @@
<CreateDatabasePrepForm
ref="form"
:project-id="projectId"
- :environment="environment"
+ :environment-name="environmentName"
:instance-name="instanceName"
@dismiss="$emit('dismiss')"
/>
@@ -21,7 +21,7 @@ import CreateDatabasePrepForm from "./CreateDatabasePrepForm.vue";
defineProps<{
projectId?: string;
- environment?: string;
+ environmentName?: string;
instanceName?: string;
}>();
diff --git a/frontend/src/components/CustomApproval/Settings/components/common/utils.ts b/frontend/src/components/CustomApproval/Settings/components/common/utils.ts
index 3f6e34f5ed..58273d1ef9 100644
--- a/frontend/src/components/CustomApproval/Settings/components/common/utils.ts
+++ b/frontend/src/components/CustomApproval/Settings/components/common/utils.ts
@@ -145,10 +145,10 @@ export const getFactorList = (source: Risk_Source) => {
const getEnvironmentIdOptions = () => {
const environmentList = useEnvironmentV1Store().getEnvironmentList();
return environmentList.map<SelectOption>((env) => {
- const environmentId = extractEnvironmentResourceName(env.name);
+ const environmentName = extractEnvironmentResourceName(env.name);
return {
- label: environmentId,
- value: environmentId,
+ label: environmentName,
+ value: environmentName,
};
});
};
diff --git a/frontend/src/components/DatabaseDetail/Settings/DatabaseSettingsPanel.vue b/frontend/src/components/DatabaseDetail/Settings/DatabaseSettingsPanel.vue
index 4757d5e692..9a12ab5498 100644
--- a/frontend/src/components/DatabaseDetail/Settings/DatabaseSettingsPanel.vue
+++ b/frontend/src/components/DatabaseDetail/Settings/DatabaseSettingsPanel.vue
@@ -7,7 +7,7 @@
</p>
<EnvironmentSelect
class="mt-1 max-w-md"
- :environment="environment?.uid"
+ :environment-name="environment?.name"
:disabled="!allowUpdateDatabase"
:render-suffix="
(env: string) =>
@@ -15,7 +15,7 @@
? `(${$t('common.default')})`
: ''
"
- @update:environment="handleSelectEnvironmentUID"
+ @update:environment-name="handleSelectEnvironment"
/>
</div>
</div>
@@ -68,13 +68,12 @@ const {
allowDeleteSecrets,
} = useDatabaseDetailContext();
-const handleSelectEnvironmentUID = async (uid?: string) => {
- const environment = envStore.getEnvironmentByUID(String(uid));
- if (environment.name === props.database.effectiveEnvironment) {
+const handleSelectEnvironment = async (name: string | undefined) => {
+ if (!name || name === props.database.effectiveEnvironment) {
return;
}
const databasePatch = cloneDeep(props.database);
- databasePatch.environment = environment.name;
+ databasePatch.environment = name;
await databaseStore.updateDatabase({
database: databasePatch,
updateMask: ["environment"],
diff --git a/frontend/src/components/DatabaseDetail/utils.ts b/frontend/src/components/DatabaseDetail/utils.ts
deleted file mode 100644
index a94867038d..0000000000
--- a/frontend/src/components/DatabaseDetail/utils.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-// MySQL only by now
-export type CreatePITRDatabaseContext = {
- projectId: string;
- environmentId: string;
- instanceId: string;
- databaseName: string;
- characterSet: string;
- collation: string;
- labels: Record<string, string>;
-};
diff --git a/frontend/src/components/DatabaseGroup/utils.ts b/frontend/src/components/DatabaseGroup/utils.ts
index 6a88d6642f..f7e40fee16 100644
--- a/frontend/src/components/DatabaseGroup/utils.ts
+++ b/frontend/src/components/DatabaseGroup/utils.ts
@@ -36,9 +36,9 @@ export const DatabaseGroupFactorOptionsMap = () => {
const getEnvironmentOptions = () => {
const environmentList = useEnvironmentV1Store().getEnvironmentList();
return environmentList.map<SelectOption>((env) => {
- const environmentId = extractEnvironmentResourceName(env.name);
+ const environmentName = extractEnvironmentResourceName(env.name);
return {
- label: environmentId,
+ label: environmentName,
value: env.name,
};
});
diff --git a/frontend/src/components/InstanceForm/Form.vue b/frontend/src/components/InstanceForm/Form.vue
index b18e1d32c4..b25ccd4cb9 100644
--- a/frontend/src/components/InstanceForm/Form.vue
+++ b/frontend/src/components/InstanceForm/Form.vue
@@ -85,13 +85,13 @@
<EnvironmentSelect
class="mt-1 w-full"
required="true"
- :environment="
- environment.uid === String(UNKNOWN_ID)
+ :environment-name="
+ environment.name === UNKNOWN_ENVIRONMENT_NAME
? undefined
- : environment.uid
+ : environment.name
"
:disabled="!allowEdit"
- @update:environment="handleSelectEnvironmentUID"
+ @update:environment-name="handleSelectEnvironment"
/>
</div>
@@ -463,13 +463,12 @@ import { SETTING_ROUTE_WORKSPACE_SUBSCRIPTION } from "@/router/dashboard/workspa
import {
useSettingV1Store,
useActuatorV1Store,
- useEnvironmentV1Store,
useInstanceV1Store,
useSubscriptionV1Store,
} from "@/store";
import { instanceNamePrefix } from "@/store/modules/v1/common";
import type { ResourceId, ValidatedMessage, ComposedInstance } from "@/types";
-import { UNKNOWN_ID } from "@/types";
+import { UNKNOWN_ENVIRONMENT_NAME, UNKNOWN_ID } from "@/types";
import type { Duration } from "@/types/proto/google/protobuf/duration";
import { Engine } from "@/types/proto/v1/common";
import {
@@ -722,10 +721,9 @@ const changeInstanceActivation = async (on: boolean) => {
}
};
-const handleSelectEnvironmentUID = (uid: string | undefined) => {
- if (!uid) return;
- const environment = useEnvironmentV1Store().getEnvironmentByUID(uid);
- basicInfo.value.environment = environment.name;
+const handleSelectEnvironment = (name: string | undefined) => {
+ if (!name || name === UNKNOWN_ENVIRONMENT_NAME) return;
+ basicInfo.value.environment = name;
};
const testConnectionForCurrentEditingDS = () => {
diff --git a/frontend/src/components/InstanceForm/context.ts b/frontend/src/components/InstanceForm/context.ts
index 9436445bb8..075aeb8903 100644
--- a/frontend/src/components/InstanceForm/context.ts
+++ b/frontend/src/components/InstanceForm/context.ts
@@ -11,7 +11,11 @@ import {
useEnvironmentV1Store,
useSubscriptionV1Store,
} from "@/store";
-import { UNKNOWN_ID, unknownEnvironment, type FeatureType } from "@/types";
+import {
+ UNKNOWN_ENVIRONMENT_NAME,
+ unknownEnvironment,
+ type FeatureType,
+} from "@/types";
import { Engine, State } from "@/types/proto/v1/common";
import type { DataSource, Instance } from "@/types/proto/v1/instance_service";
import {
@@ -200,7 +204,7 @@ export const provideInstanceFormContext = (baseContext: {
if (!hasWorkspacePermissionV2(me.value, "bb.instances.create")) {
return false;
}
- if (environment.value.uid === String(UNKNOWN_ID)) {
+ if (environment.value.name === UNKNOWN_ENVIRONMENT_NAME) {
return false;
}
if (basicInfo.value.engine === Engine.SPANNER) {
diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/index.vue b/frontend/src/components/Issue/panel/RequestExportPanel/index.vue
index beab17cea9..6c4d422aaa 100644
--- a/frontend/src/components/Issue/panel/RequestExportPanel/index.vue
+++ b/frontend/src/components/Issue/panel/RequestExportPanel/index.vue
@@ -119,7 +119,7 @@ import DatabaseResourceForm from "../RequestQueryPanel/DatabaseResourceForm/inde
interface LocalState {
projectId?: string;
- environmentId?: string;
+ environmentName?: string;
databaseId?: string;
databaseResourceCondition?: string;
databaseResources: DatabaseResource[];
@@ -181,8 +181,8 @@ const handleProjectSelect = async (projectId: string | undefined) => {
state.projectId = projectId;
};
-const handleEnvironmentSelect = (environmentId: string | undefined) => {
- state.environmentId = environmentId;
+const handleEnvironmentSelect = (environmentName: string | undefined) => {
+ state.environmentName = environmentName;
const database = databaseStore.getDatabaseByUID(
state.databaseId || String(UNKNOWN_ID)
);
@@ -190,7 +190,7 @@ const handleEnvironmentSelect = (environmentId: string | undefined) => {
if (
database &&
database.uid !== String(UNKNOWN_ID) &&
- database.effectiveEnvironmentEntity.uid !== state.environmentId
+ database.effectiveEnvironment !== state.environmentName
) {
state.databaseId = undefined;
}
@@ -203,7 +203,7 @@ const handleDatabaseSelect = (databaseId: string | undefined) => {
);
if (database && database.uid !== String(UNKNOWN_ID)) {
handleProjectSelect(database.projectEntity.uid);
- handleEnvironmentSelect(database.effectiveEnvironmentEntity.uid);
+ handleEnvironmentSelect(database.effectiveEnvironment);
}
};
diff --git a/frontend/src/components/KBar/useDatabaseActions.ts b/frontend/src/components/KBar/useDatabaseActions.ts
index 7c60de04e9..1885f49b87 100644
--- a/frontend/src/components/KBar/useDatabaseActions.ts
+++ b/frontend/src/components/KBar/useDatabaseActions.ts
@@ -45,7 +45,7 @@ const useDatabaseActions = (databaseList: MaybeRef<ComposedDatabase[]>) => {
.map((environment) => {
const databases = databasesByEnv.get(environment.name)!;
return {
- id: `bb.env.${environment.uid}`,
+ id: `bb.env.${environment.name}`,
name: environmentV1Name(environment),
children: databases.map((db) => ({
id: `bb.database.${db.uid}`,
diff --git a/frontend/src/components/SQLReview/SQLReviewInfo.vue b/frontend/src/components/SQLReview/SQLReviewInfo.vue
index bb85ed61ce..78990c4b95 100644
--- a/frontend/src/components/SQLReview/SQLReviewInfo.vue
+++ b/frontend/src/components/SQLReview/SQLReviewInfo.vue
@@ -24,11 +24,10 @@
class="mt-2"
required
name="environment"
- :environment="attachedResources[0]"
- :use-resource-id="true"
+ :environment-name="attachedResources[0]"
:disabled="!allowChangeAttachedResource"
:filter="(env: Environment, _: number) => filterResource(env.name)"
- @update:environment="
+ @update:environment-name="
(val: string | undefined) => {
if (!val) {
$emit('attached-resources-change', []);
diff --git a/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue b/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue
index 43919fe310..ee1a3a5f26 100644
--- a/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue
+++ b/frontend/src/components/SQLReview/components/SQLReviewAttachResourcesPanel.vue
@@ -19,11 +19,10 @@
<EnvironmentSelect
class="mt-3"
required
- :environments="environments"
- :use-resource-id="true"
+ :environment-names="environmentNames"
:multiple="true"
:render-suffix="getResourceAttachedConfigName"
- @update:environments="onResourcesChange($event, projects)"
+ @update:environment-names="onResourcesChange($event, projects)"
/>
</div>
<div class="flex items-center space-x-2">
@@ -45,7 +44,7 @@
:use-resource-id="true"
:multiple="true"
:render-suffix="getResourceAttachedConfigName"
- @update:projects="onResourcesChange($event, environments)"
+ @update:projects="onResourcesChange($event, environmentNames)"
/>
</div>
</div>
@@ -72,7 +71,7 @@
import { NDivider } from "naive-ui";
import { watch, ref, computed } from "vue";
import { useI18n } from "vue-i18n";
-import { Drawer, DrawerContent, ProjectSelect } from "@/components/v2";
+import { Drawer, DrawerContent, EnvironmentSelect, ProjectSelect } from "@/components/v2";
import { useSQLReviewStore, pushNotification, useCurrentUserV1 } from "@/store";
import {
environmentNamePrefix,
@@ -107,7 +106,7 @@ const hasPermission = computed(() => {
return hasWorkspacePermissionV2(me.value, "bb.policies.update");
});
-const environments = computed(() =>
+const environmentNames = computed(() =>
resources.value.filter((resource) =>
resource.startsWith(environmentNamePrefix)
)
diff --git a/frontend/src/components/SensitiveData/SensitiveColumnView.vue b/frontend/src/components/SensitiveData/SensitiveColumnView.vue
index 28cbb08323..97fc1885ca 100644
--- a/frontend/src/components/SensitiveData/SensitiveColumnView.vue
+++ b/frontend/src/components/SensitiveData/SensitiveColumnView.vue
@@ -29,7 +29,7 @@
class="!w-48"
:instance-name="state.selectedInstanceName"
:include-all="true"
- :environment="environment?.uid"
+ :environment-name="environment?.name"
@update:instance-name="onInstanceSelect($event)"
/>
<DatabaseSelect
diff --git a/frontend/src/components/SensitiveData/components/utils.ts b/frontend/src/components/SensitiveData/components/utils.ts
index 8b3423f931..14e113ce35 100644
--- a/frontend/src/components/SensitiveData/components/utils.ts
+++ b/frontend/src/components/SensitiveData/components/utils.ts
@@ -38,10 +38,10 @@ export const getClassificationLevelOptions = () => {
export const getEnvironmentIdOptions = () => {
const environmentList = useEnvironmentV1Store().getEnvironmentList();
return environmentList.map<SelectOption>((env) => {
- const environmentId = extractEnvironmentResourceName(env.name);
+ const environmentName = extractEnvironmentResourceName(env.name);
return {
- label: environmentId,
- value: environmentId,
+ label: environmentName,
+ value: environmentName,
};
});
};
diff --git a/frontend/src/components/SlowQuery/Settings/SlowQuerySettings.vue b/frontend/src/components/SlowQuery/Settings/SlowQuerySettings.vue
index 5437a4dc8f..f7a5506f06 100644
--- a/frontend/src/components/SlowQuery/Settings/SlowQuerySettings.vue
+++ b/frontend/src/components/SlowQuery/Settings/SlowQuerySettings.vue
@@ -43,7 +43,7 @@ import {
} from "@/store";
import { useGracefulRequest } from "@/store/modules/utils";
import type { ComposedInstance, ComposedSlowQueryPolicy } from "@/types";
-import { UNKNOWN_ID } from "@/types";
+import { UNKNOWN_ENVIRONMENT_NAME } from "@/types";
import type { Environment } from "@/types/proto/v1/environment_service";
import { instanceV1SupportSlowQuery } from "@/utils";
import { SlowQueryPolicyTable } from "./components";
@@ -99,9 +99,9 @@ const composedSlowQueryPolicyList = computed(() => {
const filteredComposedSlowQueryPolicyList = computed(() => {
let list = [...composedSlowQueryPolicyList.value];
const { environment } = state.filter;
- if (environment && environment.uid !== String(UNKNOWN_ID)) {
+ if (environment && environment.name !== UNKNOWN_ENVIRONMENT_NAME) {
list = list.filter(
- (item) => String(item.instance.environment) === environment.name
+ (item) => item.instance.environment === environment.name
);
}
const keyword = state.filter.keyword.trim().toLowerCase();
diff --git a/frontend/src/components/SyncDatabaseSchema/DatabaseSchemaSelector.vue b/frontend/src/components/SyncDatabaseSchema/DatabaseSchemaSelector.vue
index 9f1342240f..8c1d29ef47 100644
--- a/frontend/src/components/SyncDatabaseSchema/DatabaseSchemaSelector.vue
+++ b/frontend/src/components/SyncDatabaseSchema/DatabaseSchemaSelector.vue
@@ -24,13 +24,13 @@
<EnvironmentSelect
class="!w-60 mr-4 shrink-0"
name="environment"
- :environment="state.environmentId"
- @update:environment="handleEnvironmentSelect"
+ :environment-name="state.environmentName"
+ @update:environment-name="handleEnvironmentSelect"
/>
<DatabaseSelect
class="!w-128 max-w-full"
:database="state.databaseId"
- :environment="state.environmentId"
+ :environment="shamefulEnvironmentUID"
:project="state.projectId"
:placeholder="$t('db.select')"
:allowed-engine-type-list="allowedEngineTypeList"
@@ -122,7 +122,7 @@ const emit = defineEmits<{
interface LocalState {
showFeatureModal: boolean;
projectId?: string;
- environmentId?: string;
+ environmentName?: string;
databaseId?: string;
changeHistoryName?: string;
}
@@ -130,7 +130,7 @@ interface LocalState {
const state = reactive<LocalState>({
showFeatureModal: false,
projectId: props.selectState?.projectId,
- environmentId: props.selectState?.environmentId,
+ environmentName: props.selectState?.environmentName,
databaseId: props.selectState?.databaseId,
changeHistoryName: props.selectState?.changeHistory?.name,
});
@@ -138,7 +138,6 @@ const { t } = useI18n();
const databaseStore = useDatabaseV1Store();
const dbSchemaStore = useDBSchemaV1Store();
const changeHistoryStore = useChangeHistoryStore();
-const environmentStore = useEnvironmentV1Store();
const database = computed(() => {
const databaseId = state.databaseId;
@@ -186,11 +185,11 @@ const handleProjectSelect = async (projectId: string | undefined) => {
state.projectId = projectId;
};
-const handleEnvironmentSelect = async (environmentId: string | undefined) => {
- if (environmentId !== state.environmentId) {
+const handleEnvironmentSelect = async (name: string | undefined) => {
+ if (name !== state.environmentName) {
state.databaseId = undefined;
}
- state.environmentId = environmentId;
+ state.environmentName = name;
};
const handleDatabaseSelect = async (databaseId: string | undefined) => {
@@ -199,11 +198,8 @@ const handleDatabaseSelect = async (databaseId: string | undefined) => {
if (!database) {
return;
}
- const environment = environmentStore.getEnvironmentByName(
- database.effectiveEnvironment
- );
state.projectId = database.projectEntity.uid;
- state.environmentId = environment?.uid;
+ state.environmentName = database.effectiveEnvironment;
state.databaseId = databaseId;
dbSchemaStore.getOrFetchDatabaseMetadata({
database: database.name,
@@ -449,15 +445,15 @@ watch(
watch(
[
() => state.projectId,
- () => state.environmentId,
+ () => state.environmentName,
() => state.databaseId,
mergedChangeHistorySourceSchema,
isFetchingChangeHistorySourceSchema,
],
- ([projectId, environmentId, databaseId, source, isFetching]) => {
+ ([projectId, environmentName, databaseId, source, isFetching]) => {
const params: ChangeHistorySourceSchema = {
projectId,
- environmentId,
+ environmentName,
databaseId,
changeHistory: source?.changeHistory,
conciseHistory: source?.conciseHistory,
@@ -473,15 +469,15 @@ watch(
watch(
[
() => props.selectState?.projectId,
- () => props.selectState?.environmentId,
+ () => props.selectState?.environmentName,
() => props.selectState?.databaseId,
() => props.selectState?.changeHistory?.name,
() => props.selectState?.isFetching,
],
- ([projectId, environmentId, databaseId, changeHistoryName, isFetching]) => {
+ ([projectId, environmentName, databaseId, changeHistoryName, isFetching]) => {
if (isFetching) return;
state.projectId = projectId;
- state.environmentId = environmentId;
+ state.environmentName = environmentName;
state.databaseId = databaseId;
state.changeHistoryName = changeHistoryName;
},
@@ -489,6 +485,13 @@ watch(
immediate: false,
}
);
+
+const shamefulEnvironmentUID = computed(() => {
+ // todo(jim): refactor me
+ const { environmentName } = state;
+ if (!environmentName) return undefined;
+ return useEnvironmentV1Store().getEnvironmentByName(environmentName).uid;
+});
</script>
<style lang="postcss">
diff --git a/frontend/src/components/SyncDatabaseSchema/SelectTargetDatabasesView.vue b/frontend/src/components/SyncDatabaseSchema/SelectTargetDatabasesView.vue
index 28fd6c4603..60a9532611 100644
--- a/frontend/src/components/SyncDatabaseSchema/SelectTargetDatabasesView.vue
+++ b/frontend/src/components/SyncDatabaseSchema/SelectTargetDatabasesView.vue
@@ -258,7 +258,7 @@ import TargetDatabasesSelectPanel from "./TargetDatabasesSelectPanel.vue";
import type { RawSQLState, SourceSchemaType } from "./types";
interface DatabaseSourceSchema {
- environmentId: string;
+ environmentName: string;
databaseId: string;
changeHistory: ChangeHistory;
conciseHistory?: string;
@@ -432,8 +432,8 @@ const getDatabaseSourceSchemaEnvironment = () => {
if (!props.databaseSourceSchema) {
return;
}
- return environmentV1Store.getEnvironmentByUID(
- props.databaseSourceSchema.environmentId
+ return environmentV1Store.getEnvironmentByName(
+ props.databaseSourceSchema.environmentName
);
};
diff --git a/frontend/src/components/SyncDatabaseSchema/TargetDatabasesSelectPanel.vue b/frontend/src/components/SyncDatabaseSchema/TargetDatabasesSelectPanel.vue
index fc9c523b9a..185d496316 100644
--- a/frontend/src/components/SyncDatabaseSchema/TargetDatabasesSelectPanel.vue
+++ b/frontend/src/components/SyncDatabaseSchema/TargetDatabasesSelectPanel.vue
@@ -21,7 +21,7 @@
class="overflow-y-auto"
arrow-placement="left"
:default-expanded-names="
- databaseListGroupByEnvironment.map((group) => group.environment.uid)
+ databaseListGroupByEnvironment.map((group) => group.environment.name)
"
>
<NCollapseItem
@@ -29,8 +29,8 @@
environment,
databaseList: databaseListInEnvironment,
} in databaseListGroupByEnvironment"
- :key="environment.uid"
- :name="environment.uid"
+ :key="environment.name"
+ :name="environment.name"
>
<template #header>
<label class="flex items-center gap-x-2" @click.stop.prevent>
diff --git a/frontend/src/components/SyncDatabaseSchema/index.vue b/frontend/src/components/SyncDatabaseSchema/index.vue
index 7bd1363afb..aaa894a549 100644
--- a/frontend/src/components/SyncDatabaseSchema/index.vue
+++ b/frontend/src/components/SyncDatabaseSchema/index.vue
@@ -74,7 +74,7 @@ import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
import { WORKSPACE_HOME_MODULE } from "@/router/dashboard/workspaceRoutes";
import { useProjectV1Store } from "@/store";
import type { ComposedProject } from "@/types";
-import { UNKNOWN_ID } from "@/types";
+import { UNKNOWN_ID, isValidEnvironmentName } from "@/types";
import { Engine } from "@/types/proto/v1/common";
import { extractProjectResourceName } from "@/utils";
import DatabaseSchemaSelector from "./DatabaseSchemaSelector.vue";
@@ -160,7 +160,9 @@ const allowNext = computed(() => {
if (state.sourceSchemaType === "SCHEMA_HISTORY_VERSION") {
return (
!changeHistorySourceSchemaState.isFetching &&
- isValidId(changeHistorySourceSchemaState.environmentId) &&
+ isValidEnvironmentName(
+ changeHistorySourceSchemaState.environmentName
+ ) &&
isValidId(changeHistorySourceSchemaState.databaseId) &&
!isUndefined(changeHistorySourceSchemaState.changeHistory)
);
diff --git a/frontend/src/components/SyncDatabaseSchema/types.ts b/frontend/src/components/SyncDatabaseSchema/types.ts
index 6edd919260..aba6042c74 100644
--- a/frontend/src/components/SyncDatabaseSchema/types.ts
+++ b/frontend/src/components/SyncDatabaseSchema/types.ts
@@ -5,7 +5,7 @@ export type SourceSchemaType = "SCHEMA_HISTORY_VERSION" | "RAW_SQL";
export interface ChangeHistorySourceSchema {
projectId?: string;
- environmentId?: string;
+ environmentName?: string;
databaseId?: string;
changeHistory?: ChangeHistory;
conciseHistory?: string;
diff --git a/frontend/src/components/TransferDatabaseForm/MultipleDatabaseSelector.vue b/frontend/src/components/TransferDatabaseForm/MultipleDatabaseSelector.vue
index 0b1460f525..5d77511c0f 100644
--- a/frontend/src/components/TransferDatabaseForm/MultipleDatabaseSelector.vue
+++ b/frontend/src/components/TransferDatabaseForm/MultipleDatabaseSelector.vue
@@ -3,15 +3,15 @@
<!-- Leave some margin space to avoid accidentally clicking the Collaspe when trying to click the selector -->
<NCollapse
arrow-placement="left"
- :default-expanded-names="environmentList.map((env) => env.uid)"
+ :default-expanded-names="environmentList.map((env) => env.name)"
>
<NCollapseItem
v-for="{
environment,
databaseList: databaseListInEnvironment,
} in databaseListGroupByEnvironment"
- :key="environment.uid"
- :name="environment.uid"
+ :key="environment.name"
+ :name="environment.name"
>
<template #header>
<label class="flex items-center gap-x-2" @click.stop.prevent>
@@ -64,13 +64,13 @@
:checked="
isDatabaseSelectedForEnvironment(
database.uid,
- environment.uid
+ environment.name
)
"
@update:checked="
toggleDatabaseIdForEnvironment(
database.uid,
- environment.uid,
+ environment.name,
$event
)
"
@@ -142,17 +142,17 @@ const state = reactive<LocalState>({
const toggleDatabaseIdForEnvironment = (
databaseId: string,
- environmentId: string,
+ environmentName: string,
selected: boolean
) => {
const map = state.selectedDatabaseUidListForEnvironment;
- const set = map.get(environmentId) || new Set();
+ const set = map.get(environmentName) || new Set();
if (selected) {
set.add(databaseId);
} else {
set.delete(databaseId);
}
- map.set(environmentId, set);
+ map.set(environmentName, set);
};
watch(
@@ -167,11 +167,7 @@ watch(
if (!database) {
continue;
}
- toggleDatabaseIdForEnvironment(
- uid,
- database.effectiveEnvironmentEntity.uid,
- true
- );
+ toggleDatabaseIdForEnvironment(uid, database.effectiveEnvironment, true);
}
},
{ immediate: true }
@@ -235,10 +231,10 @@ watch(
const isDatabaseSelectedForEnvironment = (
databaseId: string,
- environmentId: string
+ environmentName: string
) => {
const map = state.selectedDatabaseUidListForEnvironment;
- const set = map.get(environmentId) || new Set();
+ const set = map.get(environmentName) || new Set();
return set.has(databaseId);
};
@@ -247,7 +243,7 @@ const getAllSelectionStateForEnvironment = (
databaseList: ComposedDatabase[]
): { checked: boolean; indeterminate: boolean } => {
const set =
- state.selectedDatabaseUidListForEnvironment.get(environment.uid) ??
+ state.selectedDatabaseUidListForEnvironment.get(environment.name) ??
new Set();
const checked = set.size > 0 && databaseList.every((db) => set.has(db.uid));
const indeterminate = !checked && databaseList.some((db) => set.has(db.uid));
@@ -264,7 +260,7 @@ const toggleAllDatabasesSelectionForEnvironment = (
on: boolean
) => {
databaseList.forEach((db) =>
- toggleDatabaseIdForEnvironment(db.uid, environment.uid, on)
+ toggleDatabaseIdForEnvironment(db.uid, environment.name, on)
);
};
@@ -273,7 +269,7 @@ const getSelectionStateSummaryForEnvironment = (
databaseList: ComposedDatabase[]
) => {
const set =
- state.selectedDatabaseUidListForEnvironment.get(environment.uid) ||
+ state.selectedDatabaseUidListForEnvironment.get(environment.name) ||
new Set();
const selected = databaseList.filter((db) => set.has(db.uid)).length;
const total = databaseList.length;
@@ -282,11 +278,11 @@ const getSelectionStateSummaryForEnvironment = (
};
const handleClickRow = (db: ComposedDatabase) => {
- const environment = db.effectiveEnvironmentEntity;
+ const environmentName = db.effectiveEnvironment;
toggleDatabaseIdForEnvironment(
db.uid,
- environment.uid,
- !isDatabaseSelectedForEnvironment(db.uid, environment.uid)
+ environmentName,
+ !isDatabaseSelectedForEnvironment(db.uid, environmentName)
);
};
</script>
diff --git a/frontend/src/components/v2/Select/EnvironmentSelect.vue b/frontend/src/components/v2/Select/EnvironmentSelect.vue
index 0f4eb8e304..904d05c954 100644
--- a/frontend/src/components/v2/Select/EnvironmentSelect.vue
+++ b/frontend/src/components/v2/Select/EnvironmentSelect.vue
@@ -1,7 +1,7 @@
<template>
<NSelect
v-bind="$attrs"
- :value="value"
+ :value="combinedValue"
:options="options"
:placeholder="$t('environment.select')"
:filterable="true"
@@ -29,20 +29,17 @@ interface EnvironmentSelectOption extends SelectOption {
const props = withDefaults(
defineProps<{
- environment?: string | undefined;
- environments?: string[] | undefined;
- defaultEnvironmentName?: string | undefined;
+ environmentName?: string | undefined;
+ environmentNames?: string[] | undefined;
includeArchived?: boolean;
showProductionIcon?: boolean;
- useResourceId?: boolean;
multiple?: boolean;
filter?: (environment: Environment, index: number) => boolean;
renderSuffix?: (environment: string) => string;
}>(),
{
- environment: undefined,
- environments: undefined,
- defaultEnvironmentName: undefined,
+ environmentName: undefined,
+ environmentNames: undefined,
includeArchived: false,
showProductionIcon: true,
useResourceId: false,
@@ -53,8 +50,8 @@ const props = withDefaults(
);
const emit = defineEmits<{
- (event: "update:environment", id: string | undefined): void;
- (event: "update:environments", id: string[]): void;
+ (event: "update:environment-name", name: string | undefined): void;
+ (event: "update:environment-names", names: string[]): void;
}>();
const projectV1Store = useProjectV1Store();
@@ -64,11 +61,11 @@ const prepare = () => {
projectV1Store.fetchProjectList(true /* showDeleted */);
};
-const value = computed(() => {
+const combinedValue = computed(() => {
if (props.multiple) {
- return props.environments || [];
+ return props.environmentNames || [];
} else {
- return props.environment;
+ return props.environmentName;
}
});
@@ -78,13 +75,13 @@ const handleValueUpdated = (value: string | string[]) => {
// normalize value
value = [];
}
- emit("update:environments", value as string[]);
+ emit("update:environment-names", value as string[]);
} else {
if (value === null) {
// normalize value
value = "";
}
- emit("update:environment", value as string);
+ emit("update:environment-name", value as string);
}
};
@@ -93,16 +90,12 @@ const rawEnvironmentList = computed(() => {
return list;
});
-const getEnvironmentValue = (environment: Environment): string => {
- return props.useResourceId ? environment.name : environment.uid;
-};
-
const combinedEnvironmentList = computed(() => {
let list = rawEnvironmentList.value.filter((environment) => {
if (props.includeArchived) return true;
if (environment.state === State.ACTIVE) return true;
// ARCHIVED
- if (getEnvironmentValue(environment) === props.environment) return true;
+ if (environment.name === props.environmentName) return true;
return false;
});
@@ -118,7 +111,7 @@ const options = computed(() => {
(environment) => {
return {
environment,
- value: getEnvironmentValue(environment),
+ value: environment.name,
label: environment.title,
};
}
diff --git a/frontend/src/components/v2/TabFilter/EnvironmentTabFilter.vue b/frontend/src/components/v2/TabFilter/EnvironmentTabFilter.vue
index 5a08105b47..a6e34a82f4 100644
--- a/frontend/src/components/v2/TabFilter/EnvironmentTabFilter.vue
+++ b/frontend/src/components/v2/TabFilter/EnvironmentTabFilter.vue
@@ -2,7 +2,7 @@
<TabFilter
:value="environment"
:items="items"
- @update:value="$emit('update:environment', $event as string)"
+ @update:value="$emit('update:environment-name', $event as string)"
>
<template #label="{ item }">
<template v-if="item.value === UNKNOWN_ENVIRONMENT_NAME">{{
@@ -42,7 +42,7 @@ const props = withDefaults(
);
defineEmits<{
- (event: "update:environment", id: string): void;
+ (event: "update:environment-name", id: string): void;
}>();
const { t } = useI18n();
diff --git a/frontend/src/router/dashboard/environmentV1.ts b/frontend/src/router/dashboard/environmentV1.ts
index 1e1c8c5571..337bac3f7d 100644
--- a/frontend/src/router/dashboard/environmentV1.ts
+++ b/frontend/src/router/dashboard/environmentV1.ts
@@ -9,14 +9,14 @@ export const ENVIRONMENT_V1_ROUTE_DETAIL = `${ENVIRONMENT_V1_ROUTE_DASHBOARD}.de
const environmentV1Routes: RouteRecordRaw[] = [
{
- path: "environments/:environmentId",
+ path: "environments/:environmentName",
name: ENVIRONMENT_V1_ROUTE_DETAIL,
meta: {
title: (route: RouteLocationNormalized) => {
- const environmentId = route.params.environmentId as string;
+ const environmentName = route.params.environmentName as string;
return (
useEnvironmentV1Store().getEnvironmentByName(
- `${environmentNamePrefix}${environmentId}`
+ `${environmentNamePrefix}${environmentName}`
) || unknownEnvironment()
).title;
},
diff --git a/frontend/src/store/modules/v1/environment.ts b/frontend/src/store/modules/v1/environment.ts
index 96246355ae..ce5b1bfacd 100644
--- a/frontend/src/store/modules/v1/environment.ts
+++ b/frontend/src/store/modules/v1/environment.ts
@@ -2,7 +2,6 @@ import { isEqual, isUndefined, orderBy } from "lodash-es";
import { defineStore } from "pinia";
import { computed } from "vue";
import { environmentServiceClient } from "@/grpcweb";
-import { environmentNamePrefix } from "@/store/modules/v1/common";
import type { ResourceId } from "@/types";
import { unknownEnvironment } from "@/types";
import { State } from "@/types/proto/v1/common";
@@ -121,10 +120,6 @@ export const useEnvironmentV1Store = defineStore("environment_v1", {
this.environmentMapByName.set(environment.name, environment);
return environment;
},
- async getOrFetchEnvironmentByUID(uid: string) {
- const name = `${environmentNamePrefix}${uid}`;
- return this.getOrFetchEnvironmentByName(name);
- },
getEnvironmentByName(name: string) {
return this.environmentMapByName.get(name) ?? unknownEnvironment();
},
diff --git a/frontend/src/types/v1/environment.ts b/frontend/src/types/v1/environment.ts
index d677b1f784..0938699b74 100644
--- a/frontend/src/types/v1/environment.ts
+++ b/frontend/src/types/v1/environment.ts
@@ -25,3 +25,11 @@ export const unknownEnvironment = () => {
title: "<<Unknown environment>>",
};
};
+
+export const isValidEnvironmentName = (name: any): name is string => {
+ return (
+ typeof name === "string" &&
+ name.startsWith("environments/") &&
+ name !== UNKNOWN_ENVIRONMENT_NAME
+ );
+};
diff --git a/frontend/src/utils/database.ts b/frontend/src/utils/database.ts
index c92a0bc848..9e23a560c3 100644
--- a/frontend/src/utils/database.ts
+++ b/frontend/src/utils/database.ts
@@ -1,6 +1,4 @@
-import { keyBy } from "lodash-es";
import { Engine } from "@/types/proto/v1/common";
-import type { Environment as EnvironmentV1 } from "@/types/proto/v1/environment_service";
import type { Database, Environment } from "../types";
import { semverCompare } from "./util";
@@ -29,22 +27,6 @@ export function sortDatabaseList(
});
}
-// Sort the list to put prod items first.
-export function sortDatabaseListByEnvironmentV1(
- list: Database[],
- environmentList: EnvironmentV1[]
-): Database[] {
- const environmentMap = keyBy(environmentList, (env) => env.uid);
- return list.sort((a: Database, b: Database) => {
- const aEnvOrder =
- environmentMap[String(a.instance.environment.id)]?.order ?? -1;
- const bEnvOrder =
- environmentMap[String(b.instance.environment.id)]?.order ?? -1;
-
- return bEnvOrder - aEnvOrder;
- });
-}
-
const MIN_GHOST_SUPPORT_MYSQL_VERSION = "5.7.0";
export function allowGhostMigration(databaseList: Database[]): boolean {
diff --git a/frontend/src/utils/instance.ts b/frontend/src/utils/instance.ts
index f0bb1a045c..4f217deee1 100644
--- a/frontend/src/utils/instance.ts
+++ b/frontend/src/utils/instance.ts
@@ -1,6 +1,4 @@
-import { keyBy } from "lodash-es";
import { computed, unref } from "vue";
-import type { Environment as EnvironmentV1 } from "@/types/proto/v1/environment_service";
import type {
InstanceResource,
Instance as InstanceV1,
@@ -68,21 +66,6 @@ export function sortInstanceList(
});
}
-// Sort the list to put prod items first.
-export function sortInstanceListByEnvironmentV1(
- list: Instance[],
- environmentList: EnvironmentV1[]
-): Instance[] {
- const environmentMap = keyBy(environmentList, (env) => env.uid);
-
- return list.sort((a, b) => {
- const aEnvOrder = environmentMap[String(a.environment.id)]?.order ?? -1;
- const bEnvOrder = environmentMap[String(b.environment.id)]?.order ?? -1;
-
- return bEnvOrder - aEnvOrder;
- });
-}
-
export const useInstanceEditorLanguage = (
instance: MaybeRef<Instance | undefined>
) => {
diff --git a/frontend/src/views/EnvironmentDashboard.vue b/frontend/src/views/EnvironmentDashboard.vue
index d4f3c14dd1..7fc5a34efc 100644
--- a/frontend/src/views/EnvironmentDashboard.vue
+++ b/frontend/src/views/EnvironmentDashboard.vue
@@ -17,7 +17,7 @@
>
<EnvironmentDetail
v-if="!state.reorder"
- :environment-id="item.id"
+ :environment-name="item.id"
@archive="doArchive"
/>
</NTabPane>
diff --git a/frontend/src/views/EnvironmentDetail.vue b/frontend/src/views/EnvironmentDetail.vue
index 0b846cd5d3..428716a8cd 100644
--- a/frontend/src/views/EnvironmentDetail.vue
+++ b/frontend/src/views/EnvironmentDetail.vue
@@ -80,7 +80,7 @@ interface LocalState {
}
const props = defineProps<{
- environmentId: string;
+ environmentName: string;
simple?: boolean;
hideArchiveRestore?: boolean;
bodyClass?: VueClass;
@@ -97,18 +97,18 @@ const policyV1Store = usePolicyV1Store();
const state = reactive<LocalState>({
environment:
environmentV1Store.getEnvironmentByName(
- `${environmentNamePrefix}${props.environmentId}`
+ `${environmentNamePrefix}${props.environmentName}`
) || unknownEnvironment(),
showArchiveModal: false,
});
const prepareEnvironment = async () => {
await environmentV1Store.getOrFetchEnvironmentByName(
- `${environmentNamePrefix}${props.environmentId}`
+ `${environmentNamePrefix}${props.environmentName}`
);
};
-watch(() => props.environmentId, prepareEnvironment, {
+watch(() => props.environmentName, prepareEnvironment, {
immediate: true,
});
@@ -179,7 +179,7 @@ const doArchive = (environment: Environment) => {
router.replace({
name: ENVIRONMENT_V1_ROUTE_DETAIL,
params: {
- environmentId: extractEnvironmentResourceName(environment.name),
+ environmentName: extractEnvironmentResourceName(environment.name),
},
});
});
diff --git a/frontend/src/views/InstanceDetail.vue b/frontend/src/views/InstanceDetail.vue
index d82d64ef2c..c9b3698761 100644
--- a/frontend/src/views/InstanceDetail.vue
+++ b/frontend/src/views/InstanceDetail.vue
@@ -61,7 +61,7 @@
:title="$t('quick-action.create-db')"
>
<CreateDatabasePrepPanel
- :environment="environment?.name"
+ :environment-name="environment?.name"
:instance-name="instance.name"
@dismiss="state.showCreateDatabaseModal = false"
/>
diff --git a/frontend/src/views/sql-editor/Setting/Environment/Environment.vue b/frontend/src/views/sql-editor/Setting/Environment/Environment.vue
index 3948519b76..a6588776cc 100644
--- a/frontend/src/views/sql-editor/Setting/Environment/Environment.vue
+++ b/frontend/src/views/sql-editor/Setting/Environment/Environment.vue
@@ -28,7 +28,7 @@
:tab="() => renderTab(item.data, index)"
>
<EnvironmentDetail
- :environment-id="item.id"
+ :environment-name="item.id"
:simple="true"
:hide-archive-restore="true"
body-class="!px-0"