feat(web): improve knowledge base form validation and parser config handling
- Refactor form validation logic to support tab-specific field validation in edit mode - Add conditional validation for knowledge graph fields when editing existing knowledge base - Preserve all existing parser_config fields when merging graphrag configuration - Skip third-party authentication check when editing on knowledge graph tab - Update form value retrieval to include disabled fields using getFieldsValue(true) - Improve comments to clarify parser_config field preservation and validation behavior - This change enables users to edit knowledge graph settings without re-validating all basic configuration fields
This commit is contained in:
@@ -221,9 +221,9 @@ const CreateModal = forwardRef<CreateModalRef, CreateModalRefProps>(({
|
|||||||
status: record.status,
|
status: record.status,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Process parser_config data, set default values if not present
|
// Process parser_config data, preserve all existing fields and merge graphrag config
|
||||||
baseValues.parser_config = {
|
baseValues.parser_config = {
|
||||||
...record.parser_config,
|
...record.parser_config, // Preserve all existing parser_config fields (yuque_user_id, yuque_token, feishu_app_id, etc.)
|
||||||
graphrag: {
|
graphrag: {
|
||||||
use_graphrag: false,
|
use_graphrag: false,
|
||||||
scene_name: '',
|
scene_name: '',
|
||||||
@@ -362,12 +362,32 @@ const CreateModal = forwardRef<CreateModalRef, CreateModalRefProps>(({
|
|||||||
// Actual save logic
|
// Actual save logic
|
||||||
const performSave = async () => {
|
const performSave = async () => {
|
||||||
try {
|
try {
|
||||||
await form.validateFields();
|
// Get fields to validate based on current tab and edit mode
|
||||||
setLoading(true);
|
let fieldsToValidate: any[] | undefined = undefined;
|
||||||
const formValues = form.getFieldsValue();
|
|
||||||
|
|
||||||
// Check Third-party authentication before saving
|
// If in edit mode and on knowledge graph tab, only validate knowledge graph fields
|
||||||
if (formValues.type === 'Third-party' || currentType === 'Third-party') {
|
if (datasets?.id && activeTab === 'knowledgeGraph') {
|
||||||
|
fieldsToValidate = [
|
||||||
|
['parser_config', 'graphrag', 'use_graphrag'],
|
||||||
|
['parser_config', 'graphrag', 'scene_name'],
|
||||||
|
['parser_config', 'graphrag', 'entity_types'],
|
||||||
|
['parser_config', 'graphrag', 'method'],
|
||||||
|
['parser_config', 'graphrag', 'resolution'],
|
||||||
|
['parser_config', 'graphrag', 'community'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate only specified fields or all fields
|
||||||
|
await form.validateFields(fieldsToValidate);
|
||||||
|
setLoading(true);
|
||||||
|
// Get all field values including disabled fields
|
||||||
|
const formValues = form.getFieldsValue(true);
|
||||||
|
|
||||||
|
// Only check Third-party authentication when creating new or explicitly on basic config tab
|
||||||
|
// Skip authentication check when editing and on knowledge graph tab
|
||||||
|
const shouldCheckAuth = !datasets?.id || activeTab === 'basic';
|
||||||
|
|
||||||
|
if (shouldCheckAuth && (formValues.type === 'Third-party' || currentType === 'Third-party')) {
|
||||||
const platform = formValues.parser_config?._third_party_platform || thirdPartyPlatform;
|
const platform = formValues.parser_config?._third_party_platform || thirdPartyPlatform;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user