mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-13 21:06:03 +08:00
### What problem does this PR solve? Feat: Support deleting knowledge graph #6747 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
parent
3ae1e9e3c4
commit
fc02929946
@ -32,7 +32,8 @@ import LayoutRecognize from '../layout-recognize';
|
|||||||
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';
|
||||||
@ -316,7 +317,7 @@ const ChunkMethodModal: React.FC<IProps> = ({
|
|||||||
<ParseConfiguration></ParseConfiguration>
|
<ParseConfiguration></ParseConfiguration>
|
||||||
</DatasetConfigurationContainer>
|
</DatasetConfigurationContainer>
|
||||||
)}
|
)}
|
||||||
{showGraphRagItems(selectedTag) && <GraphRagItems></GraphRagItems>}
|
{showGraphRagItems(selectedTag) && <UseGraphRagItem></UseGraphRagItem>}
|
||||||
{showEntityTypes && <EntityTypesItem></EntityTypesItem>}
|
{showEntityTypes && <EntityTypesItem></EntityTypesItem>}
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
@ -39,6 +39,22 @@ type GraphRagItemsProps = {
|
|||||||
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');
|
||||||
@ -62,15 +78,7 @@ const GraphRagItems = ({ marginBottom = false }: GraphRagItemsProps) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<DatasetConfigurationContainer className={cn({ 'mb-4': marginBottom })}>
|
<DatasetConfigurationContainer className={cn({ 'mb-4': marginBottom })}>
|
||||||
<Form.Item
|
<UseGraphRagItem></UseGraphRagItem>
|
||||||
name={['parser_config', 'graphrag', 'use_graphrag']}
|
|
||||||
label={t('useGraphRag')}
|
|
||||||
initialValue={false}
|
|
||||||
valuePropName="checked"
|
|
||||||
tooltip={t('useGraphRagTip')}
|
|
||||||
>
|
|
||||||
<Switch />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
shouldUpdate={(prevValues, curValues) =>
|
shouldUpdate={(prevValues, curValues) =>
|
||||||
prevValues.parser_config.graphrag.use_graphrag !==
|
prevValues.parser_config.graphrag.use_graphrag !==
|
||||||
|
@ -7,6 +7,7 @@ import {
|
|||||||
} 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,
|
||||||
@ -392,3 +393,28 @@ export function useFetchKnowledgeGraph() {
|
|||||||
|
|
||||||
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 };
|
||||||
|
};
|
||||||
|
@ -1,15 +1,31 @@
|
|||||||
|
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;
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
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 };
|
||||||
|
}
|
@ -169,4 +169,8 @@ export function getKnowledgeGraph(knowledgeId: string) {
|
|||||||
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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user