feat: preview parent child chunk in create step 2
This commit is contained in:
parent
6748b50bf1
commit
07f0140d10
@ -20,6 +20,8 @@ import { PreviewContainer } from '../../preview/container'
|
|||||||
import { ChunkContainer, QAPreview } from '../../chunk'
|
import { ChunkContainer, QAPreview } from '../../chunk'
|
||||||
import { PreviewHeader } from '../../preview/header'
|
import { PreviewHeader } from '../../preview/header'
|
||||||
import DocumentPicker from '../../common/document-picker'
|
import DocumentPicker from '../../common/document-picker'
|
||||||
|
import { FormattedText } from '../../formatted-text/formatted'
|
||||||
|
import { PreviewSlice } from '../../formatted-text/flavours/preview-slice'
|
||||||
import s from './index.module.css'
|
import s from './index.module.css'
|
||||||
import unescape from './unescape'
|
import unescape from './unescape'
|
||||||
import escape from './escape'
|
import escape from './escape'
|
||||||
@ -171,6 +173,11 @@ const StepTwo = ({
|
|||||||
const [docForm, setDocForm] = useState<ChuckingMode>(
|
const [docForm, setDocForm] = useState<ChuckingMode>(
|
||||||
(datasetId && documentDetail) ? documentDetail.doc_form as ChuckingMode : ChuckingMode.text,
|
(datasetId && documentDetail) ? documentDetail.doc_form as ChuckingMode : ChuckingMode.text,
|
||||||
)
|
)
|
||||||
|
const handleChangeDocform = (value: ChuckingMode) => {
|
||||||
|
setDocForm(value)
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||||
|
currentEstimateMutation.reset()
|
||||||
|
}
|
||||||
|
|
||||||
const [docLanguage, setDocLanguage] = useState<string>(
|
const [docLanguage, setDocLanguage] = useState<string>(
|
||||||
(datasetId && documentDetail) ? documentDetail.doc_language : (locale !== LanguagesSupported[1] ? 'English' : 'Chinese'),
|
(datasetId && documentDetail) ? documentDetail.doc_language : (locale !== LanguagesSupported[1] ? 'English' : 'Chinese'),
|
||||||
@ -498,7 +505,8 @@ const StepTwo = ({
|
|||||||
const changeToEconomicalType = () => {
|
const changeToEconomicalType = () => {
|
||||||
if (!hasSetIndexType) {
|
if (!hasSetIndexType) {
|
||||||
setIndexType(IndexingType.ECONOMICAL)
|
setIndexType(IndexingType.ECONOMICAL)
|
||||||
setDocForm(ChuckingMode.text)
|
if (docForm === ChuckingMode.qa)
|
||||||
|
handleChangeDocform(ChuckingMode.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -514,11 +522,6 @@ const StepTwo = ({
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (indexingType === IndexingType.ECONOMICAL && docForm === ChuckingMode.qa)
|
|
||||||
setDocForm(ChuckingMode.text)
|
|
||||||
}, [indexingType, docForm])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// get indexing type by props
|
// get indexing type by props
|
||||||
if (indexingType)
|
if (indexingType)
|
||||||
@ -553,7 +556,7 @@ const StepTwo = ({
|
|||||||
activeHeaderClassName='bg-gradient-to-r from-[#EFF0F9] to-[#F9FAFB]'
|
activeHeaderClassName='bg-gradient-to-r from-[#EFF0F9] to-[#F9FAFB]'
|
||||||
description={t('datasetCreation.stepTwo.generalTip')}
|
description={t('datasetCreation.stepTwo.generalTip')}
|
||||||
isActive={docForm === ChuckingMode.qa || docForm === ChuckingMode.text}
|
isActive={docForm === ChuckingMode.qa || docForm === ChuckingMode.text}
|
||||||
onClick={() => setDocForm(ChuckingMode.text)}
|
onSelect={() => handleChangeDocform(ChuckingMode.text)}
|
||||||
actions={
|
actions={
|
||||||
<>
|
<>
|
||||||
<Button variant={'secondary-accent'} onClick={() => updatePreview()}>
|
<Button variant={'secondary-accent'} onClick={() => updatePreview()}>
|
||||||
@ -605,9 +608,9 @@ const StepTwo = ({
|
|||||||
checked={docForm === ChuckingMode.qa}
|
checked={docForm === ChuckingMode.qa}
|
||||||
onCheck={() => {
|
onCheck={() => {
|
||||||
if (docForm === ChuckingMode.qa)
|
if (docForm === ChuckingMode.qa)
|
||||||
setDocForm(ChuckingMode.text)
|
handleChangeDocform(ChuckingMode.text)
|
||||||
else
|
else
|
||||||
setDocForm(ChuckingMode.qa)
|
handleChangeDocform(ChuckingMode.qa)
|
||||||
}}
|
}}
|
||||||
className='mr-2'
|
className='mr-2'
|
||||||
/>
|
/>
|
||||||
@ -648,7 +651,7 @@ const StepTwo = ({
|
|||||||
activeHeaderClassName='bg-gradient-to-r from-[#F9F1EE] to-[#F9FAFB]'
|
activeHeaderClassName='bg-gradient-to-r from-[#F9F1EE] to-[#F9FAFB]'
|
||||||
description={t('datasetCreation.stepTwo.parentChildTip')}
|
description={t('datasetCreation.stepTwo.parentChildTip')}
|
||||||
isActive={docForm === ChuckingMode.parentChild}
|
isActive={docForm === ChuckingMode.parentChild}
|
||||||
onClick={() => setDocForm(ChuckingMode.parentChild)}
|
onSelected={() => handleChangeDocform(ChuckingMode.parentChild)}
|
||||||
actions={
|
actions={
|
||||||
<>
|
<>
|
||||||
<Button variant={'secondary-accent'} onClick={() => updatePreview()}>
|
<Button variant={'secondary-accent'} onClick={() => updatePreview()}>
|
||||||
@ -937,6 +940,32 @@ const StepTwo = ({
|
|||||||
</ChunkContainer>
|
</ChunkContainer>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
|
{docForm === ChuckingMode.parentChild && currentEstimateMutation.data?.preview && (
|
||||||
|
estimate?.preview?.map((item, index) => {
|
||||||
|
const indexForLabel = index + 1
|
||||||
|
return (
|
||||||
|
<ChunkContainer
|
||||||
|
key={item.content}
|
||||||
|
label={`Chunk-${indexForLabel}`}
|
||||||
|
characterCount={item.content.length}
|
||||||
|
>
|
||||||
|
<FormattedText>
|
||||||
|
{item.child_chunks.map((child, index) => {
|
||||||
|
const indexForLabel = index + 1
|
||||||
|
return (
|
||||||
|
<PreviewSlice
|
||||||
|
key={child}
|
||||||
|
label={`C-${indexForLabel}`}
|
||||||
|
text={child}
|
||||||
|
tooltip={`Child-chunk-${indexForLabel} · ${child.length} Characters`}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</FormattedText>
|
||||||
|
</ChunkContainer>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
)}
|
||||||
{currentEstimateMutation.isIdle && (
|
{currentEstimateMutation.isIdle && (
|
||||||
<div className='h-full w-full flex items-center justify-center'>
|
<div className='h-full w-full flex items-center justify-center'>
|
||||||
<div className='flex flex-col items-center justify-center gap-3'>
|
<div className='flex flex-col items-center justify-center gap-3'>
|
||||||
|
@ -50,10 +50,11 @@ type OptionCardProps = {
|
|||||||
isActive?: boolean
|
isActive?: boolean
|
||||||
actions?: ReactNode
|
actions?: ReactNode
|
||||||
effectImg?: string
|
effectImg?: string
|
||||||
|
onSelected?: () => void
|
||||||
} & Omit<ComponentProps<'div'>, 'title'>
|
} & Omit<ComponentProps<'div'>, 'title'>
|
||||||
|
|
||||||
export const OptionCard: FC<OptionCardProps> = (props) => {
|
export const OptionCard: FC<OptionCardProps> = (props) => {
|
||||||
const { icon, className, title, description, isActive, children, actions, activeHeaderClassName, style, effectImg, ...rest } = props
|
const { icon, className, title, description, isActive, children, actions, activeHeaderClassName, style, effectImg, onSelected, onClick, ...rest } = props
|
||||||
return <div
|
return <div
|
||||||
className={classNames(
|
className={classNames(
|
||||||
'rounded-xl',
|
'rounded-xl',
|
||||||
@ -64,6 +65,11 @@ export const OptionCard: FC<OptionCardProps> = (props) => {
|
|||||||
...style,
|
...style,
|
||||||
borderWidth: 1.5,
|
borderWidth: 1.5,
|
||||||
}}
|
}}
|
||||||
|
onClick={(e) => {
|
||||||
|
if (!isActive)
|
||||||
|
onSelected?.()
|
||||||
|
onClick?.(e)
|
||||||
|
}}
|
||||||
{...rest}>
|
{...rest}>
|
||||||
<OptionCardHeader
|
<OptionCardHeader
|
||||||
icon={icon}
|
icon={icon}
|
||||||
|
@ -151,8 +151,7 @@ export type IndexingEstimateResponse = {
|
|||||||
total_price: number
|
total_price: number
|
||||||
currency: string
|
currency: string
|
||||||
total_segments: number
|
total_segments: number
|
||||||
// TODO: change it
|
preview: Array<{ content: string; child_chunks: string[] }>
|
||||||
preview: Array<{ content: string; child_chunks: any }>
|
|
||||||
qa_preview?: QA[]
|
qa_preview?: QA[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user