Skip to content

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

Create BBSelect and make PrincipalSelect leverage it.

Tianzhou Chen0c0261893a42
diff --git a/frontend/src/bbkit/BBSelect.vue b/frontend/src/bbkit/BBSelect.vue
new file mode 100644
index 0000000000..28a44f5e28
--- /dev/null
+++ b/frontend/src/bbkit/BBSelect.vue
@@ -0,0 +1,159 @@
+<template>
+ <div>
+ <div class="relative">
+ <button
+ type="button"
+ aria-haspopup="listbox"
+ aria-expanded="true"
+ aria-labelledby="listbox-label"
+ class="btn-select relative w-full pl-3 pr-10 py-2"
+ @click.prevent="state.showMenu = !state.showMenu"
+ >
+ <template v-if="state.selectedItem">
+ <slot name="menuItem" :item="state.selectedItem" />
+ </template>
+ <div v-else>{{ placeholder }}</div>
+ <span
+ class="ml-3 absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none"
+ >
+ <!-- Heroicon name: solid/selector -->
+ <svg
+ class="h-5 w-5 text-control-light"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+ >
+ <path
+ fill-rule="evenodd"
+ d="M10 3a1 1 0 01.707.293l3 3a1 1 0 01-1.414 1.414L10 5.414 7.707 7.707a1 1 0 01-1.414-1.414l3-3A1 1 0 0110 3zm-3.707 9.293a1 1 0 011.414 0L10 14.586l2.293-2.293a1 1 0 011.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z"
+ clip-rule="evenodd"
+ />
+ </svg>
+ </span>
+ </button>
+
+ <!--
+ Select popover, show/hide based on select state.
+
+ Entering: ""
+ From: ""
+ To: ""
+ Leaving: "transition ease-in duration-100"
+ From: "opacity-100"
+ To: "opacity-0"
+ -->
+ <transition
+ enter-active-class=""
+ enter-class=""
+ enter-to-class=""
+ leave-active-class="transition ease-in duration-100"
+ leave-class="opacity-100"
+ leave-to-class="opacity-0"
+ >
+ <div
+ v-show="state.showMenu"
+ class="absolute mt-1 w-full rounded-md bg-white shadow-lg"
+ >
+ <ul
+ tabindex="-1"
+ role="listbox"
+ aria-labelledby="listbox-label"
+ aria-activedescendant="listbox-item-3"
+ class="max-h-56 rounded-md py-1 ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm"
+ >
+ <!--
+ Select option, manage highlight styles based on mouseenter/mouseleave and keyboard navigation.
+
+ Highlighted: "text-white bg-indigo-600", Not Highlighted: "text-gray-900"
+ -->
+ <li
+ v-for="(item, index) in itemList"
+ :key="index"
+ role="option"
+ class="z-10 text-main hover:text-main-text hover:bg-main-hover cursor-default select-none relative py-2 pl-3 pr-9"
+ @click.prevent="
+ if (item !== state.selectedItem) {
+ $emit('select-item', item);
+ state.selectedItem = item;
+ }
+ close();
+ "
+ >
+ <slot name="menuItem" :item="item" />
+ <span
+ v-if="item === state.selectedItem"
+ class="absolute inset-y-0 right-0 flex items-center pr-4"
+ >
+ <!-- Heroicon name: solid/check -->
+ <svg
+ class="h-5 w-5"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+ >
+ <path
+ fill-rule="evenodd"
+ d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
+ clip-rule="evenodd"
+ />
+ </svg>
+ </span>
+ </li>
+ </ul>
+ </div>
+ </transition>
+ </div>
+ </div>
+</template>
+
+<script lang="ts">
+import { reactive, PropType, watch } from "vue";
+
+interface LocalState {
+ showMenu: boolean;
+ selectedItem: any;
+}
+
+export default {
+ name: "BBSelect",
+ emits: ["select-item"],
+ components: {},
+ props: {
+ selectedItem: {
+ type: Object,
+ },
+ itemList: {
+ required: true,
+ type: Object as PropType<any[]>,
+ },
+ placeholder: {
+ default: "",
+ type: String,
+ },
+ },
+ setup(props, { emit }) {
+ const state = reactive<LocalState>({
+ showMenu: false,
+ selectedItem: props.selectedItem,
+ });
+
+ watch(
+ () => props.selectedItem,
+ (cur, prev) => {
+ state.selectedItem = cur;
+ }
+ );
+
+ const close = () => {
+ state.showMenu = false;
+ };
+
+ return {
+ state,
+ close,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/bbkit/index.ts b/frontend/src/bbkit/index.ts
index 17cf1f0361..1533226d14 100644
--- a/frontend/src/bbkit/index.ts
+++ b/frontend/src/bbkit/index.ts
@@ -3,6 +3,7 @@ import BBAvatar from "./BBAvatar.vue";
import BBContextMenu from "./BBContextMenu.vue";
import BBModal from "./BBModal.vue";
import BBNotification from "./BBNotification.vue";
+import BBSelect from "./BBSelect.vue";
import BBStepBar from "./BBStepBar.vue";
import BBTab from "./BBTab.vue";
import BBTabPanel from "./BBTabPanel.vue";
@@ -14,6 +15,7 @@ export {
BBContextMenu,
BBModal,
BBNotification,
+ BBSelect,
BBStepBar,
BBTab,
BBTabPanel,
diff --git a/frontend/src/components/PrincipalSelect.vue b/frontend/src/components/PrincipalSelect.vue
index fc4d475f01..c04edd95d7 100644
--- a/frontend/src/components/PrincipalSelect.vue
+++ b/frontend/src/components/PrincipalSelect.vue
@@ -1,124 +1,19 @@
<template>
- <div>
- <div class="relative">
- <button
- type="button"
- aria-haspopup="listbox"
- aria-expanded="true"
- aria-labelledby="listbox-label"
- class="btn-select relative w-full pl-3 pr-10 py-2"
- @click.prevent="state.showMenu = !state.showMenu"
- >
- <template v-if="state.selectedPrincipal">
- <span class="flex items-center">
- <BBAvatar
- :size="'small'"
- :username="state.selectedPrincipal.name"
- />
- <span class="ml-3 block truncate">
- {{ state.selectedPrincipal.name }}
- </span>
- </span>
- </template>
- <div v-else>Unassigned</div>
- <span
- class="ml-3 absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none"
- >
- <!-- Heroicon name: solid/selector -->
- <svg
- class="h-5 w-5 text-control-light"
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 20 20"
- fill="currentColor"
- aria-hidden="true"
- >
- <path
- fill-rule="evenodd"
- d="M10 3a1 1 0 01.707.293l3 3a1 1 0 01-1.414 1.414L10 5.414 7.707 7.707a1 1 0 01-1.414-1.414l3-3A1 1 0 0110 3zm-3.707 9.293a1 1 0 011.414 0L10 14.586l2.293-2.293a1 1 0 011.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z"
- clip-rule="evenodd"
- />
- </svg>
+ <BBSelect
+ :selectedItem="state.selectedPrincipal"
+ :itemList="state.principalList"
+ :placeholder="'Unassigned'"
+ @select-item="(item) => $emit('select-principal', item)"
+ >
+ <template v-slot:menuItem="{ item }">
+ <span class="flex items-center">
+ <BBAvatar :size="'small'" :username="item.name" />
+ <span class="ml-3 block truncate">
+ {{ item.name }}
</span>
- </button>
-
- <!--
- Select popover, show/hide based on select state.
-
- Entering: ""
- From: ""
- To: ""
- Leaving: "transition ease-in duration-100"
- From: "opacity-100"
- To: "opacity-0"
- -->
- <transition
- enter-active-class=""
- enter-class=""
- enter-to-class=""
- leave-active-class="transition ease-in duration-100"
- leave-class="opacity-100"
- leave-to-class="opacity-0"
- >
- <div
- v-show="state.showMenu"
- class="absolute mt-1 w-full rounded-md bg-white shadow-lg"
- >
- <ul
- tabindex="-1"
- role="listbox"
- aria-labelledby="listbox-label"
- aria-activedescendant="listbox-item-3"
- class="max-h-56 rounded-md py-1 ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm"
- >
- <!--
- Select option, manage highlight styles based on mouseenter/mouseleave and keyboard navigation.
-
- Highlighted: "text-white bg-indigo-600", Not Highlighted: "text-gray-900"
- -->
- <li
- v-for="(item, index) in state.principalList"
- :key="index"
- role="option"
- class="z-10 text-main hover:text-main-text hover:bg-main-hover cursor-default select-none relative py-2 pl-3 pr-9"
- @click.prevent="
- if (item !== state.selectedPrincipal) {
- $emit('select-principal', item);
- state.selectedPrincipal = item;
- }
- close();
- "
- >
- <span class="flex items-center">
- <BBAvatar :size="'small'" :username="item.name" />
- <span class="ml-3 block truncate">
- {{ item.name }}
- </span>
- </span>
- <span
- v-if="item === state.selectedPrincipal"
- class="absolute inset-y-0 right-0 flex items-center pr-4"
- >
- <!-- Heroicon name: solid/check -->
- <svg
- class="h-5 w-5"
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 20 20"
- fill="currentColor"
- aria-hidden="true"
- >
- <path
- fill-rule="evenodd"
- d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
- clip-rule="evenodd"
- />
- </svg>
- </span>
- </li>
- </ul>
- </div>
- </transition>
- </div>
- </div>
+ </span>
+ </template>
+ </BBSelect>
</template>
<script lang="ts">
@@ -135,7 +30,6 @@ interface LocalState {
export default {
name: "PrincipalSelect",
emits: ["select-principal"],
- components: {},
props: {
selectedId: {
type: String,
@@ -158,7 +52,6 @@ export default {
name: member.attributes.user.name,
};
});
-
state.selectedPrincipal = state.principalList.find(
(userDisplay) => userDisplay.id == props.selectedId
);
diff --git a/frontend/src/main.js b/frontend/src/main.js
index 6f2b801016..9fce8f774a 100644
--- a/frontend/src/main.js
+++ b/frontend/src/main.js
@@ -12,6 +12,7 @@ import {
BBContextMenu,
BBModal,
BBNotification,
+ BBSelect,
BBStepBar,
BBTab,
BBTabPanel,
@@ -43,6 +44,7 @@ app
.component("BBContextMenu", BBContextMenu)
.component("BBModal", BBModal)
.component("BBNotification", BBNotification)
+ .component("BBSelect", BBSelect)
.component("BBStepBar", BBStepBar)
.component("BBTab", BBTab)
.component("BBTabPanel", BBTabPanel)