1
1
import * as React from 'react' ;
2
2
import styles from './TaxonomyForm.module.scss' ;
3
- import { Checkbox , ChoiceGroup , classNamesFunction , DetailsRow , GroupedList , GroupHeader , IBasePickerStyleProps , IBasePickerStyles , ICheckboxStyleProps , ICheckboxStyles , IChoiceGroupOption , IChoiceGroupOptionProps , IChoiceGroupOptionStyleProps , IChoiceGroupOptionStyles , IChoiceGroupStyleProps , IChoiceGroupStyles , IColumn , IGroup , IGroupedList , IGroupFooterProps , IGroupHeaderCheckboxProps , IGroupHeaderProps , IGroupHeaderStyleProps , IGroupHeaderStyles , IGroupRenderProps , IGroupShowAllProps , ILinkStyleProps , ILinkStyles , IListProps , IRenderFunction , ISpinnerStyleProps , ISpinnerStyles , IStyleFunctionOrObject , ITag , Label , Link , Spinner , TagPicker } from 'office-ui-fabric-react' ;
3
+ import { Checkbox , ChoiceGroup , GroupedList , GroupHeader , IBasePickerStyleProps , IBasePickerStyles , ICheckboxStyleProps , ICheckboxStyles , IChoiceGroupOption , IChoiceGroupOptionStyleProps , IChoiceGroupOptionStyles , IGroup , IGroupedList , IGroupFooterProps , IGroupHeaderProps , IGroupHeaderStyleProps , IGroupHeaderStyles , IGroupRenderProps , IGroupShowAllProps , ILabelStyleProps , ILabelStyles , ILinkStyleProps , ILinkStyles , IListProps , IRenderFunction , ISpinnerStyleProps , ISpinnerStyles , IStyleFunctionOrObject , ITag , Label , Link , Spinner , TagPicker } from 'office-ui-fabric-react' ;
4
4
import { ITermInfo , ITermSetInfo } from '@pnp/sp/taxonomy' ;
5
5
import { Guid } from '@microsoft/sp-core-library' ;
6
6
import { BaseComponentContext } from '@microsoft/sp-component-base' ;
7
7
import { css } from '@uifabric/utilities/lib/css' ;
8
+ import * as strings from 'ControlStrings' ;
8
9
9
10
export interface ITaxonomyFormProps {
10
11
context : BaseComponentContext ;
11
12
allowMultipleSelections : boolean ;
12
- terms : ITermInfo [ ] ;
13
13
termSetId : Guid ;
14
14
pageSize : number ;
15
15
selectedPanelOptions : ITag [ ] ;
16
16
setSelectedPanelOptions : React . Dispatch < React . SetStateAction < ITag [ ] > > ;
17
17
onResolveSuggestions : ( filter : string , selectedItems ?: ITag [ ] ) => ITag [ ] | PromiseLike < ITag [ ] > ;
18
18
onLoadMoreData : ( termSetId : Guid , parentTermId ?: Guid , skiptoken ?: string , hideDeprecatedTerms ?: boolean , pageSize ?: number ) => Promise < { value : ITermInfo [ ] , skiptoken : string } > ;
19
19
getTermSetInfo : ( termSetId : Guid ) => Promise < ITermSetInfo | undefined > ;
20
+ placeHolder : string ;
20
21
}
21
22
22
23
export function TaxonomyForm ( props : ITaxonomyFormProps ) : React . ReactElement < ITaxonomyFormProps > {
@@ -27,16 +28,16 @@ export function TaxonomyForm(props: ITaxonomyFormProps): React.ReactElement<ITax
27
28
28
29
29
30
React . useEffect ( ( ) => {
30
- setGroupsLoading ( ( prevGroupsLoading ) => [ ...prevGroupsLoading , props . termSetId . toString ( ) ] ) ;
31
-
32
31
props . getTermSetInfo ( props . termSetId )
33
32
. then ( ( termSetInfo ) => {
34
33
const languageTag = props . context . pageContext . cultureInfo . currentUICultureName !== '' ? props . context . pageContext . cultureInfo . currentUICultureName : props . context . pageContext . web . languageName ;
35
34
36
35
const termSetName = termSetInfo . localizedNames . filter ( ( name ) => name . languageTag === languageTag ) [ 0 ] . name ;
37
- const rootGroup : IGroup = { name : termSetName , key : termSetInfo . id , startIndex : - 1 , count : 50 , level : 0 , isCollapsed : false , data : { skiptoken : '' } , hasMoreData : false } ;
36
+ const rootGroup : IGroup = { name : termSetName , key : termSetInfo . id , startIndex : - 1 , count : 50 , level : 0 , isCollapsed : false , data : { skiptoken : '' } , hasMoreData : termSetInfo . childrenCount > 0 } ;
38
37
setGroups ( [ rootGroup ] ) ;
39
- props . onLoadMoreData ( props . termSetId , Guid . empty , '' , true )
38
+ setGroupsLoading ( ( prevGroupsLoading ) => [ ...prevGroupsLoading , termSetInfo . id ] ) ;
39
+ if ( termSetInfo . childrenCount > 0 ) {
40
+ props . onLoadMoreData ( props . termSetId , Guid . empty , '' , true )
40
41
. then ( ( terms ) => {
41
42
const grps : IGroup [ ] = terms . value . map ( term => {
42
43
const g : IGroup = {
@@ -60,7 +61,7 @@ export function TaxonomyForm(props: ITaxonomyFormProps): React.ReactElement<ITax
60
61
setGroupsLoading ( ( prevGroupsLoading ) => prevGroupsLoading . filter ( ( value ) => value !== props . termSetId . toString ( ) ) ) ;
61
62
setGroups ( [ rootGroup ] ) ;
62
63
} ) ;
63
-
64
+ }
64
65
} ) ;
65
66
} , [ ] ) ;
66
67
@@ -154,8 +155,9 @@ export function TaxonomyForm(props: ITaxonomyFormProps): React.ReactElement<ITax
154
155
155
156
const onRenderTitle = ( groupHeaderProps : IGroupHeaderProps ) => {
156
157
if ( groupHeaderProps . group . level === 0 ) {
158
+ const labelStyles : IStyleFunctionOrObject < ILabelStyleProps , ILabelStyles > = { root : { fontWeight : "normal" } } ;
157
159
return (
158
- < Label > { groupHeaderProps . group . name } </ Label >
160
+ < Label styles = { labelStyles } > { groupHeaderProps . group . name } </ Label >
159
161
) ;
160
162
}
161
163
if ( props . allowMultipleSelections ) {
@@ -179,21 +181,18 @@ export function TaxonomyForm(props: ITaxonomyFormProps): React.ReactElement<ITax
179
181
}
180
182
else {
181
183
const isSelected = props . selectedPanelOptions ?. [ 0 ] ?. key === groupHeaderProps . group . key ;
182
- const selectedStyle : IStyleFunctionOrObject < IChoiceGroupOptionStyleProps , IChoiceGroupOptionStyles > = isSelected ? { choiceFieldWrapper : { fontWeight : 'bold' } } : { choiceFieldWrapper : { fontWeight : 'normal' } } ;
183
- const getClassNames = classNamesFunction < IChoiceGroupOptionStyleProps , IChoiceGroupOptionStyles > ( ) ;
184
-
185
- const classNames = getClassNames ( selectedStyle ! , {
186
- theme : undefined ,
187
- hasIcon : false ,
188
- hasImage : false ,
189
- checked : false ,
190
- disabled : false ,
191
- imageIsLarge : false ,
192
- imageSize : undefined ,
193
- focused : false ,
194
- } ) ;
184
+ const selectedStyle : IStyleFunctionOrObject < IChoiceGroupOptionStyleProps , IChoiceGroupOptionStyles > = isSelected ? { root : { marginTop : 0 } , choiceFieldWrapper : { fontWeight : 'bold' , } } : { root : { marginTop : 0 } , choiceFieldWrapper : { fontWeight : 'normal' } } ;
195
185
const isDisabled = groupHeaderProps . group . data . term . isAvailableForTagging . filter ( ( t ) => t . setId === props . termSetId . toString ( ) ) [ 0 ] . isAvailable === false ;
196
- const options : IChoiceGroupOption [ ] = [ { key : groupHeaderProps . group . key , text : groupHeaderProps . group . name , styles : selectedStyle , onRenderLabel : ( p ) => < Label htmlFor = { p . id } className = { classNames . field } > < span id = { p . labelId } className = { css ( styles . choiceOption , isSelected && styles . selectedChoiceOption ) } > { p . text } </ span > </ Label > } ] ;
186
+ const options : IChoiceGroupOption [ ] = [ {
187
+ key : groupHeaderProps . group . key ,
188
+ text : groupHeaderProps . group . name ,
189
+ styles : selectedStyle ,
190
+ onRenderLabel : ( p ) =>
191
+ < span id = { p . labelId } className = { css ( styles . choiceOption , isSelected && styles . selectedChoiceOption ) } >
192
+ { p . text }
193
+ </ span >
194
+ } ] ;
195
+
197
196
return (
198
197
< ChoiceGroup
199
198
options = { options }
@@ -206,16 +205,13 @@ export function TaxonomyForm(props: ITaxonomyFormProps): React.ReactElement<ITax
206
205
} ;
207
206
208
207
const onRenderHeader = ( headerProps : IGroupHeaderProps ) : JSX . Element => {
209
- const headerCountStyle = { display : 'none' } ;
210
- const checkButtonStyle = { display : 'none' } ;
211
- const expandStyle = { visibility : 'hidden' } ;
212
208
const groupHeaderStyles : IStyleFunctionOrObject < IGroupHeaderStyleProps , IGroupHeaderStyles > = {
213
- expand : ! headerProps . group . children || headerProps . group . level === 0 ? expandStyle : null ,
214
- expandIsCollapsed : ! headerProps . group . children || headerProps . group . level === 0 ? expandStyle : null ,
215
- check : checkButtonStyle ,
216
- headerCount : headerCountStyle ,
209
+ expand : { height : 42 , visibility : ! headerProps . group . children || headerProps . group . level === 0 ? "hidden" : "visible" } ,
210
+ expandIsCollapsed : { visibility : ! headerProps . group . children || headerProps . group . level === 0 ? "hidden" : "visible" } ,
211
+ check : { display : 'none' } ,
212
+ headerCount : { display : 'none' } ,
217
213
groupHeaderContainer : { height : 36 , paddingTop : 3 , paddingBottom : 3 , paddingLeft : 3 , paddingRight : 3 , alignItems : 'center' , } ,
218
- root : { height : 42 }
214
+ root : { height : 42 } ,
219
215
} ;
220
216
221
217
return (
@@ -243,6 +239,7 @@ export function TaxonomyForm(props: ITaxonomyFormProps): React.ReactElement<ITax
243
239
return (
244
240
< div style = { { height : '48px' , lineHeight : '48px' } } >
245
241
< Link onClick = { ( ) => {
242
+ setGroupsLoading ( ( prevGroupsLoading ) => [ ...prevGroupsLoading , footerProps . group . key ] ) ;
246
243
props . onLoadMoreData ( props . termSetId , footerProps . group . key === props . termSetId . toString ( ) ? Guid . empty : Guid . parse ( footerProps . group . key ) , footerProps . group . data . skiptoken , true )
247
244
. then ( ( terms ) => {
248
245
const grps : IGroup [ ] = terms . value . map ( term => {
@@ -268,7 +265,7 @@ export function TaxonomyForm(props: ITaxonomyFormProps): React.ReactElement<ITax
268
265
} ) ;
269
266
} }
270
267
styles = { linkStyles } >
271
- Load more...
268
+ { strings . ModernTaxonomyPickerLoadMoreText }
272
269
</ Link >
273
270
</ div >
274
271
) ;
@@ -295,28 +292,28 @@ export function TaxonomyForm(props: ITaxonomyFormProps): React.ReactElement<ITax
295
292
props . setSelectedPanelOptions ( itms || [ ] ) ;
296
293
} ;
297
294
298
- const tagPickerStyles : IStyleFunctionOrObject < IBasePickerStyleProps , IBasePickerStyles > = { text : { borderStyle : 'none' , borderWidth : '0px' } } ;
295
+ const tagPickerStyles : IStyleFunctionOrObject < IBasePickerStyleProps , IBasePickerStyles > = { root : { paddingTop : 4 , paddingBottom : 4 , paddingRight : 4 } , input : { height : 34 } , text : { borderStyle : 'none' , borderWidth : '0px' } } ;
299
296
300
297
return (
301
298
< div className = { styles . taxonomyForm } >
302
299
< div className = { styles . taxonomyTreeSelector } >
303
300
< div >
304
301
< TagPicker
305
- removeButtonAriaLabel = "Remove"
302
+ removeButtonAriaLabel = { strings . ModernTaxonomyPickerRemoveButtonText }
306
303
onResolveSuggestions = { props . onResolveSuggestions }
307
304
itemLimit = { props . allowMultipleSelections ? undefined : 1 }
308
305
selectedItems = { props . selectedPanelOptions }
309
306
onChange = { onPickerChange }
310
307
getTextFromItem = { getTagText }
311
308
styles = { tagPickerStyles }
312
309
inputProps = { {
313
- 'aria-label' : 'Tag Picker' ,
314
- placeholder : 'Ange en term som du vill tagga'
310
+ 'aria-label' : props . placeHolder || strings . ModernTaxonomyPickerDefaultPlaceHolder ,
311
+ placeholder : props . placeHolder || strings . ModernTaxonomyPickerDefaultPlaceHolder
315
312
} }
316
313
/>
317
314
</ div >
318
315
</ div >
319
- < Label className = { styles . taxonomyTreeLabel } > Välj en tagg </ Label >
316
+ < Label className = { styles . taxonomyTreeLabel } > { strings . ModernTaxonomyPickerTreeTitle } </ Label >
320
317
< div >
321
318
< GroupedList
322
319
componentRef = { groupedListRef }
0 commit comments