Skip to content

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

refactor: ship several usages to environment v1 API (#6076)

Liu Ji8fa1ba6805ee
diff --git a/frontend/src/components/CreateDatabasePrepForm.vue b/frontend/src/components/CreateDatabasePrepForm.vue
index b6e0dff253..37418088bb 100644
--- a/frontend/src/components/CreateDatabasePrepForm.vue
+++ b/frontend/src/components/CreateDatabasePrepForm.vue
@@ -280,6 +280,7 @@ import {
INTERNAL_RDS_INSTANCE_USER_LIST,
} from "@/types/InstanceUser";
import {
+ extractEnvironmentResourceName,
hasWorkspacePermission,
instanceHasCollationAndCharacterSet,
instanceHasCreateDatabase,
@@ -288,7 +289,7 @@ import {
import {
hasFeature,
useCurrentUser,
- useEnvironmentStore,
+ useEnvironmentV1Store,
useInstanceStore,
useIssueStore,
useProjectV1Store,
@@ -612,9 +613,16 @@ export default defineComponent({
const key = "bb.environment";
const index = labelList.findIndex((label) => label.key === key);
if (envId) {
- const env = useEnvironmentStore().getEnvironmentById(envId);
- if (index >= 0) labelList[index].value = env.resourceId;
- else labelList.unshift({ key, value: env.resourceId });
+ const env = useEnvironmentV1Store().getEnvironmentByUID(envId);
+ const resourceId = extractEnvironmentResourceName(env.name);
+ if (index >= 0) {
+ labelList[index].value = resourceId;
+ } else {
+ labelList.unshift({
+ key,
+ value: resourceId,
+ });
+ }
} else {
if (index >= 0) labelList.splice(index, 1);
}
diff --git a/frontend/src/components/EnvironmentTable.vue b/frontend/src/components/EnvironmentTable.vue
deleted file mode 100644
index b8c65f345a..0000000000
--- a/frontend/src/components/EnvironmentTable.vue
+++ /dev/null
@@ -1,73 +0,0 @@
-<template>
- <BBTable
- :column-list="columnList"
- :data-source="environmentList"
- :show-header="true"
- :left-bordered="false"
- :right-bordered="false"
- @click-row="clickEnvironment"
- >
- <template #body="{ rowData: environment }">
- <BBTableCell :left-padding="4" class="w-4 table-cell text-gray-500">
- <span class="">#{{ environment.id }}</span>
- </BBTableCell>
- <BBTableCell class="w-48 table-cell">
- {{ environmentName(environment) }}
- </BBTableCell>
- <BBTableCell class="w-24 table-cell">
- {{ humanizeTs(environment.createdTs) }}
- </BBTableCell>
- <BBTableCell class="w-24 table-cell">
- {{ humanizeTs(environment.updatedTs) }}
- </BBTableCell>
- </template>
- </BBTable>
-</template>
-
-<script lang="ts">
-import { computed, defineComponent, PropType } from "vue";
-import { useRouter } from "vue-router";
-import { Environment } from "../types";
-import { environmentSlug } from "../utils";
-import { useI18n } from "vue-i18n";
-
-export default defineComponent({
- name: "EnvironmentTable",
- props: {
- environmentList: {
- required: true,
- type: Object as PropType<Environment[]>,
- },
- },
- setup(props) {
- const router = useRouter();
-
- const { t } = useI18n();
-
- const columnList = computed(() => [
- {
- title: t("common.id"),
- },
- {
- title: t("common.name"),
- },
- {
- title: t("common.created-at"),
- },
- {
- title: t("common.updated-at"),
- },
- ]);
-
- const clickEnvironment = function (section: number, row: number) {
- const environment = props.environmentList[row];
- router.push(`/environment/${environmentSlug(environment)}`);
- };
-
- return {
- columnList,
- clickEnvironment,
- };
- },
-});
-</script>
diff --git a/frontend/src/components/Issue/IssueSidebar.vue b/frontend/src/components/Issue/IssueSidebar.vue
index 11eda095c9..31bd5327e0 100644
--- a/frontend/src/components/Issue/IssueSidebar.vue
+++ b/frontend/src/components/Issue/IssueSidebar.vue
@@ -209,13 +209,11 @@
<h2 class="textlabel flex items-center col-span-1 col-start-1">
{{ $t("common.environment") }}
</h2>
- <router-link
- :to="`/environment/${environmentSlug(environment)}`"
- class="col-span-2 text-sm font-medium text-main hover:underline flex items-center"
- >
- {{ environmentName(environment) }}
- <ProductionEnvironmentIcon class="ml-1" :environment="environment" />
- </router-link>
+ <EnvironmentV1Name
+ :environment="environment"
+ :link="true"
+ class="col-span-2 !text-sm !font-medium !text-main !hover:underline flex items-center"
+ />
<template v-for="label in visibleLabelList" :key="label.key">
<h2
@@ -309,10 +307,10 @@ import InstanceEngineIcon from "../InstanceEngineIcon.vue";
import PrincipalAvatar from "../PrincipalAvatar.vue";
import MemberSelect from "../MemberSelect.vue";
import FeatureModal from "../FeatureModal.vue";
+import { EnvironmentV1Name } from "@/components/v2";
import { InputField } from "@/plugins";
import {
Database,
- Environment,
Project,
Issue,
IssueCreate,
@@ -338,7 +336,7 @@ import {
hasFeature,
useCurrentUser,
useDatabaseStore,
- useEnvironmentStore,
+ useEnvironmentV1Store,
useProjectStore,
} from "@/store";
import {
@@ -348,8 +346,8 @@ import {
useExtraIssueLogic,
useIssueLogic,
} from "./logic";
-import ProductionEnvironmentIcon from "@/components/Environment/ProductionEnvironmentIcon.vue";
import { SQLEditorButton } from "@/components/DatabaseDetail";
+import { Environment } from "@/types/proto/v1/environment_service";
dayjs.extend(isSameOrAfter);
@@ -430,10 +428,11 @@ const databaseName = computed((): string | undefined => {
const environment = computed((): Environment => {
if (create.value) {
const stage = selectedStage.value as StageCreate;
- return useEnvironmentStore().getEnvironmentById(stage.environmentId);
+ return useEnvironmentV1Store().getEnvironmentByUID(stage.environmentId);
}
const stage = selectedStage.value as Stage;
- return stage.environment;
+
+ return useEnvironmentV1Store().getEnvironmentByUID(stage.environment.id);
});
const project = computed((): Project => {
diff --git a/frontend/src/components/Issue/logic/assignee.ts b/frontend/src/components/Issue/logic/assignee.ts
index 2f0ce2d974..e2207493de 100644
--- a/frontend/src/components/Issue/logic/assignee.ts
+++ b/frontend/src/components/Issue/logic/assignee.ts
@@ -7,7 +7,6 @@ import {
Principal,
Project,
SYSTEM_BOT_ID,
- Environment,
} from "@/types";
import { useIssueLogic } from ".";
import {
@@ -26,8 +25,7 @@ import {
usePolicyByParentAndType,
defaultApprovalStrategy,
} from "@/store/modules/v1/policy";
-import { useEnvironmentStore } from "@/store";
-import { getEnvironmentPathByLegacyEnvironment } from "@/store/modules/v1/common";
+import { useEnvironmentV1Store } from "@/store";
export const useCurrentRollOutPolicyForActiveEnvironment = () => {
const { create, issue, activeStageOfPipeline } = useIssueLogic();
@@ -40,28 +38,27 @@ export const useCurrentRollOutPolicyForActiveEnvironment = () => {
}));
}
- const activeEnvironment = computed((): Environment => {
+ const activeEnvironment = computed(() => {
if (create.value) {
// When creating an issue, activeEnvironmentId is the first stage's environmentId
const stage = (issue.value as IssueCreate).pipeline!.stageList[0];
- return useEnvironmentStore().getEnvironmentById(stage.environmentId);
+ return useEnvironmentV1Store().getEnvironmentByUID(stage.environmentId);
}
const stage = activeStageOfPipeline(issue.value.pipeline as Pipeline);
- return stage.environment;
+ return useEnvironmentV1Store().getEnvironmentByUID(stage.environment.id);
});
const activeEnvironmentApprovalPolicy = usePolicyByParentAndType(
computed(() => ({
- parentPath: getEnvironmentPathByLegacyEnvironment(
- activeEnvironment.value
- ),
+ parentPath: activeEnvironment.value.name,
policyType: PolicyType.DEPLOYMENT_APPROVAL,
}))
);
return computed(() => {
const policy = activeEnvironmentApprovalPolicy.value;
+ console.log("policy", policy);
return extractRollOutPolicyValue(policy, issue.value.type);
});
};
diff --git a/frontend/src/components/TransferOutDatabaseForm/Label.vue b/frontend/src/components/TransferOutDatabaseForm/Label.vue
index 0072c75de0..4bed087cf2 100644
--- a/frontend/src/components/TransferOutDatabaseForm/Label.vue
+++ b/frontend/src/components/TransferOutDatabaseForm/Label.vue
@@ -1,5 +1,5 @@
<template>
- <EnvironmentName
+ <EnvironmentV1Name
v-if="environment"
:environment="environment"
:link="false"
@@ -23,8 +23,8 @@ import { computed } from "vue";
import { escape } from "lodash-es";
import { DatabaseTreeOption } from "./common";
-import { useDatabaseStore, useEnvironmentStore } from "@/store";
-import { EnvironmentName, InstanceName } from "@/components/v2";
+import { useDatabaseStore, useEnvironmentV1Store } from "@/store";
+import { EnvironmentV1Name, InstanceName } from "@/components/v2";
import { getHighlightHTMLByRegExp } from "@/utils";
const props = defineProps<{
@@ -38,13 +38,13 @@ const id = computed(() => {
const environment = computed(() => {
const { option } = props;
- if (option.level === "database") return undefined;
- return useEnvironmentStore().getEnvironmentById(id.value);
+ if (option.level !== "environment") return undefined;
+ return useEnvironmentV1Store().getEnvironmentByUID(id.value);
});
const database = computed(() => {
const { option } = props;
- if (option.level === "environment") return undefined;
+ if (option.level !== "database") return undefined;
return useDatabaseStore().getDatabaseById(id.value);
});
diff --git a/frontend/src/components/TransferOutDatabaseForm/common.ts b/frontend/src/components/TransferOutDatabaseForm/common.ts
index 14be9e5f7c..91c49dc89a 100644
--- a/frontend/src/components/TransferOutDatabaseForm/common.ts
+++ b/frontend/src/components/TransferOutDatabaseForm/common.ts
@@ -1,6 +1,6 @@
import { groupBy } from "lodash-es";
import { TransferOption, TreeOption } from "naive-ui";
-import { useEnvironmentStore } from "@/store";
+import { useEnvironmentV1Store } from "@/store";
import { Database } from "@/types";
export interface DatabaseTreeOption<L = "environment" | "database">
@@ -10,7 +10,7 @@ export interface DatabaseTreeOption<L = "environment" | "database">
}
export const mapTreeOptions = (databaseList: Database[]) => {
- const environmentStore = useEnvironmentStore();
+ const environmentV1Store = useEnvironmentV1Store();
const databaseListGroupByEnvironment = groupBy(
databaseList,
(db) => db.instance.environment.id
@@ -18,7 +18,7 @@ export const mapTreeOptions = (databaseList: Database[]) => {
return Object.keys(databaseListGroupByEnvironment).map<
DatabaseTreeOption<"environment">
>((environmentId) => {
- const environment = environmentStore.getEnvironmentById(environmentId);
+ const environment = environmentV1Store.getEnvironmentByUID(environmentId);
const group = databaseListGroupByEnvironment[environmentId];
const children = group.map<DatabaseTreeOption<"database">>((db) => ({
level: "database",
@@ -29,7 +29,7 @@ export const mapTreeOptions = (databaseList: Database[]) => {
return {
level: "environment",
value: `environment-${environmentId}`,
- label: environment.name,
+ label: environment.title,
children,
};
});
diff --git a/frontend/src/components/v2/Model/EnvironmentV1Table.vue b/frontend/src/components/v2/Model/EnvironmentV1Table.vue
new file mode 100644
index 0000000000..dd3d8cb7b7
--- /dev/null
+++ b/frontend/src/components/v2/Model/EnvironmentV1Table.vue
@@ -0,0 +1,64 @@
+<template>
+ <BBGrid
+ :column-list="columnList"
+ :data-source="environmentList"
+ :show-header="true"
+ :left-bordered="false"
+ :right-bordered="false"
+ @click-row="clickEnvironment"
+ >
+ <template #item="{ item: environment }: EnvironmentRow">
+ <div class="bb-grid-cell text-gray-500">
+ <span class="">#{{ environment.uid }}</span>
+ </div>
+ <div class="bb-grid-cell">
+ <EnvironmentV1Name :environment="environment" :link="false" />
+ </div>
+ </template>
+ </BBGrid>
+</template>
+
+<script lang="ts" setup>
+import { computed } from "vue";
+import { useRouter } from "vue-router";
+import { useI18n } from "vue-i18n";
+import { Environment } from "@/types/proto/v1/environment_service";
+import { environmentV1Slug } from "@/utils";
+import { BBGridColumn, BBGridRow, BBGrid } from "@/bbkit";
+import { EnvironmentV1Name } from ".";
+
+export type EnvironmentRow = BBGridRow<Environment>;
+
+defineProps<{
+ environmentList: Environment[];
+}>();
+
+const router = useRouter();
+
+const { t } = useI18n();
+
+const columnList = computed((): BBGridColumn[] => [
+ {
+ title: t("common.id"),
+ width: "minmax(auto, 10rem)",
+ },
+ {
+ title: t("common.name"),
+ width: "1fr",
+ },
+]);
+
+const clickEnvironment = function (
+ environment: Environment,
+ section: number,
+ row: number,
+ e: MouseEvent
+) {
+ const url = `/environment/${environmentV1Slug(environment)}`;
+ if (e.ctrlKey || e.metaKey) {
+ window.open(url, "_blank");
+ } else {
+ router.push(url);
+ }
+};
+</script>
diff --git a/frontend/src/components/v2/Model/index.ts b/frontend/src/components/v2/Model/index.ts
index c0b0357b64..1a01bbc532 100644
--- a/frontend/src/components/v2/Model/index.ts
+++ b/frontend/src/components/v2/Model/index.ts
@@ -2,6 +2,7 @@ import DatabaseName from "./DatabaseName.vue";
import InstanceName from "./InstanceName.vue";
import EnvironmentName from "./EnvironmentName.vue";
import EnvironmentV1Name from "./EnvironmentV1Name.vue";
+import EnvironmentV1Table from "./EnvironmentV1Table.vue";
import ProductionEnvironmentV1Icon from "./ProductionEnvironmentV1Icon.vue";
import ProjectName from "./ProjectName.vue";
import ProjectV1Table from "./ProjectV1Table.vue";
@@ -11,6 +12,7 @@ export {
InstanceName,
EnvironmentName,
EnvironmentV1Name,
+ EnvironmentV1Table,
ProductionEnvironmentV1Icon,
ProjectName,
ProjectV1Table,
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index fbba733b7b..a471b49254 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -44,7 +44,6 @@ import {
useAuthStore,
useActuatorStore,
useDatabaseStore,
- useEnvironmentStore,
useInstanceStore,
usePrincipalStore,
useRouterStore,
@@ -58,6 +57,7 @@ import {
useUserStore,
useProjectV1Store,
useProjectWebhookV1Store,
+ useEnvironmentV1Store,
} from "@/store";
import { useConversationStore } from "@/plugins/ai/store";
import { PlanType } from "@/types/proto/v1/subscription_service";
@@ -652,9 +652,9 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: (route: RouteLocationNormalized) => {
const slug = route.params.environmentSlug as string;
- return useEnvironmentStore().getEnvironmentById(
+ return useEnvironmentV1Store().getEnvironmentByUID(
idFromSlug(slug)
- ).name;
+ ).title;
},
allowBookmark: true,
},
@@ -1134,7 +1134,6 @@ router.beforeEach((to, from, next) => {
const authStore = useAuthStore();
const databaseStore = useDatabaseStore();
const dbSchemaStore = useDBSchemaStore();
- const environmentStore = useEnvironmentStore();
const instanceStore = useInstanceStore();
const routerStore = useRouterStore();
const projectStore = useProjectStore();
@@ -1441,19 +1440,25 @@ router.beforeEach((to, from, next) => {
}
if (environmentSlug) {
- const env = environmentStore.getEnvironmentById(
- idFromSlug(environmentSlug)
- );
- // getEnvironmentById returns unknown("ENVIRONMENT") when it doesn't exist
- // so we need to check the id here
- if (env && env.id !== UNKNOWN_ID) {
- next();
- return;
- }
- next({
- name: "error.404",
- replace: false,
- });
+ useEnvironmentV1Store()
+ .getOrFetchEnvironmentByUID(idFromSlug(environmentSlug))
+ .then((env) => {
+ // getEnvironmentById returns unknown("ENVIRONMENT") when it doesn't exist
+ // so we need to check the id here
+ if (env && env.uid !== String(UNKNOWN_ID)) {
+ next();
+ return;
+ } else {
+ throw new Error();
+ }
+ })
+ .catch(() => {
+ next({
+ name: "error.404",
+ replace: false,
+ });
+ });
+ return;
}
if (projectSlug) {
diff --git a/frontend/src/store/modules/v1/environment.ts b/frontend/src/store/modules/v1/environment.ts
index 7b3a889ca9..3375b40e90 100644
--- a/frontend/src/store/modules/v1/environment.ts
+++ b/frontend/src/store/modules/v1/environment.ts
@@ -111,7 +111,9 @@ export const useEnvironmentV1Store = defineStore("environment_v1", {
}
return (
this.environmentList.find((env) => parseInt(env.uid, 10) == uid) ??
- Environment.fromJSON({})
+ Environment.fromJSON({
+ uid: "-1",
+ })
);
},
},
diff --git a/frontend/src/views/Archive.vue b/frontend/src/views/Archive.vue
index 9790cc4b34..d0e73ffff7 100644
--- a/frontend/src/views/Archive.vue
+++ b/frontend/src/views/Archive.vue
@@ -26,9 +26,9 @@
v-else-if="state.selectedIndex == INSTANCE_TAB"
:instance-list="filteredInstanceList(instanceList)"
/>
- <EnvironmentTable
+ <EnvironmentV1Table
v-else-if="state.selectedIndex == ENVIRONMENT_TAB"
- :environment-list="filteredEnvironmentList(environmentList)"
+ :environment-list="filteredEnvironmentList"
/>
<IdentityProviderTable
v-else-if="state.selectedIndex == SSO_TAB"
@@ -39,17 +39,15 @@
<script lang="ts">
import { computed, defineComponent, reactive, watchEffect } from "vue";
-import EnvironmentTable from "../components/EnvironmentTable.vue";
import InstanceTable from "../components/InstanceTable.vue";
-import { ProjectV1Table } from "../components/v2";
-import { Environment, Instance } from "../types";
+import { EnvironmentV1Table, ProjectV1Table } from "../components/v2";
+import { Instance } from "../types";
import { filterProjectV1ListByKeyword, hasWorkspacePermission } from "../utils";
import { BBTabFilterItem } from "../bbkit/types";
import { useI18n } from "vue-i18n";
import {
useCurrentUser,
- useEnvironmentList,
- useEnvironmentStore,
+ useEnvironmentV1Store,
useIdentityProviderStore,
useInstanceStore,
useProjectV1ListByCurrentUser,
@@ -71,7 +69,7 @@ interface LocalState {
export default defineComponent({
name: "Archive",
components: {
- EnvironmentTable,
+ EnvironmentV1Table,
InstanceTable,
ProjectV1Table,
IdentityProviderTable,
@@ -114,7 +112,7 @@ export default defineComponent({
) {
instanceStore.fetchInstanceList(["ARCHIVED"]);
- useEnvironmentStore().fetchEnvironmentList(["ARCHIVED"]);
+ useEnvironmentV1Store().fetchEnvironments(true);
}
};
@@ -124,7 +122,11 @@ export default defineComponent({
return instanceStore.getInstanceList(["ARCHIVED"]);
});
- const environmentList = useEnvironmentList(["ARCHIVED"]);
+ const environmentList = computed(() => {
+ return useEnvironmentV1Store().environmentList.filter(
+ (env) => env.state === State.DELETED
+ );
+ });
const deletedSSOList = computed(() => {
return useIdentityProviderStore().deletedIdentityProviderList;
@@ -183,16 +185,16 @@ export default defineComponent({
});
};
- const filteredEnvironmentList = (list: Environment[]) => {
- if (!state.searchText) {
+ const filteredEnvironmentList = computed(() => {
+ const list = environmentList.value;
+ const keyword = state.searchText.trim().toLowerCase();
+ if (!keyword) {
return list;
}
return list.filter((environment) => {
- return environment.name
- .toLowerCase()
- .includes(state.searchText.toLowerCase());
+ environment.title.toLowerCase().includes(keyword);
});
- };
+ });
const filteredSSOList = (list: IdentityProvider[]) => {
if (!state.searchText) {