@@ -25,6 +25,7 @@ import {
2525 Header ,
2626 Input ,
2727 Modal ,
28+ Select ,
2829 SpaceBetween ,
2930 StatusIndicator ,
3031 Table ,
@@ -35,6 +36,7 @@ import { valueAsArray } from '@/utils';
3536import { AcceleratorConfigurationNode } from '../configuration' ;
3637import { isDisabled , setDisabled } from '../util' ;
3738import { LabelWithDescription } from './label-with-description' ;
39+ import { OptionDefinition } from '../../../../node_modules/@awsui/components-react/internal/components/option/interfaces' ;
3840
3941interface SimpleAccountValue {
4042 key : string ;
@@ -45,6 +47,7 @@ interface SimpleAccountValue {
4547 budgetAmount : number ;
4648 budgetEmail : string ;
4749 useOuSettings : boolean ;
50+ srcFile : string ;
4851}
4952
5053export interface AccountTableProps {
@@ -64,6 +67,7 @@ export const AccountTable = observer(({ state, accountType }: AccountTableProps)
6467 const [ modalType , setModalType ] = useState < 'add' | 'edit' > ( 'add' ) ;
6568 const [ modalInitialValue , setModalInitialValue ] = useState < Partial < SimpleAccountValue > > ( { } ) ;
6669 const [ selectedItem , setSelectedItem ] = useState < SimpleAccountValue | undefined > ( undefined ) ;
70+ const [ cannotAddAccount , setCannotAddAccount ] = useState ( false ) ;
6771 const [ permAlertVisible , setPermAlertVisible ] = useState ( false ) ;
6872 const [ dependencyAlertVisible , setDependencyAlertVisible ] = useState ( false ) ;
6973 const [ editNameAlert , setEditNameAlert ] = useState ( false ) ;
@@ -93,6 +97,7 @@ export const AccountTable = observer(({ state, accountType }: AccountTableProps)
9397 budgetAmount : budget ?. amount ?? 1000 ,
9498 budgetEmail : budget ?. alerts ?. [ 0 ] ?. emails ?. [ 0 ] ?? 'you@example.com' ,
9599 useOuSettings : budget === undefined || isDisabled ( state , [ ...node . path , key ] ) ,
100+ srcFile : accountConfig ?. [ 'src-file' ] ?? '' ,
96101 } ;
97102 } ) ;
98103
@@ -106,31 +111,35 @@ export const AccountTable = observer(({ state, accountType }: AccountTableProps)
106111 setModalType ( 'edit' ) ;
107112 setModalInitialValue ( selectedItem ?? { } ) ;
108113 setModalVisible ( true ) ;
109- console . log ( items )
110114 } ;
111115
112116 const handleSubmitAdd = action ( ( value : SimpleAccountValue ) => {
113- const { key, ou, name, budgetAmount : amount , budgetEmail : email , useOuSettings } = value ;
117+ const { key, ou, name, budgetAmount : amount , budgetEmail : email , useOuSettings, srcFile } = value ;
118+ console . log ( key , ou , name , amount , email , useOuSettings , srcFile )
114119 if ( keyExists ( key ) || nameExists ( name ) ) {
115120 setAddNameAlert ( true ) ;
116- } else {
117- accounts [ key ] = {
121+ return
122+ } else if ( validateForm ( key , ou , name , amount , email , srcFile ) ) {
123+ accounts [ String ( key ) ] = {
118124 'account-name' : name ,
119125 ou,
120- budget : createInitialBudget ( amount , email ) ,
121- }
122- } ;
123-
126+ email,
127+ "src-filename" : srcFile ,
128+ budget : createInitialBudget ( amount , email )
129+ }
130+ return
131+ } else {
132+ setCannotAddAccount ( true ) ;
133+ }
124134 // Disable the budget if the "use OU settings" field is checked
125135 setDisabled ( state , [ ...node . path , key ] , useOuSettings ?? false ) ;
126136 } ) ;
127137
128138 const handleSubmitEdit = action ( ( value : SimpleAccountValue ) => {
129139 const { key, ou, name, budgetAmount : amount , budgetEmail : email , useOuSettings } = value ;
130- console . log ( name )
131140 accounts [ key ] [ 'ou' ] = ou ;
132141
133- if ( nameExists ( name ) ) {
142+ if ( value . name != name && nameExists ( name ) ) {
134143 setEditNameAlert ( true ) ;
135144 } else {
136145 accounts [ key ] [ 'account-name' ] = name ;
@@ -149,6 +158,16 @@ export const AccountTable = observer(({ state, accountType }: AccountTableProps)
149158 setDisabled ( state , [ ...node . path , key ] , useOuSettings ?? false ) ;
150159 } ) ;
151160
161+ const validateForm = ( key : string , ou : string , name : string , amount : number , email : string , srcFile : string ) => {
162+ if ( key == '' || key == null || ou == '' ||
163+ name == '' || name == null || Number . isNaN ( amount ) || email == '' ||
164+ srcFile == '' ) {
165+ return false
166+ } else {
167+ return true
168+ }
169+ }
170+
152171 const keyExists = ( addKey : string | undefined ) => {
153172 for ( let each in items ) {
154173 if ( items [ each ] [ 'key' ] == addKey ) {
@@ -221,6 +240,7 @@ export const AccountTable = observer(({ state, accountType }: AccountTableProps)
221240 initialValue = { modalInitialValue }
222241 onDismiss = { ( ) => setModalVisible ( false ) }
223242 onSubmit = { handleSubmit }
243+ state = { state }
224244 />
225245 < Table
226246 items = { items }
@@ -257,6 +277,10 @@ export const AccountTable = observer(({ state, accountType }: AccountTableProps)
257277 < Box textAlign = "right" > { currency ( amount ) } </ Box >
258278 ) ,
259279 } ,
280+ {
281+ header : "Source File Name" ,
282+ cell : ( { srcFile } ) => srcFile ,
283+ } ,
260284 ] }
261285 header = {
262286 < >
@@ -286,6 +310,19 @@ export const AccountTable = observer(({ state, accountType }: AccountTableProps)
286310 ? tr ( 'wizard.headers.mandatory_accounts' )
287311 : tr ( 'wizard.headers.workload_accounts' ) }
288312 </ Header >
313+ {
314+ cannotAddAccount === true &&
315+ < Alert
316+ onDismiss = { ( ) => setCannotAddAccount ( false ) }
317+ visible = { cannotAddAccount }
318+ dismissible
319+ type = "error"
320+ dismissAriaLabel = "Close alert"
321+ header = "Can't add new account"
322+ >
323+ Account fields cannot be left empty when adding a new account.
324+ </ Alert >
325+ }
289326 {
290327 permAlertVisible === true &&
291328 < Alert
@@ -360,6 +397,7 @@ interface AddModifyAccountModalProps {
360397 initialValue : Partial < SimpleAccountValue > ;
361398 onDismiss : ( ) => void ;
362399 onSubmit : ( value : SimpleAccountValue ) => void ;
400+ state : any ;
363401}
364402
365403/**
@@ -372,15 +410,16 @@ const AddModifyAccountModal = ({
372410 initialValue,
373411 onDismiss,
374412 onSubmit,
413+ state,
375414} : AddModifyAccountModalProps ) => {
376415 const { tr } = useI18n ( ) ;
377416 const accountKeyInputProps = useInput ( ) ;
378417 const accountNameInputProps = useInput ( ) ;
379418 const emailInputProps = useInput ( ) ;
380- const ouInputProps = useInput ( ) ;
381419 const useOuInputProps = useCheckboxInput ( ) ;
382420 const budgetAmountInputProps = useInput ( ) ;
383421 const budgetEmailInputProps = useInput ( ) ;
422+ const srcFileInputProps = useInput ( ) ;
384423
385424 // prettier-ignore
386425 const headerText = type === 'add'
@@ -395,31 +434,44 @@ const AddModifyAccountModal = ({
395434 const { title : emailTitle , description : emailDesc } = tr ( dummyAccountNode . nested ( 'email' ) ) ;
396435 const { title : ouTitle , description : ouDesc } = tr ( dummyAccountNode . nested ( 'ou' ) ) ;
397436
437+ const organizationalUnitsNode = AcceleratorConfigurationNode . nested ( 'organizational-units' ) ;
438+ const organizationalUnits = organizationalUnitsNode . get ( state ) ?? { } ;
439+
440+ var options : { label : string ; value : string ; } [ ] = [ ]
441+ const populateSelect = ( ) => {
442+ for ( const each in organizationalUnits ) {
443+ options . push ( { label : each , value : each } )
444+ }
445+ }
446+
398447 const keyTitle = tr ( 'wizard.labels.account_key' ) ;
399448 const useOuSettingTitle = tr ( 'wizard.labels.account_budget_use_ou' ) ;
400449 const budgetAmountTitle = tr ( 'wizard.labels.account_budget_amount' ) ;
401450 const budgetEmailTitle = tr ( 'wizard.labels.account_budget_email' ) ;
402-
451+ const [ selectedOption , setSelectedOption ] = useState < OptionDefinition > ( { label : "" , value : "" } ) ;
452+
403453 const handleSubmit = ( ) => {
404454 onSubmit ( {
405- key : accountKeyInputProps . value ,
406- ou : ouInputProps . value ,
407- name : accountNameInputProps . value ,
408- email : budgetEmailInputProps . value ,
455+ key : accountKeyInputProps . value ?? '' ,
456+ ou : String ( selectedOption . value ) ?? '' ,
457+ name : accountNameInputProps . value ?? '' ,
458+ email : emailInputProps . value ?? '' ,
409459 useOuSettings : useOuInputProps . checked ,
410- budgetAmount : Number ( budgetAmountInputProps . value ) ,
411- budgetEmail : budgetEmailInputProps . value ,
460+ budgetAmount : Number ( budgetAmountInputProps . value ) ?? NaN ,
461+ budgetEmail : budgetEmailInputProps . value ?? '' ,
462+ srcFile : srcFileInputProps . value ?? '' ,
412463 } ) ;
413464 } ;
414465
415466 useEffect ( ( ) => {
416467 accountKeyInputProps . setValue ( initialValue . key ?? '' ) ;
417468 accountNameInputProps . setValue ( initialValue . name ?? '' ) ;
418469 emailInputProps . setValue ( initialValue . email ?? '' ) ;
419- ouInputProps . setValue ( initialValue . ou ?? '' ) ;
470+ setSelectedOption ( { label : initialValue . ou ?? '' , value : initialValue . ou ?? '' } ) ;
420471 useOuInputProps . setChecked ( initialValue . useOuSettings ?? false ) ;
421472 budgetAmountInputProps . setValue ( `${ initialValue . budgetAmount } ` ) ;
422473 budgetEmailInputProps . setValue ( initialValue . budgetEmail ?? '' ) ;
474+ srcFileInputProps . setValue ( initialValue . srcFile ?? '' ) ;
423475 } , [ visible ] ) ;
424476
425477 return (
@@ -440,7 +492,7 @@ const AddModifyAccountModal = ({
440492 handleSubmit ( ) ;
441493 } }
442494 >
443- { console . log ( ouInputProps ) }
495+ { populateSelect ( ) }
444496 < SpaceBetween size = "m" >
445497 < FormField label = { keyTitle } stretch >
446498 < Input { ...accountKeyInputProps } disabled = { type === 'edit' } />
@@ -452,17 +504,27 @@ const AddModifyAccountModal = ({
452504 < Input { ...emailInputProps } />
453505 </ FormField >
454506 < FormField label = { ouTitle } description = { ouDesc } stretch >
455- < Input { ...ouInputProps } />
507+ < Select
508+ selectedOption = { selectedOption }
509+ onChange = { ( { detail } ) =>
510+ setSelectedOption ( detail . selectedOption )
511+ }
512+ options = { options }
513+ selectedAriaLabel = "Selected"
514+ />
456515 </ FormField >
457516 < FormField label = { useOuSettingTitle } stretch >
458- < Checkbox { ...useOuInputProps } />
517+ < Checkbox { ...useOuInputProps } disabled />
459518 </ FormField >
460519 < FormField label = { budgetAmountTitle } stretch >
461520 < Input { ...budgetAmountInputProps } disabled = { useOuInputProps . checked } type = "number" />
462521 </ FormField >
463522 < FormField label = { budgetEmailTitle } stretch >
464523 < Input { ...budgetEmailInputProps } disabled = { useOuInputProps . checked } />
465524 </ FormField >
525+ < FormField label = { "Source File Path" } description = { "Add the Src File path for this account" } stretch >
526+ < Input { ...srcFileInputProps } />
527+ </ FormField >
466528 </ SpaceBetween >
467529 </ form >
468530 </ Modal >
0 commit comments