From b0a4819ec1f1632e9df1c3098948ff3a0ab6d4de Mon Sep 17 00:00:00 2001 From: twwu Date: Fri, 6 Dec 2024 18:20:59 +0800 Subject: [PATCH] feat: enhance translations and UI components for segment management --- .../documents/detail/completed/index.tsx | 8 +- .../detail/completed/segment-card.tsx | 2 +- .../detail/completed/segment-detail.tsx | 8 +- .../detail/completed/segment-list.tsx | 2 +- .../documents/detail/new-segment-modal.tsx | 153 +++++++++++++----- web/i18n/en-US/dataset-documents.ts | 5 +- web/i18n/zh-Hans/dataset-documents.ts | 1 + 7 files changed, 127 insertions(+), 52 deletions(-) diff --git a/web/app/components/datasets/documents/detail/completed/index.tsx b/web/app/components/datasets/documents/detail/completed/index.tsx index a117367468..713b421398 100644 --- a/web/app/components/datasets/documents/detail/completed/index.tsx +++ b/web/app/components/datasets/documents/detail/completed/index.tsx @@ -48,7 +48,7 @@ export const useSegmentListContext = (selector: (value: SegmentListContextValue) return useContextSelector(SegmentListContext, selector) } -export const SegmentIndexTag: FC<{ positionId: string | number; className?: string }> = ({ positionId, className }) => { +export const SegmentIndexTag: FC<{ positionId?: string | number; label?: string; className?: string }> = ({ positionId, label, className }) => { const localPositionId = useMemo(() => { const positionIdStr = String(positionId) if (positionIdStr.length >= 3) @@ -59,7 +59,7 @@ export const SegmentIndexTag: FC<{ positionId: string | number; className?: stri
- {localPositionId} + {label || localPositionId}
) @@ -305,6 +305,7 @@ const Completed: FC = ({ fullScreen, toggleFullScreen, }}> + {/* Menu Bar */} {!isFullDocMode &&
= ({
} + {/* Segment list */} { isFullDocMode ?
@@ -378,12 +380,14 @@ const Completed: FC = ({ onCancel={onCloseDrawer} /> + {/* Create New Segment */} onNewSegmentModalChange(false)} onSave={resetList} /> + {/* Batch Action Buttons */} {selectedSegmentIds.length > 0 && = ({ return (
diff --git a/web/app/components/datasets/documents/detail/completed/segment-detail.tsx b/web/app/components/datasets/documents/detail/completed/segment-detail.tsx index 80c7c0077d..03d0b499d5 100644 --- a/web/app/components/datasets/documents/detail/completed/segment-detail.tsx +++ b/web/app/components/datasets/documents/detail/completed/segment-detail.tsx @@ -137,7 +137,7 @@ const SegmentDetail: FC = ({ const renderKeywords = () => { return ( -
+
{t('datasetDocuments.segment.keywords')}
{!segInfo?.keywords?.length @@ -162,7 +162,7 @@ const SegmentDetail: FC = ({
{isEditMode ? 'Edit Chunk' : 'Chunk Detail'}
- + · {formatNumber(segInfo?.word_count as number)} {t('datasetDocuments.segment.characters')}
@@ -182,8 +182,8 @@ const SegmentDetail: FC = ({
-
-
+
+
{renderContent()}
{renderKeywords()} diff --git a/web/app/components/datasets/documents/detail/completed/segment-list.tsx b/web/app/components/datasets/documents/detail/completed/segment-list.tsx index e305841191..485f70ea8e 100644 --- a/web/app/components/datasets/documents/detail/completed/segment-list.tsx +++ b/web/app/components/datasets/documents/detail/completed/segment-list.tsx @@ -45,7 +45,7 @@ const SegmentList: FC = ({ checked={selectedSegmentIds.includes(segItem.id)} onCheck={() => onSelected(segItem.id)} /> -
+
= ({ const { notify } = useContext(ToastContext) const [question, setQuestion] = useState('') const [answer, setAnswer] = useState('') - const { datasetId, documentId } = useParams() + const { datasetId, documentId } = useParams<{ datasetId: string; documentId: string }>() const [keywords, setKeywords] = useState([]) const [loading, setLoading] = useState(false) + const [fullScreen, toggleFullScreen] = useSegmentListContext(s => [s.fullScreen, s.toggleFullScreen]) const handleCancel = () => { + onCancel() setQuestion('') setAnswer('') - onCancel() setKeywords([]) } @@ -74,6 +80,17 @@ const NewSegmentModal: FC = ({ } } + useKeyPress(['esc'], (e) => { + e.preventDefault() + handleCancel() + }) + + useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.s`, (e) => { + e.preventDefault() + handleSave() + } + , { exactMatch: true, useCapture: true }) + const renderContent = () => { if (docForm === 'qa_model') { return ( @@ -101,7 +118,7 @@ const NewSegmentModal: FC = ({ return ( setQuestion(e.target.value)} @@ -110,46 +127,98 @@ const NewSegmentModal: FC = ({ ) } - return ( - { }} className='pt-8 px-8 pb-6 !max-w-[640px] !rounded-xl'> -
-
-
- + const renderActionButtons = () => { + return ( +
+
-
- - - - { - docForm === 'qa_model' - ? t('datasetDocuments.segment.newQaSegment') - : t('datasetDocuments.segment.newTextSegment') - } - - -
-
{renderContent()}
-
{t('datasetDocuments.segment.keywords')}
-
+ + +
+ ) + } + + const renderKeywords = () => { + return ( +
+
{t('datasetDocuments.segment.keywords')}
+
setKeywords(newKeywords)} />
-
- - -
- + ) + } + + return ( + {}} + panelClassname={`!p-0 ${fullScreen + ? '!max-w-full !w-full' + : 'mt-16 mr-2 mb-2 !max-w-[560px] !w-[560px] border-[0.5px] border-components-panel-border rounded-xl'}`} + mask={false} + unmount + footer={null} + > +
+
+
+
{ + docForm === 'qa_model' + ? t('datasetDocuments.segment.newQaSegment') + : t('datasetDocuments.segment.addChunk') + }
+
+ + · + {formatNumber(question.length)} {t('datasetDocuments.segment.characters')} +
+
+
+ {fullScreen && ( + <> + {renderActionButtons()} + + + )} +
+ +
+
+ +
+
+
+
+
+ {renderContent()} +
+ {renderKeywords()} +
+ {!fullScreen && ( +
+ {renderActionButtons()} +
+ )} +
+
) } diff --git a/web/i18n/en-US/dataset-documents.ts b/web/i18n/en-US/dataset-documents.ts index df26449dc3..a0bcb5bba0 100644 --- a/web/i18n/en-US/dataset-documents.ts +++ b/web/i18n/en-US/dataset-documents.ts @@ -340,14 +340,15 @@ const translation = { characters: 'characters', hitCount: 'Retrieval count', vectorHash: 'Vector hash: ', - questionPlaceholder: 'add question here', + questionPlaceholder: 'Add question here', questionEmpty: 'Question can not be empty', - answerPlaceholder: 'add answer here', + answerPlaceholder: 'Add answer here', answerEmpty: 'Answer can not be empty', contentPlaceholder: 'Add content here', contentEmpty: 'Content can not be empty', newTextSegment: 'New Text Segment', newQaSegment: 'New Q&A Segment', + addChunk: 'Add Chunk', delete: 'Delete this chunk ?', }, } diff --git a/web/i18n/zh-Hans/dataset-documents.ts b/web/i18n/zh-Hans/dataset-documents.ts index 35288c04d6..355c4bee7f 100644 --- a/web/i18n/zh-Hans/dataset-documents.ts +++ b/web/i18n/zh-Hans/dataset-documents.ts @@ -346,6 +346,7 @@ const translation = { contentEmpty: '内容不能为空', newTextSegment: '新文本分段', newQaSegment: '新问答分段', + addChunk: '新增分段', delete: '删除这个分段?', }, }