@@ -17,6 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1717import React from 'react'
1818import styled from 'styled-components'
1919
20+ import { showOpenstackCurrentUserSwitch } from '../../../config'
21+
2022import ToggleButtonBar from '../../../components/atoms/ToggleButtonBar'
2123import type { Field } from '../../../types/Field'
2224import { Wrapper , Fields , FieldStyled , Row } from '../default/ContentPlugin'
@@ -48,6 +50,10 @@ class ContentPlugin extends React.Component<Props, State> {
4850
4951 previouslySelectedChoices : string [ ] = [ ]
5052
53+ get useCurrentUser ( ) : boolean {
54+ return Boolean ( this . getFieldValue ( this . props . connectionInfoSchema . find ( n => n . name === 'openstack_use_current_user' ) ) )
55+ }
56+
5157 componentDidMount ( ) {
5258 this . props . onRef ( this )
5359 }
@@ -99,7 +105,7 @@ class ContentPlugin extends React.Component<Props, State> {
99105 let inputChoices = [ 'user_domain' , 'project_domain' ]
100106
101107 const invalidFields = this . props . connectionInfoSchema . filter ( field => {
102- if ( field . required ) {
108+ if ( this . isFieldRequired ( field ) ) {
103109 let value = this . getFieldValue ( field )
104110 return ! value
105111 }
@@ -117,11 +123,15 @@ class ContentPlugin extends React.Component<Props, State> {
117123 }
118124
119125 filterSimpleAdvanced ( ) : Field [ ] {
120- let extraAdvancedFields = [ 'description' , 'glance_api_version' , 'identity_api_version' ]
126+ let extraAdvancedFields = [ 'description' , 'glance_api_version' , 'identity_api_version' , 'openstack_use_current_user' ]
121127 if ( this . getApiVersion ( ) > 2 ) {
122128 extraAdvancedFields = extraAdvancedFields . concat ( [ 'user_domain' , 'project_domain' ] )
123129 }
124130 let ignoreFields = [ 'user_domain_id' , 'project_domain_id' , 'user_domain_name' , 'project_domain_name' ]
131+ if ( ! showOpenstackCurrentUserSwitch ) {
132+ ignoreFields . push ( 'openstack_use_current_user' )
133+ }
134+
125135 return this . props . connectionInfoSchema . filter ( f => ! ignoreFields . find ( i => i === f . name ) ) . filter ( field => {
126136 if ( this . state . useAdvancedOptions ) {
127137 return true
@@ -130,6 +140,10 @@ class ContentPlugin extends React.Component<Props, State> {
130140 } )
131141 }
132142
143+ isFieldRequired ( field : Field ) {
144+ return this . useCurrentUser ? field . name = = = 'name' : field . required
145+ }
146+
133147 renderSimpleAdvancedToggle ( ) {
134148 return (
135149 < ToggleButtonBarStyled
@@ -146,12 +160,17 @@ class ContentPlugin extends React.Component<Props, State> {
146160 let fields = this . filterSimpleAdvanced ( )
147161
148162 fields . forEach ( ( field , i ) => {
163+ let disabled = this . props . disabled
164+ || ( this . useCurrentUser && field . name !== 'name' && field . name !== 'description' && field . name !== 'openstack_use_current_user' )
165+ let required = this . isFieldRequired ( field )
166+ || ( this . getApiVersion ( ) > 2 ? field . name === 'user_domain' || field . name === 'project_domain' : false )
167+
149168 const currentField = (
150169 < FieldStyled
151170 { ...field }
152- required = { field . required || ( this . getApiVersion ( ) > 2 ? field . name === 'user_domain' || field . name === 'project_domain' : false ) }
171+ required = { required }
153172 large
154- disabled = { this . props . disabled }
173+ disabled = { disabled }
155174 password = { field . name === 'password' }
156175 highlight = { this . props . invalidFields . findIndex ( fn => fn === field . name ) > - 1 }
157176 value = { this . getFieldValue ( field ) }
@@ -167,7 +186,7 @@ class ContentPlugin extends React.Component<Props, State> {
167186 { currentField }
168187 </ Row >
169188 ) )
170- } else if ( i === this . props . connectionInfoSchema . length - 1 ) {
189+ } else if ( i === fields . length - 1 ) {
171190 rows . push ( (
172191 < Row key = { field . name } >
173192 { currentField }
0 commit comments