Skip to content

Commit 2c45009

Browse files
committed
Scroll to current view if not in viewport
1 parent 34e2879 commit 2c45009

File tree

3 files changed

+20
-29
lines changed

3 files changed

+20
-29
lines changed

report-front-end/src/common/API.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ChatBotHistoryItem } from "@/components/chatbot/types";
22
import { Dispatch, SetStateAction } from "react";
33
import { BACKEND_URL } from "../tools/const";
4+
import { DEFAULT_QUERY_CONFIG } from "../enum/DefaultQueryEnum";
45

56
export interface QueryProps {
67
query: string;
@@ -14,12 +15,12 @@ export async function query(props: QueryProps) {
1415
try {
1516
const param = {
1617
query: props.query,
17-
bedrock_model_id: props.configuration.selectedLLM,
18+
bedrock_model_id: props.configuration.selectedLLM || DEFAULT_QUERY_CONFIG.selectedLLM,
1819
use_rag_flag: true,
1920
visualize_results_flag: true,
2021
intent_ner_recognition_flag: props.configuration.intentChecked,
2122
agent_cot_flag: props.configuration.complexChecked,
22-
profile_name: props.configuration.selectedDataPro,
23+
profile_name: props.configuration.selectedDataPro || DEFAULT_QUERY_CONFIG.selectedDataPro,
2324
explain_gen_process_flag: true,
2425
gen_suggested_question_flag: props.configuration.modelSuggestChecked,
2526
top_k: props.configuration.topK,

report-front-end/src/components/chatbot/chat.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,33 @@ export default function Chat(
7171

7272
// On first render and on unmount there is no DOM element so `element` will be `null`
7373
const scrollTo = (element : any) => {
74-
if (element) {
74+
if (element && !isInViewPort(element)) {
7575
element.scrollIntoView({behavior: "smooth"});
7676
}
7777
};
7878

79+
function isInViewPort(element: any) {
80+
const viewWidth = window.innerWidth || document.documentElement.clientWidth;
81+
const viewHeight = window.innerHeight || document.documentElement.clientHeight;
82+
const {
83+
top,
84+
right,
85+
bottom,
86+
left,
87+
} = element.getBoundingClientRect();
88+
89+
return (
90+
top >= 0 && left >= 0 && right <= viewWidth && bottom <= (viewHeight - 200)
91+
);
92+
}
93+
7994
return (
8095
<div className={styles.chat_container}>
8196
<SpaceBetween size={'xxl'}>
8297
{messageHistory.map((message, idx) => {
8398
const isLast = idx === messageHistory.length - 1;
8499
return (
85-
<div key={idx} ref={isLast ? scrollTo : undefined}>
100+
<div key={idx} ref={isLast && !loading ? scrollTo : undefined}>
86101
<ChatMessage
87102
key={idx}
88103
message={message}

report-front-end/src/components/chatbot/common.tsx

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)