feat: add copy-as-markdown and copy-as-json buttons to question card (#1305)
* feat: add copy-as-markdown and copy-as-json buttons to question card Adds two small icon buttons in the QuestionCard header so users can copy the full question payload (text, options, descriptions) to the clipboard in either Markdown or JSON form. Useful for forwarding interactive questions to an external LLM or note. - Markdown serialization preserves question headers, multi-select hints and option descriptions. - JSON serialization mirrors the on-wire QuestionRequest shape for programmatic reuse. - Toast feedback on success/failure using the shared @/components/ui wrapper and the existing copyTextToClipboard helper (clipboard API with execCommand fallback). - New i18n keys added across all 7 locales. * test: extract question serializers and cover with 15 unit tests The two serializers backing the copy-as-markdown and copy-as-json buttons on QuestionCard were defined as top-level consts inside QuestionCard.tsx. Exposing them for unit tests would trip the react-refresh/only-export-components ESLint rule because that file also exports the QuestionCard component. Move serializeQuestionAsMarkdown and serializeQuestionAsJson into a React-free sibling module, questionSerializers.ts, and re-import them from QuestionCard.tsx. Behavior is byte-identical. Add 15 unit tests via bun:test covering header fallback, multi-select hint gating, blank-description elision, ordering across multiple questions, JSON canonical shape (no transient id/sessionID), boolean normalisation, and the empty-questions edge case.
This commit is contained in:
@@ -1474,6 +1474,11 @@ export const dict = {
|
||||
'chat.questionCard.submit': 'Submit',
|
||||
'chat.questionCard.next': 'Next',
|
||||
'chat.questionCard.dismiss': 'Dismiss',
|
||||
'chat.questionCard.copyMarkdown': 'Copy as Markdown',
|
||||
'chat.questionCard.copyJson': 'Copy as JSON',
|
||||
'chat.questionCard.copiedMarkdown': 'Question copied as Markdown',
|
||||
'chat.questionCard.copiedJson': 'Question copied as JSON',
|
||||
'chat.questionCard.copyFailed': 'Failed to copy question',
|
||||
'chat.textSelection.toast.noProject': 'No project found for this session',
|
||||
'chat.textSelection.toast.addToNotesFailed': 'Failed to add to notes',
|
||||
'chat.textSelection.toast.addToNotesSuccess': 'Added distilled insight to notes',
|
||||
|
||||
@@ -1440,6 +1440,11 @@ export const dict: Record<I18nKey, string> = {
|
||||
"chat.questionCard.submit": "Enviar",
|
||||
"chat.questionCard.next": "Siguiente",
|
||||
"chat.questionCard.dismiss": "Descartar",
|
||||
"chat.questionCard.copyMarkdown": "Copiar como Markdown",
|
||||
"chat.questionCard.copyJson": "Copiar como JSON",
|
||||
"chat.questionCard.copiedMarkdown": "Pregunta copiada como Markdown",
|
||||
"chat.questionCard.copiedJson": "Pregunta copiada como JSON",
|
||||
"chat.questionCard.copyFailed": "No se pudo copiar la pregunta",
|
||||
"chat.textSelection.toast.noProject": "No se encontró proyecto para esta sesión",
|
||||
"chat.textSelection.toast.addToNotesFailed": "No se pudo añadir a las notas",
|
||||
"chat.textSelection.toast.addToNotesSuccess": "Se añadió la información destilada a notas",
|
||||
|
||||
@@ -1476,6 +1476,11 @@ export const dict: Record<I18nKey, string> = {
|
||||
'chat.questionCard.submit': '제출',
|
||||
'chat.questionCard.next': '다음',
|
||||
'chat.questionCard.dismiss': '닫기',
|
||||
'chat.questionCard.copyMarkdown': 'Markdown으로 복사',
|
||||
'chat.questionCard.copyJson': 'JSON으로 복사',
|
||||
'chat.questionCard.copiedMarkdown': '질문을 Markdown으로 복사했습니다',
|
||||
'chat.questionCard.copiedJson': '질문을 JSON으로 복사했습니다',
|
||||
'chat.questionCard.copyFailed': '질문 복사에 실패했습니다',
|
||||
'chat.textSelection.toast.noProject': '이 세션의 프로젝트를 찾을 수 없음',
|
||||
'chat.textSelection.toast.addToNotesFailed': '메모 추가 실패',
|
||||
'chat.textSelection.toast.addToNotesSuccess': '정리된 인사이트를 메모에 추가함',
|
||||
|
||||
@@ -521,6 +521,11 @@ export const dict: Record<I18nKey, string> = {
|
||||
'chat.questionCard.submit': 'Wyślij',
|
||||
'chat.questionCard.next': 'Następne',
|
||||
'chat.questionCard.dismiss': 'Odrzuć',
|
||||
'chat.questionCard.copyMarkdown': 'Kopiuj jako Markdown',
|
||||
'chat.questionCard.copyJson': 'Kopiuj jako JSON',
|
||||
'chat.questionCard.copiedMarkdown': 'Pytanie skopiowane jako Markdown',
|
||||
'chat.questionCard.copiedJson': 'Pytanie skopiowane jako JSON',
|
||||
'chat.questionCard.copyFailed': 'Nie udało się skopiować pytania',
|
||||
'chat.textSelection.toast.noProject': 'Nie znaleziono projektu dla tej sesji',
|
||||
'chat.textSelection.toast.addToNotesFailed': 'Nie udało się dodać do notatek',
|
||||
'chat.textSelection.toast.addToNotesSuccess': 'Dodano destylowaną wiedzę do notatek',
|
||||
|
||||
@@ -1440,6 +1440,11 @@ export const dict: Record<I18nKey, string> = {
|
||||
"chat.questionCard.submit": "Enviar",
|
||||
"chat.questionCard.next": "Próximo",
|
||||
"chat.questionCard.dismiss": "Descartar",
|
||||
"chat.questionCard.copyMarkdown": "Copiar como Markdown",
|
||||
"chat.questionCard.copyJson": "Copiar como JSON",
|
||||
"chat.questionCard.copiedMarkdown": "Pergunta copiada como Markdown",
|
||||
"chat.questionCard.copiedJson": "Pergunta copiada como JSON",
|
||||
"chat.questionCard.copyFailed": "Falha ao copiar a pergunta",
|
||||
"chat.textSelection.toast.noProject": "Não foi encontrado projeto para esta sessão",
|
||||
"chat.textSelection.toast.addToNotesFailed": "Não foi possível adicionar às notas",
|
||||
"chat.textSelection.toast.addToNotesSuccess": "Informação destilada adicionada às notas",
|
||||
|
||||
@@ -1440,6 +1440,11 @@ export const dict: Record<I18nKey, string> = {
|
||||
"chat.questionCard.submit": "Надіслати",
|
||||
"chat.questionCard.next": "Далі",
|
||||
"chat.questionCard.dismiss": "Відхилити",
|
||||
"chat.questionCard.copyMarkdown": "Скопіювати як Markdown",
|
||||
"chat.questionCard.copyJson": "Скопіювати як JSON",
|
||||
"chat.questionCard.copiedMarkdown": "Питання скопійовано як Markdown",
|
||||
"chat.questionCard.copiedJson": "Питання скопійовано як JSON",
|
||||
"chat.questionCard.copyFailed": "Не вдалося скопіювати питання",
|
||||
"chat.textSelection.toast.noProject": "Для цієї сесії не знайдено жодного проєкту",
|
||||
"chat.textSelection.toast.addToNotesFailed": "Не вдалося додати до нотаток",
|
||||
"chat.textSelection.toast.addToNotesSuccess": "Інсайт додано до нотаток",
|
||||
|
||||
@@ -1440,6 +1440,11 @@ export const dict: Record<I18nKey, string> = {
|
||||
'chat.questionCard.submit': '提交',
|
||||
'chat.questionCard.next': '下一个',
|
||||
'chat.questionCard.dismiss': '忽略',
|
||||
'chat.questionCard.copyMarkdown': '复制为 Markdown',
|
||||
'chat.questionCard.copyJson': '复制为 JSON',
|
||||
'chat.questionCard.copiedMarkdown': '问题已复制为 Markdown',
|
||||
'chat.questionCard.copiedJson': '问题已复制为 JSON',
|
||||
'chat.questionCard.copyFailed': '复制问题失败',
|
||||
'chat.textSelection.toast.noProject': '未找到此会话对应的项目',
|
||||
'chat.textSelection.toast.addToNotesFailed': '添加到笔记失败',
|
||||
'chat.textSelection.toast.addToNotesSuccess': '已将洞察添加到笔记',
|
||||
|
||||
Reference in New Issue
Block a user