Skip to content

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

Collapse/Expand for BBOutline and make BookmarkSidePanel use it.

Tianzhou Chenfb6f915ee953
diff --git a/frontend/src/assets/css/tailwind.css b/frontend/src/assets/css/tailwind.css
index e77b541106..049e9cef15 100644
--- a/frontend/src/assets/css/tailwind.css
+++ b/frontend/src/assets/css/tailwind.css
@@ -102,8 +102,16 @@
@apply text-main focus:ring-control focus:border-control sm:text-sm border-control-border shadow-sm;
}
+.outline-title {
+ @apply text-control-light w-full group items-center text-xs leading-5 font-semibold focus:outline-none select-none uppercase tracking-wider;
+}
+
+.outline-title.collapsible {
+ @apply cursor-pointer hover:bg-link-hover;
+}
+
.outline-item {
- @apply text-control cursor-pointer group items-center hover:bg-link-hover text-sm leading-5 font-medium focus:outline-none select-none;
+ @apply text-control cursor-pointer w-full group items-center hover:bg-link-hover text-sm leading-5 font-medium focus:outline-none select-none;
}
.link {
diff --git a/frontend/src/bbkit/BBOutline.vue b/frontend/src/bbkit/BBOutline.vue
index 020cf330c9..a8ccb87be9 100644
--- a/frontend/src/bbkit/BBOutline.vue
+++ b/frontend/src/bbkit/BBOutline.vue
@@ -1,58 +1,88 @@
<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"
+ @click.prevent="toggleExpand"
+ class="outline-title flex text-xs px-2 py-1"
+ :class="allowCollapse ? 'collapsible' : ''"
+ @mouseenter="state.hoverTitle = true"
+ @mouseleave="state.hoverTitle = false"
>
+ {{ title }}
+ <template v-if="allowCollapse && state.hoverTitle">
+ <svg
+ v-if="expandState"
+ class="mr-2 h-4 w-4 transform rotate-90 group-hover:text-gray-400 group-focus:text-gray-400 transition-colors ease-in-out duration-150"
+ viewBox="0 0 20 20"
+ >
+ <path d="M6 6L14 10L6 14V6Z" fill="currentColor" />
+ </svg>
+ <svg
+ v-else
+ class="mr-2 h-4 w-4 transform group-hover:text-gray-400 group-focus:text-gray-400 transition-colors ease-in-out duration-150"
+ viewBox="0 0 20 20"
+ >
+ <path d="M6 6L14 10L6 14V6Z" fill="currentColor" />
+ </svg>
+ </template>
+ </div>
+ <template v-if="expandState">
<div
- class="outline-item flex justify-between px-3 py-1"
- @click.prevent="$emit('click-item', item)"
+ 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"
>
- <span class="truncate">{{ item.name }}</span>
- <button
- v-if="allowDelete && index == state.hoverIndex"
- class="focus:outline-none"
- @click.prevent="$emit('delete-item', item)"
+ <div
+ class="outline-item flex justify-between px-3 py-1"
+ @click.prevent="$emit('click-index', index)"
>
- <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"
+ <span class="truncate">{{ item }}</span>
+ <button
+ v-if="allowDelete && index == state.hoverIndex"
+ class="focus:outline-none"
+ @click.prevent="$emit('delete-index', index)"
>
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M6 18L18 6M6 6l12 12"
- ></path>
- </svg>
- </button>
+ <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>
- </div>
+ </template>
</template>
<script lang="ts">
interface LocalState {
hoverIndex: number;
+ hoverTitle: boolean;
+ expandState: boolean;
}
-import { reactive, PropType } from "vue";
+import { computed, reactive, PropType } from "vue";
+import { useStore } from "vuex";
export default {
name: "BBOutline",
- emits: ["click-item", "delete-item"],
+ emits: ["click-index", "delete-index"],
props: {
+ // Used for storing the expand state.
+ // Empty id means not to store expand state.
+ id: {
+ default: "",
+ type: String,
+ },
title: {
required: true,
type: String,
@@ -65,14 +95,50 @@ export default {
default: false,
type: Boolean,
},
+ allowCollapse: {
+ default: false,
+ type: Boolean,
+ },
},
setup(props, ctx) {
+ const store = useStore();
+
const state = reactive<LocalState>({
hoverIndex: -1,
+ hoverTitle: false,
+ expandState: true,
});
+ const expandState = computed(() => {
+ if (props.id) {
+ return store.getters["uistate/expandStateByKey"](props.id);
+ }
+ return state.expandState;
+ });
+
+ const toggleExpand = () => {
+ if (props.allowCollapse) {
+ if (props.id) {
+ const newState = !expandState.value;
+ store
+ .dispatch("uistate/saveExpandStateByKey", {
+ key: props.id,
+ expand: newState,
+ })
+ .catch((error) => {
+ console.log(error);
+ return;
+ });
+ } else {
+ state.expandState = !state.expandState;
+ }
+ }
+ };
+
return {
state,
+ expandState,
+ toggleExpand,
};
},
};
diff --git a/frontend/src/components/BookmarkListSidePanel.vue b/frontend/src/components/BookmarkListSidePanel.vue
index 20a8e352ee..a7289ace44 100644
--- a/frontend/src/components/BookmarkListSidePanel.vue
+++ b/frontend/src/components/BookmarkListSidePanel.vue
@@ -1,10 +1,12 @@
<template>
<BBOutline
+ :id="'bookmark'"
:title="'Bookmarks'"
- :itemList="bookmarkList"
+ :itemList="bookmarkList.map((item) => item.name)"
:allowDelete="true"
- @click-item="clickItem"
- @delete-item="deleteItem"
+ :allowCollapse="true"
+ @click-index="clickIndex"
+ @delete-index="deleteIndex"
/>
</template>
@@ -29,20 +31,22 @@ export default {
store.getters["bookmark/bookmarkListByUser"](currentUser.id)
);
- const clickItem = (bookmark: Bookmark) => {
- router.push(bookmark.link);
+ const clickIndex = (index: number) => {
+ router.push(bookmarkList.value[index].link);
};
- const deleteItem = (bookmark: Bookmark) => {
- store.dispatch("bookmark/deleteBookmark", bookmark).catch((error) => {
- console.log(error);
- });
+ const deleteIndex = (index: number) => {
+ store
+ .dispatch("bookmark/deleteBookmark", bookmarkList.value[index])
+ .catch((error) => {
+ console.log(error);
+ });
};
return {
bookmarkList,
- clickItem,
- deleteItem,
+ clickIndex,
+ deleteIndex,
};
},
};
diff --git a/frontend/src/components/ProvideContext.vue b/frontend/src/components/ProvideContext.vue
index bef4a2de50..a2e0309f44 100644
--- a/frontend/src/components/ProvideContext.vue
+++ b/frontend/src/components/ProvideContext.vue
@@ -22,6 +22,7 @@ export default {
"bookmark/fetchBookmarkListByUser",
currentUser.value.id
);
+ await store.dispatch("uistate/restoreExpandState");
},
};
</script>
diff --git a/frontend/src/store/modules/uistate.ts b/frontend/src/store/modules/uistate.ts
index 2c1f898938..59a01aa2da 100644
--- a/frontend/src/store/modules/uistate.ts
+++ b/frontend/src/store/modules/uistate.ts
@@ -35,6 +35,10 @@ const saveExpandStateByKey = function (
};
const getters = {
+ expandStateByKey: (state: UIState) => (key: string) => {
+ return expandStateByKey(state, key);
+ },
+
expandStateByGroup: (state: UIState) => (groupId: GroupId) => {
const key = ["grp", groupId].join(".");
return expandStateByKey(state, key);
@@ -56,6 +60,19 @@ const actions = {
return fullState;
},
+ async saveExpandStateByKey(
+ { commit }: any,
+ {
+ key,
+ expand,
+ }: {
+ key: string;
+ expand: boolean;
+ }
+ ) {
+ return saveExpandStateByKey(commit, key, expand);
+ },
+
async saveExpandStateByGroup(
{ commit }: any,
{
diff --git a/frontend/src/views/DashboardSidebar.vue b/frontend/src/views/DashboardSidebar.vue
index e177efbade..98f6f72c06 100644
--- a/frontend/src/views/DashboardSidebar.vue
+++ b/frontend/src/views/DashboardSidebar.vue
@@ -36,8 +36,7 @@
</template>
<script lang="ts">
-import { onMounted, reactive } from "vue";
-import { useStore } from "vuex";
+import { reactive } from "vue";
import BookmarkListSidePanel from "../components/BookmarkListSidePanel.vue";
// import GroupListSidePanel from "../components/GroupListSidePanel.vue";
// import ProjectListSidePanel from "../components/ProjectListSidePanel.vue";
@@ -55,20 +54,10 @@ export default {
// ProjectListSidePanel,
},
setup(props, ctx) {
- const store = useStore();
-
const state = reactive<LocalState>({
hasUnreadMessage: Math.random() > 0.5,
});
- const restoreExpandState = () => {
- store.dispatch("uistate/restoreExpandState").catch((error) => {
- console.log(error);
- });
- };
-
- onMounted(restoreExpandState);
-
return {
state,
};