@@ -20,6 +20,7 @@ import {
2020 iconStar ,
2121 iconTable ,
2222} from "@surrealdb/ui" ;
23+ import { compareVersions } from "compare-versions" ;
2324import { useEffect , useState } from "react" ;
2425import { openCloudAuthentication } from "~/cloud/api/auth" ;
2526import { INSTANCE_PLAN_SUGGESTIONS , isOrganisationBillable } from "~/cloud/helpers" ;
@@ -55,7 +56,15 @@ import { useDatabaseStore } from "~/stores/database";
5556import { useDeployStore } from "~/stores/deploy" ;
5657import { useInterfaceStore } from "~/stores/interface" ;
5758import { CloudDeployConfig } from "~/types" ;
58- import { getConnectionById } from "~/util/connection" ;
59+ import { getConnection , getConnectionById } from "~/util/connection" ;
60+ import {
61+ SURREAL_START_BASICS ,
62+ SURREAL_START_GRAPH_V2 ,
63+ SURREAL_START_GRAPH_V3 ,
64+ SURREAL_START_VECTOR_V2 ,
65+ SURREAL_START_VECTOR_V3 ,
66+ } from "~/util/dataset" ;
67+ import { createBaseQuery } from "~/util/defaults" ;
5968import { useFeatureFlags } from "~/util/feature-flags" ;
6069import { showErrorNotification } from "~/util/helpers" ;
6170import { dispatchIntent } from "~/util/intents" ;
@@ -323,8 +332,47 @@ export function SurrealistToolbar() {
323332 const showNS = ! isSandbox && id && isConnected ;
324333 const showDB = showNS && namespace ;
325334
335+ const [ dataset , setDataset ] = useState ( "surreal-deal-store-mini" ) ;
326336 const selectDataset = useRequireDatabase ( ( ) => datasetModalOpenHandle . open ( ) ) ;
327337
338+ const handleApplyDataset = useStable ( async ( ) => {
339+ if ( dataset === "surreal-deal-store-mini" ) {
340+ await applyDataset ( version ) ;
341+ } else if ( dataset === "surreal-start" ) {
342+ const { settings, updateConnection } = useConfigStore . getState ( ) ;
343+ const connection = getConnection ( ) ;
344+ const queries = [ SURREAL_START_BASICS ] ;
345+
346+ if ( ! connection ) {
347+ return ;
348+ }
349+
350+ const canUse30Queries = compareVersions ( version , "3.0.0" ) >= 0 ;
351+
352+ if ( canUse30Queries ) {
353+ queries . push ( SURREAL_START_GRAPH_V3 ) ;
354+ queries . push ( SURREAL_START_VECTOR_V3 ) ;
355+ } else {
356+ queries . push ( SURREAL_START_GRAPH_V2 ) ;
357+ queries . push ( SURREAL_START_VECTOR_V2 ) ;
358+ }
359+
360+ const configs = queries . map ( ( query ) => ( {
361+ ...createBaseQuery ( settings , "config" ) ,
362+ name : query . name ,
363+ query : query . query ,
364+ } ) ) ;
365+
366+ updateConnection ( {
367+ id : connection . id ,
368+ activeQuery : configs [ 0 ] . id ,
369+ queries : [ ...connection . queries , ...configs ] ,
370+ } ) ;
371+ }
372+
373+ datasetModalOpenHandle . close ( ) ;
374+ } ) ;
375+
328376 return (
329377 < >
330378 < SidebarToggle />
@@ -619,12 +667,17 @@ export function SurrealistToolbar() {
619667
620668 < Select
621669 placeholder = "Select a dataset"
622- value = "surreal-deal-store-mini"
670+ value = { dataset }
671+ onChange = { ( value ) => setDataset ( value || "" ) }
623672 data = { [
624673 {
625674 label : "Surreal Deal Store (Mini)" ,
626675 value : "surreal-deal-store-mini" ,
627676 } ,
677+ {
678+ label : "Surreal Start" ,
679+ value : "surreal-start" ,
680+ } ,
628681 ] }
629682 />
630683
@@ -641,10 +694,7 @@ export function SurrealistToolbar() {
641694 type = "submit"
642695 variant = "gradient"
643696 flex = { 1 }
644- onClick = { async ( ) => {
645- await applyDataset ( version ) ;
646- datasetModalOpenHandle . close ( ) ;
647- } }
697+ onClick = { handleApplyDataset }
648698 loading = { isDatasetLoading }
649699 >
650700 Apply
0 commit comments