Skip to content

Commit

Permalink
NN-647 fix scroll height in lists and recenter graph button
Browse files Browse the repository at this point in the history
  • Loading branch information
anlisha-maharjan committed Jan 17, 2025
1 parent 1eaa70c commit 2cfca50
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 35 deletions.
6 changes: 3 additions & 3 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<PersistentWindow />
<AxoChatBot />
<DocumentWindow />
<Toast />
<router-view v-slot="{ Component }">
Expand All @@ -14,7 +14,7 @@ import TermView from "@/views/TermView.vue";
import CitationView from "@/views/CitationView.vue";
import ProteinView from "@/views/ProteinView.vue";
import HomeView from "@/views/HomeView.vue";
import PersistentWindow from "@/components/PersistentWindow.vue";
import AxoChatBot from "@/components/AxoChatBot.vue";
import DocumentWindow from "@/components/DocumentWindow.vue";
import Toast from 'primevue/toast';
Expand All @@ -25,7 +25,7 @@ export default {
ProteinView,
HomeView,
CitationView,
PersistentWindow,
AxoChatBot,
DocumentWindow,
Toast
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
<template>
<Dialog v-model:visible="windowCheck" header="AxoBot" position="bottomright" :closable="false" :minY="60" :minX="60"
<!-- :minY="60" :minX="60" -->
<Dialog v-model:visible="windowCheck" header="AxoBot" position="bottomright" :maximizable="true"
:pt="{
root: {
id: 'scrollBox',
class:
'!h-full w-[26rem] !mt-[60px] !ml-[60px] !bg-white/75 dark:!bg-slate-900/75 !backdrop-blur overflow-y-auto',
'!h-full w-[26rem] !bg-white/75 dark:!bg-slate-900/75 !backdrop-blur overflow-y-auto', // !mt-[60px] !ml-[60px]
},
header: { class: 'sticky top-0 !p-2 !px-3 !justify-start gap-3 !font-medium cursor-move backdrop-blur z-[1]' },
headerActions: { class: '!hidden' },
headerActions: { class: '!ml-auto' },
title: { class: '!text-base' },
content: { class: '!px-3 !pb-2 !overflow-y-visible' },
footer: { class: 'sticky bottom-0 !px-2 !pt-1 !pb-2 cursor-move backdrop-blur-xl !mt-auto' },
}">
<template #header>
AxoBot
<Button class="ml-auto" size="small" text plain rounded @click="windowCheck = false">
<span class="material-symbols-rounded"> close </span>
</Button>
</template>

}" @hide="windowCheck = false">
<main class="flex flex-col">
<ul class="flex flex-col gap-1.5">
<li v-for="(msg, index) in messages" :key="index" :class="`flex flex-col p-3 rounded-lg
Expand All @@ -39,12 +33,12 @@
<template v-if="index !== 0">
<div :class="`flex gap-3 ${msg.sender === 'Bot' ? 'mb-5 flex-wrap' : 'gap-1.5 items-center'}`">
<template v-if="msg.data && msg.data.length">
<Splide :options="{ autoWidth: true, pagination: false }"
<Splide :options="{ autoWidth: true, pagination: false, gap: '8px' }"
:class="`mb-1.5 ${msg.sender === 'Bot' ? 'w-[calc(100%+(12px*2))] -mx-3' : 'w-[80%] -ml-3'}`">
<SplideSlide v-for="(element, index) in msg.data" :key="index">
<Chip class="cursor-pointer" :pt="{
root: { class: 'h-6 !grid grid-cols-[1fr_auto] dark:!bg-slate-700 !px-2 !py-1' },
label: { class: 'max-w-[150px] !text-sm !line-clamp-1' },
root: { class: 'h-6 dark:!bg-slate-700 !px-2' },
label: { class: '!text-sm' },
}" :label="element.id" @click="searchInput(element)" />
</SplideSlide>
</Splide>
Expand Down Expand Up @@ -87,15 +81,12 @@
</fieldset>

<template v-if="tags && tags.length">
<Splide :options="{ autoWidth: true, pagination: false }">
<Splide :options="{ autoWidth: true, pagination: false, gap: '8px' }">
<SplideSlide v-for="(tag, index) in tags" :key="index">
<Chip class="cursor-pointer" :pt="{
root: { class: 'h-6 !grid grid-cols-[1fr_auto] dark:!bg-slate-700 !px-2 !py-1' },
label: { class: 'max-w-[150px] !text-sm !line-clamp-1' },
}" :label="tag.id">
<span @click="searchInput(tag)">{{ tag.id }}</span>
<div class="flex items-center gap-2 rounded-2xl cursor-pointer !h-6 dark:!bg-slate-700 !px-2">
<span @click="searchInput(tag)" class="!text-sm">{{ tag.id }}</span>
<span class="material-symbols-rounded !text-lg" @click="removeTag(index)"> cancel </span>
</Chip>
</div>
</SplideSlide>
</Splide>
</template>
Expand All @@ -116,7 +107,7 @@
import { useToast } from "primevue/usetoast";
import { Splide, SplideSlide } from "@splidejs/vue-splide";
export default {
name: "PersistentWindow",
name: "AxoChatBot",
components: {
Splide,
SplideSlide,
Expand Down
122 changes: 122 additions & 0 deletions frontend/src/components/DraggableView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<template>
<section :class="`absolute peer select-none z-[9] ${wrapperClass}`"
:style="{ top: `${position.top}px`, left: `${position.left}px` }" ref="dragWrapper">
<header :class="`cursor-grab ${handlerClass}`" @mousedown="onMouseDown" ref="draggable">
<slot name="handler" />
</header>
<div v-if="$slots.content" :class="contentClass">
<slot name="content" />
</div>
</section>
</template>

<script>
export default {
props: {
wrapperClass: {
type: String,
default: "",
},
handlerClass: {
type: String,
default: "",
},
contentClass: {
type: String,
default: "",
},
initialPosition: {
type: Object,
default: () => ({ top: 100, left: 100 }),
},
minX: {
type: Number,
default: 0, // Minimum left coordinate
},
minY: {
type: Number,
default: 0, // Minimum top coordinate
},
dragHandle: {
type: String,
default: null, // CSS selector for the drag handle
},
},
data() {
return {
position: { ...this.initialPosition },
isDragging: false,
dragOffset: { x: 0, y: 0 },
};
},
mounted() {
// Safely access the handler element after DOM updates
this.$nextTick(() => {
if (this.dragHandle && this.$refs.handler) {
const handle = this.$refs.handler.querySelector(this.dragHandle);
if (handle) {
// Add mousedown listener only to the handle
handle.addEventListener("mousedown", this.onMouseDown);
}
}
});
},
beforeUnmount() {
// Remove event listener safely if handler exists
if (this.dragHandle && this.$refs.handler) {
const handle = this.$refs.handler.querySelector(this.dragHandle);
if (handle) {
handle.removeEventListener("mousedown", this.onMouseDown);
}
}
},
methods: {
onMouseDown(event) {
// Prevent default behavior (like clicking) when dragging starts
event.preventDefault();
// Ensure the drag starts only from the handle and avoid errors
if (this.dragHandle && this.$refs.handler) {
const handle = this.$refs.handler.querySelector(this.dragHandle);
if (!handle || !handle.contains(event.target)) {
return; // Stop if the event is not from the handle
}
}
this.isDragging = true;
this.dragOffset.x = event.clientX - this.position.left;
this.dragOffset.y = event.clientY - this.position.top;
// Add listeners for drag movement and release
window.addEventListener("mousemove", this.onMouseMove);
window.addEventListener("mouseup", this.onMouseUp);
},
onMouseMove(event) {
if (!this.isDragging) return;
const handler = this.$refs.draggable.querySelector(this.dragHandle);
let newTop = event.clientY - this.dragOffset.y;
let newLeft = event.clientX - this.dragOffset.x;
const rect = this.$refs.dragWrapper.getBoundingClientRect();
const containerWidth = window.innerWidth;
const containerHeight = window.innerHeight;
handler.classList.add("!pointer-events-none");
newTop = Math.max(this.minY, Math.min(newTop, containerHeight - rect.height));
newLeft = Math.max(this.minX, Math.min(newLeft, containerWidth - rect.width));
this.position.top = newTop;
this.position.left = newLeft;
},
onMouseUp() {
this.isDragging = false;
this.$refs.draggable.querySelector(this.dragHandle).classList.remove("!pointer-events-none");
window.removeEventListener("mousemove", this.onMouseMove);
window.removeEventListener("mouseup", this.onMouseUp);
},
},
};
</script>
4 changes: 2 additions & 2 deletions frontend/src/components/citation/CitationCommunities.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

<Listbox v-if="citation_data?.community_scores?.length != 0 && !await_load" v-model="selected_citation"
optionLabel="name" :options="filt_communities" :pt="{
listContainer: { class: 'order-2' },
listContainer: { class: '!h-full !order-2' },
list: { class: '!p-0' },
emptyMessage: { class: '!flex !justify-center !items-center !text-sm !text-slate-500 dark:!text-slate-300' },
option: {
class:
'!px-0 !py-1 !text-slate-500 dark:!text-slate-300 leading-tight transition-all duration-300 ease-in-out',
},
}" :virtualScrollerOptions="{ itemSize: 28 }" listStyle="max-height:100%" class="h-full flex flex-col !p-0 !bg-transparent !border-0"
}" :virtualScrollerOptions="{ itemSize: 28 }" scrollHeight="100%" listStyle="max-height:100%" class="h-full flex flex-col !p-0 !bg-transparent !border-0"
@update:modelValue="select_community" :tabindex="0" emptyMessage="No communities available.">

<template #footer>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/citation/CitationList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

<Listbox v-if="citation_data?.nodes?.length != 0 && !await_load" v-model="selected_citation" optionLabel="id"
:options="filt_abstracts" :pt="{
listContainer: { class: 'order-2' },
listContainer: { class: '!h-full !order-2' },
list: { class: '!p-0' },
emptyMessage: { class: '!flex !justify-center !items-center !text-sm !text-slate-500 dark:!text-slate-300' },
option: {
class:
'!px-0 !py-1 !text-slate-500 dark:!text-slate-300 leading-tight transition-all duration-300 ease-in-out',
},
}" :virtualScrollerOptions="{ itemSize: 28 }" listStyle="max-height:100%"
}" :virtualScrollerOptions="{ itemSize: 28 }" scrollHeight="100%" listStyle="max-height:100%"
class="h-full flex flex-col !p-0 !bg-transparent !border-0" @update:modelValue="select_abstract" :tabindex="0"
emptyMessage="No abstracts available.">

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/enrichment/PathwayList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
</EmptyState>

<Listbox v-if="terms !== null && !await_load" v-model="selected_pathway" optionLabel="name" :options="filt_terms" :pt="{
listContainer: { class: 'order-2' },
listContainer: { class: '!h-full !order-2' },
list: { class: '!p-0' },
emptyMessage: { class: '!flex !justify-center !items-center !text-sm !text-slate-500 dark:!text-slate-300' },
option: {
class:
'!px-0 !py-1 !text-slate-500 dark:!text-slate-300 leading-tight transition-all duration-300 ease-in-out',
},
}" :virtualScrollerOptions="{ itemSize: 28 }" listStyle="max-height:100%" class="h-full flex flex-col !p-0 !bg-transparent !border-0"
}" :virtualScrollerOptions="{ itemSize: 28 }" scrollHeight="100%" listStyle="max-height:100%" class="h-full flex flex-col !p-0 !bg-transparent !border-0"
@value-change="select_term" :tabindex="0" emptyMessage="No terms available.">

<template #footer>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/pathwaytools/PathwayGraphList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
</EmptyState>

<Listbox v-if="term_data !== null" v-model="selected_pathway" optionLabel="name" :options="filt_terms" :pt="{
listContainer: { class: 'order-2' },
listContainer: { class: '!h-full !order-2' },
list: { class: '!p-0' },
emptyMessage: { class: '!flex !justify-center !items-center !text-sm !text-slate-500 dark:!text-slate-300' },
option: {
class:
'!px-0 !py-1 !text-slate-500 dark:!text-slate-300 leading-tight transition-all duration-300 ease-in-out',
},
}" :virtualScrollerOptions="{ itemSize: 28 }" listStyle="max-height:100%" class="h-full flex flex-col !p-0 !bg-transparent !border-0"
}" :virtualScrollerOptions="{ itemSize: 28 }" scrollHeight="100%" listStyle="max-height:100%" class="h-full flex flex-col !p-0 !bg-transparent !border-0"
@update:modelValue="select_term" :tabindex="0" emptyMessage="No terms available.">

<template #footer>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<template #center>
<Button @click="center" plain text class="capitalize">
<span class="material-symbols-rounded">center_focus_strong</span>
<span class="material-symbols-rounded">fullscreen</span>
Recenter graph
</Button>
</template>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout/MainToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</Button>

<Button class="group" icon="material-symbols-rounded" text plain v-tooltip="'Recenter graph'" @click="center">
<span class="material-symbols-rounded group-hover:font-variation-ico-filled">center_focus_strong</span>
<span class="material-symbols-rounded group-hover:font-variation-ico-filled">fullscreen</span>
</Button>

<Button class="group" icon="material-symbols-rounded" text plain v-tooltip="'Open AxoBot'" @click="chatbot">
Expand Down

0 comments on commit 2cfca50

Please sign in to comment.