Skip to content

Commit

Permalink
Update view results panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewjordan committed Feb 7, 2025
1 parent 78773d6 commit 9feb197
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 30 deletions.
1 change: 1 addition & 0 deletions components/Chat/Conversation.styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const StyledChatConversation = styled("div", {
fontSize: "$gr3",
padding: "0 $gr2",
gap: "$gr2",
zIndex: 0,
fontFamily: "$northwesternSansRegular",

"&:hover, &:focus": {
Expand Down
29 changes: 29 additions & 0 deletions components/Chat/Response/Aggregations.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { IconArrowForward, IconSparkles } from "@/components/Shared/SVG/Icons";

import React from "react";
import { StyledInterstitialWrapper } from "@/components/Chat/Response/Interstitial.styled";
import { ToolStartMessage } from "@/types/components/chat";

interface ResponseInterstitialProps {
message: ToolStartMessage["message"];
}

const ResponseAggregations: React.FC<ResponseInterstitialProps> = ({
message,
}) => {
const { buckets } = message;
console.log(buckets);

return (
<StyledInterstitialWrapper>
{buckets.map((bucket) => (
<>
Aggregation counts:
{bucket.key} {bucket.doc_count}
</>
))}
</StyledInterstitialWrapper>
);
};

export default ResponseAggregations;
11 changes: 1 addition & 10 deletions components/Chat/Response/Interstitial.styled.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { keyframes, styled } from "@/stitches.config";

const gradientAnimation = keyframes({
to: {
backgroundSize: "500%",
backgroundPosition: "38.2%",
},
});

const StyledInterstitialIcon = styled("div", {
display: "flex",
width: "1rem",
Expand Down Expand Up @@ -53,9 +46,7 @@ const StyledInterstitial = styled("div", {
color: "$purple60",
borderRadius: "1em",
paddingRight: "$gr2",
backgroundSize: "250%",
backgroundPosition: "61.8%",
animation: `${gradientAnimation} 5s infinite alternate`,

strong: {
fontFamily: "$northwesternSansBold",
Expand Down Expand Up @@ -83,7 +74,7 @@ const StyledInterstitialAction = styled("button", {
width: "1rem",
stroke: "$purple30",
transition: "$dcAll",
margin: "0",
margin: "-2px 0 0",

path: {
stroke: "inherit",
Expand Down
34 changes: 29 additions & 5 deletions components/Chat/Response/Interstitial.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { IconArrowForward, IconSparkles } from "@/components/Shared/SVG/Icons";
import React, { useEffect } from "react";
import {
StyledInterstitial,
StyledInterstitialAction,
StyledInterstitialIcon,
StyledInterstitialWrapper,
} from "@/components/Chat/Response/Interstitial.styled";

import React from "react";
import { ToolStartMessage } from "@/types/components/chat";
import { useSearchState } from "@/context/search-context";
import { v4 as uuidv4 } from "uuid";

interface ResponseInterstitialProps {
message: ToolStartMessage["message"];
Expand All @@ -21,7 +22,11 @@ const ResponseInterstitial: React.FC<ResponseInterstitialProps> = ({
}) => {
const { tool, input } = message;

const { searchDispatch } = useSearchState();
const { searchState, searchDispatch } = useSearchState();
const {
panel: { open, interstitial },
} = searchState;
const id = uuidv4();

const handleViewResults = (action: string) => {
window.scrollTo({
Expand All @@ -33,19 +38,38 @@ const ResponseInterstitial: React.FC<ResponseInterstitialProps> = ({
panel: {
open: true,
query: action,
interstitial: id,
},
});
};

let text: InterstitialContent;
let action: InterstitialContent;

useEffect(() => {
if (open && !interstitial) return;

console.log({
id,
interstitial,
});

if (id === interstitial) {
const interstitialElement = document.getElementById(`interstitial-${id}`);
// if (interstitialElement)
// interstitialElement.scrollIntoView({
// behavior: "smooth",
// block: "start",
// });
}
}, [open]);

switch (tool) {
case "aggregate":
text = `Aggregating <strong>${input.agg_field}</strong> by <strong>${input.term_field} ${input.term}</strong>`;
text = `Aggregating`;
break;
case "discover_fields":
text = `Discovering fields`;
text = `Discovering`;
break;
case "search":
text = `Searching for <strong>${input.query}</strong>`;
Expand All @@ -56,7 +80,7 @@ const ResponseInterstitial: React.FC<ResponseInterstitialProps> = ({
}

return (
<StyledInterstitialWrapper>
<StyledInterstitialWrapper id={`interstitial-${id}`}>
<StyledInterstitial data-testid="response-interstitial" data-tool={tool}>
<StyledInterstitialIcon>
<IconSparkles />
Expand Down
3 changes: 2 additions & 1 deletion components/Chat/Response/Response.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {

import BouncingLoader from "@/components/Shared/BouncingLoader";
import Container from "@/components/Shared/Container";
import ResponseAggregations from "@/components/Chat/Response/Aggregations";
import ResponseImages from "@/components/Chat/Response/Images";
import ResponseInterstitial from "@/components/Chat/Response/Interstitial";
import ResponseMarkdown from "@/components/Chat/Response/Markdown";
Expand Down Expand Up @@ -96,7 +97,7 @@ const ChatResponse: React.FC<ChatResponseProps> = ({
setRenderedMessage((prev) => (
<>
{prev}
<></>
<ResponseAggregations message={message.message} />
</>
));
}
Expand Down
105 changes: 93 additions & 12 deletions components/Search/Panel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import Container, { ContainerStyled } from "../Shared/Container";
import { IconArrowBack, IconSparkles } from "../Shared/SVG/Icons";
import {
StyledInterstitial,
StyledInterstitialIcon,
} from "../Chat/Response/Interstitial.styled";
import { useEffect, useState } from "react";

import { ApiSearchRequestBody } from "@/types/api/request";
Expand All @@ -22,7 +27,7 @@ const defaultSearchResultsState: SearchResultsState = {
const SearchPanel = () => {
const { searchState, searchDispatch } = useSearchState();
const {
panel: { open, query },
panel: { open, query, interstitial },
} = searchState;

const [searchResults, setSearchResults] = useState<SearchResultsState>(
Expand All @@ -38,12 +43,18 @@ const SearchPanel = () => {
if (!query) return;

(async () => {
setSearchResults({
data: null,
error: "",
loading: true,
});

try {
const requestUrl = new URL(DC_API_SEARCH_URL);
const body: ApiSearchRequestBody = buildQuery(
{
size: SEARCH_RESULTS_PER_PAGE,
term: query as string,
term: String(query),
urlFacets: {},
},
true,
Expand All @@ -53,11 +64,14 @@ const SearchPanel = () => {
body,
url: requestUrl.toString(),
});
setSearchResults({
data: response || null,
error: "",
loading: false,
});
setTimeout(() => {
setSearchResults({
data: response || null,
error: "",
loading: false,
});
}, 100);

console.log(`response`, response);
} catch (error) {
console.error(error);
Expand All @@ -75,6 +89,7 @@ const SearchPanel = () => {
panel: {
open: false,
query: undefined,
interstitial,
},
});
};
Expand All @@ -84,13 +99,32 @@ const SearchPanel = () => {
return (
<StyledSearchPanel isOpen={open}>
<Container containerType="wide" className="search-panel">
<StyledSearchPanelContent>
<StyledSearchPanelContent id="search-panel-content">
<Container>
<SearchOptions
activeTab="results"
renderTabList={true}
tabs={<button onClick={handleBack}>back</button>}
tabs={<></>}
/>
{query && (
<SearchResultsLabel>
<div>
<StyledBackButton onClick={handleBack}>
<IconArrowBack /> Update Conversation
{/* <span style={{ opacity: 0.5 }}>Filtered</span> */}
</StyledBackButton>
</div>

<div>
<StyledInterstitialIcon>
<IconSparkles />
</StyledInterstitialIcon>
<label>
Search results for <strong>{query}</strong>
</label>
</div>
</SearchResultsLabel>
)}
</Container>
<SearchResults {...searchResults} />
</StyledSearchPanelContent>
Expand All @@ -99,6 +133,55 @@ const SearchPanel = () => {
);
};

const SearchResultsLabel = styled(StyledInterstitial, {
marginBottom: "$gr4",
textAlign: "center",
justifyContent: "space-between",
width: "100%",

div: {
display: "flex",
alignItems: "center",
gap: "$gr2",
},
});

const StyledBackButton = styled("button", {
display: "inline-flex",
padding: "0 $gr2",
height: "38px",
alignItems: "center",
gap: "$gr1",
color: "$purple",
background: "transparent",
fontFamily: "$northwesternSansBold",
fontSize: "$gr3",
border: "none",
cursor: "pointer",
whiteSpace: "nowrap",

svg: {
height: "1rem",
width: "1rem",
stroke: "$purple30",
transition: "$dcAll",
margin: "-2px 0 0",

path: {
stroke: "inherit",
strokeWidth: "48px",
},
},

"&:hover": {
svg: {
marginLeft: "-3px",
marginRight: "3px",
stroke: "$purple",
},
},
});

const StyledSearchPanel = styled("aside", {
position: "absolute",
top: "0",
Expand All @@ -108,9 +191,6 @@ const StyledSearchPanel = styled("aside", {
zIndex: "1",
transition: "all 382ms ease-in-out",
opacity: "0",
maskImage:
"linear-gradient(to bottom, transparent, black 29px, black 80%, transparent)",

variants: {
isOpen: {
true: {
Expand All @@ -133,6 +213,7 @@ const StyledSearchPanel = styled("aside", {
const StyledSearchPanelContent = styled("div", {
height: "100%",
padding: "$gr4 0",
background: "white",
boxShadow: "-29px 0 29px rgba(0, 0, 0, 0.0382)",
});

Expand Down
2 changes: 2 additions & 0 deletions context/search-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Action =
| {
type: "updatePanel";
panel: {
interstitial?: string;
open: boolean;
query?: string;
};
Expand All @@ -43,6 +44,7 @@ const defaultState: SearchContextStore = {
ref: "",
},
panel: {
interstitial: undefined,
open: false,
query: undefined,
},
Expand Down
Loading

0 comments on commit 9feb197

Please sign in to comment.