Skip to content

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

chore: feature badge for custom roles in plans not supported (#7068)

Liu Ji47d0a1c74972
diff --git a/frontend/src/components/FeatureGuard/FeatureBadge.vue b/frontend/src/components/FeatureGuard/FeatureBadge.vue
index 5ad5639b98..e8ad7dcab4 100644
--- a/frontend/src/components/FeatureGuard/FeatureBadge.vue
+++ b/frontend/src/components/FeatureGuard/FeatureBadge.vue
@@ -13,13 +13,18 @@
</span>
</NTooltip>
</div>
- <router-link
- v-else-if="!hasFeature"
- to="/setting/subscription"
- exact-active-class=""
- >
- <heroicons-solid:sparkles class="text-accent w-5 h-5" />
- </router-link>
+ <template v-else-if="!hasFeature">
+ <router-link
+ v-if="clickable"
+ to="/setting/subscription"
+ exact-active-class=""
+ >
+ <heroicons-solid:sparkles class="text-accent w-5 h-5" />
+ </router-link>
+ <span v-else>
+ <heroicons-solid:sparkles class="text-accent w-5 h-5" />
+ </span>
+ </template>
<InstanceAssignment
v-if="!hasFeature"
:show="state.showInstanceAssignmentDrawer"
@@ -52,6 +57,10 @@ const props = defineProps({
default: "",
type: String,
},
+ clickable: {
+ type: Boolean,
+ default: false,
+ },
});
const state = reactive<LocalState>({
diff --git a/frontend/src/components/v2/Select/ProjectMemberRoleSelect.vue b/frontend/src/components/v2/Select/ProjectMemberRoleSelect.vue
index 7c8128fc37..3aae019af0 100644
--- a/frontend/src/components/v2/Select/ProjectMemberRoleSelect.vue
+++ b/frontend/src/components/v2/Select/ProjectMemberRoleSelect.vue
@@ -4,41 +4,103 @@
:options="roleOptions"
:max-tag-count="'responsive'"
:placeholder="'Select role'"
- @update:value="$emit('update:role', $event)"
+ :render-label="renderLabel"
+ v-bind="$attrs"
+ @update:value="changeRole"
+ />
+ <FeatureModal
+ feature="bb.feature.custom-role"
+ :open="showFeatureModal"
+ @cancel="showFeatureModal = false"
/>
</template>
<script setup lang="ts">
-import { computed } from "vue";
+import { computed, defineComponent, h, ref } from "vue";
import { type SelectOption, NSelect } from "naive-ui";
import { featureToRef, useRoleStore } from "@/store";
import { PresetRoleType, ProjectRoleType } from "@/types";
import { displayRoleTitle } from "@/utils";
+import FeatureBadge from "@/components/FeatureGuard/FeatureBadge.vue";
+import FeatureModal from "@/components/FeatureGuard/FeatureModal.vue";
+import { Role } from "@/types/proto/v1/role_service";
+
+type ProjectRoleSelectOption = SelectOption & {
+ value: string;
+ role: Role;
+};
defineProps<{
role: ProjectRoleType;
}>();
-defineEmits<{
+const emit = defineEmits<{
(event: "update:role", role: ProjectRoleType): void;
}>();
+const FREE_ROLE_LIST = [PresetRoleType.OWNER, PresetRoleType.DEVELOPER];
const hasCustomRoleFeature = featureToRef("bb.feature.custom-role");
-
-const roleOptions = computed(() => {
- let roleList = useRoleStore().roleList;
+const showFeatureModal = ref(false);
+const roleList = computed(() => {
+ const roleList = useRoleStore().roleList;
// For enterprise plan, we don't allow to add exporter role.
if (hasCustomRoleFeature.value) {
- roleList = useRoleStore().roleList.filter((role) => {
+ return roleList.filter((role) => {
return role.name !== PresetRoleType.EXPORTER;
});
}
- return roleList.map<SelectOption>((role) => {
+ return roleList;
+});
+
+const roleOptions = computed(() => {
+ return roleList.value.map<ProjectRoleSelectOption>((role) => {
return {
label: displayRoleTitle(role.name),
value: role.name,
+ role,
};
});
});
+
+const renderLabel = (option: SelectOption) => {
+ const role = (option as ProjectRoleSelectOption).role;
+ const label = h("span", {}, option.label as string);
+ if (hasCustomRoleFeature.value) {
+ return label;
+ }
+ if (FREE_ROLE_LIST.includes(role.name)) {
+ return label;
+ }
+
+ const icon = h(FeatureBadge, {
+ feature: "bb.feature.custom-approval",
+ clickable: false,
+ });
+ return h(
+ "div",
+ {
+ class: "flex items-center gap-1",
+ },
+ [label, icon]
+ );
+};
+
+const changeRole = (value: string) => {
+ const role = roleList.value.find((role) => role.name === value);
+ if (!role) return;
+ if (!hasCustomRoleFeature.value) {
+ if (!FREE_ROLE_LIST.includes(role.name)) {
+ showFeatureModal.value = true;
+ return;
+ }
+ }
+ emit("update:role", value);
+};
+</script>
+
+<script lang="ts">
+defineComponent({
+ inheritAttrs: false,
+});
</script>