### What problem does this PR solve? Feat: Support deleting knowledge graph #6747 ### Type of change - [x] New Feature (non-breaking change which adds functionality)tags/v0.18.0
| import ParseConfiguration, { | import ParseConfiguration, { | ||||
| showRaptorParseConfiguration, | showRaptorParseConfiguration, | ||||
| } from '../parse-configuration'; | } from '../parse-configuration'; | ||||
| import GraphRagItems, { | |||||
| import { | |||||
| UseGraphRagItem, | |||||
| showGraphRagItems, | showGraphRagItems, | ||||
| } from '../parse-configuration/graph-rag-items'; | } from '../parse-configuration/graph-rag-items'; | ||||
| import styles from './index.less'; | import styles from './index.less'; | ||||
| <ParseConfiguration></ParseConfiguration> | <ParseConfiguration></ParseConfiguration> | ||||
| </DatasetConfigurationContainer> | </DatasetConfigurationContainer> | ||||
| )} | )} | ||||
| {showGraphRagItems(selectedTag) && <GraphRagItems></GraphRagItems>} | |||||
| {showGraphRagItems(selectedTag) && <UseGraphRagItem></UseGraphRagItem>} | |||||
| {showEntityTypes && <EntityTypesItem></EntityTypesItem>} | {showEntityTypes && <EntityTypesItem></EntityTypesItem>} | ||||
| </Form> | </Form> | ||||
| </Modal> | </Modal> |
| marginBottom?: boolean; | marginBottom?: boolean; | ||||
| }; | }; | ||||
| export function UseGraphRagItem() { | |||||
| const { t } = useTranslate('knowledgeConfiguration'); | |||||
| return ( | |||||
| <Form.Item | |||||
| name={['parser_config', 'graphrag', 'use_graphrag']} | |||||
| label={t('useGraphRag')} | |||||
| initialValue={false} | |||||
| valuePropName="checked" | |||||
| tooltip={t('useGraphRagTip')} | |||||
| > | |||||
| <Switch /> | |||||
| </Form.Item> | |||||
| ); | |||||
| } | |||||
| // The three types "table", "resume" and "one" do not display this configuration. | // The three types "table", "resume" and "one" do not display this configuration. | ||||
| const GraphRagItems = ({ marginBottom = false }: GraphRagItemsProps) => { | const GraphRagItems = ({ marginBottom = false }: GraphRagItemsProps) => { | ||||
| const { t } = useTranslate('knowledgeConfiguration'); | const { t } = useTranslate('knowledgeConfiguration'); | ||||
| return ( | return ( | ||||
| <DatasetConfigurationContainer className={cn({ 'mb-4': marginBottom })}> | <DatasetConfigurationContainer className={cn({ 'mb-4': marginBottom })}> | ||||
| <Form.Item | |||||
| name={['parser_config', 'graphrag', 'use_graphrag']} | |||||
| label={t('useGraphRag')} | |||||
| initialValue={false} | |||||
| valuePropName="checked" | |||||
| tooltip={t('useGraphRagTip')} | |||||
| > | |||||
| <Switch /> | |||||
| </Form.Item> | |||||
| <UseGraphRagItem></UseGraphRagItem> | |||||
| <Form.Item | <Form.Item | ||||
| shouldUpdate={(prevValues, curValues) => | shouldUpdate={(prevValues, curValues) => | ||||
| prevValues.parser_config.graphrag.use_graphrag !== | prevValues.parser_config.graphrag.use_graphrag !== |
| } from '@/interfaces/database/knowledge'; | } from '@/interfaces/database/knowledge'; | ||||
| import i18n from '@/locales/config'; | import i18n from '@/locales/config'; | ||||
| import kbService, { | import kbService, { | ||||
| deleteKnowledgeGraph, | |||||
| getKnowledgeGraph, | getKnowledgeGraph, | ||||
| listTag, | listTag, | ||||
| removeTag, | removeTag, | ||||
| return { data, loading }; | return { data, loading }; | ||||
| } | } | ||||
| export const useRemoveKnowledgeGraph = () => { | |||||
| const knowledgeBaseId = useKnowledgeBaseId(); | |||||
| const queryClient = useQueryClient(); | |||||
| const { | |||||
| data, | |||||
| isPending: loading, | |||||
| mutateAsync, | |||||
| } = useMutation({ | |||||
| mutationKey: ['removeKnowledgeGraph'], | |||||
| mutationFn: async () => { | |||||
| const { data } = await deleteKnowledgeGraph(knowledgeBaseId); | |||||
| if (data.code === 0) { | |||||
| message.success(i18n.t(`message.deleted`)); | |||||
| queryClient.invalidateQueries({ | |||||
| queryKey: ['fetchKnowledgeGraph'], | |||||
| }); | |||||
| } | |||||
| return data?.code; | |||||
| }, | |||||
| }); | |||||
| return { data, loading, removeKnowledgeGraph: mutateAsync }; | |||||
| }; |
| import { ConfirmDeleteDialog } from '@/components/confirm-delete-dialog'; | |||||
| import { Button } from '@/components/ui/button'; | |||||
| import { useFetchKnowledgeGraph } from '@/hooks/knowledge-hooks'; | import { useFetchKnowledgeGraph } from '@/hooks/knowledge-hooks'; | ||||
| import { Trash2 } from 'lucide-react'; | |||||
| import React from 'react'; | import React from 'react'; | ||||
| import { useTranslation } from 'react-i18next'; | |||||
| import ForceGraph from './force-graph'; | import ForceGraph from './force-graph'; | ||||
| import { useDeleteKnowledgeGraph } from './use-delete-graph'; | |||||
| const KnowledgeGraphModal: React.FC = () => { | |||||
| const KnowledgeGraph: React.FC = () => { | |||||
| const { data } = useFetchKnowledgeGraph(); | const { data } = useFetchKnowledgeGraph(); | ||||
| const { t } = useTranslation(); | |||||
| const { handleDeleteKnowledgeGraph } = useDeleteKnowledgeGraph(); | |||||
| return ( | return ( | ||||
| <section className={'w-full h-full'}> | |||||
| <section className={'w-full h-full relative'}> | |||||
| <ConfirmDeleteDialog onOk={handleDeleteKnowledgeGraph}> | |||||
| <Button | |||||
| variant="outline" | |||||
| size={'sm'} | |||||
| className="absolute right-0 top-0 z-50" | |||||
| > | |||||
| <Trash2 /> {t('common.delete')} | |||||
| </Button> | |||||
| </ConfirmDeleteDialog> | |||||
| <ForceGraph data={data?.graph} show></ForceGraph> | <ForceGraph data={data?.graph} show></ForceGraph> | ||||
| </section> | </section> | ||||
| ); | ); | ||||
| }; | }; | ||||
| export default KnowledgeGraphModal; | |||||
| export default KnowledgeGraph; |
| import { | |||||
| useKnowledgeBaseId, | |||||
| useRemoveKnowledgeGraph, | |||||
| } from '@/hooks/knowledge-hooks'; | |||||
| import { useCallback } from 'react'; | |||||
| import { useNavigate } from 'umi'; | |||||
| export function useDeleteKnowledgeGraph() { | |||||
| const { removeKnowledgeGraph, loading } = useRemoveKnowledgeGraph(); | |||||
| const navigate = useNavigate(); | |||||
| const knowledgeBaseId = useKnowledgeBaseId(); | |||||
| const handleDeleteKnowledgeGraph = useCallback(async () => { | |||||
| const ret = await removeKnowledgeGraph(); | |||||
| if (ret === 0) { | |||||
| navigate(`/knowledge/dataset?id=${knowledgeBaseId}`); | |||||
| } | |||||
| }, [knowledgeBaseId, navigate, removeKnowledgeGraph]); | |||||
| return { handleDeleteKnowledgeGraph, loading }; | |||||
| } |
| return request.get(api.getKnowledgeGraph(knowledgeId)); | return request.get(api.getKnowledgeGraph(knowledgeId)); | ||||
| } | } | ||||
| export function deleteKnowledgeGraph(knowledgeId: string) { | |||||
| return request.delete(api.getKnowledgeGraph(knowledgeId)); | |||||
| } | |||||
| export default kbService; | export default kbService; |