Skip to content

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

feat: add resource id field to project (#4902)

boojackeb4f8adcd8cb
diff --git a/backend/legacyapi/project.go b/backend/legacyapi/project.go
index cdfc2ad972..44123dbe3e 100644
--- a/backend/legacyapi/project.go
+++ b/backend/legacyapi/project.go
@@ -98,6 +98,8 @@ type Project struct {
// ProjectCreate is the API message for creating a project.
type ProjectCreate struct {
+ ResourceID string `jsonapi:"attr,resourceId"`
+
// Domain specific fields
Name string `jsonapi:"attr,name"`
Key string `jsonapi:"attr,key"`
diff --git a/backend/server/project.go b/backend/server/project.go
index e9255322eb..f4b3c097a9 100644
--- a/backend/server/project.go
+++ b/backend/server/project.go
@@ -12,7 +12,6 @@ import (
"time"
"github.com/google/jsonapi"
- "github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
"go.uber.org/zap"
@@ -58,7 +57,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
creatorID := c.Get(getPrincipalIDContextKey()).(int)
project, err := s.store.CreateProjectV2(ctx, &store.ProjectMessage{
- ResourceID: fmt.Sprintf("project-%s", uuid.New().String()[:8]),
+ ResourceID: projectCreate.ResourceID,
Title: projectCreate.Name,
Key: projectCreate.Key,
TenantMode: projectCreate.TenantMode,
diff --git a/backend/tests/backup_restore_test.go b/backend/tests/backup_restore_test.go
index 89fc1d8528..967ec1e99a 100644
--- a/backend/tests/backup_restore_test.go
+++ b/backend/tests/backup_restore_test.go
@@ -419,6 +419,7 @@ func setUpForPITRTest(ctx context.Context, t *testing.T, ctl *controller) (*api.
a.NoError(err)
project, err := ctl.createProject(api.ProjectCreate{
+ ResourceID: generateRandomString("project", 10),
Name: "PITRTest",
Key: "PTT",
TenantMode: api.TenantModeDisabled,
diff --git a/backend/tests/database_edit_test.go b/backend/tests/database_edit_test.go
index 72cd1e13b1..9cd128421d 100644
--- a/backend/tests/database_edit_test.go
+++ b/backend/tests/database_edit_test.go
@@ -54,8 +54,9 @@ func TestDatabaseEdit(t *testing.T) {
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
- Name: "Test Schema Editor Data Project",
- Key: "TestSchemaEditor",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test Schema Editor Data Project",
+ Key: "TestSchemaEditor",
})
a.NoError(err)
diff --git a/backend/tests/external_approval_test.go b/backend/tests/external_approval_test.go
index aa01333b83..9364562635 100644
--- a/backend/tests/external_approval_test.go
+++ b/backend/tests/external_approval_test.go
@@ -68,8 +68,9 @@ func TestExternalApprovalFeishu_AllUserCanBeFound(t *testing.T) {
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
- Name: "Test Project",
- Key: "TestExternalApprovalFeishu",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test Project",
+ Key: "TestExternalApprovalFeishu",
})
a.NoError(err)
@@ -223,8 +224,9 @@ func TestExternalApprovalFeishu_AssigneeCanBeFound(t *testing.T) {
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
- Name: "Test Project",
- Key: "TestExternalApprovalFeishu",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test Project",
+ Key: "TestExternalApprovalFeishu",
})
a.NoError(err)
diff --git a/backend/tests/ghost_test.go b/backend/tests/ghost_test.go
index 6411c932e0..42c74486c2 100644
--- a/backend/tests/ghost_test.go
+++ b/backend/tests/ghost_test.go
@@ -97,8 +97,9 @@ func TestGhostSchemaUpdate(t *testing.T) {
a.NoError(err)
project, err := ctl.createProject(api.ProjectCreate{
- Name: "Test Ghost Project",
- Key: "TestGhostSchemaUpdate",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test Ghost Project",
+ Key: "TestGhostSchemaUpdate",
})
a.NoError(err)
@@ -236,6 +237,7 @@ func TestGhostTenant(t *testing.T) {
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
+ ResourceID: generateRandomString("project", 10),
Name: "Test Project",
Key: "TestTenantGhost",
TenantMode: api.TenantModeTenant,
diff --git a/backend/tests/project_test.go b/backend/tests/project_test.go
index a00b08a13e..3905543bf6 100644
--- a/backend/tests/project_test.go
+++ b/backend/tests/project_test.go
@@ -49,6 +49,7 @@ func TestArchiveProject(t *testing.T) {
t.Run("ArchiveProjectWithDatbase", func(t *testing.T) {
project, err := ctl.createProject(api.ProjectCreate{
+ ResourceID: generateRandomString("project", 10),
Name: "ProjectWithDatabase",
Key: "PWD",
TenantMode: api.TenantModeDisabled,
@@ -69,6 +70,7 @@ func TestArchiveProject(t *testing.T) {
t.Run("ArchiveProjectWithOpenIssue", func(t *testing.T) {
project, err := ctl.createProject(api.ProjectCreate{
+ ResourceID: generateRandomString("project", 10),
Name: "ProjectWithOpenIssue",
Key: "PWO",
TenantMode: api.TenantModeDisabled,
diff --git a/backend/tests/rollback_test.go b/backend/tests/rollback_test.go
index 70946456c8..61e1e993f9 100644
--- a/backend/tests/rollback_test.go
+++ b/backend/tests/rollback_test.go
@@ -120,8 +120,9 @@ func TestCreateRollbackIssueMySQL(t *testing.T) {
// Create a project.
project, err := ctl.createProject(
api.ProjectCreate{
- Name: fmt.Sprintf("Project %s", t.Name()),
- Key: "ROLLBACK",
+ ResourceID: generateRandomString("project", 10),
+ Name: fmt.Sprintf("Project %s", t.Name()),
+ Key: "ROLLBACK",
},
)
a.NoError(err)
@@ -322,8 +323,9 @@ func TestCreateRollbackIssueMySQLByPatch(t *testing.T) {
// Create a project.
project, err := ctl.createProject(
api.ProjectCreate{
- Name: fmt.Sprintf("Project %s", t.Name()),
- Key: "ROLLBACK",
+ ResourceID: generateRandomString("project", 10),
+ Name: fmt.Sprintf("Project %s", t.Name()),
+ Key: "ROLLBACK",
},
)
a.NoError(err)
@@ -532,8 +534,9 @@ func TestRollbackCanceled(t *testing.T) {
// Create a project.
project, err := ctl.createProject(
api.ProjectCreate{
- Name: fmt.Sprintf("Project %s", t.Name()),
- Key: "ROLLBACK",
+ ResourceID: generateRandomString("project", 10),
+ Name: fmt.Sprintf("Project %s", t.Name()),
+ Key: "ROLLBACK",
},
)
a.NoError(err)
diff --git a/backend/tests/schema_update_test.go b/backend/tests/schema_update_test.go
index 5135617a67..dd15b24535 100644
--- a/backend/tests/schema_update_test.go
+++ b/backend/tests/schema_update_test.go
@@ -48,8 +48,9 @@ func TestSchemaAndDataUpdate(t *testing.T) {
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
- Name: "Test Project",
- Key: "TestSchemaUpdate",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test Project",
+ Key: "TestSchemaUpdate",
})
a.NoError(err)
@@ -384,8 +385,9 @@ func TestVCS1(t *testing.T) {
// Create a project.
project, err := ctl.createProject(
api.ProjectCreate{
- Name: "Test VCS Project",
- Key: "TestVCSSchemaUpdate",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test VCS Project",
+ Key: "TestVCSSchemaUpdate",
},
)
a.NoError(err)
@@ -817,6 +819,7 @@ func TestVCS_SDL(t *testing.T) {
// Create a project
project, err := ctl.createProject(
api.ProjectCreate{
+ ResourceID: generateRandomString("project", 10),
Name: "Test VCS Project",
Key: "TestVCSSchemaUpdate",
SchemaChangeType: api.ProjectSchemaChangeTypeSDL,
@@ -1282,8 +1285,9 @@ func TestWildcardInVCSFilePathTemplate(t *testing.T) {
// Create a project.
project, err := ctl.createProject(
api.ProjectCreate{
- Name: "Test VCS Project",
- Key: "TVP",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test VCS Project",
+ Key: "TVP",
},
)
a.NoError(err)
@@ -1522,8 +1526,9 @@ func TestVCS_SQL_Review(t *testing.T) {
// Create a project.
project, err := ctl.createProject(
api.ProjectCreate{
- Name: "Test VCS Project",
- Key: "TestVCSSchemaUpdate",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test VCS Project",
+ Key: "TestVCSSchemaUpdate",
},
)
a.NoError(err)
@@ -1774,8 +1779,9 @@ func TestBranchNameInVCSSetupAndUpdate(t *testing.T) {
// Create a project.
project, err := ctl.createProject(
api.ProjectCreate{
- Name: "Test VSC Project",
- Key: "TVP",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test VSC Project",
+ Key: "TVP",
},
)
a.NoError(err)
@@ -2003,8 +2009,9 @@ CREATE TABLE public.book (
}
project, err := ctl.createProject(
api.ProjectCreate{
- Name: test.name,
- Key: test.name,
+ ResourceID: generateRandomString("project", 10),
+ Name: test.name,
+ Key: test.name,
},
)
a.NoError(err)
@@ -2108,8 +2115,9 @@ func TestMarkTaskAsDone(t *testing.T) {
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
- Name: "Test Project",
- Key: "TestSchemaUpdate",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test Project",
+ Key: "TestSchemaUpdate",
})
a.NoError(err)
@@ -2342,6 +2350,7 @@ func TestVCS_SDL_MySQL(t *testing.T) {
// Create a project
project, err := ctl.createProject(
api.ProjectCreate{
+ ResourceID: generateRandomString("project", 10),
Name: "Test VCS Project",
Key: "TestVCSSchemaUpdate",
SchemaChangeType: api.ProjectSchemaChangeTypeSDL,
diff --git a/backend/tests/sensitive_data_test.go b/backend/tests/sensitive_data_test.go
index a61bdc7089..a26979fdba 100644
--- a/backend/tests/sensitive_data_test.go
+++ b/backend/tests/sensitive_data_test.go
@@ -71,8 +71,9 @@ func TestSensitiveData(t *testing.T) {
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
- Name: "Test Sensitive Data Project",
- Key: "TestSensitiveData",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test Sensitive Data Project",
+ Key: "TestSensitiveData",
})
a.NoError(err)
diff --git a/backend/tests/sheet_vcs_test.go b/backend/tests/sheet_vcs_test.go
index 03a5de0d40..b3c8a9e702 100644
--- a/backend/tests/sheet_vcs_test.go
+++ b/backend/tests/sheet_vcs_test.go
@@ -70,8 +70,9 @@ func TestSheetVCS(t *testing.T) {
// Create a project.
project, err := ctl.createProject(
api.ProjectCreate{
- Name: "Test VCS Project",
- Key: "TestVCSSchemaUpdate",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test VCS Project",
+ Key: "TestVCSSchemaUpdate",
},
)
a.NoError(err)
diff --git a/backend/tests/sql_editor_test.go b/backend/tests/sql_editor_test.go
index 5592d19fe6..cbf507eea4 100644
--- a/backend/tests/sql_editor_test.go
+++ b/backend/tests/sql_editor_test.go
@@ -78,8 +78,9 @@ func TestAdminQueryAffectedRows(t *testing.T) {
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
- Name: "Test Project",
- Key: t.Name(),
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test Project",
+ Key: t.Name(),
})
a.NoError(err)
environments, err := ctl.getEnvironments()
diff --git a/backend/tests/sql_review_test.go b/backend/tests/sql_review_test.go
index 7e6a689290..4c9836d32e 100644
--- a/backend/tests/sql_review_test.go
+++ b/backend/tests/sql_review_test.go
@@ -108,8 +108,9 @@ func TestSQLReviewForPostgreSQL(t *testing.T) {
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
- Name: "Test SQL Review Project",
- Key: "TestSQLReview",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test SQL Review Project",
+ Key: "TestSQLReview",
})
a.NoError(err)
@@ -286,8 +287,9 @@ func TestSQLReviewForMySQL(t *testing.T) {
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
- Name: "Test SQL Review Project",
- Key: "TestSQLReview",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test SQL Review Project",
+ Key: "TestSQLReview",
})
a.NoError(err)
diff --git a/backend/tests/sync_schema_test.go b/backend/tests/sync_schema_test.go
index a7515d8131..57ed9cec97 100644
--- a/backend/tests/sync_schema_test.go
+++ b/backend/tests/sync_schema_test.go
@@ -78,8 +78,9 @@ DROP SCHEMA "schema_a";
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
- Name: "Test sync schema Project",
- Key: "TestSyncSchemaProject",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test sync schema Project",
+ Key: "TestSyncSchemaProject",
})
a.NoError(err)
diff --git a/backend/tests/syncer_test.go b/backend/tests/syncer_test.go
index c73d93d555..0f96326bf6 100644
--- a/backend/tests/syncer_test.go
+++ b/backend/tests/syncer_test.go
@@ -160,8 +160,9 @@ func TestSyncerForPostgreSQL(t *testing.T) {
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
- Name: "Test Syncer For PostgreSQL",
- Key: "TestSyncerForPostgreSQL",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test Syncer For PostgreSQL",
+ Key: "TestSyncerForPostgreSQL",
})
a.NoError(err)
@@ -439,8 +440,9 @@ func TestSyncerForMySQL(t *testing.T) {
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
- Name: "Test Sync MySQL Schema",
- Key: "TestSyncMySQLSchema",
+ ResourceID: generateRandomString("project", 10),
+ Name: "Test Sync MySQL Schema",
+ Key: "TestSyncMySQLSchema",
})
a.NoError(err)
diff --git a/backend/tests/tenant_test.go b/backend/tests/tenant_test.go
index 918e889b7b..a811983a0c 100644
--- a/backend/tests/tenant_test.go
+++ b/backend/tests/tenant_test.go
@@ -43,6 +43,7 @@ func TestTenant(t *testing.T) {
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
+ ResourceID: generateRandomString("project", 10),
Name: "Test Project",
Key: "TestSchemaUpdate",
TenantMode: api.TenantModeTenant,
@@ -306,6 +307,7 @@ func TestTenantVCS(t *testing.T) {
// Create a project.
project, err := ctl.createProject(
api.ProjectCreate{
+ ResourceID: generateRandomString("project", 10),
Name: "Test VCS Project",
Key: "TestVCSSchemaUpdate",
TenantMode: api.TenantModeTenant,
@@ -515,6 +517,7 @@ func TestTenantDatabaseNameTemplate(t *testing.T) {
// Create a project.
project, err := ctl.createProject(api.ProjectCreate{
+ ResourceID: generateRandomString("project", 10),
Name: "Test Project",
Key: "TestSchemaUpdate",
TenantMode: api.TenantModeTenant,
@@ -750,6 +753,7 @@ func TestTenantVCSDatabaseNameTemplate(t *testing.T) {
// Create a project.
project, err := ctl.createProject(
api.ProjectCreate{
+ ResourceID: generateRandomString("project", 10),
Name: "Test VCS Project",
Key: "TestVCSSchemaUpdate",
TenantMode: api.TenantModeTenant,
@@ -1079,6 +1083,7 @@ func TestTenantVCSDatabaseNameTemplate_Empty(t *testing.T) {
// Create a tenant project with empty database name template.
project, err := ctl.createProject(
api.ProjectCreate{
+ ResourceID: generateRandomString("project", 10),
Name: "Test VCS Project",
Key: "TestTenantVCSDatabaseNameTemplate_Empty",
TenantMode: api.TenantModeTenant,
@@ -1358,6 +1363,7 @@ func TestTenantVCS_YAML(t *testing.T) {
// Create a tenant project with empty database name template.
project, err := ctl.createProject(
api.ProjectCreate{
+ ResourceID: generateRandomString("project", 10),
Name: "Test VCS Project",
Key: "TestTenantVCS_YAML",
TenantMode: api.TenantModeTenant,
diff --git a/frontend/src/components/ProjectCreate.vue b/frontend/src/components/ProjectCreate.vue
index 670c49a489..3a08dad29d 100644
--- a/frontend/src/components/ProjectCreate.vue
+++ b/frontend/src/components/ProjectCreate.vue
@@ -16,6 +16,16 @@
"
/>
</div>
+ <div class="-mt-6">
+ <ResourceIdField
+ ref="resourceIdField"
+ resource="project"
+ :value="state.project.resourceId"
+ :random-string="true"
+ :resource-title="state.project.name"
+ :validator="validateResourceId"
+ />
+ </div>
<div class="col-span-1">
<label for="name" class="text-base leading-6 font-medium text-control">
{{ $t("project.create-modal.key") }}
@@ -100,19 +110,24 @@
</template>
<script lang="ts">
-import { computed, reactive, defineComponent } from "vue";
+import { computed, reactive, defineComponent, ref } from "vue";
import { useRouter } from "vue-router";
import { isEmpty } from "lodash-es";
import { useI18n } from "vue-i18n";
import { useEventListener } from "@vueuse/core";
import { projectSlug, randomString } from "@/utils";
-import { Project, ProjectCreate } from "@/types";
+import { Project, ProjectCreate, ResourceId } from "@/types";
import {
hasFeature,
pushNotification,
useUIStateStore,
useProjectStore,
} from "@/store";
+import ResourceIdField from "./ResourceIdField.vue";
+import { useProjectV1Store } from "@/store/modules/v1/project";
+import { projectNamePrefix } from "@/store/modules/v1/common";
+import { getErrorCode } from "@/utils/grpcweb";
+import { Status } from "nice-grpc-common";
interface LocalState {
project: ProjectCreate;
@@ -122,14 +137,17 @@ interface LocalState {
export default defineComponent({
name: "ProjectCreate",
+ components: { ResourceIdField },
emits: ["dismiss"],
setup(props, { emit }) {
const router = useRouter();
const { t } = useI18n();
const projectStore = useProjectStore();
+ const projectV1Store = useProjectV1Store();
const state = reactive<LocalState>({
project: {
+ resourceId: "",
name: "New Project",
key: randomString(3).toUpperCase(),
tenantMode: "DISABLED",
@@ -138,6 +156,7 @@ export default defineComponent({
showFeatureModal: false,
isCreating: false,
});
+ const resourceIdField = ref<InstanceType<typeof ResourceIdField>>();
useEventListener("keydown", (e) => {
if (e.code == "Escape") {
@@ -145,9 +164,29 @@ export default defineComponent({
}
});
+ const validateResourceId = async (resourceId: ResourceId) => {
+ if (!resourceId) {
+ return;
+ }
+
+ try {
+ const project = await projectV1Store.getOrFetchProjectByName(
+ projectNamePrefix + resourceId
+ );
+ if (project) {
+ return t("resource-id.validation.duplicated", {
+ resource: t("resource.project"),
+ });
+ }
+ } catch (error) {
+ if (getErrorCode(error) !== Status.NOT_FOUND) {
+ throw error;
+ }
+ }
+ };
+
const allowCreate = computed(() => {
if (isEmpty(state.project.name)) return false;
-
return true;
});
@@ -159,16 +198,20 @@ export default defineComponent({
state.showFeatureModal = true;
return;
}
+ if (!allowCreate.value) {
+ return;
+ }
try {
state.isCreating = true;
-
- const createdProject = await projectStore.createProject(state.project);
+ const createdProject = await projectStore.createProject({
+ ...state.project,
+ resourceId: resourceIdField.value?.resourceId as string,
+ });
useUIStateStore().saveIntroStateByKey({
key: "project.visit",
newState: true,
});
-
pushNotification({
module: "bytebase",
style: "SUCCESS",
@@ -176,7 +219,6 @@ export default defineComponent({
name: createdProject.name,
}),
});
-
const url = {
path: `/project/${projectSlug(createdProject)}`,
hash: "",
@@ -195,6 +237,8 @@ export default defineComponent({
return {
state,
allowCreate,
+ resourceIdField,
+ validateResourceId,
cancel,
create,
};
diff --git a/frontend/src/components/ProjectGeneralSettingPanel.vue b/frontend/src/components/ProjectGeneralSettingPanel.vue
index eb501a2244..939d999d37 100644
--- a/frontend/src/components/ProjectGeneralSettingPanel.vue
+++ b/frontend/src/components/ProjectGeneralSettingPanel.vue
@@ -19,6 +19,12 @@
class="textfield"
/>
</dd>
+ <ResourceIdField
+ ref="resourceIdField"
+ resource="project"
+ :readonly="true"
+ :value="project.resourceId"
+ />
</dl>
<dl class="">
@@ -136,6 +142,7 @@ import {
} from "../types";
import FeatureModal from "@/components/FeatureModal.vue";
import { hasFeature, pushNotification, useProjectStore } from "@/store";
+import ResourceIdField from "./ResourceIdField.vue";
interface LocalState {
name: string;
@@ -149,6 +156,7 @@ export default defineComponent({
name: "ProjectGeneralSettingPanel",
components: {
FeatureModal,
+ ResourceIdField,
},
props: {
project: {
diff --git a/frontend/src/components/ResourceIdField.vue b/frontend/src/components/ResourceIdField.vue
index 5a049bec3e..e22bd9a2c6 100644
--- a/frontend/src/components/ResourceIdField.vue
+++ b/frontend/src/components/ResourceIdField.vue
@@ -78,7 +78,7 @@ interface LocalState {
validatedMessages: ValidatedMessage[];
}
-type ResourceType = "environment" | "instance" | "idp";
+type ResourceType = "environment" | "instance" | "project" | "idp";
const props = withDefaults(
defineProps<{
@@ -94,6 +94,7 @@ const props = withDefaults(
resourceTitle: "",
randomString: false,
readonly: false,
+ validator: () => Promise.resolve(undefined),
}
);
@@ -114,6 +115,8 @@ const getPrefix = (resource: string) => {
return "env";
case "instance":
return "ins";
+ case "project":
+ return "proj";
case "idp":
return "idp";
default:
diff --git a/frontend/src/grpcweb/index.ts b/frontend/src/grpcweb/index.ts
index cb5593a9bf..a1098816d1 100644
--- a/frontend/src/grpcweb/index.ts
+++ b/frontend/src/grpcweb/index.ts
@@ -4,6 +4,7 @@ import { AuthServiceDefinition } from "@/types/proto/v1/auth_service";
import { IdentityProviderServiceDefinition } from "@/types/proto/v1/idp_service";
import { EnvironmentServiceDefinition } from "@/types/proto/v1/environment_service";
import { InstanceServiceDefinition } from "@/types/proto/v1/instance_service";
+import { ProjectServiceDefinition } from "@/types/proto/v1/project_service";
// Create each grpc service client.
// Reference: https://github.com/deeplay-io/nice-grpc/blob/master/packages/nice-grpc-web/README.md
@@ -36,6 +37,11 @@ export const instanceServiceClient = clientFactory.create(
channel
);
+export const projectServiceClient = clientFactory.create(
+ ProjectServiceDefinition,
+ channel
+);
+
export const identityProviderClient = clientFactory.create(
IdentityProviderServiceDefinition,
channel
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 7ae919a35b..d06c27a164 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1897,6 +1897,7 @@
"resource": {
"environment": "Environment",
"instance": "Instance",
+ "project": "Project",
"idp": "Identity Provider"
},
"resource-id": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 1c6ef75362..9dd8d3c9fb 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1896,6 +1896,7 @@
"resource": {
"environment": "环境",
"instance": "实例",
+ "project": "项目",
"idp": "身份提供商"
},
"resource-id": {
diff --git a/frontend/src/store/modules/v1/common.ts b/frontend/src/store/modules/v1/common.ts
index 1d0331e8ed..6be547ee0c 100644
--- a/frontend/src/store/modules/v1/common.ts
+++ b/frontend/src/store/modules/v1/common.ts
@@ -2,6 +2,7 @@ import { ResourceId, UNKNOWN_ID } from "@/types";
export const userNamePrefix = "users/";
export const environmentNamePrefix = "environments/";
+export const projectNamePrefix = "projects/";
export const instanceNamePrefix = "instances/";
export const idpNamePrefix = "idps/";
diff --git a/frontend/src/store/modules/v1/project.ts b/frontend/src/store/modules/v1/project.ts
new file mode 100644
index 0000000000..5ad3e5207b
--- /dev/null
+++ b/frontend/src/store/modules/v1/project.ts
@@ -0,0 +1,41 @@
+import { defineStore } from "pinia";
+import { projectServiceClient } from "@/grpcweb";
+import { ResourceId } from "@/types";
+import { Project } from "@/types/proto/v1/project_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;
+ },
+ },
+});
diff --git a/frontend/src/types/project.ts b/frontend/src/types/project.ts
index 7a45e75357..a8c2f870e7 100644
--- a/frontend/src/types/project.ts
+++ b/frontend/src/types/project.ts
@@ -1,5 +1,5 @@
import { RowStatus } from "./common";
-import { MemberId, PrincipalId, ProjectId } from "./id";
+import { MemberId, PrincipalId, ProjectId, ResourceId } from "./id";
import { OAuthToken } from "./oauth";
import { Principal } from "./principal";
import { ExternalRepositoryInfo, RepositoryConfig } from "./repository";
@@ -48,6 +48,8 @@ export const getDefaultLGTMCheckSetting = (): LGTMCheckSetting => {
};
export type ProjectCreate = {
+ resourceId: ResourceId;
+
// Domain specific fields
name: string;
key: string;