@@ -6,8 +6,8 @@ import { getAllSites, getHubSites } from '../../services/SPSitesService';
6
6
import { IDropdownOption , Dropdown } from 'office-ui-fabric-react/lib/Dropdown' ;
7
7
import { ISelectableOption , SelectableOptionMenuItemType } from 'office-ui-fabric-react/lib/utilities/selectableOption/SelectableOption.types' ;
8
8
import orderBy from 'lodash/orderBy' ;
9
+ import findIndex from 'lodash/findIndex' ;
9
10
import { SearchBox } from 'office-ui-fabric-react/lib/SearchBox' ;
10
- import { Checkbox } from 'office-ui-fabric-react/lib/Checkbox' ;
11
11
import { toRelativeUrl } from '../../common/utilities/GeneralHelper' ;
12
12
13
13
const styles = mergeStyleSets ( {
@@ -110,6 +110,30 @@ export const SitePicker: React.FunctionComponent<ISitePickerProps> = (props: Rea
110
110
return result ;
111
111
} ;
112
112
113
+ const onSelectionChange = React . useCallback ( ( e , item : IDropdownOption , index : number ) => {
114
+ const newSelectedSites = selectedSites ? [ ...selectedSites ] : [ ] ;
115
+
116
+ if ( multiSelect !== false ) {
117
+ const existingIndex = findIndex ( newSelectedSites , s => s . id === item . key ) ;
118
+
119
+ if ( existingIndex >= 0 ) {
120
+ newSelectedSites . splice ( existingIndex , 1 ) ;
121
+ }
122
+ else {
123
+ newSelectedSites . push ( {
124
+ ...item . data !
125
+ } ) ;
126
+ }
127
+ }
128
+
129
+ if ( onChange ) {
130
+ onChange ( newSelectedSites ) ;
131
+ }
132
+
133
+ setSelectedSites ( newSelectedSites ) ;
134
+
135
+ } , [ selectedSites , multiSelect , onChange ] ) ;
136
+
113
137
React . useEffect ( ( ) => {
114
138
if ( ! initialSites ) {
115
139
return ;
@@ -180,6 +204,7 @@ export const SitePicker: React.FunctionComponent<ISitePickerProps> = (props: Rea
180
204
disabled = { disabled }
181
205
multiSelect = { multiSelect !== false }
182
206
onRenderOption = { onRenderOption }
207
+ onChange = { onSelectionChange }
183
208
/>
184
209
</ >
185
210
) ;
0 commit comments