mirror of
https://github.com/langgenius/dify.git
synced 2025-12-22 07:17:26 +00:00
- Introduced new test files for Processing and EmbeddingProcess components, covering rendering, props variations, edge cases, and memoization. - Added mock implementations for external dependencies to facilitate testing. - Enhanced Jest configuration to handle module resolution for lodash and ky. - Created a mock for the ky HTTP client to avoid ESM issues in Jest tests. - Updated Processing component to handle optional chaining for retrieval method. This commit significantly improves test coverage and stability for the document processing features.
85 lines
2.8 KiB
TypeScript
85 lines
2.8 KiB
TypeScript
import React, { useCallback } from 'react'
|
|
import { IndexingType } from '@/app/components/datasets/create/step-two'
|
|
import { ProcessMode, type ProcessRuleResponse } from '@/models/datasets'
|
|
import { RETRIEVE_METHOD } from '@/types/app'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { FieldInfo } from '@/app/components/datasets/documents/detail/metadata'
|
|
import Image from 'next/image'
|
|
import { indexMethodIcon, retrievalIcon } from '@/app/components/datasets/create/icons'
|
|
|
|
type RuleDetailProps = {
|
|
sourceData?: ProcessRuleResponse
|
|
indexingType?: IndexingType
|
|
retrievalMethod?: RETRIEVE_METHOD
|
|
}
|
|
|
|
const RuleDetail = ({
|
|
sourceData,
|
|
indexingType,
|
|
retrievalMethod,
|
|
}: RuleDetailProps) => {
|
|
const { t } = useTranslation()
|
|
|
|
const getValue = useCallback((field: string) => {
|
|
let value = '-'
|
|
switch (field) {
|
|
case 'mode':
|
|
value = !sourceData?.mode
|
|
? value
|
|
// eslint-disable-next-line sonarjs/no-nested-conditional
|
|
: sourceData.mode === ProcessMode.general
|
|
? (t('datasetDocuments.embedding.custom') as string)
|
|
// eslint-disable-next-line sonarjs/no-nested-conditional
|
|
: `${t('datasetDocuments.embedding.hierarchical')} · ${sourceData?.rules?.parent_mode === 'paragraph'
|
|
? t('dataset.parentMode.paragraph')
|
|
: t('dataset.parentMode.fullDoc')}`
|
|
break
|
|
}
|
|
return value
|
|
}, [sourceData, t])
|
|
|
|
return (
|
|
<div className='flex flex-col gap-1' data-testid='rule-detail'>
|
|
<FieldInfo
|
|
label={t('datasetDocuments.embedding.mode')}
|
|
displayedValue={getValue('mode')}
|
|
/>
|
|
<FieldInfo
|
|
label={t('datasetCreation.stepTwo.indexMode')}
|
|
displayedValue={t(`datasetCreation.stepTwo.${indexingType === IndexingType.ECONOMICAL ? 'economical' : 'qualified'}`) as string}
|
|
valueIcon={
|
|
<Image
|
|
className='size-4'
|
|
src={
|
|
indexingType === IndexingType.ECONOMICAL
|
|
? indexMethodIcon.economical
|
|
: indexMethodIcon.high_quality
|
|
}
|
|
alt=''
|
|
/>
|
|
}
|
|
/>
|
|
<FieldInfo
|
|
label={t('datasetSettings.form.retrievalSetting.title')}
|
|
displayedValue={t(`dataset.retrieval.${indexingType === IndexingType.ECONOMICAL ? 'keyword_search' : retrievalMethod}.title`) as string}
|
|
valueIcon={
|
|
<Image
|
|
className='size-4'
|
|
src={
|
|
retrievalMethod === RETRIEVE_METHOD.fullText
|
|
? retrievalIcon.fullText
|
|
// eslint-disable-next-line sonarjs/no-nested-conditional
|
|
: retrievalMethod === RETRIEVE_METHOD.hybrid
|
|
? retrievalIcon.hybrid
|
|
: retrievalIcon.vector
|
|
}
|
|
alt=''
|
|
/>
|
|
}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default React.memo(RuleDetail)
|