mirror of
https://github.com/langgenius/dify.git
synced 2026-05-01 22:47:15 +08:00
feat: auto disabled api
This commit is contained in:
parent
335e57f3c9
commit
d1743ee3e5
@ -1,9 +1,10 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React from 'react'
|
import React, { useCallback } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import StatusWithAction from './status-with-action'
|
import StatusWithAction from './status-with-action'
|
||||||
|
import { useAutoDisabledDocuments, useDocumentEnable, useInvalidDisabledDocument } from '@/service/knowledge/use-document'
|
||||||
|
import Toast from '@/app/components/base/toast'
|
||||||
type Props = {
|
type Props = {
|
||||||
datasetId: string
|
datasetId: string
|
||||||
}
|
}
|
||||||
@ -12,17 +13,25 @@ const AutoDisabledDocument: FC<Props> = ({
|
|||||||
datasetId,
|
datasetId,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const data = ['', '']
|
const { data, isLoading } = useAutoDisabledDocuments(datasetId)
|
||||||
const hasDisabledDocument = data.length > 0
|
const invalidDisabledDocument = useInvalidDisabledDocument()
|
||||||
if (!hasDisabledDocument)
|
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 null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StatusWithAction
|
<StatusWithAction
|
||||||
type='info'
|
type='info'
|
||||||
description={t('dataset.documentsDisabled', { num: data.length })}
|
description={t('dataset.documentsDisabled', { num: documentIds?.length })}
|
||||||
actionText={t('dataset.enable')}
|
actionText={t('dataset.enable')}
|
||||||
onAction={() => { }}
|
onAction={handleEnableDocuments}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,17 +46,19 @@ const StatusAction: FC<Props> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { Icon, color } = getIcon(type)
|
const { Icon, color } = getIcon(type)
|
||||||
return (
|
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%)]')
|
<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 === '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 === '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%)]')
|
|| (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='relative z-10 flex h-full items-center space-x-2'>
|
||||||
<div className='text-[13px] font-normal text-text-secondary'>{description}</div>
|
<Icon className={cn('w-4 h-4', color)} />
|
||||||
<Divider type='vertical' className='!h-4' />
|
<div className='text-[13px] font-normal text-text-secondary'>{description}</div>
|
||||||
<div onClick={onAction} className={cn('text-text-accent font-semibold text-[13px] cursor-pointer', disabled && 'text-text-disabled cursor-not-allowed')}>{actionText}</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>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import {
|
|||||||
useQuery,
|
useQuery,
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
import { del, get, patch } from '../base'
|
import { del, get, patch } from '../base'
|
||||||
|
import { useInvalid } from '../use-base'
|
||||||
import type { SimpleDocumentDetail, UpdateDocumentBatchParams } from '@/models/datasets'
|
import type { SimpleDocumentDetail, UpdateDocumentBatchParams } from '@/models/datasets'
|
||||||
import { DocumentActionType } from '@/models/datasets'
|
import { DocumentActionType } from '@/models/datasets'
|
||||||
import type { CommonResponse } from '@/models/common'
|
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 toBatchDocumentsIdParams = (documentIds: string[] | string) => {
|
||||||
const ids = Array.isArray(documentIds) ? documentIds : [documentIds]
|
const ids = Array.isArray(documentIds) ? documentIds : [documentIds]
|
||||||
return ids.map(id => `document_id=${id}`).join('&')
|
return ids.map(id => `document_id=${id}`).join('&')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user