mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Feat: Extract the save buttons for dataset and chat configurations to separate files to increase permission control #3221 (#9803)
### What problem does this PR solve? Feat: Extract the save buttons for dataset and chat configurations to separate files to increase permission control #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -1,12 +1,9 @@
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Loader2Icon } from 'lucide-react';
|
|
||||||
import { useFormContext, useWatch } from 'react-hook-form';
|
import { useFormContext, useWatch } from 'react-hook-form';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { DocumentParserType } from '@/constants/knowledge';
|
import { DocumentParserType } from '@/constants/knowledge';
|
||||||
import { useUpdateKnowledge } from '@/hooks/use-knowledge-request';
|
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useParams } from 'umi';
|
|
||||||
import { AudioConfiguration } from './configuration/audio';
|
import { AudioConfiguration } from './configuration/audio';
|
||||||
import { BookConfiguration } from './configuration/book';
|
import { BookConfiguration } from './configuration/book';
|
||||||
import { EmailConfiguration } from './configuration/email';
|
import { EmailConfiguration } from './configuration/email';
|
||||||
@ -22,6 +19,7 @@ import { QAConfiguration } from './configuration/qa';
|
|||||||
import { ResumeConfiguration } from './configuration/resume';
|
import { ResumeConfiguration } from './configuration/resume';
|
||||||
import { TableConfiguration } from './configuration/table';
|
import { TableConfiguration } from './configuration/table';
|
||||||
import { TagConfiguration } from './configuration/tag';
|
import { TagConfiguration } from './configuration/tag';
|
||||||
|
import { SavingButton } from './saving-button';
|
||||||
|
|
||||||
const ConfigurationComponentMap = {
|
const ConfigurationComponentMap = {
|
||||||
[DocumentParserType.Naive]: NaiveConfiguration,
|
[DocumentParserType.Naive]: NaiveConfiguration,
|
||||||
@ -48,11 +46,6 @@ function EmptyComponent() {
|
|||||||
export function ChunkMethodForm() {
|
export function ChunkMethodForm() {
|
||||||
const form = useFormContext();
|
const form = useFormContext();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
// const [submitLoading, setSubmitLoading] = useState(false); // submit button loading
|
|
||||||
const { id: kb_id } = useParams();
|
|
||||||
|
|
||||||
const { saveKnowledgeConfiguration, loading: submitLoading } =
|
|
||||||
useUpdateKnowledge();
|
|
||||||
|
|
||||||
const finalParserId: DocumentParserType = useWatch({
|
const finalParserId: DocumentParserType = useWatch({
|
||||||
control: form.control,
|
control: form.control,
|
||||||
@ -80,37 +73,7 @@ export function ChunkMethodForm() {
|
|||||||
>
|
>
|
||||||
{t('knowledgeConfiguration.cancel')}
|
{t('knowledgeConfiguration.cancel')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<SavingButton></SavingButton>
|
||||||
disabled={submitLoading}
|
|
||||||
onClick={() => {
|
|
||||||
(async () => {
|
|
||||||
try {
|
|
||||||
let beValid = await form.formControl.trigger();
|
|
||||||
if (beValid) {
|
|
||||||
// setSubmitLoading(true);
|
|
||||||
// let postData = form.formState.values;
|
|
||||||
// console.log('submit form -->', form);
|
|
||||||
// delete postData['avatar']; // has submitted in first form general
|
|
||||||
form.handleSubmit(async (values) => {
|
|
||||||
console.log('saveKnowledgeConfiguration: ', values);
|
|
||||||
delete values['avatar'];
|
|
||||||
await saveKnowledgeConfiguration({
|
|
||||||
kb_id,
|
|
||||||
...values,
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
} finally {
|
|
||||||
// setSubmitLoading(false);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{submitLoading && <Loader2Icon className="animate-spin" />}
|
|
||||||
{t('knowledgeConfiguration.save')}
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { AvatarUpload } from '@/components/avatar-upload';
|
|||||||
import { FormContainer } from '@/components/form-container';
|
import { FormContainer } from '@/components/form-container';
|
||||||
import { SelectWithSearch } from '@/components/originui/select-with-search';
|
import { SelectWithSearch } from '@/components/originui/select-with-search';
|
||||||
import { RAGFlowFormItem } from '@/components/ragflow-form';
|
import { RAGFlowFormItem } from '@/components/ragflow-form';
|
||||||
import { Button, ButtonLoading } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
import {
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
@ -12,26 +12,15 @@ import {
|
|||||||
} from '@/components/ui/form';
|
} from '@/components/ui/form';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { PermissionRole } from '@/constants/permission';
|
import { PermissionRole } from '@/constants/permission';
|
||||||
import { useUpdateKnowledge } from '@/hooks/use-knowledge-request';
|
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useFormContext } from 'react-hook-form';
|
import { useFormContext } from 'react-hook-form';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useParams } from 'umi';
|
import { GeneralSavingButton } from './saving-button';
|
||||||
|
|
||||||
export function GeneralForm() {
|
export function GeneralForm() {
|
||||||
const form = useFormContext();
|
const form = useFormContext();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { saveKnowledgeConfiguration, loading: submitLoading } =
|
|
||||||
useUpdateKnowledge();
|
|
||||||
|
|
||||||
const defaultValues = useMemo(
|
|
||||||
() => form.formState.defaultValues ?? {},
|
|
||||||
[form.formState.defaultValues],
|
|
||||||
);
|
|
||||||
const parser_id = defaultValues['parser_id'];
|
|
||||||
const { id: kb_id } = useParams();
|
|
||||||
|
|
||||||
const teamOptions = useMemo(() => {
|
const teamOptions = useMemo(() => {
|
||||||
return Object.values(PermissionRole).map((x) => ({
|
return Object.values(PermissionRole).map((x) => ({
|
||||||
label: t('knowledgeConfiguration.' + x),
|
label: t('knowledgeConfiguration.' + x),
|
||||||
@ -131,30 +120,7 @@ export function GeneralForm() {
|
|||||||
>
|
>
|
||||||
{t('knowledgeConfiguration.cancel')}
|
{t('knowledgeConfiguration.cancel')}
|
||||||
</Button>
|
</Button>
|
||||||
<ButtonLoading
|
<GeneralSavingButton></GeneralSavingButton>
|
||||||
type="button"
|
|
||||||
loading={submitLoading}
|
|
||||||
onClick={() => {
|
|
||||||
(async () => {
|
|
||||||
let isValidate = await form.trigger('name');
|
|
||||||
const { name, description, permission, avatar } =
|
|
||||||
form.getValues();
|
|
||||||
|
|
||||||
if (isValidate) {
|
|
||||||
saveKnowledgeConfiguration({
|
|
||||||
kb_id,
|
|
||||||
parser_id,
|
|
||||||
name,
|
|
||||||
description,
|
|
||||||
avatar,
|
|
||||||
permission,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t('knowledgeConfiguration.save')}
|
|
||||||
</ButtonLoading>
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
82
web/src/pages/dataset/setting/saving-button.tsx
Normal file
82
web/src/pages/dataset/setting/saving-button.tsx
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import { ButtonLoading } from '@/components/ui/button';
|
||||||
|
import { useUpdateKnowledge } from '@/hooks/use-knowledge-request';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
import { useFormContext } from 'react-hook-form';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { useParams } from 'umi';
|
||||||
|
|
||||||
|
export function GeneralSavingButton() {
|
||||||
|
const form = useFormContext();
|
||||||
|
const { saveKnowledgeConfiguration, loading: submitLoading } =
|
||||||
|
useUpdateKnowledge();
|
||||||
|
const { id: kb_id } = useParams();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const defaultValues = useMemo(
|
||||||
|
() => form.formState.defaultValues ?? {},
|
||||||
|
[form.formState.defaultValues],
|
||||||
|
);
|
||||||
|
const parser_id = defaultValues['parser_id'];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ButtonLoading
|
||||||
|
type="button"
|
||||||
|
loading={submitLoading}
|
||||||
|
onClick={() => {
|
||||||
|
(async () => {
|
||||||
|
let isValidate = await form.trigger('name');
|
||||||
|
const { name, description, permission, avatar } = form.getValues();
|
||||||
|
|
||||||
|
if (isValidate) {
|
||||||
|
saveKnowledgeConfiguration({
|
||||||
|
kb_id,
|
||||||
|
parser_id,
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
avatar,
|
||||||
|
permission,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('knowledgeConfiguration.save')}
|
||||||
|
</ButtonLoading>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SavingButton() {
|
||||||
|
const { saveKnowledgeConfiguration, loading: submitLoading } =
|
||||||
|
useUpdateKnowledge();
|
||||||
|
const form = useFormContext();
|
||||||
|
const { id: kb_id } = useParams();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ButtonLoading
|
||||||
|
loading={submitLoading}
|
||||||
|
onClick={() => {
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
let beValid = await form.formControl.trigger();
|
||||||
|
if (beValid) {
|
||||||
|
form.handleSubmit(async (values) => {
|
||||||
|
console.log('saveKnowledgeConfiguration: ', values);
|
||||||
|
delete values['avatar'];
|
||||||
|
await saveKnowledgeConfiguration({
|
||||||
|
kb_id,
|
||||||
|
...values,
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
} finally {
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('knowledgeConfiguration.save')}
|
||||||
|
</ButtonLoading>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { Button, ButtonLoading } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Form } from '@/components/ui/form';
|
import { Form } from '@/components/ui/form';
|
||||||
import { Separator } from '@/components/ui/separator';
|
import { Separator } from '@/components/ui/separator';
|
||||||
import { DatasetMetadata } from '@/constants/chat';
|
import { DatasetMetadata } from '@/constants/chat';
|
||||||
@ -18,6 +18,7 @@ import { z } from 'zod';
|
|||||||
import ChatBasicSetting from './chat-basic-settings';
|
import ChatBasicSetting from './chat-basic-settings';
|
||||||
import { ChatModelSettings } from './chat-model-settings';
|
import { ChatModelSettings } from './chat-model-settings';
|
||||||
import { ChatPromptEngine } from './chat-prompt-engine';
|
import { ChatPromptEngine } from './chat-prompt-engine';
|
||||||
|
import { SavingButton } from './saving-button';
|
||||||
import { useChatSettingSchema } from './use-chat-setting-schema';
|
import { useChatSettingSchema } from './use-chat-setting-schema';
|
||||||
|
|
||||||
type ChatSettingsProps = { switchSettingVisible(): void };
|
type ChatSettingsProps = { switchSettingVisible(): void };
|
||||||
@ -110,9 +111,7 @@ export function ChatSettings({ switchSettingVisible }: ChatSettingsProps) {
|
|||||||
<Button variant={'outline'} onClick={switchSettingVisible}>
|
<Button variant={'outline'} onClick={switchSettingVisible}>
|
||||||
{t('chat.cancel')}
|
{t('chat.cancel')}
|
||||||
</Button>
|
</Button>
|
||||||
<ButtonLoading type="submit" loading={loading}>
|
<SavingButton loading={loading}></SavingButton>
|
||||||
{t('common.save')}
|
|
||||||
</ButtonLoading>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
|
|||||||
16
web/src/pages/next-chats/chat/app-settings/saving-button.tsx
Normal file
16
web/src/pages/next-chats/chat/app-settings/saving-button.tsx
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { ButtonLoading } from '@/components/ui/button';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
type SaveButtonProps = {
|
||||||
|
loading: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function SavingButton({ loading }: SaveButtonProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ButtonLoading type="submit" loading={loading}>
|
||||||
|
{t('common.save')}
|
||||||
|
</ButtonLoading>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user