Skip to content

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

fix(frontend): BYT-1026 activity hash positioning (#2143)

Liu Ji05a7c346b9d3
diff --git a/frontend/src/components/Issue/IssueActivityPanel.vue b/frontend/src/components/Issue/IssueActivityPanel.vue
index 48ea2531b9..620298d852 100644
--- a/frontend/src/components/Issue/IssueActivityPanel.vue
+++ b/frontend/src/components/Issue/IssueActivityPanel.vue
@@ -1,5 +1,5 @@
<template>
- <div>
+ <div id="activity">
<div class="divide-y divide-block-border">
<div class="pb-4">
<h2 id="activity-title" class="text-lg font-medium text-main">
@@ -9,8 +9,8 @@
<div class="pt-6">
<!-- Activity feed-->
<ul>
- <li v-for="(activity, index) in activityList" :key="index">
- <div :id="'activity' + activity.id" class="relative pb-4">
+ <li v-for="(activity, index) in activityList" :key="activity.id">
+ <div :id="`#activity${activity.id}`" class="relative pb-4">
<span
v-if="index != activityList.length - 1"
class="absolute left-4 -ml-px h-full w-0.5 bg-block-border"
@@ -303,8 +303,17 @@
</template>
<script lang="ts" setup>
-import { computed, nextTick, ref, reactive, watchEffect, Ref } from "vue";
-import { useRouter } from "vue-router";
+import {
+ computed,
+ nextTick,
+ ref,
+ reactive,
+ watch,
+ watchEffect,
+ Ref,
+ onMounted,
+} from "vue";
+import { useRoute } from "vue-router";
import PrincipalAvatar from "../PrincipalAvatar.vue";
import type {
Issue,
@@ -362,7 +371,7 @@ type ActionIconType =
const { t } = useI18n();
const activityStore = useActivityStore();
-const router = useRouter();
+const route = useRoute();
const newComment = ref("");
const newCommentTextArea = ref();
@@ -407,16 +416,6 @@ const prepareActivityList = () => {
watchEffect(prepareActivityList);
-// The activity list and its anchor is not immediately available when the issue shows up.
-// Thus the scrollBehavior set in the vue router won't work (also tried promise to resolve async with no luck either)
-// So we manually use scrollIntoView after rendering the activity list.
-nextTick(() => {
- if (router.currentRoute.value.hash) {
- const el = document.getElementById(router.currentRoute.value.hash.slice(1));
- el?.scrollIntoView();
- }
-});
-
// Need to use computed to make list reactive to activity list changes.
const activityList = computed((): Activity[] => {
const list = activityStore.getActivityListByIssue(issue.value.id);
@@ -668,4 +667,22 @@ const fileCommitActivityUrl = (activity: Activity) => {
const payload = activity.payload as ActivityTaskFileCommitPayload;
return `${payload.vcsInstanceUrl}/${payload.repositoryFullPath}/-/commit/${payload.commitId}`;
};
+
+onMounted(() => {
+ watch(
+ () => route.hash,
+ (hash) => {
+ if (hash.match(/^#activity(\d+)/)) {
+ // use '#activity' element as a fallback
+ const elem =
+ document.querySelector(hash) || document.querySelector("#activity");
+ // We use `setTimeout` here since this should be executed very late.
+ setTimeout(() => elem?.scrollIntoView());
+ }
+ },
+ {
+ immediate: true,
+ }
+ );
+});
</script>
diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vue
index 912045007e..9a6bf7b48e 100644
--- a/frontend/src/components/Issue/IssueDetailLayout.vue
+++ b/frontend/src/components/Issue/IssueDetailLayout.vue
@@ -278,7 +278,11 @@ onMounted(() => {
// The hypothesis is that because the scroll bar is in the nested
// route, thus setting the scrollBehavior in the global router
// won't work.
- document.getElementById("issue-detail-top")!.scrollIntoView();
+ // BUT when we have a location.hash #activity(\d+) we won't scroll to the top,
+ // since #activity(\d+) is used as an activity anchor
+ if (!location.hash.match(/^#activity(\d+)/)) {
+ document.getElementById("issue-detail-top")!.scrollIntoView();
+ }
});
const hasSQLReviewPolicyFeature = featureToRef("bb.feature.sql-review");
diff --git a/frontend/src/components/Issue/logic/base.ts b/frontend/src/components/Issue/logic/base.ts
index abe2199988..25348fb1f1 100644
--- a/frontend/src/components/Issue/logic/base.ts
+++ b/frontend/src/components/Issue/logic/base.ts
@@ -57,8 +57,8 @@ export const useBaseIssueLogic = (params: {
};
const selectedStage = computed((): Stage | StageCreate => {
- const stageSlug = router.currentRoute.value.query.stage as string;
- const taskSlug = router.currentRoute.value.query.task as string;
+ const stageSlug = route.query.stage as string;
+ const taskSlug = route.query.task as string;
// For stage slug, we support both index based and id based.
// Index based is used when creating the new task and is the one used when clicking the UI.
// Id based is used when the context only has access to the stage id (e.g. Task only contains StageId)
@@ -105,10 +105,11 @@ export const useBaseIssueLogic = (params: {
router.replace({
name: "workspace.issue.detail",
query: {
- ...router.currentRoute.value.query,
+ ...route.query,
stage: stageSlug(stageList[index].name, index),
task: taskSlug,
},
+ hash: route.hash,
});
};
diff --git a/frontend/src/components/Quickstart.vue b/frontend/src/components/Quickstart.vue
index f5a371aaeb..ee5f55afbc 100644
--- a/frontend/src/components/Quickstart.vue
+++ b/frontend/src/components/Quickstart.vue
@@ -99,7 +99,7 @@ export default defineComponent({
},
{
name: computed(() => t("quick-start.add-a-comment")),
- link: "/issue/hello-world-101#activity101",
+ link: "/issue/hello-world-101#activity14001",
allowDBA: true,
allowDeveloper: true,
done: computed(() => uiStateStore.getIntroStateByKey("comment.create")),
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 9bd99df30c..3037cd9b1a 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -875,7 +875,7 @@ export const router = createRouter({
routes,
linkExactActiveClass: "bg-link-hover",
scrollBehavior(to /*, from, savedPosition */) {
- if (to.hash) {
+ if (to.hash && document.querySelector(to.hash)) {
return {
el: to.hash,
behavior: "smooth",