Skip to content

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

Extract BBOutline and make BookmarkSidePanel use it.

Tianzhou Chen56d7bbd21b9e
diff --git a/frontend/src/assets/css/tailwind.css b/frontend/src/assets/css/tailwind.css
index 0785f8281b..92dc24e740 100644
--- a/frontend/src/assets/css/tailwind.css
+++ b/frontend/src/assets/css/tailwind.css
@@ -102,6 +102,10 @@
@apply text-main focus:ring-control focus:border-control sm:text-sm border-control-border shadow-sm;
}
+.outline-item {
+ @apply text-control cursor-pointer group flex justify-between items-center hover:bg-link-hover text-sm leading-5 font-medium focus:outline-none select-none;
+}
+
.link {
@apply text-main hover:underline focus:outline-none;
}
@@ -114,10 +118,6 @@
@apply text-control hover:bg-link-hover focus:outline-none;
}
-.sidebar-link {
- @apply text-control hover:bg-link-hover text-sm leading-5 font-medium focus:outline-none select-none;
-}
-
.anchor-link {
@apply hover:underline focus:outline-none;
}
diff --git a/frontend/src/bbkit/BBOutline.vue b/frontend/src/bbkit/BBOutline.vue
new file mode 100644
index 0000000000..6ba9000f8c
--- /dev/null
+++ b/frontend/src/bbkit/BBOutline.vue
@@ -0,0 +1,79 @@
+<template>
+ <!-- Secondary navigation -->
+ <h3
+ class="px-3 text-xs leading-4 font-semibold text-control-light uppercase tracking-wider"
+ >
+ {{ title }}
+ </h3>
+ <div
+ class="mt-2 space-y-1"
+ role="group"
+ v-for="(item, index) in itemList"
+ :key="item.id"
+ @mouseenter="state.hoverIndex = index"
+ @mouseleave="state.hoverIndex = -1"
+ >
+ <div
+ class="outline-item px-3 py-1"
+ @click.prevent="$emit('click-item', item)"
+ >
+ <span class="truncate">{{ item.name }}</span>
+ <button
+ v-if="allowDelete && index == state.hoverIndex"
+ class="focus:outline-none"
+ @click.prevent="$emit('delete-item', item)"
+ >
+ <svg
+ class="w-4 h-4 hover:text-control-hover"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M6 18L18 6M6 6l12 12"
+ ></path>
+ </svg>
+ </button>
+ </div>
+ </div>
+</template>
+
+<script lang="ts">
+interface LocalState {
+ hoverIndex: number;
+}
+
+import { reactive, PropType } from "vue";
+
+export default {
+ name: "BBOutline",
+ emits: ["click-item", "delete-item"],
+ props: {
+ title: {
+ required: true,
+ type: String,
+ },
+ itemList: {
+ required: true,
+ type: Object as PropType<any[]>,
+ },
+ allowDelete: {
+ default: false,
+ type: Boolean,
+ },
+ },
+ setup(props, ctx) {
+ const state = reactive<LocalState>({
+ hoverIndex: -1,
+ });
+
+ return {
+ state,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/bbkit/index.ts b/frontend/src/bbkit/index.ts
index 1533226d14..793ed3dfff 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 BBOutline from "./BBOutline.vue";
import BBSelect from "./BBSelect.vue";
import BBStepBar from "./BBStepBar.vue";
import BBTab from "./BBTab.vue";
@@ -15,6 +16,7 @@ export {
BBContextMenu,
BBModal,
BBNotification,
+ BBOutline,
BBSelect,
BBStepBar,
BBTab,
diff --git a/frontend/src/components/BookmarkListSidePanel.vue b/frontend/src/components/BookmarkListSidePanel.vue
index dd784ae315..20a8e352ee 100644
--- a/frontend/src/components/BookmarkListSidePanel.vue
+++ b/frontend/src/components/BookmarkListSidePanel.vue
@@ -1,56 +1,17 @@
<template>
- <!-- Secondary navigation -->
- <h3
- class="px-3 text-xs leading-4 font-semibold text-gray-500 uppercase tracking-wider"
- id="bookmark-headline"
- >
- Bookmarks
- </h3>
- <div
- class="mt-2 space-y-1"
- role="group"
- aria-labelledby="bookmark-headline"
- v-for="(item, index) in bookmarkList"
- :key="item.id"
- @mouseenter="state.hoverIndex = index"
- @mouseleave="state.hoverIndex = -1"
- >
- <router-link
- :to="item.link"
- class="sidebar-link group flex justify-between items-center px-3 py-1 text-sm"
- >
- <span class="truncate">{{ item.name }}</span>
- <button
- v-if="index == state.hoverIndex"
- class="focus:outline-none"
- @click.prevent="deleteItem(item)"
- >
- <svg
- class="w-4 h-4 hover:text-control-hover"
- fill="none"
- stroke="currentColor"
- viewBox="0 0 24 24"
- xmlns="http://www.w3.org/2000/svg"
- >
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M6 18L18 6M6 6l12 12"
- ></path>
- </svg>
- </button>
- </router-link>
- </div>
+ <BBOutline
+ :title="'Bookmarks'"
+ :itemList="bookmarkList"
+ :allowDelete="true"
+ @click-item="clickItem"
+ @delete-item="deleteItem"
+ />
</template>
<script lang="ts">
-interface LocalState {
- hoverIndex: number;
-}
-
-import { watchEffect, computed, reactive } from "vue";
+import { computed } from "vue";
import { useStore } from "vuex";
+import { useRouter } from "vue-router";
import { Bookmark, User } from "../types";
export default {
@@ -58,10 +19,7 @@ export default {
props: {},
setup(props, ctx) {
const store = useStore();
-
- const state = reactive({
- hoverIndex: -1,
- });
+ const router = useRouter();
const currentUser: User = computed(() =>
store.getters["auth/currentUser"]()
@@ -71,6 +29,10 @@ export default {
store.getters["bookmark/bookmarkListByUser"](currentUser.id)
);
+ const clickItem = (bookmark: Bookmark) => {
+ router.push(bookmark.link);
+ };
+
const deleteItem = (bookmark: Bookmark) => {
store.dispatch("bookmark/deleteBookmark", bookmark).catch((error) => {
console.log(error);
@@ -78,8 +40,8 @@ export default {
};
return {
- state,
bookmarkList,
+ clickItem,
deleteItem,
};
},
diff --git a/frontend/src/main.js b/frontend/src/main.js
index 9fce8f774a..cd877ec3e9 100644
--- a/frontend/src/main.js
+++ b/frontend/src/main.js
@@ -12,6 +12,7 @@ import {
BBContextMenu,
BBModal,
BBNotification,
+ BBOutline,
BBSelect,
BBStepBar,
BBTab,
@@ -44,6 +45,7 @@ app
.component("BBContextMenu", BBContextMenu)
.component("BBModal", BBModal)
.component("BBNotification", BBNotification)
+ .component("BBOutline", BBOutline)
.component("BBSelect", BBSelect)
.component("BBStepBar", BBStepBar)
.component("BBTab", BBTab)