1- import React , { useEffect , useState } from 'react'
1+ import React from 'react'
22import {
33 DefaultButton ,
4- DetailsHeader ,
54 Dialog ,
65 DialogFooter ,
76 DialogType ,
8- IColumn ,
9- IDetailsHeaderProps ,
10- IGroup ,
117 PrimaryButton ,
128 Stack ,
139 TextField ,
14- Selection ,
15- DetailsList ,
16- Spinner ,
17- SpinnerSize
10+ Selection
1811} from '@fluentui/react'
1912import { useNavigate } from 'react-router-dom'
20- import { observer } from 'mobx-react-lite'
2113import { useForm } from 'react-hook-form'
2214import { Branch , BundledApplicationSnapshotIn , useStores } from '../../../models'
15+ import { SelectApplicationList } from './SelectApplicationList'
2316import { useConst } from '@fluentui/react-hooks'
2417
25- const columns : Array < IColumn > = [
26- {
27- key : 'name' ,
28- name : 'Name' ,
29- fieldName : 'name' ,
30- minWidth : 100 ,
31- maxWidth : 200 ,
32- isResizable : true
33- } ,
34- {
35- key : 'token' ,
36- name : 'token' ,
37- onRender : ( item : Branch ) => item . application ?. token ?. name ,
38- minWidth : 100 ,
39- maxWidth : 200 ,
40- isResizable : true
41- }
42- ]
43-
44- export const AddBundledAppDialog = observer ( ( ) => {
18+ export const AddBundledAppDialog = ( ) => {
4519 const {
46- applicationStore : { fetchApplications, applicationList } ,
47- bundledApplicationStore : { addBundledApplication } ,
48- tokenStore : { tokens }
20+ bundledApplicationStore : { addBundledApplication }
4921 } = useStores ( )
5022
5123 const navigate = useNavigate ( )
@@ -58,8 +30,6 @@ export const AddBundledAppDialog = observer(() => {
5830 formState : { errors }
5931 } = useForm < BundledApplicationSnapshotIn > ( )
6032
61- const [ isLoading , setIsLoading ] = useState ( true )
62-
6333 // TODO: a rules to check that their is at least one branches
6434 React . useEffect ( ( ) => {
6535 register ( 'branches' )
@@ -68,42 +38,16 @@ export const AddBundledAppDialog = observer(() => {
6838
6939 const selection = useConst (
7040 ( ) =>
71- new Selection ( {
41+ new Selection < Branch > ( {
7242 onSelectionChanged : ( ) => {
7343 setValue (
7444 'branches' ,
75- ( selection . getSelection ( ) as Array < Branch > ) . map ( ( b ) => b . id )
45+ selection . getSelection ( ) . map ( ( branch ) => branch . id )
7646 )
7747 }
7848 } )
7949 )
8050
81- useEffect ( ( ) => {
82- setIsLoading ( true )
83- Promise . all (
84- tokens . map ( ( token ) => fetchApplications ( token . token , { withBranches : true } ) )
85- ) . finally ( ( ) => setIsLoading ( false ) )
86- } , [ ] )
87-
88- const [ items , groups ] = ( ( ) => {
89- let items : Array < Branch > = [ ]
90- const groups : Array < IGroup > = [ ]
91- for ( const application of applicationList ) {
92- const branches = application . configuredBranches
93- groups . push ( {
94- key : application . id ,
95- name : application . displayName ,
96- startIndex : items . length ,
97- count : branches . length ,
98- level : 0 ,
99- isCollapsed : true
100- } )
101- items = items . concat ( branches )
102- }
103-
104- return [ items , groups ]
105- } ) ( )
106-
10751 const onDismiss = ( ) => {
10852 navigate ( - 1 )
10953 }
@@ -135,38 +79,7 @@ export const AddBundledAppDialog = observer(() => {
13579 { ...register ( 'name' , { required : { value : true , message : 'Name is required' } } ) }
13680 errorMessage = { errors . name ?. message }
13781 />
138- { isLoading ? (
139- < Spinner size = { SpinnerSize . large } label = 'Fetching applications...' />
140- ) : (
141- < DetailsList
142- styles = { { root : { flex : 1 } } }
143- selection = { selection }
144- items = { items }
145- groups = { groups }
146- columns = { columns }
147- ariaLabelForSelectAllCheckbox = 'Toggle selection for all items'
148- ariaLabelForSelectionColumn = 'Toggle selection'
149- checkButtonAriaLabel = 'select row'
150- checkButtonGroupAriaLabel = 'select section'
151- onRenderDetailsHeader = { ( props ?: IDetailsHeaderProps ) => (
152- < DetailsHeader
153- { ...props ! }
154- ariaLabelForToggleAllGroupsButton = { 'Expand collapse groups' }
155- />
156- ) }
157- groupProps = { {
158- showEmptyGroups : true
159- } }
160- onRenderItemColumn = { ( item ?: Branch , index ?: number , column ?: IColumn ) => {
161- const value =
162- item && column && column . fieldName
163- ? item [ column . fieldName as keyof Branch ] || ''
164- : ''
165-
166- return < div data-is-focusable = { true } > { value } </ div >
167- } }
168- />
169- ) }
82+ < SelectApplicationList selection = { selection } />
17083 </ Stack >
17184 < DialogFooter >
17285 < PrimaryButton type = 'submit' text = 'Save' />
@@ -175,4 +88,4 @@ export const AddBundledAppDialog = observer(() => {
17588 </ form >
17689 </ Dialog >
17790 )
178- } )
91+ }
0 commit comments