Skip to content

Commit

Permalink
feat(wren-ui): Click recommended questions to go to thread creation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fredalai authored Nov 28, 2024
1 parent 80a2cc8 commit 611054b
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 36 deletions.
9 changes: 7 additions & 2 deletions wren-ui/src/components/pages/home/RecommendedQuestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import {
RecommendedQuestionsTaskStatus,
} from '@/apollo/client/graphql/__types__';

export interface SelectQuestionProps {
question: string;
sql: string;
}

interface Props {
items: { question: string; sql: string }[];
loading?: boolean;
Expand All @@ -19,7 +24,7 @@ interface Props {
stacktrace?: string[];
};
className?: string;
onSelect?: ({ question, sql }: { question: string; sql: string }) => void;
onSelect: ({ question, sql }: SelectQuestionProps) => void;
}

const StyledSkeleton = styled(Skeleton)`
Expand Down Expand Up @@ -59,7 +64,7 @@ const QuestionItem = (props: {
index: number;
question: string;
sql: string;
onSelect?: ({ question, sql }: { question: string; sql: string }) => void;
onSelect: ({ question, sql }: SelectQuestionProps) => void;
}) => {
const { index, question, sql, onSelect } = props;
return (
Expand Down
2 changes: 1 addition & 1 deletion wren-ui/src/components/pages/home/prompt/DemoPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const DemoBlock = styled.div`

interface Props {
demo: any[];
onSelect: (data: any) => void;
onSelect: (data: { label: string; question: string }) => void;
}

const DemoTemplate = ({ label, question, onSelect }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import MinusOutlined from '@ant-design/icons/MinusOutlined';
import EllipsisWrapper from '@/components/EllipsisWrapper';
import { Logo } from '@/components/Logo';
import { makeIterable } from '@/utils/iteration';
import { GroupedQuestion } from '@/hooks/useRecommendedQuestionsInstruction';

const CategorySectionBlock = styled.div`
background: var(--gray-1);
Expand All @@ -27,6 +28,11 @@ const QuestionBlock = styled.div`

const MAX_EXPANDED_QUESTIONS = 9;

interface Props {
onSelect: (payload: { sql: string; question: string }) => void;
recommendedQuestions: GroupedQuestion[];
}

const QuestionTemplate = ({ category, sql, question, onSelect }) => {
return (
<Col span={8}>
Expand All @@ -47,7 +53,7 @@ const QuestionTemplate = ({ category, sql, question, onSelect }) => {

const QuestionColumnIterator = makeIterable(QuestionTemplate);

export default function RecommendedQuestionsPrompt(props) {
export default function RecommendedQuestionsPrompt(props: Props) {
const { onSelect, recommendedQuestions } = props;

const [isExpanded, setIsExpanded] = useState<boolean>(false);
Expand Down
10 changes: 5 additions & 5 deletions wren-ui/src/components/pages/home/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import {
AskingTask,
AskingTaskStatus,
AskingTaskType,
CreateThreadInput,
CreateThreadResponseInput,
} from '@/apollo/client/graphql/__types__';

interface Props {
onSelect: (payload: {
sql?: string;
question?: string;
viewId?: number;
}) => Promise<void>;
onSelect: (
payload: CreateThreadInput | CreateThreadResponseInput,
) => Promise<void>;
onStop: () => void;
onSubmit: (value: string) => Promise<void>;
onStopPolling: () => void;
Expand Down
45 changes: 33 additions & 12 deletions wren-ui/src/components/pages/home/promptThread/AnswerResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ const QuestionTitle = (props) => {
);
};

const renderRecommendedQuestions = (
isLastThreadResponse: boolean,
recommendedQuestionProps,
onSelect: RecommendedQuestionsProps['onSelect'],
) => {
if (!isLastThreadResponse || !recommendedQuestionProps.show) return null;

return (
<RecommendedQuestions
className="mt-5 mb-4"
{...recommendedQuestionProps.state}
onSelect={onSelect}
/>
);
};

export default function AnswerResult(props: Props) {
const {
motion,
Expand Down Expand Up @@ -92,12 +108,19 @@ export default function AnswerResult(props: Props) {
<div style={resultStyle} className="adm-answer-result">
<QuestionTitle className="mb-9" question={question} />
{error ? (
<Alert
message={error.shortMessage}
description={error.message}
type="error"
showIcon
/>
<>
<Alert
message={error.shortMessage}
description={error.message}
type="error"
showIcon
/>
{renderRecommendedQuestions(
isLastThreadResponse,
recommendedQuestionProps,
recommendedQuestionsProps.onSelect,
)}
</>
) : (
<StyledSkeleton active loading={loading}>
<div className={clsx({ 'promptThread-answer': motion })}>
Expand Down Expand Up @@ -150,12 +173,10 @@ export default function AnswerResult(props: Props) {
Save as View
</Button>
)}
{isLastThreadResponse && recommendedQuestionProps.show && (
<RecommendedQuestions
className="mt-5 mb-4"
{...recommendedQuestionProps.state}
onSelect={recommendedQuestionsProps.onSelect}
/>
{renderRecommendedQuestions(
isLastThreadResponse,
recommendedQuestionProps,
recommendedQuestionsProps.onSelect,
)}
</div>
</StyledSkeleton>
Expand Down
12 changes: 2 additions & 10 deletions wren-ui/src/components/pages/home/promptThread/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import {
RecommendedQuestionsTask,
ThreadResponse,
} from '@/apollo/client/graphql/__types__';

interface SelectQuestionProps {
question: string;
sql: string;
}
import { SelectQuestionProps } from '@/components/pages/home/RecommendedQuestions';

export interface RecommendedQuestionsProps {
data: RecommendedQuestionsTask;
Expand Down Expand Up @@ -61,11 +57,7 @@ const AnswerResultTemplate: React.FC<
motion: boolean;
onOpenSaveAsViewModal: (data: { sql: string; responseId: number }) => void;
onInitPreviewDone: () => void;
recommendedQuestionsProps: {
data: RecommendedQuestionsTask;
show: boolean;
onSelect: ({ question, sql }: SelectQuestionProps) => void;
};
recommendedQuestionsProps: RecommendedQuestionsProps;
}
> = ({
data,
Expand Down
3 changes: 1 addition & 2 deletions wren-ui/src/hooks/useRecommendedQuestionsInstruction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
useGenerateProjectRecommendationQuestionsMutation,
} from '@/apollo/client/graphql/home.generated';

interface GroupedQuestion {
export interface GroupedQuestion {
category: string;
question: string;
sql: string;
Expand Down Expand Up @@ -125,7 +125,6 @@ export default function useRecommendedQuestionsInstruction() {
};

if (showRecommendedQuestionsPromptMode && isRegenerate) {
// The cost of generating recommend questions is too high, so we still return button pops, but the button will not show on the UI now.
return {
...baseProps,
icon: <ReloadOutlined />,
Expand Down
3 changes: 2 additions & 1 deletion wren-ui/src/pages/home/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
useGetThreadRecommendationQuestionsLazyQuery,
} from '@/apollo/client/graphql/home.generated';
import { useCreateViewMutation } from '@/apollo/client/graphql/view.generated';
import { CreateThreadResponseInput } from '@/apollo/client/graphql/__types__';

export default function HomeThread() {
const $prompt = useRef<ComponentRef<typeof Prompt>>(null);
Expand Down Expand Up @@ -152,7 +153,7 @@ export default function HomeThread() {
[thread, recommendedQuestions, showRecommendedQuestions],
);

const onSelect = async (payload) => {
const onSelect = async (payload: CreateThreadResponseInput) => {
try {
askPrompt.onStopPolling();
const response = await createThreadResponse({
Expand Down
5 changes: 3 additions & 2 deletions wren-ui/src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
useGenerateThreadRecommendationQuestionsMutation,
} from '@/apollo/client/graphql/home.generated';
import { useGetSettingsQuery } from '@/apollo/client/graphql/settings.generated';
import { CreateThreadInput } from '@/apollo/client/graphql/__types__';

const { Text } = Typography;

Expand Down Expand Up @@ -120,7 +121,7 @@ export default function Home() {
$prompt.current.submit();
};

const onSelect = async (payload) => {
const onSelect = async (payload: CreateThreadInput) => {
try {
askPrompt.onStopPolling();
const response = await createThread({ variables: { data: payload } });
Expand All @@ -143,7 +144,7 @@ export default function Home() {
)}

{!isSampleDataset && (
<RecommendedQuestionsInstruction onSelect={onSelectQuestion} />
<RecommendedQuestionsInstruction onSelect={onSelect} />
)}
<Prompt ref={$prompt} {...askPrompt} onSelect={onSelect} />
</SiderLayout>
Expand Down

0 comments on commit 611054b

Please sign in to comment.