@@ -22,7 +22,7 @@ import {
22
22
TacoMarkDown ,
23
23
} from "lowcoder-design" ;
24
24
import { DatasourceFormProps } from "./datasourceFormRegistry" ;
25
- import { DatasourceNameFormInputItem , GeneralSettingFormSectionLabel } from "../form" ;
25
+ import { AdvancedSettingFormSectionLabel , CertValidationFormItem , DatasourceNameFormInputItem , ForwardCookiesFormItem , GeneralSettingFormSectionLabel , encryptedPlaceholder } from "../form" ;
26
26
import {
27
27
DataSourceParamConfig ,
28
28
ParamOption ,
@@ -38,6 +38,9 @@ import { FieldData } from "rc-field-form/es/interface";
38
38
import { default as Alert } from "antd/es/alert" ;
39
39
import { default as Form } from "antd/es/form" ;
40
40
import { 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" ;
41
44
42
45
const TooltipWrapper = styled . div `
43
46
.markdown-body {
@@ -130,14 +133,24 @@ export const PluginDataSourceForm = (props: DatasourceFormProps) => {
130
133
const [ extraParamConfigs , setExtraParamConfigs ] = useState < DataSourceParamConfig [ ] > ( [ ] ) ;
131
134
const [ isExtraParamsRefreshing , setExtraParamRefreshing ] = useState ( false ) ;
132
135
const [ isExtraParamsRefreshError , setExtraParamRefreshError ] = useState ( false ) ;
136
+
133
137
const pluginDef = dataSourceTypeInfo ?. definition || datasource . pluginDefinition ;
134
138
const pluginName = dataSourceTypeInfo ?. id || datasource . pluginDefinition ?. id ;
135
139
const isEditing = ! ! datasource ;
136
140
const hasDynamicConfig = ! ! pluginDef ?. dataSourceConfig ?. extra ;
141
+
142
+ const [ authType , setAuthType ] = useState ( pluginDef ?. dataSourceConfig ?. authConfig ?. type ) ;
143
+ const [ authId , setAuthId ] = useState ( pluginDef ?. dataSourceConfig ?. authConfig ?. authId ) ;
137
144
138
145
const readyStatusCallbackRef = useRef ( onFormReadyStatusChange ) ;
139
146
readyStatusCallbackRef . current = onFormReadyStatusChange ;
140
147
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
+
141
154
const handleRefreshExtraParams = useCallback ( ( ) => {
142
155
if ( ! pluginName ) {
143
156
return ;
@@ -205,6 +218,65 @@ export const PluginDataSourceForm = (props: DatasourceFormProps) => {
205
218
const initialValues = getDefaultValues ( pluginDef , datasource ) ;
206
219
const hasGeneralSettings = dataSourceConfig . params ?. [ 0 ] ?. type !== "groupTitle" ;
207
220
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
+
208
280
return (
209
281
< DatasourceForm form = { form } initialValues = { initialValues } onFieldsChange = { handleFieldsChange } >
210
282
< Form . Item noStyle name = "extra" >
@@ -237,6 +309,25 @@ export const PluginDataSourceForm = (props: DatasourceFormProps) => {
237
309
) ;
238
310
} ) }
239
311
</ 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 >
240
331
{ isExtraParamsRefreshing && (
241
332
< Alert showIcon type = "info" message = { trans ( "query.dynamicDataSourceConfigLoadingText" ) } />
242
333
) }
0 commit comments