@@ -18,10 +18,12 @@ import {
1818import { createStore } from "solid-js/store" ;
1919import {
2020 $OpenApiTs ,
21+ ChunkMetadata ,
2122 CrawlRequest ,
2223 PriceToolCallOptions ,
2324 PublicPageTabMessage ,
2425 RelevanceToolCallOptions ,
26+ SearchOverGroupsResponseBody ,
2527} from "trieve-ts-sdk" ;
2628import FilterSidebarBuilder from "../../components/FilterSidebarBuilder" ;
2729import { DatasetContext } from "../../contexts/DatasetContext" ;
@@ -254,6 +256,15 @@ const PublicPageControls = () => {
254256 } ;
255257 } ) ;
256258
259+ createEffect ( ( ) => {
260+ const singleProductOptions = extraParams . singleProductOptions ;
261+ const hasKey =
262+ singleProductOptions &&
263+ Object . keys ( singleProductOptions ) . length > 0 &&
264+ Object . values ( singleProductOptions ) . some ( ( option ) => option ) ;
265+ setExtraParams ( "inline" , hasKey ) ;
266+ } ) ;
267+
257268 return (
258269 < >
259270 < Show when = { ! isPublic ( ) } >
@@ -1650,7 +1661,10 @@ const PublicPageControls = () => {
16501661} ;
16511662
16521663export const SingleProductOptions = ( ) => {
1664+ const [ loadingAutoFill , setLoadingAutoFill ] = createSignal ( false ) ;
16531665 const { extraParams, setExtraParams } = usePublicPage ( ) ;
1666+ const datasetContext = useContext ( DatasetContext ) ;
1667+ const trieve = useTrieve ( ) ;
16541668
16551669 return (
16561670 < details class = "my-4" >
@@ -1690,17 +1704,63 @@ export const SingleProductOptions = () => {
16901704 </ div >
16911705 < div class = "grow" >
16921706 < label class = "block" > Product Name</ label >
1693- < input
1694- placeholder = "Name of the product to display"
1695- value = { extraParams . singleProductOptions ?. productName || "" }
1696- onInput = { ( e ) => {
1697- setExtraParams ( "singleProductOptions" , {
1698- ...extraParams . singleProductOptions ,
1699- productName : e . currentTarget . value ,
1700- } ) ;
1701- } }
1702- class = "block w-full rounded border border-neutral-300 px-3 py-1.5 shadow-sm placeholder:text-neutral-400 focus:outline-magenta-500 sm:text-sm sm:leading-6"
1703- />
1707+ < div class = "flex items-center gap-2" >
1708+ < input
1709+ placeholder = "Name of the product to display"
1710+ value = { extraParams . singleProductOptions ?. productName || "" }
1711+ onInput = { ( e ) => {
1712+ setExtraParams ( "singleProductOptions" , {
1713+ ...extraParams . singleProductOptions ,
1714+ productName : e . currentTarget . value ,
1715+ } ) ;
1716+ } }
1717+ class = "block w-full rounded border border-neutral-300 px-3 py-1.5 shadow-sm placeholder:text-neutral-400 focus:outline-magenta-500 sm:text-sm sm:leading-6"
1718+ />
1719+ < button
1720+ onClick = { ( ) => {
1721+ setLoadingAutoFill ( true ) ;
1722+ void trieve
1723+ . fetch ( "/api/chunk_group/group_oriented_search" , "post" , {
1724+ data : {
1725+ query :
1726+ extraParams . singleProductOptions ?. productName || "" ,
1727+ page_size : 10 ,
1728+ search_type : "fulltext" ,
1729+ } ,
1730+ datasetId : datasetContext . datasetId ( ) ,
1731+ } )
1732+ . then ( ( res ) => {
1733+ const typedRes : SearchOverGroupsResponseBody =
1734+ res as SearchOverGroupsResponseBody ;
1735+ const firstGroup = typedRes . results ?. length
1736+ ? typedRes . results [ 0 ]
1737+ : null ;
1738+ const firstChunk = firstGroup ?. chunks ?. length
1739+ ? firstGroup . chunks [ 0 ]
1740+ : null ;
1741+ if ( ! firstGroup || ! firstChunk ) {
1742+ return ;
1743+ }
1744+ setExtraParams ( "singleProductOptions" , {
1745+ groupTrackingId : firstGroup . group . tracking_id ,
1746+ productTrackingId : firstChunk . chunk . tracking_id ,
1747+ productPrimaryImageUrl : firstChunk . chunk . image_urls
1748+ ?. length
1749+ ? firstChunk . chunk . image_urls [ 0 ]
1750+ : "" ,
1751+ productDescriptionHtml : (
1752+ firstChunk . chunk as ChunkMetadata
1753+ ) . chunk_html ,
1754+ } ) ;
1755+ setLoadingAutoFill ( false ) ;
1756+ } ) ;
1757+ } }
1758+ disabled = { loadingAutoFill ( ) }
1759+ class = "inline-flex justify-center rounded-md bg-magenta-500 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-magenta-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-magenta-900 disabled:animate-pulse min-w-[130px]"
1760+ >
1761+ { loadingAutoFill ( ) ? "Loading..." : "Auto Fill" }
1762+ </ button >
1763+ </ div >
17041764 </ div >
17051765 </ div >
17061766 < div class = "flex gap-4 pb-2 pt-2" >
@@ -1733,7 +1793,6 @@ export const SingleProductOptions = () => {
17331793 value = { extraParams . singleProductOptions ?. productQuestions || [ ] }
17341794 onChange = { ( e ) => {
17351795 setExtraParams ( "singleProductOptions" , {
1736- ...extraParams . singleProductOptions ,
17371796 productQuestions : e ,
17381797 } ) ;
17391798 } }
@@ -1745,35 +1804,35 @@ export const SingleProductOptions = () => {
17451804 </ div >
17461805 < div class = "flex gap-4 pb-2 pt-2" >
17471806 < div class = "grow" >
1748- < label class = "block" > Recommendation Search Query</ label >
1749- < input
1750- placeholder = "Search query to use for recommendations"
1751- value = { extraParams . singleProductOptions ?. recSearchQuery || "" }
1807+ < label class = "block" > Product Description HTML</ label >
1808+ < textarea
1809+ cols = { 2 }
1810+ placeholder = "Description of the page"
1811+ value = {
1812+ extraParams . singleProductOptions ?. productDescriptionHtml || ""
1813+ }
17521814 onInput = { ( e ) => {
17531815 setExtraParams ( "singleProductOptions" , {
17541816 ...extraParams . singleProductOptions ,
1755- recSearchQuery : e . currentTarget . value ,
1817+ productDescriptionHtml : e . currentTarget . value ,
17561818 } ) ;
1819+ setExtraParams ( "inline" , ! ! e . currentTarget . value ) ;
17571820 } }
17581821 class = "block w-full rounded border border-neutral-300 px-3 py-1.5 shadow-sm placeholder:text-neutral-400 focus:outline-magenta-500 sm:text-sm sm:leading-6"
17591822 />
17601823 </ div >
17611824 </ div >
17621825 < div class = "flex gap-4 pb-2 pt-2" >
17631826 < div class = "grow" >
1764- < label class = "block" > Product Description HTML</ label >
1765- < textarea
1766- cols = { 2 }
1767- placeholder = "Description of the page"
1768- value = {
1769- extraParams . singleProductOptions ?. productDescriptionHtml || ""
1770- }
1827+ < label class = "block" > Recommendation Search Query</ label >
1828+ < input
1829+ placeholder = "Search query to use for recommendations"
1830+ value = { extraParams . singleProductOptions ?. recSearchQuery || "" }
17711831 onInput = { ( e ) => {
17721832 setExtraParams ( "singleProductOptions" , {
17731833 ...extraParams . singleProductOptions ,
1774- productDescriptionHtml : e . currentTarget . value ,
1834+ recSearchQuery : e . currentTarget . value ,
17751835 } ) ;
1776- setExtraParams ( "inline" , ! ! e . currentTarget . value ) ;
17771836 } }
17781837 class = "block w-full rounded border border-neutral-300 px-3 py-1.5 shadow-sm placeholder:text-neutral-400 focus:outline-magenta-500 sm:text-sm sm:leading-6"
17791838 />
0 commit comments