Fix: Switching back and forth between the wiki template's custom options caused the Instructions to disappear. (#17805)

This commit is contained in:
balibabu
2026-08-05 10:57:25 +08:00
committed by GitHub
parent b0061fb4cc
commit f5cdd0160e
5 changed files with 41 additions and 27 deletions

View File

@@ -33,7 +33,7 @@ export function CompilationTemplateCard({
return ( return (
<Card className="group cursor-pointer h-full" onClick={onClick}> <Card className="group cursor-pointer h-full" onClick={onClick}>
<CardContent className="p-4 flex gap-3"> <CardContent className="py-4 px-2.5 flex gap-3">
<RAGFlowAvatar <RAGFlowAvatar
avatar={data.avatar} avatar={data.avatar}
name={data.name} name={data.name}

View File

@@ -4,6 +4,7 @@ import { SelectWithSearch } from '@/components/originui/select-with-search';
import { RAGFlowFormItem } from '@/components/ragflow-form'; import { RAGFlowFormItem } from '@/components/ragflow-form';
import { Textarea } from '@/components/ui/textarea'; import { Textarea } from '@/components/ui/textarea';
import { useFetchWikiPresets } from '@/hooks/use-compilation-template-request'; import { useFetchWikiPresets } from '@/hooks/use-compilation-template-request';
import { ICompilationTemplateBuiltin } from '@/interfaces/database/compilation-template';
import { UseFormReturn } from 'react-hook-form'; import { UseFormReturn } from 'react-hook-form';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@@ -13,11 +14,13 @@ import { FormSchemaType } from '../schema';
type BlueprintSectionProps = { type BlueprintSectionProps = {
form: UseFormReturn<FormSchemaType>; form: UseFormReturn<FormSchemaType>;
selectedTemplateIndex: number; selectedTemplateIndex: number;
builtins: ICompilationTemplateBuiltin[];
}; };
export function BlueprintSection({ export function BlueprintSection({
form, form,
selectedTemplateIndex, selectedTemplateIndex,
builtins,
}: BlueprintSectionProps) { }: BlueprintSectionProps) {
const { t } = useTranslation(); const { t } = useTranslation();
const { data: presets } = useFetchWikiPresets(); const { data: presets } = useFetchWikiPresets();
@@ -28,7 +31,7 @@ export function BlueprintSection({
instructionPath, instructionPath,
pageExample, pageExample,
handlePageExampleChange, handlePageExampleChange,
} = useBlueprintSelection({ form, selectedTemplateIndex, presets }); } = useBlueprintSelection({ form, selectedTemplateIndex, presets, builtins });
if (presets.length === 0) { if (presets.length === 0) {
return null; return null;

View File

@@ -1,7 +1,6 @@
import { ModelTreeSelectFormField } from '@/components/model-tree-select'; import { ModelTreeSelectFormField } from '@/components/model-tree-select';
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 { Checkbox } from '@/components/ui/checkbox';
import { SwitchFormField } from '@/components/switch-fom-field'; import { SwitchFormField } from '@/components/switch-fom-field';
import { Input } from '@/components/ui/input'; import { Input } from '@/components/ui/input';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
@@ -195,17 +194,11 @@ export function TemplateConfiguration({
</RAGFlowFormItem> </RAGFlowFormItem>
{kind === CompilationTemplateKind.Artifacts && ( {kind === CompilationTemplateKind.Artifacts && (
<RAGFlowFormItem <SwitchFormField
name={`templates.${selectedTemplateIndex}.config.plan`} name={`templates.${selectedTemplateIndex}.config.plan`}
label={t('setting.plan')} label={t('setting.plan')}
> vertical={false}
{(field) => ( />
<Checkbox
checked={!!field.value}
onCheckedChange={(v: boolean) => field.onChange(v)}
/>
)}
</RAGFlowFormItem>
)} )}
{kind === CompilationTemplateKind.Tree ? ( {kind === CompilationTemplateKind.Tree ? (

View File

@@ -1,10 +1,15 @@
import { SelectWithSearchFlagOptionType } from '@/components/originui/select-with-search'; import { SelectWithSearchFlagOptionType } from '@/components/originui/select-with-search';
import { IWikiPreset } from '@/interfaces/database/compilation-template'; import {
ICompilationTemplateBuiltin,
IWikiPreset,
} from '@/interfaces/database/compilation-template';
import { capitalize, lowerCase } from 'lodash';
import { useCallback, useMemo, useState } from 'react'; import { useCallback, useMemo, useState } from 'react';
import { UseFormReturn, useWatch } from 'react-hook-form'; import { UseFormReturn, useWatch } from 'react-hook-form';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { FormSchemaType } from '../schema'; import { FormSchemaType } from '../schema';
import { splitExampleToBlueprintFields } from '../utils';
export const CustomBlueprintValue = '__custom__'; export const CustomBlueprintValue = '__custom__';
@@ -12,6 +17,7 @@ type UseBlueprintSelectionParams = {
form: UseFormReturn<FormSchemaType>; form: UseFormReturn<FormSchemaType>;
selectedTemplateIndex: number; selectedTemplateIndex: number;
presets: IWikiPreset[]; presets: IWikiPreset[];
builtins: ICompilationTemplateBuiltin[];
}; };
const isSameBlueprintContent = ( const isSameBlueprintContent = (
@@ -26,10 +32,12 @@ export function useBlueprintSelection({
form, form,
selectedTemplateIndex, selectedTemplateIndex,
presets, presets,
builtins,
}: UseBlueprintSelectionParams) { }: UseBlueprintSelectionParams) {
const { t } = useTranslation(); const { t } = useTranslation();
const [explicitValue, setExplicitValue] = useState<string>(); const [explicitValue, setExplicitValue] = useState<string>();
const kindPath = `templates.${selectedTemplateIndex}.kind` as const;
const instructionPath = const instructionPath =
`templates.${selectedTemplateIndex}.config.instruction` as const; `templates.${selectedTemplateIndex}.config.instruction` as const;
const pageExamplePath = const pageExamplePath =
@@ -37,6 +45,10 @@ export function useBlueprintSelection({
const useBlueprintPath = const useBlueprintPath =
`templates.${selectedTemplateIndex}.config.use_blueprint` as const; `templates.${selectedTemplateIndex}.config.use_blueprint` as const;
const kind = useWatch({
control: form.control,
name: kindPath,
});
const instruction = useWatch({ const instruction = useWatch({
control: form.control, control: form.control,
name: instructionPath, name: instructionPath,
@@ -63,7 +75,7 @@ export function useBlueprintSelection({
const options = useMemo<SelectWithSearchFlagOptionType[]>( const options = useMemo<SelectWithSearchFlagOptionType[]>(
() => [ () => [
...presets.map((preset) => ({ ...presets.map((preset) => ({
label: preset.id, label: capitalize(lowerCase(preset.id)),
value: preset.id, value: preset.id,
})), })),
{ label: t('setting.custom'), value: CustomBlueprintValue }, { label: t('setting.custom'), value: CustomBlueprintValue },
@@ -77,19 +89,23 @@ export function useBlueprintSelection({
setExplicitValue(value); setExplicitValue(value);
if (value === CustomBlueprintValue) { if (value === CustomBlueprintValue) {
const defaultConfig = const builtinTemplate = builtins.find(
form.formState.defaultValues?.templates?.[selectedTemplateIndex] (template) => template.kind === kind,
?.config;
form.setValue(
instructionPath,
String(defaultConfig?.instruction ?? ''),
{ shouldValidate: false },
);
form.setValue(
pageExamplePath,
String(defaultConfig?.page_example ?? ''),
{ shouldValidate: false },
); );
const example =
typeof builtinTemplate?.config?.example === 'string'
? builtinTemplate.config.example
: '';
const {
instruction: defaultInstruction,
page_example: defaultPageExample,
} = splitExampleToBlueprintFields(example);
form.setValue(instructionPath, defaultInstruction, {
shouldValidate: false,
});
form.setValue(pageExamplePath, defaultPageExample, {
shouldValidate: false,
});
} else { } else {
const preset = presets.find((item) => item.id === value); const preset = presets.find((item) => item.id === value);
if (!preset) return; if (!preset) return;
@@ -104,11 +120,12 @@ export function useBlueprintSelection({
form.setValue(useBlueprintPath, true, { shouldValidate: false }); form.setValue(useBlueprintPath, true, { shouldValidate: false });
}, },
[ [
builtins,
form, form,
instructionPath, instructionPath,
kind,
pageExamplePath, pageExamplePath,
presets, presets,
selectedTemplateIndex,
selectedValue, selectedValue,
useBlueprintPath, useBlueprintPath,
], ],

View File

@@ -66,6 +66,7 @@ export default function EditNextCompilationTemplate() {
<BlueprintSection <BlueprintSection
form={form} form={form}
selectedTemplateIndex={SelectedTemplateIndex} selectedTemplateIndex={SelectedTemplateIndex}
builtins={builtins}
/> />
)} )}
</TemplateConfiguration> </TemplateConfiguration>