[PR #24994] Refactor/model credential #30877

Closed
opened 2026-02-21 20:48:24 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/24994

State: closed
Merged: Yes


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

This pull request refactors the form field and credential management components to improve flexibility, especially around conditional field rendering and credential modal handling. The main changes include moving conditional field visibility logic from BaseField to BaseForm, introducing an onChange callback for better form value tracking, and updating modal and credential handling for more granular control.

Form Field Handling Improvements

  • Moved the show_on conditional rendering logic from BaseField to BaseForm, allowing fields to be conditionally displayed based on other field values at the form level for more centralized control. (web/app/components/base/form/components/base/base-field.tsx [1] [2]; web/app/components/base/form/components/base/base-form.tsx [3] [4] [5]
  • Added an onChange prop to both BaseField and BaseForm, enabling parent components to react to field value changes and synchronize form state externally. (web/app/components/base/form/components/base/base-field.tsx [1] [2] [3] [4] [5] [6] [7] [8]; web/app/components/base/form/components/base/base-form.tsx [9] [10] [11]

Credential and Modal Management Enhancements

  • Extended credential and provider type definitions with new fields (current_credential_name, can_added_models) and introduced ModelModalModeEnum for more explicit modal mode control. (web/app/components/header/account-setting/model-provider-page/declarations.ts [1] [2] [3]
  • Updated modal handler logic to support passing extra parameters (including mode and callbacks) and refactored modal save handling for better extensibility. (web/app/components/header/account-setting/model-provider-page/hooks.ts [1] [2]

UI and Prop Handling Updates

  • Refactored credential addition UI (AddCredentialInLoadBalancing) to use new modal modes, pass more granular props, and improve handling of credential availability and custom model configuration. (web/app/components/header/account-setting/model-provider-page/model-auth/add-credential-in-load-balancing.tsx [1] [2] [3]

These changes collectively make the form and credential management more modular, easier to extend, and better suited for dynamic UI requirements.

close https://github.com/langgenius/dify/issues/25006
close https://github.com/langgenius/dify-official-plugins/issues/1591
close https://github.com/langgenius/dify/issues/24824

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/24994 **State:** closed **Merged:** Yes --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary This pull request refactors the form field and credential management components to improve flexibility, especially around conditional field rendering and credential modal handling. The main changes include moving conditional field visibility logic from `BaseField` to `BaseForm`, introducing an `onChange` callback for better form value tracking, and updating modal and credential handling for more granular control. ### Form Field Handling Improvements * Moved the `show_on` conditional rendering logic from `BaseField` to `BaseForm`, allowing fields to be conditionally displayed based on other field values at the form level for more centralized control. (`web/app/components/base/form/components/base/base-field.tsx` [[1]](diffhunk://#diff-2457c3078008eacd7ead017ea6e3fee8215808a9761871495ce2f514fee7137eL43) [[2]](diffhunk://#diff-2457c3078008eacd7ead017ea6e3fee8215808a9761871495ce2f514fee7137eL93-R99); `web/app/components/base/form/components/base/base-form.tsx` [[3]](diffhunk://#diff-8ac9c51391fc4ca49bc7aaea03f25da34d7778fa9420b1601de8512340fd1eaeR71-R83) [[4]](diffhunk://#diff-8ac9c51391fc4ca49bc7aaea03f25da34d7778fa9420b1601de8512340fd1eaeR108-R130) [[5]](diffhunk://#diff-8ac9c51391fc4ca49bc7aaea03f25da34d7778fa9420b1601de8512340fd1eaeL112-R140) * Added an `onChange` prop to both `BaseField` and `BaseForm`, enabling parent components to react to field value changes and synchronize form state externally. (`web/app/components/base/form/components/base/base-field.tsx` [[1]](diffhunk://#diff-2457c3078008eacd7ead017ea6e3fee8215808a9761871495ce2f514fee7137eR27) [[2]](diffhunk://#diff-2457c3078008eacd7ead017ea6e3fee8215808a9761871495ce2f514fee7137eR37) [[3]](diffhunk://#diff-2457c3078008eacd7ead017ea6e3fee8215808a9761871495ce2f514fee7137eL93-R99) [[4]](diffhunk://#diff-2457c3078008eacd7ead017ea6e3fee8215808a9761871495ce2f514fee7137eL127-R121) [[5]](diffhunk://#diff-2457c3078008eacd7ead017ea6e3fee8215808a9761871495ce2f514fee7137eL142-R136) [[6]](diffhunk://#diff-2457c3078008eacd7ead017ea6e3fee8215808a9761871495ce2f514fee7137eL158-R152) [[7]](diffhunk://#diff-2457c3078008eacd7ead017ea6e3fee8215808a9761871495ce2f514fee7137eL169-R170) [[8]](diffhunk://#diff-2457c3078008eacd7ead017ea6e3fee8215808a9761871495ce2f514fee7137eL192-R189); `web/app/components/base/form/components/base/base-form.tsx` [[9]](diffhunk://#diff-8ac9c51391fc4ca49bc7aaea03f25da34d7778fa9420b1601de8512340fd1eaeR38) [[10]](diffhunk://#diff-8ac9c51391fc4ca49bc7aaea03f25da34d7778fa9420b1601de8512340fd1eaeR52) [[11]](diffhunk://#diff-8ac9c51391fc4ca49bc7aaea03f25da34d7778fa9420b1601de8512340fd1eaeR108-R130) ### Credential and Modal Management Enhancements * Extended credential and provider type definitions with new fields (`current_credential_name`, `can_added_models`) and introduced `ModelModalModeEnum` for more explicit modal mode control. (`web/app/components/header/account-setting/model-provider-page/declarations.ts` [[1]](diffhunk://#diff-10bf23a38e0528183c794f3fe75fe11a9d49b460ea74c8bcc33c6cb9b31b4e86R202) [[2]](diffhunk://#diff-10bf23a38e0528183c794f3fe75fe11a9d49b460ea74c8bcc33c6cb9b31b4e86R240-R243) [[3]](diffhunk://#diff-10bf23a38e0528183c794f3fe75fe11a9d49b460ea74c8bcc33c6cb9b31b4e86R331-R337) * Updated modal handler logic to support passing extra parameters (including mode and callbacks) and refactored modal save handling for better extensibility. (`web/app/components/header/account-setting/model-provider-page/hooks.ts` [[1]](diffhunk://#diff-11def92decc3753fadb94d96d6e2194ef5a4f13632249fd9c42a4982896ee516R16) [[2]](diffhunk://#diff-11def92decc3753fadb94d96d6e2194ef5a4f13632249fd9c42a4982896ee516L351-R376) ### UI and Prop Handling Updates * Refactored credential addition UI (`AddCredentialInLoadBalancing`) to use new modal modes, pass more granular props, and improve handling of credential availability and custom model configuration. (`web/app/components/header/account-setting/model-provider-page/model-auth/add-credential-in-load-balancing.tsx` [[1]](diffhunk://#diff-b7ff4b66b20de9616357cbd9044c3ad7089847bc2b928a78a34a61ccc1baa2deL4-R26) [[2]](diffhunk://#diff-b7ff4b66b20de9616357cbd9044c3ad7089847bc2b928a78a34a61ccc1baa2deR35-R45) [[3]](diffhunk://#diff-b7ff4b66b20de9616357cbd9044c3ad7089847bc2b928a78a34a61ccc1baa2deL77-R87) These changes collectively make the form and credential management more modular, easier to extend, and better suited for dynamic UI requirements. close https://github.com/langgenius/dify/issues/25006 close https://github.com/langgenius/dify-official-plugins/issues/1591 close https://github.com/langgenius/dify/issues/24824 ## Screenshots | Before | After | |--------|-------| | ... | ... | ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:48:24 -05:00
yindo closed this issue 2026-02-21 20:48:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30877