mirror of
https://github.com/langgenius/dify.git
synced 2026-10-04 13:47:55 +08:00
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
fde08d24fe
commit
a84c2d36a3
6213 files changed
+227959
-187183
No files matched your search
+63
-24
@@ -18,8 +18,19 @@ vi.mock('@/next/navigation', () => ({
|
||||
|
||||
// Mock next/link
|
||||
vi.mock('@/next/link', () => ({
|
||||
default: function MockLink({ children, href, ...props }: { children: React.ReactNode, href: string }) {
|
||||
return <a href={href} {...props}>{children}</a>
|
||||
default: function MockLink({
|
||||
children,
|
||||
href,
|
||||
...props
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
href: string
|
||||
}) {
|
||||
return (
|
||||
<a href={href} {...props}>
|
||||
{children}
|
||||
</a>
|
||||
)
|
||||
},
|
||||
}))
|
||||
|
||||
@@ -66,7 +77,9 @@ vi.mock('@/hooks/use-api-access-url', () => ({
|
||||
* Uses deterministic counter-based IDs to avoid flaky tests
|
||||
*/
|
||||
let documentIdCounter = 0
|
||||
const createMockDocument = (overrides: Partial<InitialDocumentDetail> = {}): InitialDocumentDetail => ({
|
||||
const createMockDocument = (
|
||||
overrides: Partial<InitialDocumentDetail> = {},
|
||||
): InitialDocumentDetail => ({
|
||||
id: overrides.id ?? `doc-${++documentIdCounter}`,
|
||||
name: 'test-document.txt',
|
||||
data_source_type: DatasourceType.localFile,
|
||||
@@ -81,7 +94,9 @@ const createMockDocument = (overrides: Partial<InitialDocumentDetail> = {}): Ini
|
||||
/**
|
||||
* Creates a mock IndexingStatusResponse for testing
|
||||
*/
|
||||
const createMockIndexingStatus = (overrides: Partial<IndexingStatusResponse> = {}): IndexingStatusResponse => ({
|
||||
const createMockIndexingStatus = (
|
||||
overrides: Partial<IndexingStatusResponse> = {},
|
||||
): IndexingStatusResponse => ({
|
||||
id: `doc-${Math.random().toString(36).slice(2, 9)}`,
|
||||
indexing_status: 'waiting' as DocumentIndexingStatus,
|
||||
processing_started_at: Date.now(),
|
||||
@@ -100,13 +115,15 @@ const createMockIndexingStatus = (overrides: Partial<IndexingStatusResponse> = {
|
||||
/**
|
||||
* Creates default props for EmbeddingProcess component
|
||||
*/
|
||||
const createDefaultProps = (overrides: Partial<{
|
||||
datasetId: string
|
||||
batchId: string
|
||||
documents: InitialDocumentDetail[]
|
||||
indexingType: IndexingType
|
||||
retrievalMethod: RETRIEVE_METHOD
|
||||
}> = {}) => ({
|
||||
const createDefaultProps = (
|
||||
overrides: Partial<{
|
||||
datasetId: string
|
||||
batchId: string
|
||||
documents: InitialDocumentDetail[]
|
||||
indexingType: IndexingType
|
||||
retrievalMethod: RETRIEVE_METHOD
|
||||
}> = {},
|
||||
) => ({
|
||||
datasetId: 'dataset-123',
|
||||
batchId: 'batch-456',
|
||||
documents: [createMockDocument({ id: 'doc-1', name: 'test-doc.pdf' })],
|
||||
@@ -192,7 +209,9 @@ describe('EmbeddingProcess', () => {
|
||||
|
||||
render(<EmbeddingProcess {...props} />)
|
||||
|
||||
expect(screen.queryByText('billing.plansCommon.documentProcessingPriorityUpgrade')).not.toBeInTheDocument()
|
||||
expect(
|
||||
screen.queryByText('billing.plansCommon.documentProcessingPriorityUpgrade'),
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show upgrade banner when billing is enabled and plan is not team', () => {
|
||||
@@ -202,7 +221,9 @@ describe('EmbeddingProcess', () => {
|
||||
|
||||
render(<EmbeddingProcess {...props} />)
|
||||
|
||||
expect(screen.getByText('billing.plansCommon.documentProcessingPriorityUpgrade')).toBeInTheDocument()
|
||||
expect(
|
||||
screen.getByText('billing.plansCommon.documentProcessingPriorityUpgrade'),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should not show upgrade banner when plan is team', () => {
|
||||
@@ -212,7 +233,9 @@ describe('EmbeddingProcess', () => {
|
||||
|
||||
render(<EmbeddingProcess {...props} />)
|
||||
|
||||
expect(screen.queryByText('billing.plansCommon.documentProcessingPriorityUpgrade')).not.toBeInTheDocument()
|
||||
expect(
|
||||
screen.queryByText('billing.plansCommon.documentProcessingPriorityUpgrade'),
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show upgrade banner for professional plan', () => {
|
||||
@@ -222,7 +245,9 @@ describe('EmbeddingProcess', () => {
|
||||
|
||||
render(<EmbeddingProcess {...props} />)
|
||||
|
||||
expect(screen.getByText('billing.plansCommon.documentProcessingPriorityUpgrade')).toBeInTheDocument()
|
||||
expect(
|
||||
screen.getByText('billing.plansCommon.documentProcessingPriorityUpgrade'),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -322,7 +347,11 @@ describe('EmbeddingProcess', () => {
|
||||
it('should show completed status when all documents have error status', async () => {
|
||||
const doc1 = createMockDocument({ id: 'doc-1' })
|
||||
mockIndexingStatusData = [
|
||||
createMockIndexingStatus({ id: 'doc-1', indexing_status: 'error', error: 'Processing failed' }),
|
||||
createMockIndexingStatus({
|
||||
id: 'doc-1',
|
||||
indexing_status: 'error',
|
||||
error: 'Processing failed',
|
||||
}),
|
||||
]
|
||||
const props = createDefaultProps({ documents: [doc1] })
|
||||
|
||||
@@ -495,14 +524,14 @@ describe('EmbeddingProcess', () => {
|
||||
|
||||
// Assert - call count should not increase significantly after completion
|
||||
// Note: Due to React Strict Mode, there might be double renders
|
||||
expect(mockFetchIndexingStatus.mock.calls.length).toBeLessThanOrEqual(callCountAfterComplete + 1)
|
||||
expect(mockFetchIndexingStatus.mock.calls.length).toBeLessThanOrEqual(
|
||||
callCountAfterComplete + 1,
|
||||
)
|
||||
})
|
||||
|
||||
it('should stop polling when all documents have errors', async () => {
|
||||
const doc1 = createMockDocument({ id: 'doc-1' })
|
||||
mockIndexingStatusData = [
|
||||
createMockIndexingStatus({ id: 'doc-1', indexing_status: 'error' }),
|
||||
]
|
||||
mockIndexingStatusData = [createMockIndexingStatus({ id: 'doc-1', indexing_status: 'error' })]
|
||||
const props = createDefaultProps({ documents: [doc1] })
|
||||
|
||||
render(<EmbeddingProcess {...props} />)
|
||||
@@ -541,7 +570,9 @@ describe('EmbeddingProcess', () => {
|
||||
vi.advanceTimersByTime(5000)
|
||||
|
||||
// Assert - should not poll significantly more after paused state
|
||||
expect(mockFetchIndexingStatus.mock.calls.length).toBeLessThanOrEqual(callCountAfterPaused + 1)
|
||||
expect(mockFetchIndexingStatus.mock.calls.length).toBeLessThanOrEqual(
|
||||
callCountAfterPaused + 1,
|
||||
)
|
||||
})
|
||||
|
||||
it('should cleanup timeout on unmount', async () => {
|
||||
@@ -786,7 +817,9 @@ describe('EmbeddingProcess', () => {
|
||||
const props = createDefaultProps({ documents: [] })
|
||||
|
||||
// Suppress console errors for expected error
|
||||
const consoleError = vi.spyOn(console, 'error').mockImplementation(Function.prototype as () => void)
|
||||
const consoleError = vi
|
||||
.spyOn(console, 'error')
|
||||
.mockImplementation(Function.prototype as () => void)
|
||||
|
||||
// Act & Assert - explicitly assert the error behavior
|
||||
expect(() => {
|
||||
@@ -905,7 +938,11 @@ describe('EmbeddingProcess', () => {
|
||||
})
|
||||
|
||||
it('should pass different retrievalMethod values', () => {
|
||||
const retrievalMethods = [RETRIEVE_METHOD.semantic, RETRIEVE_METHOD.fullText, RETRIEVE_METHOD.hybrid]
|
||||
const retrievalMethods = [
|
||||
RETRIEVE_METHOD.semantic,
|
||||
RETRIEVE_METHOD.fullText,
|
||||
RETRIEVE_METHOD.hybrid,
|
||||
]
|
||||
|
||||
retrievalMethods.forEach((retrievalMethod) => {
|
||||
const props = createDefaultProps({ retrievalMethod })
|
||||
@@ -1077,7 +1114,9 @@ describe('EmbeddingProcess', () => {
|
||||
})
|
||||
|
||||
// Assert - upgrade banner should not be present
|
||||
expect(screen.queryByText('billing.plansCommon.documentProcessingPriorityUpgrade')).not.toBeInTheDocument()
|
||||
expect(
|
||||
screen.queryByText('billing.plansCommon.documentProcessingPriorityUpgrade'),
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
+22
-5
@@ -8,7 +8,15 @@ import RuleDetail from '../rule-detail'
|
||||
|
||||
// Mock FieldInfo component
|
||||
vi.mock('@/app/components/datasets/documents/detail/metadata', () => ({
|
||||
FieldInfo: ({ label, displayedValue, valueIcon }: { label: string, displayedValue: string, valueIcon?: React.ReactNode }) => (
|
||||
FieldInfo: ({
|
||||
label,
|
||||
displayedValue,
|
||||
valueIcon,
|
||||
}: {
|
||||
label: string
|
||||
displayedValue: string
|
||||
valueIcon?: React.ReactNode
|
||||
}) => (
|
||||
<div data-testid="field-info" data-label={label}>
|
||||
<span data-testid="field-label">{label}</span>
|
||||
<span data-testid="field-value">{displayedValue}</span>
|
||||
@@ -35,7 +43,9 @@ vi.mock('@/app/components/datasets/create/icons', () => ({
|
||||
/**
|
||||
* Creates a mock ProcessRuleResponse for testing
|
||||
*/
|
||||
const createMockProcessRule = (overrides: Partial<ProcessRuleResponse> = {}): ProcessRuleResponse => ({
|
||||
const createMockProcessRule = (
|
||||
overrides: Partial<ProcessRuleResponse> = {},
|
||||
): ProcessRuleResponse => ({
|
||||
mode: ProcessMode.general,
|
||||
rules: {
|
||||
pre_processing_rules: [],
|
||||
@@ -135,7 +145,9 @@ describe('RuleDetail', () => {
|
||||
render(<RuleDetail sourceData={sourceData} />)
|
||||
|
||||
const fieldValues = screen.getAllByTestId('field-value')
|
||||
expect(fieldValues[0]).toHaveTextContent('datasetDocuments.embedding.hierarchical · dataset.parentMode.paragraph')
|
||||
expect(fieldValues[0]).toHaveTextContent(
|
||||
'datasetDocuments.embedding.hierarchical · dataset.parentMode.paragraph',
|
||||
)
|
||||
})
|
||||
|
||||
it('should show hierarchical mode with full-doc parent mode', () => {
|
||||
@@ -152,7 +164,9 @@ describe('RuleDetail', () => {
|
||||
render(<RuleDetail sourceData={sourceData} />)
|
||||
|
||||
const fieldValues = screen.getAllByTestId('field-value')
|
||||
expect(fieldValues[0]).toHaveTextContent('datasetDocuments.embedding.hierarchical · dataset.parentMode.fullDoc')
|
||||
expect(fieldValues[0]).toHaveTextContent(
|
||||
'datasetDocuments.embedding.hierarchical · dataset.parentMode.fullDoc',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -196,7 +210,10 @@ describe('RuleDetail', () => {
|
||||
render(<RuleDetail retrievalMethod={RETRIEVE_METHOD.semantic} />)
|
||||
|
||||
const fieldInfos = screen.getAllByTestId('field-info')
|
||||
expect(fieldInfos[2]).toHaveAttribute('data-label', 'datasetSettings.form.retrievalSetting.title')
|
||||
expect(fieldInfos[2]).toHaveAttribute(
|
||||
'data-label',
|
||||
'datasetSettings.form.retrievalSetting.title',
|
||||
)
|
||||
})
|
||||
|
||||
it('should show semantic search title for qualified indexing with semantic method', () => {
|
||||
|
||||
+58
-58
@@ -49,7 +49,9 @@ const EmbeddingProcess = ({
|
||||
const { t } = useTranslation()
|
||||
const router = useRouter()
|
||||
const { enableBilling, plan } = useProviderContext()
|
||||
const [indexingStatusBatchDetail, setIndexingStatusDetail] = useState<IndexingStatusResponse[]>([])
|
||||
const [indexingStatusBatchDetail, setIndexingStatusDetail] = useState<IndexingStatusResponse[]>(
|
||||
[],
|
||||
)
|
||||
const [shouldPoll, setShouldPoll] = useState(true)
|
||||
const { mutateAsync: fetchIndexingStatus } = useIndexingStatusBatch({ datasetId, batchId })
|
||||
|
||||
@@ -61,13 +63,13 @@ const EmbeddingProcess = ({
|
||||
onSuccess: (res) => {
|
||||
const indexingStatusDetailList = res.data
|
||||
setIndexingStatusDetail(indexingStatusDetailList)
|
||||
const isCompleted = indexingStatusDetailList.every(indexingStatusDetail => ['completed', 'error', 'paused'].includes(indexingStatusDetail.indexing_status))
|
||||
if (isCompleted)
|
||||
setShouldPoll(false)
|
||||
const isCompleted = indexingStatusDetailList.every((indexingStatusDetail) =>
|
||||
['completed', 'error', 'paused'].includes(indexingStatusDetail.indexing_status),
|
||||
)
|
||||
if (isCompleted) setShouldPoll(false)
|
||||
},
|
||||
onSettled: () => {
|
||||
if (shouldPoll)
|
||||
timeoutId = setTimeout(fetchData, 2500)
|
||||
if (shouldPoll) timeoutId = setTimeout(fetchData, 2500)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -91,45 +93,51 @@ const EmbeddingProcess = ({
|
||||
const apiReferenceUrl = useDatasetApiAccessUrl()
|
||||
|
||||
const isEmbeddingWaiting = useMemo(() => {
|
||||
if (!indexingStatusBatchDetail.length)
|
||||
return false
|
||||
return indexingStatusBatchDetail.every(indexingStatusDetail => ['waiting'].includes(indexingStatusDetail?.indexing_status || ''))
|
||||
if (!indexingStatusBatchDetail.length) return false
|
||||
return indexingStatusBatchDetail.every((indexingStatusDetail) =>
|
||||
['waiting'].includes(indexingStatusDetail?.indexing_status || ''),
|
||||
)
|
||||
}, [indexingStatusBatchDetail])
|
||||
const isEmbedding = useMemo(() => {
|
||||
if (!indexingStatusBatchDetail.length)
|
||||
return false
|
||||
return indexingStatusBatchDetail.some(indexingStatusDetail => ['indexing', 'splitting', 'parsing', 'cleaning'].includes(indexingStatusDetail?.indexing_status || ''))
|
||||
if (!indexingStatusBatchDetail.length) return false
|
||||
return indexingStatusBatchDetail.some((indexingStatusDetail) =>
|
||||
['indexing', 'splitting', 'parsing', 'cleaning'].includes(
|
||||
indexingStatusDetail?.indexing_status || '',
|
||||
),
|
||||
)
|
||||
}, [indexingStatusBatchDetail])
|
||||
const isEmbeddingCompleted = useMemo(() => {
|
||||
if (!indexingStatusBatchDetail.length)
|
||||
return false
|
||||
return indexingStatusBatchDetail.every(indexingStatusDetail => ['completed', 'error', 'paused'].includes(indexingStatusDetail?.indexing_status || ''))
|
||||
if (!indexingStatusBatchDetail.length) return false
|
||||
return indexingStatusBatchDetail.every((indexingStatusDetail) =>
|
||||
['completed', 'error', 'paused'].includes(indexingStatusDetail?.indexing_status || ''),
|
||||
)
|
||||
}, [indexingStatusBatchDetail])
|
||||
|
||||
const getSourceName = (id: string) => {
|
||||
const doc = documents.find(document => document.id === id)
|
||||
const doc = documents.find((document) => document.id === id)
|
||||
return doc?.name
|
||||
}
|
||||
const getFileType = (name?: string) => name?.split('.').pop() || 'txt'
|
||||
const getSourcePercent = (detail: IndexingStatusResponse) => {
|
||||
const completedCount = detail.completed_segments || 0
|
||||
const totalCount = detail.total_segments || 0
|
||||
if (totalCount === 0)
|
||||
return 0
|
||||
const percent = Math.round(completedCount * 100 / totalCount)
|
||||
if (totalCount === 0) return 0
|
||||
const percent = Math.round((completedCount * 100) / totalCount)
|
||||
return percent > 100 ? 100 : percent
|
||||
}
|
||||
const getSourceType = (id: string) => {
|
||||
const doc = documents.find(document => document.id === id)
|
||||
const doc = documents.find((document) => document.id === id)
|
||||
return doc?.data_source_type
|
||||
}
|
||||
const getIcon = (id: string) => {
|
||||
const doc = documents.find(document => document.id === id)
|
||||
const doc = documents.find((document) => document.id === id)
|
||||
|
||||
return doc?.data_source_info.notion_page_icon
|
||||
}
|
||||
const isSourceEmbedding = (detail: IndexingStatusResponse) =>
|
||||
['indexing', 'splitting', 'parsing', 'cleaning', 'waiting'].includes(detail.indexing_status || '')
|
||||
['indexing', 'splitting', 'parsing', 'cleaning', 'waiting'].includes(
|
||||
detail.indexing_status || '',
|
||||
)
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -139,32 +147,33 @@ const EmbeddingProcess = ({
|
||||
<>
|
||||
<RiLoader2Fill className="size-4 animate-spin" />
|
||||
<span>
|
||||
{isEmbeddingWaiting ? t($ => $['embedding.waiting'], { ns: 'datasetDocuments' }) : t($ => $['embedding.processing'], { ns: 'datasetDocuments' })}
|
||||
{isEmbeddingWaiting
|
||||
? t(($) => $['embedding.waiting'], { ns: 'datasetDocuments' })
|
||||
: t(($) => $['embedding.processing'], { ns: 'datasetDocuments' })}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
{isEmbeddingCompleted && t($ => $['embedding.completed'], { ns: 'datasetDocuments' })}
|
||||
{isEmbeddingCompleted && t(($) => $['embedding.completed'], { ns: 'datasetDocuments' })}
|
||||
</div>
|
||||
{
|
||||
enableBilling && plan.type !== Plan.team && (
|
||||
<div className="flex h-[52px] items-center gap-x-2 rounded-xl border-[0.5px] border-components-panel-border-subtle bg-components-panel-on-panel-item-bg p-2.5 pl-3 shadow-xs shadow-shadow-shadow-3">
|
||||
<div className="flex shrink-0 items-center justify-center rounded-lg border-[0.5px] border-divider-subtle bg-util-colors-blue-brand-blue-brand-500 shadow-md shadow-shadow-shadow-5">
|
||||
<RiAedFill className="size-4 text-text-primary-on-surface" />
|
||||
</div>
|
||||
<div className="grow system-md-medium text-text-primary">
|
||||
{t($ => $['plansCommon.documentProcessingPriorityUpgrade'], { ns: 'billing' })}
|
||||
</div>
|
||||
<UpgradeBtn loc="knowledge-speed-up" />
|
||||
{enableBilling && plan.type !== Plan.team && (
|
||||
<div className="flex h-[52px] items-center gap-x-2 rounded-xl border-[0.5px] border-components-panel-border-subtle bg-components-panel-on-panel-item-bg p-2.5 pl-3 shadow-xs shadow-shadow-shadow-3">
|
||||
<div className="flex shrink-0 items-center justify-center rounded-lg border-[0.5px] border-divider-subtle bg-util-colors-blue-brand-blue-brand-500 shadow-md shadow-shadow-shadow-5">
|
||||
<RiAedFill className="size-4 text-text-primary-on-surface" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
<div className="grow system-md-medium text-text-primary">
|
||||
{t(($) => $['plansCommon.documentProcessingPriorityUpgrade'], { ns: 'billing' })}
|
||||
</div>
|
||||
<UpgradeBtn loc="knowledge-speed-up" />
|
||||
</div>
|
||||
)}
|
||||
<div className="flex flex-col gap-0.5 pb-2">
|
||||
{indexingStatusBatchDetail.map(indexingStatusDetail => (
|
||||
{indexingStatusBatchDetail.map((indexingStatusDetail) => (
|
||||
<div
|
||||
key={indexingStatusDetail.id}
|
||||
className={cn(
|
||||
'relative h-[26px] overflow-hidden rounded-md bg-components-progress-bar-bg',
|
||||
indexingStatusDetail.indexing_status === 'error' && 'bg-state-destructive-hover-alt',
|
||||
indexingStatusDetail.indexing_status === 'error' &&
|
||||
'bg-state-destructive-hover-alt',
|
||||
)}
|
||||
>
|
||||
{isSourceEmbedding(indexingStatusDetail) && (
|
||||
@@ -189,15 +198,14 @@ const EmbeddingProcess = ({
|
||||
src={getIcon(indexingStatusDetail.id)}
|
||||
/>
|
||||
)}
|
||||
<div className="flex w-0 grow items-center gap-1" title={getSourceName(indexingStatusDetail.id)}>
|
||||
<div
|
||||
className="flex w-0 grow items-center gap-1"
|
||||
title={getSourceName(indexingStatusDetail.id)}
|
||||
>
|
||||
<div className="truncate system-xs-medium text-text-secondary">
|
||||
{getSourceName(indexingStatusDetail.id)}
|
||||
</div>
|
||||
{
|
||||
enableBilling && (
|
||||
<PriorityLabel className="ml-0" />
|
||||
)
|
||||
}
|
||||
{enableBilling && <PriorityLabel className="ml-0" />}
|
||||
</div>
|
||||
{isSourceEmbedding(indexingStatusDetail) && (
|
||||
<div className="shrink-0 text-xs text-text-secondary">{`${getSourcePercent(indexingStatusDetail)}%`}</div>
|
||||
@@ -231,24 +239,16 @@ const EmbeddingProcess = ({
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-6 flex items-center gap-x-2 py-2">
|
||||
<Link
|
||||
href={apiReferenceUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Button
|
||||
className="w-fit gap-x-0.5 px-3"
|
||||
>
|
||||
<Link href={apiReferenceUrl} target="_blank" rel="noopener noreferrer">
|
||||
<Button className="w-fit gap-x-0.5 px-3">
|
||||
<RiTerminalBoxLine className="size-4" />
|
||||
<span className="px-0.5">Access the API</span>
|
||||
</Button>
|
||||
</Link>
|
||||
<Button
|
||||
className="w-fit gap-x-0.5 px-3"
|
||||
variant="primary"
|
||||
onClick={navToDocumentList}
|
||||
>
|
||||
<span className="px-0.5">{t($ => $['stepThree.navTo'], { ns: 'datasetCreation' })}</span>
|
||||
<Button className="w-fit gap-x-0.5 px-3" variant="primary" onClick={navToDocumentList}>
|
||||
<span className="px-0.5">
|
||||
{t(($) => $['stepThree.navTo'], { ns: 'datasetCreation' })}
|
||||
</span>
|
||||
<RiArrowRightLine className="size-4 stroke-current stroke-1" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
+42
-32
@@ -14,41 +14,46 @@ type RuleDetailProps = {
|
||||
retrievalMethod?: RETRIEVE_METHOD
|
||||
}
|
||||
|
||||
const RuleDetail = ({
|
||||
sourceData,
|
||||
indexingType,
|
||||
retrievalMethod,
|
||||
}: RuleDetailProps) => {
|
||||
const RuleDetail = ({ sourceData, indexingType, retrievalMethod }: RuleDetailProps) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const getValue = useCallback((field: string) => {
|
||||
let value = '-'
|
||||
switch (field) {
|
||||
case 'mode':
|
||||
value = !sourceData?.mode
|
||||
? value
|
||||
|
||||
: sourceData.mode === ProcessMode.general
|
||||
? (t($ => $['embedding.custom'], { ns: 'datasetDocuments' }) as string)
|
||||
|
||||
: `${t($ => $['embedding.hierarchical'], { ns: 'datasetDocuments' })} · ${sourceData?.rules?.parent_mode === 'paragraph'
|
||||
? t($ => $['parentMode.paragraph'], { ns: 'dataset' })
|
||||
: t($ => $['parentMode.fullDoc'], { ns: 'dataset' })}`
|
||||
break
|
||||
}
|
||||
return value
|
||||
}, [sourceData, t])
|
||||
const getValue = useCallback(
|
||||
(field: string) => {
|
||||
let value = '-'
|
||||
switch (field) {
|
||||
case 'mode':
|
||||
value = !sourceData?.mode
|
||||
? value
|
||||
: sourceData.mode === ProcessMode.general
|
||||
? (t(($) => $['embedding.custom'], { ns: 'datasetDocuments' }) as string)
|
||||
: `${t(($) => $['embedding.hierarchical'], { ns: 'datasetDocuments' })} · ${
|
||||
sourceData?.rules?.parent_mode === 'paragraph'
|
||||
? t(($) => $['parentMode.paragraph'], { ns: 'dataset' })
|
||||
: t(($) => $['parentMode.fullDoc'], { ns: 'dataset' })
|
||||
}`
|
||||
break
|
||||
}
|
||||
return value
|
||||
},
|
||||
[sourceData, t],
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-1" data-testid="rule-detail">
|
||||
<FieldInfo
|
||||
label={t($ => $['embedding.mode'], { ns: 'datasetDocuments' })}
|
||||
label={t(($) => $['embedding.mode'], { ns: 'datasetDocuments' })}
|
||||
displayedValue={getValue('mode')}
|
||||
/>
|
||||
<FieldInfo
|
||||
label={t($ => $['stepTwo.indexMode'], { ns: 'datasetCreation' })}
|
||||
displayedValue={t($ => $[`stepTwo.${indexingType === IndexingType.ECONOMICAL ? 'economical' : 'qualified'}`], { ns: 'datasetCreation' }) as string}
|
||||
valueIcon={(
|
||||
label={t(($) => $['stepTwo.indexMode'], { ns: 'datasetCreation' })}
|
||||
displayedValue={
|
||||
t(
|
||||
($) =>
|
||||
$[`stepTwo.${indexingType === IndexingType.ECONOMICAL ? 'economical' : 'qualified'}`],
|
||||
{ ns: 'datasetCreation' },
|
||||
) as string
|
||||
}
|
||||
valueIcon={
|
||||
<img
|
||||
className="size-4"
|
||||
src={
|
||||
@@ -58,25 +63,30 @@ const RuleDetail = ({
|
||||
}
|
||||
alt=""
|
||||
/>
|
||||
)}
|
||||
}
|
||||
/>
|
||||
<FieldInfo
|
||||
label={t($ => $['form.retrievalSetting.title'], { ns: 'datasetSettings' })}
|
||||
displayedValue={t($ => $[`retrieval.${indexingType === IndexingType.ECONOMICAL ? 'keyword_search' : retrievalMethod ?? 'semantic_search'}.title`], { ns: 'dataset' })}
|
||||
valueIcon={(
|
||||
label={t(($) => $['form.retrievalSetting.title'], { ns: 'datasetSettings' })}
|
||||
displayedValue={t(
|
||||
($) =>
|
||||
$[
|
||||
`retrieval.${indexingType === IndexingType.ECONOMICAL ? 'keyword_search' : (retrievalMethod ?? 'semantic_search')}.title`
|
||||
],
|
||||
{ ns: 'dataset' },
|
||||
)}
|
||||
valueIcon={
|
||||
<img
|
||||
className="size-4"
|
||||
src={
|
||||
retrievalMethod === RETRIEVE_METHOD.fullText
|
||||
? retrievalIcon.fullText
|
||||
|
||||
: retrievalMethod === RETRIEVE_METHOD.hybrid
|
||||
? retrievalIcon.hybrid
|
||||
: retrievalIcon.vector
|
||||
}
|
||||
alt=""
|
||||
/>
|
||||
)}
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user