Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix popup overlap #389

Merged
merged 1 commit into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions web/src/components/admin/connectors/Popup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useRef, useState } from "react";

export interface PopupSpec {
message: string;
Expand All @@ -17,9 +17,17 @@ export const Popup: React.FC<PopupSpec> = ({ message, type }) => (

export const usePopup = () => {
const [popup, setPopup] = useState<PopupSpec | null>(null);
// using NodeJS.Timeout because setTimeout in NodeJS returns a different type than in browsers
const timeoutRef = useRef<NodeJS.Timeout | null>(null);

const setPopupWithExpiration = (popupSpec: PopupSpec | null) => {
// Clear any previous timeout
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}

setPopup(popupSpec);
setTimeout(() => {
timeoutRef.current = setTimeout(() => {
setPopup(null);
}, 4000);
};
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/search/DocumentDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { DanswerDocument } from "@/lib/search/interfaces";
import { DocumentFeedbackBlock } from "./DocumentFeedbackBlock";
import { getSourceIcon } from "../source";
import { useState } from "react";
import { usePopup } from "../admin/connectors/Popup";
import { PopupSpec } from "../admin/connectors/Popup";

interface DocumentDisplayProps {
document: DanswerDocument;
queryEventId: number | null;
setPopup: (popupSpec: PopupSpec | null) => void;
}

export const DocumentDisplay = ({
document,
queryEventId,
setPopup,
}: DocumentDisplayProps) => {
const { popup, setPopup } = usePopup();
const [isHovered, setIsHovered] = useState(false);

return (
Expand All @@ -25,7 +26,6 @@ export const DocumentDisplay = ({
}}
onMouseLeave={() => setIsHovered(false)}
>
{popup}
<div className="flex relative">
<div className="absolute -left-10 top-2/4 -translate-y-2/4 w-10 flex">
<div
Expand Down
1 change: 0 additions & 1 deletion web/src/components/search/DocumentFeedbackBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const DocumentFeedback = ({
queryId,
feedbackType
);
console.log(errorMsg);
if (!errorMsg) {
setPopup({
message: "Thanks for your feedback!",
Expand Down
11 changes: 6 additions & 5 deletions web/src/components/search/QAFeedback.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from "react";
import { PopupSpec, usePopup } from "../admin/connectors/Popup";
import { PopupSpec } from "../admin/connectors/Popup";
import { ThumbsDownIcon, ThumbsUpIcon } from "../icons/icons";

type Feedback = "like" | "dislike";
Expand Down Expand Up @@ -71,14 +71,15 @@ const QAFeedback = ({

interface QAFeedbackBlockProps {
queryId: number;
setPopup: (popupSpec: PopupSpec | null) => void;
}

export const QAFeedbackBlock = ({ queryId }: QAFeedbackBlockProps) => {
const { popup, setPopup } = usePopup();

export const QAFeedbackBlock = ({
queryId,
setPopup,
}: QAFeedbackBlockProps) => {
return (
<div className="flex">
{popup}
<QAFeedback queryId={queryId} setPopup={setPopup} feedbackType="like" />
<div className="ml-2">
<QAFeedback
Expand Down
11 changes: 9 additions & 2 deletions web/src/components/search/SearchResultsDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
getAIThoughtsIsOpenSavedValue,
setAIThoughtsIsOpenSavedValue,
} from "@/lib/search/aiThoughtUtils";
import { Grid, ThreeDots } from "react-loader-spinner";
import { ThreeDots } from "react-loader-spinner";
import { usePopup } from "../admin/connectors/Popup";

const removeDuplicateDocs = (documents: DanswerDocument[]) => {
const seen = new Set<string>();
Expand All @@ -45,6 +46,7 @@ export const SearchResultsDisplay: React.FC<SearchResultsDisplayProps> = ({
isFetching,
defaultOverrides,
}) => {
const { popup, setPopup } = usePopup();
const [isAIThoughtsOpen, setIsAIThoughtsOpen] = React.useState<boolean>(
getAIThoughtsIsOpenSavedValue()
);
Expand Down Expand Up @@ -106,6 +108,7 @@ export const SearchResultsDisplay: React.FC<SearchResultsDisplayProps> = ({

return (
<>
{popup}
{shouldDisplayQA && (
<div className="min-h-[16rem] p-4 border-2 rounded-md border-gray-700 relative">
<div>
Expand Down Expand Up @@ -150,7 +153,10 @@ export const SearchResultsDisplay: React.FC<SearchResultsDisplayProps> = ({

{searchResponse.queryEventId !== null && (
<div className="absolute right-3 bottom-3">
<QAFeedbackBlock queryId={searchResponse.queryEventId} />
<QAFeedbackBlock
queryId={searchResponse.queryEventId}
setPopup={setPopup}
/>
</div>
)}
</div>
Expand All @@ -169,6 +175,7 @@ export const SearchResultsDisplay: React.FC<SearchResultsDisplayProps> = ({
key={document.document_id}
document={document}
queryEventId={queryEventId}
setPopup={setPopup}
/>
))}
</div>
Expand Down
Loading