@@ -3,13 +3,15 @@ import { ISecurityTrimmedControlProps, ISecurityTrimmedControlState, PermissionL
33import { SPHttpClient } from '@microsoft/sp-http' ;
44import { SPPermission } from '@microsoft/sp-page-context' ;
55import * as telemetry from '../../common/telemetry' ;
6+ import { Spinner } from 'office-ui-fabric-react/lib/Spinner' ;
67
78export class SecurityTrimmedControl extends React . Component < ISecurityTrimmedControlProps , ISecurityTrimmedControlState > {
89 constructor ( props : ISecurityTrimmedControlProps ) {
910 super ( props ) ;
1011
1112 this . state = {
12- allowRender : false
13+ allowRender : false ,
14+ loading : true
1315 } ;
1416
1517 telemetry . track ( 'ReactPlaceholder' , { } ) ;
@@ -49,11 +51,13 @@ export class SecurityTrimmedControl extends React.Component<ISecurityTrimmedCont
4951 // Check the user its permissions
5052 if ( permissions . hasAllPermissions ( ...this . props . permissions ) ) {
5153 this . setState ( {
52- allowRender : true
54+ allowRender : true ,
55+ loading : false
5356 } ) ;
5457 } else {
5558 this . setState ( {
56- allowRender : false
59+ allowRender : false ,
60+ loading : false
5761 } ) ;
5862 }
5963 } else if ( level === PermissionLevel . remoteWeb ) {
@@ -84,21 +88,24 @@ export class SecurityTrimmedControl extends React.Component<ISecurityTrimmedCont
8488 if ( result . error ) {
8589 // Do not allow rendering when there was an error
8690 this . setState ( {
87- allowRender : false
91+ allowRender : false ,
92+ loading : false
8893 } ) ;
8994 console . error ( `Error retrieved while checking user's remote site permissions.` ) ;
9095 return ;
9196 }
9297 // Check the result value
9398 if ( typeof result . value !== "undefined" && result . value === false ) {
9499 this . setState ( {
95- allowRender : false
100+ allowRender : false ,
101+ loading : false
96102 } ) ;
97103 return ;
98104 }
99105 } else {
100106 this . setState ( {
101- allowRender : false
107+ allowRender : false ,
108+ loading : false
102109 } ) ;
103110 console . error ( `No result value was retrieved when checking the user's remote site permissions.` ) ;
104111 return ;
@@ -107,7 +114,8 @@ export class SecurityTrimmedControl extends React.Component<ISecurityTrimmedCont
107114
108115 // Render the controls when the permissions were OK for the user
109116 this . setState ( {
110- allowRender : true
117+ allowRender : true ,
118+ loading : false
111119 } ) ;
112120 }
113121 }
@@ -122,7 +130,8 @@ export class SecurityTrimmedControl extends React.Component<ISecurityTrimmedCont
122130 const apiUrl = `${ remoteSiteUrl } /_api/web/GetList(@listUrl)/EffectiveBasePermissions?@listUrl='${ encodeURIComponent ( relativeLibOrListUrl ) } '` ;
123131 const hasPermissions = await this . checkRemotePermissions ( apiUrl ) ;
124132 this . setState ( {
125- allowRender : hasPermissions
133+ allowRender : hasPermissions ,
134+ loading : false
126135 } ) ;
127136 }
128137 }
@@ -137,7 +146,8 @@ export class SecurityTrimmedControl extends React.Component<ISecurityTrimmedCont
137146 const apiUrl = `${ remoteSiteUrl } /_api/web/GetList(@listUrl)/Items(${ itemId } )/EffectiveBasePermissions?@listUrl='${ encodeURIComponent ( relativeLibOrListUrl ) } '` ;
138147 const hasPermissions = await this . checkRemotePermissions ( apiUrl ) ;
139148 this . setState ( {
140- allowRender : hasPermissions
149+ allowRender : hasPermissions ,
150+ loading : false
141151 } ) ;
142152 }
143153 }
@@ -153,7 +163,8 @@ export class SecurityTrimmedControl extends React.Component<ISecurityTrimmedCont
153163 const apiUrl = `${ remoteSiteUrl } /_api/web/GetFolderByServerRelativeUrl(@folderByServerRelativeUrl)/ListItemAllFields/EffectiveBasePermissions?@folderByServerRelativeUrl='${ folderByServerRelativeUrl } '` ;
154164 const hasPermissions = await this . checkRemotePermissions ( apiUrl ) ;
155165 this . setState ( {
156- allowRender : hasPermissions
166+ allowRender : hasPermissions ,
167+ loading : false
157168 } ) ;
158169 }
159170 }
@@ -194,10 +205,15 @@ export class SecurityTrimmedControl extends React.Component<ISecurityTrimmedCont
194205 */
195206 public render ( ) : React . ReactElement < ISecurityTrimmedControlProps > {
196207 const { className } = this . props ;
197- return (
198- this . state . allowRender ? (
199- < div className = { className ? className : "" } > { this . props . children } </ div >
200- ) : null
201- ) ;
208+ if ( this . state . loading && this . props . showLoadingAnimation ) {
209+ return < Spinner /> ;
210+ }
211+ if ( this . state . allowRender ) {
212+ return < div className = { className ? className : "" } > { this . props . children } </ div > ;
213+ }
214+ else if ( this . props . noPermissionsControl ) {
215+ return this . props . noPermissionsControl ;
216+ }
217+ return null ;
202218 }
203219}
0 commit comments