Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,19 @@
display: 'flex',
flexDirection: 'column',
flex: 1,
'& .pf-chatbot__jump': {
left: '50% !important',
right: 'auto !important',
transform: 'translateX(-50%)',
visibility: 'hidden',
pointerEvents: 'none',
},
},
chatbotContentHasOverflow: {
'& .pf-chatbot__jump': {
visibility: 'visible',
pointerEvents: 'auto',
},
},
// Inner scroll container we control: always scrollable so zoomed-in users see full content.
chatbotContentScroll: {
Expand Down Expand Up @@ -458,6 +471,7 @@
const contentScrollRef = useRef<HTMLDivElement>(null);
const bottomSentinelRef = useRef<HTMLDivElement>(null);
const [messageBarKey, setMessageBarKey] = useState(0);
const [hasChatContentOverflow, setHasChatContentOverflow] = useState(false);
const wasStoppedByUserRef = useRef(false);
const { isReady, lastOpenedId, setLastOpenedId, clearLastOpenedId } =
useLastOpenedConversation(user);
Expand Down Expand Up @@ -944,6 +958,136 @@
};
}, [welcomePrompts.length]);

useEffect(() => {
const scrollContainer = contentScrollRef.current;
if (!scrollContainer) {
setHasChatContentOverflow(false);
return undefined;
}

const getMessageBox = () =>
scrollContainer.querySelector(
'.pf-chatbot__messagebox',
) as HTMLElement | null;

const messageBoxOwnsScroll = (messageBox: HTMLElement | null) => {
if (!messageBox || typeof window === 'undefined') {

Check warning on line 974 in workspaces/lightspeed/plugins/lightspeed/src/components/LightSpeedChat.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis.window` over `window`.

See more on https://sonarcloud.io/project/issues?id=redhat-developer_rhdh-plugins&issues=AZ2IHxwrdequgXJ-6AhM&open=AZ2IHxwrdequgXJ-6AhM&pullRequest=2746
return false;
}
const overflowY = window.getComputedStyle(messageBox).overflowY;

Check warning on line 977 in workspaces/lightspeed/plugins/lightspeed/src/components/LightSpeedChat.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=redhat-developer_rhdh-plugins&issues=AZ2IHxwrdequgXJ-6AhN&open=AZ2IHxwrdequgXJ-6AhN&pullRequest=2746
return (
overflowY === 'auto' ||
overflowY === 'scroll' ||
overflowY === 'overlay'
);
};

const getScrollTarget = () => {
const messageBox = getMessageBox();
return messageBoxOwnsScroll(messageBox) ? messageBox! : scrollContainer;

Check warning on line 987 in workspaces/lightspeed/plugins/lightspeed/src/components/LightSpeedChat.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This assertion is unnecessary since it does not change the type of the expression.

See more on https://sonarcloud.io/project/issues?id=redhat-developer_rhdh-plugins&issues=AZ2IHxwrdequgXJ-6AhO&open=AZ2IHxwrdequgXJ-6AhO&pullRequest=2746
};

let observedScrollTarget: HTMLElement | null = getScrollTarget();
let rafId: number | null = null;
let updateScheduled = false;

const updateOverflow = () => {
const scrollTarget = observedScrollTarget ?? scrollContainer;
setHasChatContentOverflow(
scrollTarget.scrollHeight > scrollTarget.clientHeight + 1,
);
};

const scheduleOverflowUpdate = () => {
if (updateScheduled) {
return;
}
updateScheduled = true;
if (typeof requestAnimationFrame !== 'undefined') {

Check warning on line 1006 in workspaces/lightspeed/plugins/lightspeed/src/components/LightSpeedChat.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=redhat-developer_rhdh-plugins&issues=AZ2IHxwrdequgXJ-6AhP&open=AZ2IHxwrdequgXJ-6AhP&pullRequest=2746
rafId = requestAnimationFrame(() => {
updateScheduled = false;
updateOverflow();
});
} else {
updateScheduled = false;
updateOverflow();
}
};

scheduleOverflowUpdate();

// Use capture so scroll events from inner messagebox also trigger updates.
scrollContainer.addEventListener('scroll', scheduleOverflowUpdate, {
passive: true,
capture: true,
});

const resizeObserver =
typeof ResizeObserver !== 'undefined'

Check warning on line 1026 in workspaces/lightspeed/plugins/lightspeed/src/components/LightSpeedChat.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=redhat-developer_rhdh-plugins&issues=AZ14s8fxAuf7ECOysQ-J&open=AZ14s8fxAuf7ECOysQ-J&pullRequest=2746
? new ResizeObserver(() => scheduleOverflowUpdate())
: undefined;
resizeObserver?.observe(scrollContainer);
if (observedScrollTarget !== scrollContainer) {
resizeObserver?.observe(observedScrollTarget);
}

const syncObservedScrollTarget = () => {
const nextScrollTarget = getScrollTarget();
if (nextScrollTarget === observedScrollTarget) {
return;
}
if (observedScrollTarget && observedScrollTarget !== scrollContainer) {
resizeObserver?.unobserve(observedScrollTarget);
}
if (nextScrollTarget !== scrollContainer) {
resizeObserver?.observe(nextScrollTarget);
}
observedScrollTarget = nextScrollTarget;
};

const mutationObserver =
typeof MutationObserver !== 'undefined'

Check warning on line 1049 in workspaces/lightspeed/plugins/lightspeed/src/components/LightSpeedChat.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=redhat-developer_rhdh-plugins&issues=AZ14s8fxAuf7ECOysQ-K&open=AZ14s8fxAuf7ECOysQ-K&pullRequest=2746
? new MutationObserver(() => {
syncObservedScrollTarget();
scheduleOverflowUpdate();
})
: undefined;
mutationObserver?.observe(scrollContainer, {
childList: true,
subtree: true,
characterData: true,
});

if (typeof window !== 'undefined') {

Check warning on line 1061 in workspaces/lightspeed/plugins/lightspeed/src/components/LightSpeedChat.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis.window` over `window`.

See more on https://sonarcloud.io/project/issues?id=redhat-developer_rhdh-plugins&issues=AZ14s8fxAuf7ECOysQ-L&open=AZ14s8fxAuf7ECOysQ-L&pullRequest=2746
window.addEventListener('resize', updateOverflow);
}

return () => {
if (rafId !== null && typeof cancelAnimationFrame !== 'undefined') {
cancelAnimationFrame(rafId);
}
scrollContainer.removeEventListener(
'scroll',
scheduleOverflowUpdate,
true,
);
if (observedScrollTarget && observedScrollTarget !== scrollContainer) {
resizeObserver?.unobserve(observedScrollTarget);
}
resizeObserver?.disconnect();
mutationObserver?.disconnect();
if (typeof window !== 'undefined') {

Check warning on line 1079 in workspaces/lightspeed/plugins/lightspeed/src/components/LightSpeedChat.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis.window` over `window`.

See more on https://sonarcloud.io/project/issues?id=redhat-developer_rhdh-plugins&issues=AZ14s8fxAuf7ECOysQ-M&open=AZ14s8fxAuf7ECOysQ-M&pullRequest=2746
window.removeEventListener('resize', updateOverflow);
}
};
}, [
conversationId,
displayMode,
isMcpSettingsOpen,
messages.length,
welcomePrompts.length,
]);

const handleFilter = useCallback((value: string) => {
setFilterValue(value);
}, []);
Expand Down Expand Up @@ -1087,7 +1231,11 @@

const chatMainContent = (
<>
<ChatbotContent className={classes.chatbotContent}>
<ChatbotContent
className={`${classes.chatbotContent} ${
hasChatContentOverflow ? classes.chatbotContentHasOverflow : ''
}`}
>
<div ref={contentScrollRef} className={classes.chatbotContentScroll}>
{welcomePrompts.length > 0 && (
<div className={classes.chatbotContentSpacer} aria-hidden />
Expand Down
Loading