Skip to content

Commit

Permalink
web(explore): adapt stream json (pingcap#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
634750802 committed Feb 8, 2023
1 parent 3645097 commit d6d4675
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
30 changes: 15 additions & 15 deletions web/src/pages/explore/_components/SqlSection/AIMessages.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Question, QuestionErrorType } from '@site/src/api/explorer';
import { Question, QuestionErrorType, QuestionStatus } from '@site/src/api/explorer';
import React, { cloneElement, ReactElement, ReactNode, useEffect, useMemo, useState } from 'react';
import { isNullish, notFalsy } from '@site/src/utils/value';
import { notNone } from '@site/src/pages/explore/_components/SqlSection/utils';
Expand Down Expand Up @@ -57,7 +57,7 @@ export default function AIMessages<TitleLineArgs extends any[]> ({ question, has
},
{
key: 'rq',
show: !notNone(question?.combinedTitle) && notNone(question?.revisedTitle),
show: question?.status !== QuestionStatus.AnswerGenerating && !notNone(question?.combinedTitle) && notNone(question?.revisedTitle),
content: (
<Line>
- Seems like you are asking about&nbsp;
Expand All @@ -84,21 +84,21 @@ export default function AIMessages<TitleLineArgs extends any[]> ({ question, has
},
{
key: 'tips',
show: question?.errorType !== QuestionErrorType.SQL_CAN_NOT_ANSWER,
show: notNone(question?.combinedTitle) && question?.errorType !== QuestionErrorType.SQL_CAN_NOT_ANSWER,
content: (
<Line fontSize="14px" fontWeight="normal">- You can copy and revise it based on the question above 👆.</Line>
),
},
{
key: 'status',
show: true,
show: hasPrompt,
content: (...titleLineDeps: TitleLineArgs) => (
<Line mt={2}>
{titleLine(...titleLineDeps)}
</Line>
),
},
].filter(item => item.show), [question?.revisedTitle, question?.combinedTitle, question?.notClear, question?.assumption, question?.errorType]);
].filter(item => item.show), [question?.status, question?.revisedTitle, question?.combinedTitle, question?.notClear, question?.assumption, question?.errorType]);

const whenMounted = useWhenMounted();

Expand All @@ -107,23 +107,23 @@ export default function AIMessages<TitleLineArgs extends any[]> ({ question, has
onReady?.();
return;
}
let index = 1;
setIndex(1);
const h = setInterval(() => {
setIndex(index + 1);
index += 1;
if (index >= messages.length) {
let internalIndex = index + 1;
setIndex(internalIndex);
const h = setInterval(whenMounted(() => {
setIndex(internalIndex + 1);
internalIndex += 1;
if (internalIndex >= messages.length) {
setTimeout(whenMounted(() => {
onReady?.();
}), 600);
clearInterval(h);
}
}, 600);
}), 600);
onStart?.();
return () => {
clearInterval(h);
};
}, [messages, hasPrompt]);
}, [messages.length, hasPrompt]);

const botMessages = useMemo(() => {
if (hasPrompt) {
Expand All @@ -132,7 +132,7 @@ export default function AIMessages<TitleLineArgs extends any[]> ({ question, has
const childContent = cloneElement(el, {
children: (
<>
<Indicator bot={i === 0} animated={index < messages.length} show={i < messages.length - 1} />
<Indicator bot={i === 0} animated={question?.status === QuestionStatus.AnswerGenerating || index < messages.length} show={i < messages.length - 1} />
{el.props.children}
</>
),
Expand All @@ -146,7 +146,7 @@ export default function AIMessages<TitleLineArgs extends any[]> ({ question, has
} else {
return [];
}
}, [messages, hasPrompt, index, ...titleLineDeps]);
}, [messages.length, question?.status, hasPrompt, index, ...titleLineDeps]);

return (
<TransitionGroup component={AIMessagesRoot}>
Expand Down
16 changes: 11 additions & 5 deletions web/src/pages/explore/_components/useQuestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,15 @@ export function isEmptyResult (question: Question) {
}

export function hasAIPrompts (question: Question) {
return (
notNone(question.revisedTitle) ||
notNone(question.combinedTitle) ||
notNone(question.notClear)
);
if (question.status === QuestionStatus.AnswerGenerating) {
// RQ are generate first
return notNone(question.combinedTitle) || notNone(question.notClear);
} else {
// For previous questions without CQ
return (
notNone(question.revisedTitle) ||
notNone(question.combinedTitle) ||
notNone(question.notClear)
);
}
}

0 comments on commit d6d4675

Please sign in to comment.