Skip to content

Commit

Permalink
bugfix: checkbox for chat feature in search UI for group search
Browse files Browse the repository at this point in the history
  • Loading branch information
skeptrunedev committed May 21, 2024
1 parent 9a78fb7 commit b2f28af
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
18 changes: 14 additions & 4 deletions search/src/components/ChatPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from "solid-js";
import { FiSend, FiStopCircle } from "solid-icons/fi";
import {
GroupScoreChunkDTO,
type Message,
messageRoleFromIndex,
ScoreChunkDTO,
Expand All @@ -23,10 +24,11 @@ import { DatasetAndUserContext } from "./Contexts/DatasetAndUserContext";
export interface LayoutProps {
selectedIds: Accessor<string[]>;
chunks: Accessor<ScoreChunkDTO[]>;
groupChunks?: Accessor<GroupScoreChunkDTO[]>;
setOpenChat: Setter<boolean>;
}

const ChatPopup = (props: LayoutProps) => {
export const ChatPopup = (props: LayoutProps) => {
const api_host = import.meta.env.VITE_API_HOST as unknown as string;
const datasetAndUserContext = useContext(DatasetAndUserContext);
const $dataset = datasetAndUserContext.currentDataset;
Expand Down Expand Up @@ -166,7 +168,17 @@ const ChatPopup = (props: LayoutProps) => {

const messageChunks = createMemo(() => {
const selectedIds = props.selectedIds();
const chunks = props.chunks();
let chunks = props.chunks();
if (!chunks.length) {
chunks =
props
.groupChunks?.()
?.flatMap((group) =>
group.metadata.flatMap((metadata) => metadata),
) ?? [];

console.log("groups", chunks);
}

return chunks.filter((chunk) => selectedIds.includes(chunk.metadata[0].id));
});
Expand Down Expand Up @@ -273,5 +285,3 @@ const ChatPopup = (props: LayoutProps) => {
</div>
);
};

export default ChatPopup;
2 changes: 1 addition & 1 deletion search/src/components/GroupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { ScoreChunkArray } from "./ScoreChunkArray";
import SearchForm from "./SearchForm";
import ChunkMetadataDisplay from "./ChunkMetadataDisplay";
import { Portal } from "solid-js/web";
import ChatPopup from "./ChatPopup";
import { ChatPopup } from "./ChatPopup";
import { AiOutlineRobot } from "solid-icons/ai";
import { IoDocumentOutline, IoDocumentsOutline } from "solid-icons/io";
import { useLocation, useNavigate } from "@solidjs/router";
Expand Down
11 changes: 7 additions & 4 deletions search/src/components/ResultsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { ConfirmModal } from "./Atoms/ConfirmModal";
import { ScoreChunkArray } from "./ScoreChunkArray";
import { Portal } from "solid-js/web";
import { AiOutlineRobot } from "solid-icons/ai";
import ChatPopup from "./ChatPopup";
import { ChatPopup } from "./ChatPopup";
import { IoDocumentOutline, IoDocumentsOutline } from "solid-icons/io";
import { DatasetAndUserContext } from "./Contexts/DatasetAndUserContext";
import { FaSolidChevronDown, FaSolidChevronUp } from "solid-icons/fa";
Expand Down Expand Up @@ -283,6 +283,7 @@ const ResultsPage = (props: ResultsPageProps) => {
<div class="max-h-[75vh] min-h-[75vh] min-w-[75vw] max-w-[75vw] overflow-y-auto rounded-md scrollbar-thin">
<ChatPopup
chunks={resultChunks}
groupChunks={groupResultChunks}
selectedIds={selectedIds}
setOpenChat={setOpenChat}
/>
Expand Down Expand Up @@ -501,11 +502,13 @@ const ResultsPage = (props: ResultsPageProps) => {
class="relative h-[52px] w-[52px] items-center justify-center rounded-lg border border-gray-200 bg-white text-gray-500 shadow-sm hover:bg-gray-50 hover:text-gray-900 focus:outline-none focus:ring-4 focus:ring-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-400 dark:hover:bg-gray-600 dark:hover:text-white dark:focus:ring-gray-400"
onClick={() => {
setSelectedIds(
resultChunks()
groupResultChunks()
.flatMap((g) => {
return g.metadata;
})
.flatMap((c) => {
return c.metadata.map((m) => m.id);
})
.slice(0, 10),
}),
);
setOpenChat(true);
}}
Expand Down
2 changes: 1 addition & 1 deletion search/src/components/SingleChunkPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { FullScreenModal } from "./Atoms/FullScreenModal";
import { ConfirmModal } from "./Atoms/ConfirmModal";
import ChunkMetadataDisplay from "./ChunkMetadataDisplay";
import { Portal } from "solid-js/web";
import ChatPopup from "./ChatPopup";
import { ChatPopup } from "./ChatPopup";
import { AiOutlineRobot } from "solid-icons/ai";
import { IoDocumentOutline } from "solid-icons/io";
import { DatasetAndUserContext } from "./Contexts/DatasetAndUserContext";
Expand Down

0 comments on commit b2f28af

Please sign in to comment.