mirror of https://github.com/langgenius/dify.git
Merge branch 'feat/parent-child-retrieval' of https://github.com/langgenius/dify into feat/parent-child-retrieval
This commit is contained in:
commit
6055e27050
|
|
@ -0,0 +1,38 @@
|
|||
'use client'
|
||||
import type { FC } from 'react'
|
||||
import React, { useCallback } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import StatusWithAction from './status-with-action'
|
||||
import { useAutoDisabledDocuments, useDocumentEnable, useInvalidDisabledDocument } from '@/service/knowledge/use-document'
|
||||
import Toast from '@/app/components/base/toast'
|
||||
type Props = {
|
||||
datasetId: string
|
||||
}
|
||||
|
||||
const AutoDisabledDocument: FC<Props> = ({
|
||||
datasetId,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const { data, isLoading } = useAutoDisabledDocuments(datasetId)
|
||||
const invalidDisabledDocument = useInvalidDisabledDocument()
|
||||
const documentIds = data?.document_ids
|
||||
const hasDisabledDocument = documentIds && documentIds.length > 0
|
||||
const { mutateAsync: enableDocument } = useDocumentEnable()
|
||||
const handleEnableDocuments = useCallback(async () => {
|
||||
await enableDocument({ datasetId, documentIds })
|
||||
invalidDisabledDocument()
|
||||
Toast.notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
||||
}, [])
|
||||
if (!hasDisabledDocument || isLoading)
|
||||
return null
|
||||
|
||||
return (
|
||||
<StatusWithAction
|
||||
type='info'
|
||||
description={t('dataset.documentsDisabled', { num: documentIds?.length })}
|
||||
actionText={t('dataset.enable')}
|
||||
onAction={handleEnableDocuments}
|
||||
/>
|
||||
)
|
||||
}
|
||||
export default React.memo(AutoDisabledDocument)
|
||||
|
|
@ -34,7 +34,7 @@ const indexStateReducer = (state: IIndexState, action: IAction) => {
|
|||
const RetryButton: FC<Props> = ({ datasetId }) => {
|
||||
const { t } = useTranslation()
|
||||
const [indexState, dispatch] = useReducer(indexStateReducer, { value: 'success' })
|
||||
const { data: errorDocs } = useSWR({ datasetId }, getErrorDocs)
|
||||
const { data: errorDocs, isLoading } = useSWR({ datasetId }, getErrorDocs)
|
||||
|
||||
const onRetryErrorDocs = async () => {
|
||||
dispatch({ type: 'retry' })
|
||||
|
|
@ -53,7 +53,7 @@ const RetryButton: FC<Props> = ({ datasetId }) => {
|
|||
dispatch({ type: 'error' })
|
||||
}, [errorDocs?.total])
|
||||
|
||||
if (indexState.value === 'success')
|
||||
if (isLoading || indexState.value === 'success')
|
||||
return null
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -46,17 +46,19 @@ const StatusAction: FC<Props> = ({
|
|||
}) => {
|
||||
const { Icon, color } = getIcon(type)
|
||||
return (
|
||||
<div className='relative flex items-center h-[34px] rounded-lg pl-1 pr-3 border border-components-panel-border bg-components-panel-bg-blur shadow-xs space-x-2'>
|
||||
<div className='relative flex items-center h-[34px] rounded-lg pl-2 pr-3 border border-components-panel-border bg-components-panel-bg-blur shadow-xs'>
|
||||
<div className={`absolute inset-0 opacity-40 rounded-lg ${(type === 'success' && 'bg-[linear-gradient(92deg,rgba(23,178,106,0.25)_0%,rgba(255,255,255,0.00)_100%)]')
|
||||
|| (type === 'warning' && 'bg-[linear-gradient(92deg,rgba(247,144,9,0.25)_0%,rgba(255,255,255,0.00)_100%)]')
|
||||
|| (type === 'error' && 'bg-[linear-gradient(92deg,rgba(240,68,56,0.25)_0%,rgba(255,255,255,0.00)_100%)]')
|
||||
|| (type === 'info' && 'bg-[linear-gradient(92deg,rgba(11,165,236,0.25)_0%,rgba(255,255,255,0.00)_100%)]')
|
||||
}`}
|
||||
/>
|
||||
<Icon className={cn('w-4 h-4', color)} />
|
||||
<div className='text-[13px] font-normal text-text-secondary'>{description}</div>
|
||||
<Divider type='vertical' className='!h-4' />
|
||||
<div onClick={onAction} className={cn('text-text-accent font-semibold text-[13px] cursor-pointer', disabled && 'text-text-disabled cursor-not-allowed')}>{actionText}</div>
|
||||
<div className='relative z-10 flex h-full items-center space-x-2'>
|
||||
<Icon className={cn('w-4 h-4', color)} />
|
||||
<div className='text-[13px] font-normal text-text-secondary'>{description}</div>
|
||||
<Divider type='vertical' className='!h-4' />
|
||||
<div onClick={onAction} className={cn('text-text-accent font-semibold text-[13px] cursor-pointer', disabled && 'text-text-disabled cursor-not-allowed')}>{actionText}</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { useDebounce, useDebounceFn } from 'ahooks'
|
|||
import { groupBy, omit } from 'lodash-es'
|
||||
import { PlusIcon } from '@heroicons/react/24/solid'
|
||||
import { RiExternalLinkLine } from '@remixicon/react'
|
||||
import AutoDisabledDocument from '../common/document-status-with-action/auto-disabled-document'
|
||||
import List from './list'
|
||||
import s from './style.module.css'
|
||||
import Loading from '@/app/components/base/loading'
|
||||
|
|
@ -231,6 +232,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|||
onClear={() => handleInputChange('')}
|
||||
/>
|
||||
<div className='flex gap-2 justify-center items-center !h-8'>
|
||||
<AutoDisabledDocument datasetId={datasetId} />
|
||||
<IndexFailed datasetId={datasetId} />
|
||||
{embeddingAvailable && (
|
||||
<Button variant='primary' onClick={routeToDocCreate} className='shrink-0'>
|
||||
|
|
|
|||
|
|
@ -119,8 +119,10 @@ const translation = {
|
|||
change: 'Change',
|
||||
changeRetrievalMethod: 'Change retrieval method',
|
||||
},
|
||||
docsFailedNotice: 'documents failed to be indexed',
|
||||
docsFailedNotice: 'documents indexed failed',
|
||||
retry: 'Retry',
|
||||
documentsDisabled: '{{num}} documents disabled - inactive for over 30 days',
|
||||
enable: 'Enable',
|
||||
indexingTechnique: {
|
||||
high_quality: 'HQ',
|
||||
economy: 'ECO',
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {
|
|||
useQuery,
|
||||
} from '@tanstack/react-query'
|
||||
import { del, get, patch } from '../base'
|
||||
import { useInvalid } from '../use-base'
|
||||
import type { SimpleDocumentDetail, UpdateDocumentBatchParams } from '@/models/datasets'
|
||||
import { DocumentActionType } from '@/models/datasets'
|
||||
import type { CommonResponse } from '@/models/common'
|
||||
|
|
@ -27,6 +28,18 @@ export const useDocumentList = (payload: {
|
|||
})
|
||||
}
|
||||
|
||||
const useAutoDisabledDocumentKey = [NAME_SPACE, 'autoDisabledDocument']
|
||||
export const useAutoDisabledDocuments = (datasetId: string) => {
|
||||
return useQuery({
|
||||
queryKey: [...useAutoDisabledDocumentKey, datasetId],
|
||||
queryFn: () => get<{ document_ids: string[] }>(`/datasets/${datasetId}/auto-disable-logs`),
|
||||
})
|
||||
}
|
||||
|
||||
export const useInvalidDisabledDocument = () => {
|
||||
return useInvalid(useAutoDisabledDocumentKey)
|
||||
}
|
||||
|
||||
const toBatchDocumentsIdParams = (documentIds: string[] | string) => {
|
||||
const ids = Array.isArray(documentIds) ? documentIds : [documentIds]
|
||||
return ids.map(id => `document_id=${id}`).join('&')
|
||||
|
|
|
|||
Loading…
Reference in New Issue