From 33312538e11c7f89df33606465cf5fcddfae1844 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Fri, 9 May 2025 15:30:04 -0600 Subject: [PATCH] Warning for setup --- .../ui/inputs/InputTextAreaButton.tsx | 2 +- web/src/controllers/HomePage/NewChatInput.tsx | 39 +++-- .../controllers/HomePage/NewChatWarning.tsx | 139 ++++++++++++++++++ .../controllers/HomePage/useNewChatWarning.ts | 23 +++ 4 files changed, 188 insertions(+), 15 deletions(-) create mode 100644 web/src/controllers/HomePage/NewChatWarning.tsx create mode 100644 web/src/controllers/HomePage/useNewChatWarning.ts diff --git a/web/src/components/ui/inputs/InputTextAreaButton.tsx b/web/src/components/ui/inputs/InputTextAreaButton.tsx index 081a3f399..f2886033d 100644 --- a/web/src/components/ui/inputs/InputTextAreaButton.tsx +++ b/web/src/components/ui/inputs/InputTextAreaButton.tsx @@ -64,7 +64,7 @@ export const InputTextAreaButton = forwardRef diff --git a/web/src/controllers/HomePage/NewChatInput.tsx b/web/src/controllers/HomePage/NewChatInput.tsx index c68d2a076..31f911016 100644 --- a/web/src/controllers/HomePage/NewChatInput.tsx +++ b/web/src/controllers/HomePage/NewChatInput.tsx @@ -6,6 +6,9 @@ import { useBusterNewChatContextSelector } from '@/context/Chats'; import { inputHasText } from '@/lib/text'; import { useMemoizedFn, useMount } from '@/hooks'; import { ChangeEvent, useMemo, useState } from 'react'; +import { useGetDatasets } from '@/api/buster_rest'; +import { NewChatWarning } from './NewChatWarning'; +import { useNewChatWarning } from './useNewChatWarning'; const autoResizeConfig = { minRows: 3, @@ -17,10 +20,12 @@ export const NewChatInput: React.FC<{}> = () => { const [inputValue, setInputValue] = useState(''); const [loading, setLoading] = useState(false); const textAreaRef = useRef(null); + const newChatWarningProps = useNewChatWarning(); + const { showWarning } = newChatWarningProps; const disabledSubmit = useMemo(() => { - return !inputHasText(inputValue); - }, [inputValue]); + return !inputHasText(inputValue) || showWarning; + }, [inputValue, showWarning]); const onSubmit = useMemoizedFn(async (value: string) => { if (disabledSubmit) return; @@ -49,17 +54,23 @@ export const NewChatInput: React.FC<{}> = () => { }); return ( - +
+ + {newChatWarningProps.showWarning && } +
); }; diff --git a/web/src/controllers/HomePage/NewChatWarning.tsx b/web/src/controllers/HomePage/NewChatWarning.tsx new file mode 100644 index 000000000..51dd2ab21 --- /dev/null +++ b/web/src/controllers/HomePage/NewChatWarning.tsx @@ -0,0 +1,139 @@ +import { useGetDatasets } from '@/api/buster_rest'; +import { useGetDatasource, useListDatasources } from '@/api/buster_rest/data_source'; +import { cn } from '@/lib/classMerge'; +import React, { useMemo } from 'react'; +import { useNewChatWarning } from './useNewChatWarning'; +import { ArrowUpRight, CircleCheck, CircleXmark } from '@/components/ui/icons'; +import { Paragraph, Text } from '@/components/ui/typography'; +import { Button } from '@/components/ui/buttons'; +import Link from 'next/link'; + +export const NewChatWarning = React.memo(({}: ReturnType) => { + const hasDatasources = true; + const hasDatasets = false; + const allCompleted = hasDatasets && hasDatasources; + const progress = [hasDatasources, hasDatasets].filter(Boolean).length; + const progressPercentage = (progress / 2) * 100; + + return ( +
+
+ Setup Checklist +
+
{progress}/2 completed
+
+
+
+
+
+ +
+ + + +
+ +
+
+ {allCompleted ? ( + + ) : ( +
+ )} +
+
+ + {allCompleted + ? "You're all set! Ask questions to get answers from your data." + : 'Complete both steps to start querying your information.'} + + + {allCompleted + ? ' Your data is ready to be explored.' + : " Without proper setup, we can't retrieve relevant information."} + +
+
+
+ ); +}); + +interface SetupItemProps { + number: string; + status: boolean; + title: string; + description: string; + link?: string; + linkText?: string; +} + +const SetupItem = ({ number, status, title, description, link, linkText }: SetupItemProps) => { + return ( +
+
+ {status ? : number} +
+ +
+
+ {title} + {status && ( + + Complete + + )} +
+ + {description} + + {link && ( + + + + )} +
+
+ ); +}; diff --git a/web/src/controllers/HomePage/useNewChatWarning.ts b/web/src/controllers/HomePage/useNewChatWarning.ts new file mode 100644 index 000000000..8cddb5249 --- /dev/null +++ b/web/src/controllers/HomePage/useNewChatWarning.ts @@ -0,0 +1,23 @@ +import { useGetDatasets } from '@/api/buster_rest'; +import { useListDatasources } from '@/api/buster_rest/data_source'; +import { useMemo } from 'react'; + +export const useNewChatWarning = () => { + const { data: datasets, isFetched: isDatasetsFetched } = useGetDatasets(); + const { data: datasources, isFetched: isDatasourcesFetched } = useListDatasources(); + + const showWarning = useMemo(() => { + return true; + if (!isDatasetsFetched || !isDatasourcesFetched) return false; + if (datasets?.length === 0) return true; + if (datasources?.length === 0) return true; + return false; + }, [datasets, datasources, isDatasetsFetched, isDatasourcesFetched]); + + return { + showWarning, + hasDatasets: datasets?.length > 0, + hasDatasources: datasources?.length > 0, + isFetched: isDatasetsFetched && isDatasourcesFetched + }; +};