@@ -22,7 +22,7 @@ import {
2222 TacoMarkDown ,
2323} from "lowcoder-design" ;
2424import { DatasourceFormProps } from "./datasourceFormRegistry" ;
25- import { DatasourceNameFormInputItem , GeneralSettingFormSectionLabel } from "../form" ;
25+ import { AdvancedSettingFormSectionLabel , CertValidationFormItem , DatasourceNameFormInputItem , ForwardCookiesFormItem , GeneralSettingFormSectionLabel , encryptedPlaceholder } from "../form" ;
2626import {
2727 DataSourceParamConfig ,
2828 ParamOption ,
@@ -38,6 +38,9 @@ import { FieldData } from "rc-field-form/es/interface";
3838import { default as Alert } from "antd/es/alert" ;
3939import { default as Form } from "antd/es/form" ;
4040import { default as Input } from "antd/es/input" ;
41+ import { AuthType , AuthTypeOptions } from "./httpDatasourceForm" ;
42+ import { useSelector } from "react-redux" ;
43+ import { getUser } from "@lowcoder-ee/redux/selectors/usersSelectors" ;
4144
4245const TooltipWrapper = styled . div `
4346 .markdown-body {
@@ -130,14 +133,24 @@ export const PluginDataSourceForm = (props: DatasourceFormProps) => {
130133 const [ extraParamConfigs , setExtraParamConfigs ] = useState < DataSourceParamConfig [ ] > ( [ ] ) ;
131134 const [ isExtraParamsRefreshing , setExtraParamRefreshing ] = useState ( false ) ;
132135 const [ isExtraParamsRefreshError , setExtraParamRefreshError ] = useState ( false ) ;
136+
133137 const pluginDef = dataSourceTypeInfo ?. definition || datasource . pluginDefinition ;
134138 const pluginName = dataSourceTypeInfo ?. id || datasource . pluginDefinition ?. id ;
135139 const isEditing = ! ! datasource ;
136140 const hasDynamicConfig = ! ! pluginDef ?. dataSourceConfig ?. extra ;
141+
142+ const [ authType , setAuthType ] = useState ( pluginDef ?. dataSourceConfig ?. authConfig ?. type ) ;
143+ const [ authId , setAuthId ] = useState ( pluginDef ?. dataSourceConfig ?. authConfig ?. authId ) ;
137144
138145 const readyStatusCallbackRef = useRef ( onFormReadyStatusChange ) ;
139146 readyStatusCallbackRef . current = onFormReadyStatusChange ;
140147
148+ const userAuthSources = useSelector ( getUser ) . connections ?. filter ( authSource => authSource . source !== "EMAIL" ) ; ;
149+ const userAuthSourcesOptions = userAuthSources ?. map ( item => ( {
150+ label : item . source ,
151+ value : item . authId
152+ } ) ) || [ ] ;
153+
141154 const handleRefreshExtraParams = useCallback ( ( ) => {
142155 if ( ! pluginName ) {
143156 return ;
@@ -205,6 +218,65 @@ export const PluginDataSourceForm = (props: DatasourceFormProps) => {
205218 const initialValues = getDefaultValues ( pluginDef , datasource ) ;
206219 const hasGeneralSettings = dataSourceConfig . params ?. [ 0 ] ?. type !== "groupTitle" ;
207220
221+ const UsernameFormItem = (
222+ < FormInputItem
223+ name = { "username" }
224+ label = "Username"
225+ initialValue = { ( dataSourceConfig ?. authConfig as any ) ?. username }
226+ required = { true }
227+ rules = { [ { required : true , message : trans ( "query.userNameRequiredMessage" ) } ] }
228+ labelWidth = { 142 }
229+ />
230+ ) ;
231+
232+ const PasswordFormItem = (
233+ < FormInputItem
234+ name = { "password" }
235+ label = "Password"
236+ initialValue = { ( dataSourceConfig ?. authConfig as any ) ?. password }
237+ required = { true }
238+ rules = { [ { required : ! dataSourceConfig , message : trans ( "query.passwordRequiredMessage" ) } ] }
239+ labelWidth = { 142 }
240+ // eslint-disable-next-line only-ascii/only-ascii
241+ placeholder = { props . datasource ? encryptedPlaceholder : "••••••••••••" }
242+ />
243+ ) ;
244+
245+ const showAuthItem = ( type : AuthType ) => {
246+ switch ( type ) {
247+ case "BASIC_AUTH" :
248+ return (
249+ < >
250+ { UsernameFormItem }
251+ { PasswordFormItem }
252+ </ >
253+ ) ;
254+ case "DIGEST_AUTH" :
255+ return (
256+ < >
257+ { UsernameFormItem }
258+ { PasswordFormItem }
259+ </ >
260+ ) ;
261+ }
262+ } ;
263+
264+ const showUserAuthSourceSelector = ( ) => {
265+ if ( authType === "OAUTH2_INHERIT_FROM_LOGIN" ) {
266+ return (
267+ < FormSelectItem
268+ name = { "authId" }
269+ label = "User Authentication Source"
270+ options = { userAuthSourcesOptions }
271+ initialValue = { dataSourceConfig ?. authConfig ? authId : null }
272+ afterChange = { ( value ) => setAuthId ( value ) }
273+ labelWidth = { 142 }
274+ />
275+ ) ;
276+ }
277+ return null ;
278+ } ;
279+
208280 return (
209281 < DatasourceForm form = { form } initialValues = { initialValues } onFieldsChange = { handleFieldsChange } >
210282 < Form . Item noStyle name = "extra" >
@@ -237,6 +309,25 @@ export const PluginDataSourceForm = (props: DatasourceFormProps) => {
237309 ) ;
238310 } ) }
239311 </ FormSection >
312+ < FormSection $size = { props . size } >
313+ < FormSectionLabel > { trans ( "query.authentication" ) } </ FormSectionLabel >
314+ < FormSelectItem
315+ name = { "authConfigType" }
316+ label = { trans ( "query.authenticationType" ) }
317+ options = { AuthTypeOptions }
318+ initialValue = { dataSourceConfig ?. authConfig ?. type ?? "NO_AUTH" }
319+ afterChange = { ( value ) => setAuthType ( value ) }
320+ labelWidth = { 142 }
321+ />
322+ { showUserAuthSourceSelector ( ) }
323+ { showAuthItem ( authType ) }
324+ </ FormSection >
325+
326+ < FormSection $size = { props . size } >
327+ < AdvancedSettingFormSectionLabel />
328+ < CertValidationFormItem datasource = { props . datasource } />
329+ < ForwardCookiesFormItem datasource = { props . datasource } />
330+ </ FormSection >
240331 { isExtraParamsRefreshing && (
241332 < Alert showIcon type = "info" message = { trans ( "query.dynamicDataSourceConfigLoadingText" ) } />
242333 ) }
0 commit comments