Skip to content

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

refactor(frontend): shipping to project v1 API (part.1) (#5962)

Liu Ji12d8f1ee3c11
diff --git a/frontend/src/components/ProjectListSidePanel.vue b/frontend/src/components/ProjectListSidePanel.vue
index a6824f0b76..4c22e938fa 100644
--- a/frontend/src/components/ProjectListSidePanel.vue
+++ b/frontend/src/components/ProjectListSidePanel.vue
@@ -7,75 +7,51 @@
/>
</template>
-<script lang="ts">
-import { computed, defineComponent, watchEffect } from "vue";
-
-import { Project, UNKNOWN_ID, RowStatus } from "../types";
-import { projectName, projectSlug } from "../utils";
-import { BBOutlineItem } from "../bbkit/types";
-import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
+<script lang="ts" setup>
+import { computed } from "vue";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
-import { useCurrentUser, useProjectStore } from "@/store";
-
-export default defineComponent({
- name: "ProjectListSidePanel",
- setup() {
- const { t } = useI18n();
- const router = useRouter();
-
- const currentUser = useCurrentUser();
- const projectStore = useProjectStore();
-
- const prepareProjectList = () => {
- // It will also be called when user logout
- if (currentUser.value.id != UNKNOWN_ID) {
- projectStore.fetchProjectListByUser({
- userId: currentUser.value.id,
- });
- }
- };
-
- watchEffect(prepareProjectList);
-
- const outlineItemList = computed((): BBOutlineItem[] => {
- const projectList = projectStore.getProjectListByUser(
- currentUser.value.id,
- ["NORMAL"] as RowStatus[]
- );
- return projectList
- .map((item: Project): BBOutlineItem => {
- return {
- id: item.id.toString(),
- name: projectName(item),
- link: `/project/${projectSlug(item)}#overview`,
- };
- })
- .sort((a: any, b: any) => {
- return a.name.localeCompare(b.name);
- });
- });
+import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
- const kbarActions = computed((): Action[] => {
- const actions = outlineItemList.value.map((proj: any) =>
- defineAction({
- // here `id` looks like "bb.project.1234"
- id: `bb.project.${proj.id}`,
- section: t("common.projects"),
- name: proj.name,
- keywords: "project",
- perform: () => {
- router.push({ path: proj.link });
- },
- })
- );
- return actions;
+import { projectV1Slug } from "../utils";
+import { BBOutlineItem } from "../bbkit/types";
+import { useCurrentUserV1, useProjectV1ListByUser } from "@/store";
+
+const { t } = useI18n();
+const router = useRouter();
+
+const currentUserV1 = useCurrentUserV1();
+
+const { projectList } = useProjectV1ListByUser(currentUserV1);
+
+const outlineItemList = computed((): BBOutlineItem[] => {
+ return projectList.value
+ .map((project): BBOutlineItem => {
+ return {
+ id: project.uid,
+ name: project.title,
+ link: `/project/${projectV1Slug(project)}#overview`,
+ };
+ })
+ .sort((a: any, b: any) => {
+ return a.name.localeCompare(b.name);
});
- useRegisterActions(kbarActions);
+});
- return {
- outlineItemList,
- };
- },
+const kbarActions = computed((): Action[] => {
+ const actions = outlineItemList.value.map((proj: any) =>
+ defineAction({
+ // here `id` looks like "bb.project.1234"
+ id: `bb.project.${proj.id}`,
+ section: t("common.projects"),
+ name: proj.name,
+ keywords: "project",
+ perform: () => {
+ router.push({ path: proj.link });
+ },
+ })
+ );
+ return actions;
});
+useRegisterActions(kbarActions);
</script>
diff --git a/frontend/src/components/ProjectTable.vue b/frontend/src/components/ProjectTable.vue
deleted file mode 100644
index ce8c7397c9..0000000000
--- a/frontend/src/components/ProjectTable.vue
+++ /dev/null
@@ -1,105 +0,0 @@
-<template>
- <BBTable
- :column-list="columnList"
- :data-source="projectList"
- :show-header="true"
- :left-bordered="leftBordered"
- :right-bordered="rightBordered"
- @click-row="clickProject"
- >
- <template #header>
- <BBTableHeaderCell class="table-cell" :title="columnList[0].title" />
- <BBTableHeaderCell class="table-cell" :title="columnList[1].title" />
- </template>
- <template #body="{ rowData: project }">
- <BBTableCell :left-padding="4" class="table-cell text-gray-500 w-[30%]">
- <span class="flex flex-row items-center space-x-1">
- <span>{{ project.key }}</span>
- <div v-if="project.tenantMode === 'TENANT'" class="tooltip-wrapper">
- <TenantIcon class="ml-1 w-4 h-4 text-control" />
- <span class="tooltip whitespace-nowrap">
- {{ $t("project.mode.tenant") }}
- </span>
- </div>
- <div v-if="project.rowStatus === 'ARCHIVED'" class="tooltip-wrapper">
- <heroicons-outline:archive class="ml-1 w-4 h-4 text-control" />
- <span class="tooltip whitespace-nowrap">
- {{ $t("archive.archived") }}
- </span>
- </div>
- <div v-if="project.workflowType === 'VCS'" class="tooltip-wrapper">
- <heroicons-outline:collection class="ml-1 w-4 h-4 text-control" />
- <span class="tooltip whitespace-nowrap">
- {{ $t("database.gitops-enabled") }}
- </span>
- </div>
- </span>
- </BBTableCell>
- <BBTableCell class="truncate">
- {{ projectName(project) }}
- </BBTableCell>
- </template>
- </BBTable>
-</template>
-
-<script lang="ts">
-import { PropType, computed, defineComponent } from "vue";
-import { useRouter } from "vue-router";
-import { useI18n } from "vue-i18n";
-import { projectSlug } from "../utils";
-import { Project } from "../types";
-import TenantIcon from "./TenantIcon.vue";
-
-export default defineComponent({
- name: "ProjectTable",
- components: {
- TenantIcon,
- },
- props: {
- projectList: {
- required: true,
- type: Object as PropType<Project[]>,
- },
- leftBordered: {
- default: true,
- type: Boolean,
- },
- rightBordered: {
- default: true,
- type: Boolean,
- },
- },
-
- setup(props) {
- const router = useRouter();
- const { t } = useI18n();
- const columnList = computed(() => [
- {
- title: t("project.table.key"),
- },
- {
- title: t("project.table.name"),
- },
- ]);
-
- const clickProject = function (
- section: number,
- row: number,
- e: MouseEvent
- ) {
- const project = props.projectList[row];
- const url = `/project/${projectSlug(project)}`;
- if (e.ctrlKey || e.metaKey) {
- window.open(url, "_blank");
- } else {
- router.push(url);
- }
- };
-
- return {
- columnList,
- clickProject,
- };
- },
-});
-</script>
diff --git a/frontend/src/components/v2/Model/ProjectV1Table.vue b/frontend/src/components/v2/Model/ProjectV1Table.vue
new file mode 100644
index 0000000000..5ae74efa7e
--- /dev/null
+++ b/frontend/src/components/v2/Model/ProjectV1Table.vue
@@ -0,0 +1,97 @@
+<template>
+ <BBGrid
+ :column-list="columnList"
+ :data-source="projectList"
+ class="border"
+ :show-placeholder="true"
+ @click-row="clickProject"
+ >
+ <template #item="{ item: project }: ProjectGridRow">
+ <div class="bb-grid-cell text-gray-500">
+ <span class="flex flex-row items-center space-x-1">
+ <span>{{ project.key }}</span>
+ <NTooltip
+ v-if="project.tenantMode === TenantMode.TENANT_MODE_ENABLED"
+ >
+ <template #trigger>
+ <TenantIcon class="ml-1 w-4 h-4 text-control" />
+ </template>
+ <span class="whitespace-nowrap">
+ {{ $t("project.mode.tenant") }}
+ </span>
+ </NTooltip>
+ <NTooltip v-if="project.state === State.DELETED">
+ <template #trigger>
+ <heroicons-outline:archive class="ml-1 w-4 h-4 text-control" />
+ </template>
+ <span class="whitespace-nowrap">
+ {{ $t("archive.archived") }}
+ </span>
+ </NTooltip>
+ <NTooltip v-if="project.workflow === Workflow.VCS">
+ <template #trigger>
+ <heroicons-outline:collection class="ml-1 w-4 h-4 text-control" />
+ </template>
+ <span class="whitespace-nowrap">
+ {{ $t("database.gitops-enabled") }}
+ </span>
+ </NTooltip>
+ </span>
+ </div>
+ <div class="bb-grid-cell truncate">
+ {{ projectV1Name(project) }}
+ </div>
+ </template>
+ </BBGrid>
+</template>
+
+<script lang="ts" setup>
+import { PropType, computed } from "vue";
+import { useRouter } from "vue-router";
+import { useI18n } from "vue-i18n";
+import { projectV1Slug, projectV1Name } from "@/utils";
+import TenantIcon from "@/components/TenantIcon.vue";
+import {
+ Project,
+ TenantMode,
+ Workflow,
+} from "@/types/proto/v1/project_service";
+import { BBGridColumn, BBGridRow, BBGrid } from "@/bbkit";
+import { State } from "@/types/proto/v1/common";
+
+export type ProjectGridRow = BBGridRow<Project>;
+
+defineProps({
+ projectList: {
+ required: true,
+ type: Object as PropType<Project[]>,
+ },
+});
+
+const router = useRouter();
+const { t } = useI18n();
+const columnList = computed((): BBGridColumn[] => [
+ {
+ title: t("project.table.key"),
+ width: "minmax(auto, 25%)",
+ },
+ {
+ title: t("project.table.name"),
+ width: "1fr",
+ },
+]);
+
+const clickProject = function (
+ project: Project,
+ section: number,
+ row: number,
+ e: MouseEvent
+) {
+ const url = `/project/${projectV1Slug(project)}`;
+ 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 02e57cc919..a05fa14e09 100644
--- a/frontend/src/components/v2/Model/index.ts
+++ b/frontend/src/components/v2/Model/index.ts
@@ -2,5 +2,12 @@ import DatabaseName from "./DatabaseName.vue";
import InstanceName from "./InstanceName.vue";
import EnvironmentName from "./EnvironmentName.vue";
import ProjectName from "./ProjectName.vue";
+import ProjectV1Table from "./ProjectV1Table.vue";
-export { DatabaseName, InstanceName, EnvironmentName, ProjectName };
+export {
+ DatabaseName,
+ InstanceName,
+ EnvironmentName,
+ ProjectName,
+ ProjectV1Table,
+};
diff --git a/frontend/src/store/modules/auth.ts b/frontend/src/store/modules/auth.ts
index c6c82226eb..7506ec023d 100644
--- a/frontend/src/store/modules/auth.ts
+++ b/frontend/src/store/modules/auth.ts
@@ -104,6 +104,11 @@ export const useCurrentUser = () => {
});
};
+export const useCurrentUserV1 = () => {
+ const authStore = useAuthStore();
+ return computed(() => authStore.currentUser);
+};
+
export const useIsLoggedIn = () => {
const store = useAuthStore();
return computed(() => store.isLoggedIn() && store.currentUser.name !== "");
diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.ts
index 43f7725fb2..712ac42ebc 100644
--- a/frontend/src/store/modules/index.ts
+++ b/frontend/src/store/modules/index.ts
@@ -52,5 +52,5 @@ export * from "./workspaceApprovalSetting";
export * from "./review";
export * from "./slowQuery";
export * from "./role";
-export * from "./v1/projectIamPolicy";
-export * from "./v1/databaseSecret";
+
+export * from "./v1";
diff --git a/frontend/src/store/modules/v1/index.ts b/frontend/src/store/modules/v1/index.ts
new file mode 100644
index 0000000000..02592f538b
--- /dev/null
+++ b/frontend/src/store/modules/v1/index.ts
@@ -0,0 +1,3 @@
+export * from "./project";
+export * from "./projectIamPolicy";
+export * from "./databaseSecret";
diff --git a/frontend/src/store/modules/v1/project.ts b/frontend/src/store/modules/v1/project.ts
index 5ad3e5207b..1687a94f9a 100644
--- a/frontend/src/store/modules/v1/project.ts
+++ b/frontend/src/store/modules/v1/project.ts
@@ -1,41 +1,154 @@
import { defineStore } from "pinia";
+import { computed, reactive, ref, unref, watchEffect } from "vue";
+
+import {
+ ComposedProject,
+ emptyProject,
+ EMPTY_ID,
+ IdType,
+ MaybeRef,
+ ResourceId,
+ unknownProject,
+} from "@/types";
import { projectServiceClient } from "@/grpcweb";
-import { ResourceId } from "@/types";
import { Project } from "@/types/proto/v1/project_service";
+import { useProjectIamPolicyStore } from "./projectIamPolicy";
+import { State } from "@/types/proto/v1/common";
+import { User } from "@/types/proto/v1/auth_service";
-interface ProjectState {
- projectMapByName: Map<ResourceId, Project>;
-}
-
-export const useProjectV1Store = defineStore("project_v1", {
- state: (): ProjectState => ({
- projectMapByName: new Map(),
- }),
- getters: {
- projectList(state) {
- return Array.from(state.projectMapByName.values());
- },
- },
- actions: {
- async fetchProjects(showDeleted = false) {
- const { projects } = await projectServiceClient.listProjects({
- showDeleted,
- });
- for (const project of projects) {
- this.projectMapByName.set(project.name, project);
- }
- return projects;
- },
- async getOrFetchProjectByName(name: string) {
- const cachedData = this.projectMapByName.get(name);
- if (cachedData) {
- return cachedData;
- }
- const project = await projectServiceClient.getProject({
- name,
- });
- this.projectMapByName.set(project.name, project);
- return project;
- },
- },
+export const useProjectV1Store = defineStore("project_v1", () => {
+ const projectMapByName = reactive(new Map<ResourceId, ComposedProject>());
+
+ // Getters
+ const projectList = computed(() => {
+ return Array.from(projectMapByName.values());
+ });
+
+ // Actions
+ const upsertProjectMap = async (projectList: Project[]) => {
+ for (const project of projectList) {
+ const composed = await composeProjectIamPolicy(project);
+ projectMapByName.set(composed.name, composed);
+ }
+ };
+ const fetchProjectList = async (showDeleted = false) => {
+ const { projects } = await projectServiceClient.listProjects({
+ showDeleted,
+ });
+ await upsertProjectMap(projects);
+ return projects;
+ };
+ const getProjectByUID = (uid: IdType) => {
+ if (typeof uid === "string") {
+ uid = parseInt(uid, 10);
+ }
+ if (uid === EMPTY_ID) {
+ return emptyProject();
+ }
+ return (
+ projectList.value.find((project) => parseInt(project.uid, 10) === uid) ??
+ unknownProject()
+ );
+ };
+ const fetchProjectByName = async (name: string) => {
+ const project = await projectServiceClient.getProject({
+ name,
+ });
+ await upsertProjectMap([project]);
+ return project;
+ };
+ const fetchProjectByUID = async (uid: IdType) => {
+ return fetchProjectByName(`projects/${uid}`);
+ };
+ const getOrFetchProjectByName = async (name: string) => {
+ const cachedData = projectMapByName.get(name);
+ if (cachedData) {
+ return cachedData;
+ }
+ return fetchProjectByName(name);
+ };
+ const updateProject = async (
+ project: Project,
+ updateMask: Array<keyof Project>
+ ) => {
+ const updated = await projectServiceClient.updateProject({
+ project,
+ updateMask,
+ });
+ await upsertProjectMap([updated]);
+ return updated;
+ };
+ const archiveProject = async (project: Project) => {
+ await projectServiceClient.deleteProject({
+ name: project.name,
+ });
+ project.state = State.DELETED;
+ await upsertProjectMap([project]);
+ };
+ const restoreProject = async (project: Project) => {
+ await projectServiceClient.undeleteProject({
+ name: project.name,
+ });
+ project.state = State.ACTIVE;
+ await upsertProjectMap([project]);
+ };
+
+ return {
+ projectMapByName,
+ projectList,
+ getProjectByUID,
+ fetchProjectList,
+ fetchProjectByName,
+ fetchProjectByUID,
+ getOrFetchProjectByName,
+ updateProject,
+ archiveProject,
+ restoreProject,
+ };
});
+
+export const useProjectV1List = (showDeleted: MaybeRef<boolean> = false) => {
+ const store = useProjectV1Store();
+ const ready = ref(false);
+ watchEffect(() => {
+ ready.value = false;
+ store.fetchProjectList(unref(showDeleted)).then(() => {
+ ready.value = true;
+ });
+ });
+ const projectList = computed(() => {
+ if (unref(showDeleted)) {
+ return store.projectList;
+ }
+ return store.projectList.filter(
+ (project) => project.state === State.ACTIVE
+ );
+ });
+ return { projectList, ready };
+};
+
+export const useProjectV1ListByUser = (
+ user: MaybeRef<User>,
+ showDeleted: MaybeRef<boolean> = false
+) => {
+ const { projectList: rawProjectList, ready } = useProjectV1List(showDeleted);
+ const projectList = computed(() => {
+ return rawProjectList.value.filter((project) => {
+ return project.iamPolicy.bindings.some((binding) => {
+ return binding.members.some((email) => {
+ return email === `user:${unref(user).email}`;
+ });
+ });
+ });
+ });
+ return { projectList, ready };
+};
+
+const composeProjectIamPolicy = async (project: Project) => {
+ const policy = await useProjectIamPolicyStore().getOrFetchProjectIamPolicy(
+ project.name
+ );
+ const composedProject = project as ComposedProject;
+ composedProject.iamPolicy = policy;
+ return composedProject;
+};
diff --git a/frontend/src/store/modules/v1/projectIamPolicy.ts b/frontend/src/store/modules/v1/projectIamPolicy.ts
index e70440e09c..738394660f 100644
--- a/frontend/src/store/modules/v1/projectIamPolicy.ts
+++ b/frontend/src/store/modules/v1/projectIamPolicy.ts
@@ -11,12 +11,23 @@ export const useProjectIamPolicyStore = defineStore(
"project-iam-policy",
() => {
const policyMap = ref(new Map<string, IamPolicy>());
+ const requestCache = new Map<string, Promise<IamPolicy>>();
const fetchProjectIamPolicy = async (project: string) => {
- const policy = await projectServiceClient.getIamPolicy({
- project,
- });
- policyMap.value.set(project, policy);
+ const cache = requestCache.get(project);
+ if (cache) {
+ return cache;
+ }
+ const request = projectServiceClient
+ .getIamPolicy({
+ project,
+ })
+ .then((policy) => {
+ policyMap.value.set(project, policy);
+ return policy;
+ });
+ requestCache.set(project, request);
+ return request;
};
const updateProjectIamPolicy = async (
@@ -36,10 +47,21 @@ export const useProjectIamPolicyStore = defineStore(
);
await useProjectStore().fetchProjectById(parseInt(projectEntity.uid, 10));
};
+ const getProjectIamPolicy = (project: string) => {
+ return policyMap.value.get(project) ?? IamPolicy.fromJSON({});
+ };
+ const getOrFetchProjectIamPolicy = async (project: string) => {
+ if (!policyMap.value.has(project)) {
+ await fetchProjectIamPolicy(project);
+ }
+ return getProjectIamPolicy(project);
+ };
return {
policyMap,
+ getProjectIamPolicy,
fetchProjectIamPolicy,
+ getOrFetchProjectIamPolicy,
updateProjectIamPolicy,
};
}
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index 644678fa59..cfbaed9f9a 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -53,3 +53,5 @@ export * from "./risk";
export * from "./workspaceApprovalSetting";
export * from "./review";
export * from "./slowQuery";
+
+export * from "./v1";
diff --git a/frontend/src/types/v1/index.ts b/frontend/src/types/v1/index.ts
new file mode 100644
index 0000000000..9ff8c7dff4
--- /dev/null
+++ b/frontend/src/types/v1/index.ts
@@ -0,0 +1 @@
+export * from "./project";
diff --git a/frontend/src/types/v1/project.ts b/frontend/src/types/v1/project.ts
new file mode 100644
index 0000000000..5bcb0a36a9
--- /dev/null
+++ b/frontend/src/types/v1/project.ts
@@ -0,0 +1,29 @@
+import { EMPTY_ID, UNKNOWN_ID } from "../const";
+import { IamPolicy, Project } from "../proto/v1/project_service";
+
+export const DEFAULT_PROJECT_V1_NAME = "projects/default";
+
+export interface ComposedProject extends Project {
+ iamPolicy: IamPolicy;
+}
+
+export const emptyProject = (): ComposedProject => {
+ return {
+ ...Project.fromJSON({
+ name: `projects/${EMPTY_ID}`,
+ uid: EMPTY_ID,
+ }),
+ iamPolicy: IamPolicy.fromJSON({}),
+ };
+};
+
+export const unknownProject = (): ComposedProject => {
+ return {
+ ...Project.fromJSON({
+ name: `projects/${UNKNOWN_ID}`,
+ uid: UNKNOWN_ID,
+ title: "<<Unknown project>>",
+ }),
+ iamPolicy: IamPolicy.fromJSON({}),
+ };
+};
diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts
index f8ba269d55..367d268b1b 100644
--- a/frontend/src/utils/index.ts
+++ b/frontend/src/utils/index.ts
@@ -29,3 +29,5 @@ export * from "./id";
export * from "./workspaceApprovalSetting";
export * from "./projectIamPolicy";
export * from "./slowQuery";
+
+export * from "./v1";
diff --git a/frontend/src/utils/v1/index.ts b/frontend/src/utils/v1/index.ts
new file mode 100644
index 0000000000..e27958507b
--- /dev/null
+++ b/frontend/src/utils/v1/index.ts
@@ -0,0 +1,2 @@
+export * from "./slug";
+export * from "./project";
diff --git a/frontend/src/utils/v1/project.ts b/frontend/src/utils/v1/project.ts
new file mode 100644
index 0000000000..9cca823e89
--- /dev/null
+++ b/frontend/src/utils/v1/project.ts
@@ -0,0 +1,51 @@
+import { DEFAULT_PROJECT_V1_NAME } from "@/types";
+import { User } from "@/types/proto/v1/auth_service";
+import { State } from "@/types/proto/v1/common";
+import { IamPolicy, Project } from "@/types/proto/v1/project_service";
+import {
+ extractRoleResourceName,
+ hasProjectPermission,
+ ProjectPermissionType,
+} from "../role";
+
+export const hasPermissionInProjectV1 = (
+ policy: IamPolicy,
+ user: User,
+ permission: ProjectPermissionType
+) => {
+ return policy.bindings.some((binding) => {
+ if (binding.members.includes(`user:${user.email}`)) {
+ return hasProjectPermission(
+ permission,
+ extractRoleResourceName(binding.role)
+ );
+ }
+ return false;
+ });
+};
+
+export function projectV1Name(project: Project) {
+ if (project.name === DEFAULT_PROJECT_V1_NAME) {
+ return "Unassigned";
+ }
+
+ const parts = [project.title];
+ if (project.state === State.DELETED) {
+ parts.push("(Archived)");
+ }
+ return parts.join(" ");
+}
+
+export function filterProjectV1ListByKeyword<T extends Project>(
+ projectList: T[],
+ keyword: string
+) {
+ keyword = keyword.trim().toLowerCase();
+ if (!keyword) return projectList;
+ return projectList.filter((project) => {
+ return (
+ project.title.toLowerCase().includes(keyword) ||
+ project.key.toLowerCase().includes(keyword)
+ );
+ });
+}
diff --git a/frontend/src/utils/v1/slug.ts b/frontend/src/utils/v1/slug.ts
new file mode 100644
index 0000000000..66d11219e2
--- /dev/null
+++ b/frontend/src/utils/v1/slug.ts
@@ -0,0 +1,7 @@
+import slug from "slug";
+
+import type { Project } from "@/types/proto/v1/project_service";
+
+export function projectV1Slug(project: Project): string {
+ return [slug(project.title), project.uid].join("-");
+}
diff --git a/frontend/src/views/Archive.vue b/frontend/src/views/Archive.vue
index c283941d81..f1a08e68cf 100644
--- a/frontend/src/views/Archive.vue
+++ b/frontend/src/views/Archive.vue
@@ -17,11 +17,10 @@
@change-text="(text: string) => changeSearchText(text)"
/>
</div>
- <ProjectTable
+ <ProjectV1Table
v-if="state.selectedIndex == PROJECT_TAB"
- :project-list="filteredProjectList(projectList)"
- :left-bordered="false"
- :right-bordered="false"
+ :project-list="filteredProjectList"
+ class="border-x-0"
/>
<InstanceTable
v-else-if="state.selectedIndex == INSTANCE_TAB"
@@ -42,21 +41,23 @@
import { computed, defineComponent, reactive, watchEffect } from "vue";
import EnvironmentTable from "../components/EnvironmentTable.vue";
import InstanceTable from "../components/InstanceTable.vue";
-import ProjectTable from "../components/ProjectTable.vue";
-import { Environment, Instance, Project, UNKNOWN_ID } from "../types";
-import { hasWorkspacePermission } from "../utils";
+import { ProjectV1Table } from "../components/v2";
+import { Environment, Instance } from "../types";
+import { filterProjectV1ListByKeyword, hasWorkspacePermission } from "../utils";
import { BBTabFilterItem } from "../bbkit/types";
import { useI18n } from "vue-i18n";
import {
useCurrentUser,
+ useCurrentUserV1,
useEnvironmentList,
useEnvironmentStore,
useIdentityProviderStore,
useInstanceStore,
- useProjectStore,
+ useProjectV1ListByUser,
} from "@/store";
import { IdentityProvider } from "@/types/proto/v1/idp_service";
import IdentityProviderTable from "@/components/IdentityProviderTable.vue";
+import { State } from "@/types/proto/v1/common";
const PROJECT_TAB = 0;
const INSTANCE_TAB = 1;
@@ -73,13 +74,12 @@ export default defineComponent({
components: {
EnvironmentTable,
InstanceTable,
- ProjectTable,
+ ProjectV1Table,
IdentityProviderTable,
},
setup() {
const { t } = useI18n();
const instanceStore = useInstanceStore();
- const projectStore = useProjectStore();
const state = reactive<LocalState>({
selectedIndex: PROJECT_TAB,
@@ -87,6 +87,7 @@ export default defineComponent({
});
const currentUser = useCurrentUser();
+ const currentUserV1 = useCurrentUserV1();
const searchFieldPlaceholder = computed(() => {
if (state.selectedIndex == PROJECT_TAB) {
@@ -102,15 +103,12 @@ export default defineComponent({
}
});
- const prepareList = () => {
- // It will also be called when user logout
- if (currentUser.value.id != UNKNOWN_ID) {
- projectStore.fetchProjectListByUser({
- userId: currentUser.value.id,
- rowStatusList: ["ARCHIVED"],
- });
- }
+ const { projectList } = useProjectV1ListByUser(
+ currentUserV1,
+ true /* showDeleted */
+ );
+ const prepareList = () => {
if (
hasWorkspacePermission(
"bb.permission.workspace.manage-instance",
@@ -125,12 +123,6 @@ export default defineComponent({
watchEffect(prepareList);
- const projectList = computed((): Project[] => {
- return projectStore.getProjectListByUser(currentUser.value.id, [
- "ARCHIVED",
- ]);
- });
-
const instanceList = computed((): Instance[] => {
return instanceStore.getInstanceList(["ARCHIVED"]);
});
@@ -176,16 +168,12 @@ export default defineComponent({
return list;
});
- const filteredProjectList = (list: Project[]) => {
- if (!state.searchText) {
- return list;
- }
- return list.filter((project) => {
- return project.name
- .toLowerCase()
- .includes(state.searchText.toLowerCase());
- });
- };
+ const filteredProjectList = computed(() => {
+ const list = projectList.value.filter(
+ (project) => project.state === State.DELETED
+ );
+ return filterProjectV1ListByKeyword(list, state.searchText);
+ });
const filteredInstanceList = (list: Instance[]) => {
if (!state.searchText) {
@@ -230,7 +218,6 @@ export default defineComponent({
ENVIRONMENT_TAB,
SSO_TAB,
state,
- projectList,
instanceList,
environmentList,
deletedSSOList,
diff --git a/frontend/src/views/ProjectDashboard.vue b/frontend/src/views/ProjectDashboard.vue
index 4b4553fa5e..8f56140e78 100644
--- a/frontend/src/views/ProjectDashboard.vue
+++ b/frontend/src/views/ProjectDashboard.vue
@@ -9,37 +9,44 @@
@update:value="changeSearchText($event)"
/>
</div>
- <ProjectTable
- :project-list="filteredList(state.projectList)"
- :left-bordered="false"
- :right-bordered="false"
- />
+ <ProjectV1Table :project-list="filteredProjectList" class="border-x-0" />
</div>
</template>
<script lang="ts" setup>
-import { watchEffect, onMounted, reactive } from "vue";
+import { computed, onMounted, reactive } from "vue";
-import { useCurrentUser, useUIStateStore, useProjectStore } from "@/store";
-import { SearchBox } from "@/components/v2";
-import ProjectTable from "../components/ProjectTable.vue";
-import { Project, UNKNOWN_ID } from "../types";
+import {
+ useUIStateStore,
+ useProjectV1ListByUser,
+ useCurrentUserV1,
+} from "@/store";
+import { SearchBox, ProjectV1Table } from "@/components/v2";
+import { filterProjectV1ListByKeyword } from "@/utils";
interface LocalState {
- projectList: Project[];
searchText: string;
}
-const uiStateStore = useUIStateStore();
-const currentUser = useCurrentUser();
-const projectStore = useProjectStore();
+const currentUserV1 = useCurrentUserV1();
const state = reactive<LocalState>({
- projectList: [],
searchText: "",
});
+const { projectList } = useProjectV1ListByUser(currentUserV1);
+
+const changeSearchText = (searchText: string) => {
+ state.searchText = searchText;
+};
+
+const filteredProjectList = computed(() => {
+ const list = projectList.value;
+ return filterProjectV1ListByKeyword(list, state.searchText);
+});
+
onMounted(() => {
+ const uiStateStore = useUIStateStore();
if (!uiStateStore.getIntroStateByKey("project.visit")) {
uiStateStore.saveIntroStateByKey({
key: "project.visit",
@@ -47,38 +54,4 @@ onMounted(() => {
});
}
});
-
-const prepareProjectList = () => {
- // It will also be called when user logout
- if (currentUser.value.id != UNKNOWN_ID) {
- projectStore
- .fetchProjectListByUser({
- userId: currentUser.value.id,
- rowStatusList: ["NORMAL"],
- })
- .then((projectList: Project[]) => {
- state.projectList = projectList;
- });
- }
-};
-
-watchEffect(prepareProjectList);
-
-const changeSearchText = (searchText: string) => {
- state.searchText = searchText;
-};
-
-const filteredList = (list: Project[]) => {
- const keyword = state.searchText.trim().toLowerCase();
- if (!keyword) {
- // Select "All"
- return list;
- }
- return list.filter((project) => {
- return (
- project.name.toLowerCase().includes(keyword) ||
- project.key.toLowerCase().includes(keyword)
- );
- });
-};
</script>
diff --git a/frontend/src/views/SettingWorkspaceProject.vue b/frontend/src/views/SettingWorkspaceProject.vue
index 5cda8ca030..0caf20ed65 100644
--- a/frontend/src/views/SettingWorkspaceProject.vue
+++ b/frontend/src/views/SettingWorkspaceProject.vue
@@ -26,7 +26,7 @@
</NCheckbox>
</div>
- <ProjectTable :project-list="filteredList" />
+ <ProjectV1Table :project-list="filteredProjectList" />
<BBModal
v-if="state.showCreateModal"
@@ -40,63 +40,49 @@
</template>
<script setup lang="ts">
-import { watchEffect, reactive, computed } from "vue";
+import { reactive, computed } from "vue";
import { NCheckbox } from "naive-ui";
-import { DEFAULT_PROJECT_ID, Project } from "../types";
-import { useProjectStore } from "@/store";
-import ProjectTable from "../components/ProjectTable.vue";
+import { DEFAULT_PROJECT_V1_NAME } from "../types";
+import { useProjectV1List } from "@/store";
import ProjectCreate from "../components/ProjectCreate.vue";
-import { SearchBox } from "@/components/v2";
+import { ProjectV1Table, SearchBox } from "@/components/v2";
+import { State } from "@/types/proto/v1/common";
+import { filterProjectV1ListByKeyword } from "@/utils";
interface LocalState {
- projectList: Project[];
searchText: string;
showCreateModal: boolean;
includesArchived: boolean;
}
-const projectStore = useProjectStore();
+const { projectList } = useProjectV1List(true /* showDeleted */);
const state = reactive<LocalState>({
- projectList: [],
searchText: "",
showCreateModal: false,
includesArchived: false,
});
-const prepareProjectList = async () => {
- const projectList = [...(await projectStore.fetchAllProjectList())];
- // Put "Unassigned" to the first;
- const unassignedIndex = projectList.findIndex(
- (project) => project.id === DEFAULT_PROJECT_ID
- );
- if (unassignedIndex >= 0) {
- const unassignedProject = projectList[unassignedIndex];
- projectList.splice(unassignedIndex, 1);
- projectList.unshift(unassignedProject);
- }
- state.projectList = projectList;
-};
-
-watchEffect(prepareProjectList);
-
const changeSearchText = (searchText: string) => {
state.searchText = searchText;
};
-const filteredList = computed(() => {
- let list = state.projectList;
- const keyword = state.searchText.trim().toLowerCase();
- if (keyword) {
- list = list.filter(
- (project) =>
- project.name.toLowerCase().includes(keyword) ||
- project.key.toLowerCase().includes(keyword)
- );
+const filteredProjectList = computed(() => {
+ let list = [...projectList.value];
+ list = filterProjectV1ListByKeyword(list, state.searchText);
+
+ // Put "Unassigned" to the first;
+ const unassignedIndex = list.findIndex(
+ (project) => project.name === DEFAULT_PROJECT_V1_NAME
+ );
+ if (unassignedIndex >= 0) {
+ const unassignedProject = list[unassignedIndex];
+ list.splice(unassignedIndex, 1);
+ list.unshift(unassignedProject);
}
if (!state.includesArchived) {
- list = list.filter((project) => project.rowStatus === "NORMAL");
+ list = list.filter((project) => project.state !== State.DELETED);
}
return list;
});