Skip to content

Commit

Permalink
different copy for no answers
Browse files Browse the repository at this point in the history
  • Loading branch information
scazan committed Jun 28, 2024
1 parent 3c48f56 commit 281d703
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 17 deletions.
22 changes: 15 additions & 7 deletions src/components/Search/SearchAskAnswer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { atom, useRecoilState } from 'recoil';
import { Loading } from '@/components/primitives';
import { useLanguage } from '@/intl/client';
import { t } from '@/intl/translate';
import { TranslationLanguage } from '@/intl/translations';
import { iterateStreamResponse } from '@/lib/actions';
import { tcls } from '@/lib/tailwind';

import { AskAnswerResult, AskAnswerSource, streamAskQuestion } from './server-actions';
import { useSearch, useSearchLink } from './useSearch';
import { Link } from '../primitives';
import { TranslationLanguage } from '@/intl/translations';

/**
* Store the state of the answer in a global state so that it can be
Expand Down Expand Up @@ -112,8 +112,8 @@ export function SearchAskAnswer(props: { spaceId: string; query: string }) {
>
{state?.type === 'answer' ? (
<>
{state.answer?.body ? (
<div className={tcls('w-full')}>
{state.answer ? (
<div className={tcls('w-full pb-4')}>
<AnswerBody answer={state.answer} />
</div>
) : (
Expand Down Expand Up @@ -148,13 +148,18 @@ function AnswerBody(props: { answer: AskAnswerResult }) {
data-test="search-ask-answer"
className={tcls('mt-4', 'px-4', 'text-dark/9', 'dark:text-light/8')}
>
{answer.body}
{answer.hasAnswer ? answer.body : t(language, 'search_ask_no_answer')}
</div>
{answer.followupQuestions.length > 0 ? (
<AnswerFollowupQuestions followupQuestions={answer.followupQuestions} />
) : null}
{answer.sources.length > 0 ? (
<AnswerSources sources={answer.sources} language={language} onClose={onClose} />
<AnswerSources
hasAnswer={answer.hasAnswer}
sources={answer.sources}
language={language}
onClose={onClose}
/>
) : null}
</>
);
Expand Down Expand Up @@ -208,8 +213,9 @@ function AnswerSources(props: {
sources: AskAnswerSource[];
language: TranslationLanguage;
onClose: () => void;
hasAnswer?: boolean;
}) {
const { sources, onClose, language } = props;
const { sources, onClose, language, hasAnswer } = props;

return (
<div
Expand All @@ -225,7 +231,9 @@ function AnswerSources(props: {
'dark:border-light/1',
)}
>
<span className={tcls('text-sm')}>{t(language, 'search_ask_sources')}</span>
<span className={tcls('text-sm')}>
{t(language, hasAnswer ? 'search_ask_sources' : 'search_ask_sources_no_answer')}
</span>

{sources.map((source) => (
<span key={source.id} className={tcls()}>
Expand Down
4 changes: 3 additions & 1 deletion src/components/Search/server-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface AskAnswerResult {
body?: React.ReactNode;
followupQuestions: string[];
sources: AskAnswerSource[];
hasAnswer: boolean;
}

/**
Expand Down Expand Up @@ -141,7 +142,7 @@ function transformAnswer(
return null;
}

const hasAnswer = 'document' in answer.answer;
const hasAnswer = answer.answer && 'document' in answer.answer;

const sources = answer.sources
.map((source) => {
Expand Down Expand Up @@ -177,6 +178,7 @@ function transformAnswer(
) : null,
followupQuestions: answer.followupQuestions,
sources,
hasAnswer,
};
}

Expand Down
10 changes: 7 additions & 3 deletions src/intl/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export const de = {
search_scope_all: 'Alle Inhalte',
search_ask: 'Fragen "${1}"',
search_ask_sources: 'Quellen',
search_ask_no_answer: 'Es konnte keine Antwort auf Ihre Frage gefunden werden, versuchen Sie es mit einer anderen Frage.',
search_ask_sources_no_answer: 'Verwandte Seiten',
search_ask_no_answer:
'Es konnte keine Antwort auf Ihre Frage gefunden werden. Versuchen Sie, sie umzuformulieren oder genauer zu sein.',
search_ask_error: 'Etwas ist schief gelaufen. Bitte versuchen Sie es später noch einmal.',
on_this_page: 'Auf dieser Seite',
next_page: 'Nächste',
Expand All @@ -39,14 +41,16 @@ export const de = {
notfound_title: 'Seite nicht gefunden',
notfound: 'Die gesuchte Seite existiert nicht.',
unexpected_error_title: 'Ein Fehler ist aufgetreten',
unexpected_error: 'Entschuldigung, ein unerwarteter Fehler ist aufgetreten. Bitte versuchen Sie es später erneut.',
unexpected_error:
'Entschuldigung, ein unerwarteter Fehler ist aufgetreten. Bitte versuchen Sie es später erneut.',
unexpected_error_retry: 'Erneut versuchen',
pdf_download: 'Als PDF exportieren',
pdf_goback: 'Zurück zum Inhalt',
pdf_print: 'Drucken oder als PDF speichern',
pdf_page_of: '${1} von ${2}',
pdf_mode_only_page: 'Nur diese Seite',
pdf_mode_all: 'Alle Seiten',
pdf_limit_reached: 'Das PDF konnte für ${1} Seiten nicht generiert werden, Generierung wurde bei ${2} gestoppt.',
pdf_limit_reached:
'Das PDF konnte für ${1} Seiten nicht generiert werden, Generierung wurde bei ${2} gestoppt.',
pdf_limit_reached_continue: 'Mit ${1} weiteren Seiten erweitern.',
};
4 changes: 3 additions & 1 deletion src/intl/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export const en = {
search_scope_all: 'All the content',
search_ask: 'Ask "${1}"',
search_ask_sources: 'Sources',
search_ask_no_answer: 'No answer could be found for your question, try with another one.',
search_ask_sources_no_answer: 'Related pages',
search_ask_no_answer:
'No answer could be found for your question. You could try rephrasing it, or be more specific.',
search_ask_error: 'Something went wrong. Please try again later.',
on_this_page: 'On this page',
next_page: 'Next',
Expand Down
4 changes: 3 additions & 1 deletion src/intl/translations/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export const es: TranslationLanguage = {
search_scope_all: 'Todo el contenido',
search_ask: 'Preguntar "${1}"',
search_ask_sources: 'Fuentes',
search_ask_no_answer: 'No se pudo encontrar una respuesta a tu pregunta, intenta con otra.',
search_ask_sources_no_answer: 'Páginas relacionadas',
search_ask_no_answer:
'No se pudo encontrar una respuesta para su pregunta. Puede intentar reformularla o ser más específico.',
search_ask_error: 'Algo salió mal. Por favor, inténtalo de nuevo más tarde.',
on_this_page: 'En esta página',
next_page: 'Siguiente',
Expand Down
4 changes: 3 additions & 1 deletion src/intl/translations/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export const fr: TranslationLanguage = {
search_scope_all: 'Tout le contenu',
search_ask: 'Demander "${1}"',
search_ask_sources: 'Sources',
search_ask_no_answer: 'Aucune réponse trouvée à votre question, essayez-en une autre.',
search_ask_sources_no_answer: 'Pages connexes',
search_ask_no_answer:
"Aucune réponse n'a pu être trouvée pour votre question.Vous pourriez essayer de la reformuler ou d'être plus précis",
search_ask_error: 'Quelque chose a mal fonctionné. Veuillez réessayer plus tard.',
on_this_page: 'Sur cette page',
next_page: 'Suivant',
Expand Down
3 changes: 2 additions & 1 deletion src/intl/translations/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export const ja: TranslationLanguage = {
search_scope_all: '全てのコンテンツ',
search_ask: '"${1}" を質問する',
search_ask_sources: '情報源',
search_ask_sources_no_answer: '関連ページ',
search_ask_no_answer:
'ご質問に答えられる答えが見つかりませんでした、他の質問を試してください。',
'ご質問への回答が見つかりませんでした。質問を言い換えるか、もう少し具体的にしてください。',
search_ask_error: '何らかのエラーが発生しました。後ほど再度お試しください。',
on_this_page: 'このページ内',
next_page: '次へ',
Expand Down
3 changes: 2 additions & 1 deletion src/intl/translations/pt-br.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export const pt_br = {
search_scope_all: 'Todo o conteúdo',
search_ask: 'Perguntar "${1}"',
search_ask_sources: 'Fontes',
search_ask_sources_no_answer: 'Páginas relacionadas',
search_ask_no_answer:
'Nenhuma resposta foi encontrada para sua pergunta, tente outra pergunta.',
'Não foi possível encontrar uma resposta para sua pergunta. Você pode tentar reformulá-la ou ser mais específico.',
search_ask_error: 'Algo deu errado. Por favor tente novamente mais tarde.',
on_this_page: 'Nesta página',
next_page: 'Próximo',
Expand Down
3 changes: 2 additions & 1 deletion src/intl/translations/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export const zh: TranslationLanguage = {
search_scope_all: '所有内容',
search_ask: '询问"${1}"',
search_ask_sources: '来源',
search_ask_no_answer: '找不到您的问题的答案,请尝试另一个问题。',
search_ask_sources_no_answer: '相关页面',
search_ask_no_answer: '无法找到您的问题的答案。您可以尝试改述问题或提供更具体的信息。',
search_ask_error: '出了些问题。请稍后再试。',
on_this_page: '在本页',
next_page: '下一页',
Expand Down

0 comments on commit 281d703

Please sign in to comment.