1
1
import { override } from '@microsoft/decorators' ;
2
2
import * as React from 'react' ;
3
- import { css , DialogType , Link } from 'office-ui-fabric-react' ;
3
+ import { css , Dialog , DialogType , Link , Spinner , SpinnerSize } from 'office-ui-fabric-react' ;
4
4
5
5
import { ISPFieldLookupValue } from "../../../common/SPEntities" ;
6
6
import { IFieldRendererProps } from '../fieldCommon/IFieldRendererProps' ;
7
7
import * as appInsights from '../../../common/appInsights' ;
8
8
9
9
import styles from './FieldLookupRenderer.module.scss' ;
10
10
import IFrameDialog from '../../iFrameDialog/IFrameDialog' ;
11
+ import { SPHelper } from '../../../Utilities' ;
12
+ import { IContext } from '../../../Common' ;
11
13
14
+ /**
15
+ * Field Lookup Renderer Props
16
+ * There are 3 options to provide the props:
17
+ * - [recommended, used in FieldRendererHelper] Provide fieldId and context. In that case request for DispUrl will be sent only if a user clicks on the value
18
+ * - Provide dispFormUrl: if you know this URL a priori you can provide it into the renderer
19
+ * - Provide onClick handler to handle value's click event outside the renderer
20
+ */
12
21
export interface IFieldLookupRendererProps extends IFieldRendererProps {
13
22
/**
14
23
* lookup values
@@ -22,14 +31,23 @@ export interface IFieldLookupRendererProps extends IFieldRendererProps {
22
31
* custom event handler of lookup item click. If not set the dialog with Display Form will be shown
23
32
*/
24
33
onClick ?: ( args : IFieldLookupClickEventArgs ) => { } ;
34
+ /**
35
+ * Field's id.
36
+ */
37
+ fieldId ?: string ;
38
+ /**
39
+ * Customizer context. Must be providede if fieldId is set
40
+ */
41
+ context ?: IContext ;
25
42
}
26
43
27
44
/**
28
- * For future
45
+ * Field Lookup Renderer State
29
46
*/
30
47
export interface IFieldLookupRendererState {
31
48
hideDialog ?: boolean ;
32
49
lookupDispFormUrl ?: string ;
50
+ dispFormUrl ?: string ;
33
51
}
34
52
35
53
/**
@@ -51,7 +69,8 @@ export class FieldLookupRenderer extends React.Component<IFieldLookupRendererPro
51
69
appInsights . track ( 'FieldLookupRenderer' , { } ) ;
52
70
53
71
this . state = {
54
- hideDialog : true
72
+ hideDialog : true ,
73
+ dispFormUrl : props . dispFormUrl
55
74
} ;
56
75
}
57
76
@@ -61,23 +80,35 @@ export class FieldLookupRenderer extends React.Component<IFieldLookupRendererPro
61
80
return < Link onClick = { this . _onClick . bind ( this , lookup ) } className = { styles . lookup } style = { this . props . cssProps } > { lookup . lookupValue } </ Link > ;
62
81
} ) ;
63
82
return (
64
- < div style = { this . props . cssProps } className = { css ( this . props . className ) } > { lookupLinks }
65
- { ! this . state . hideDialog && < IFrameDialog
66
- url = { this . state . lookupDispFormUrl }
67
- iframeOnLoad = { this . _onIframeLoaded . bind ( this ) }
68
- hidden = { this . state . hideDialog }
69
- onDismiss = { this . _onDialogDismiss . bind ( this ) }
70
- modalProps = { {
71
- isBlocking : true ,
72
- containerClassName : styles . dialogContainer
73
- } }
74
- dialogContentProps = { {
75
- type : DialogType . close ,
76
- showCloseButton : true
77
- } }
78
- width = { '570px' }
79
- height = { '315px' } /> }
80
- </ div > ) ;
83
+ < div style = { this . props . cssProps } className = { css ( this . props . className ) } > { lookupLinks }
84
+ { ! this . state . hideDialog && this . state . dispFormUrl && < IFrameDialog
85
+ url = { this . state . lookupDispFormUrl }
86
+ iframeOnLoad = { this . _onIframeLoaded . bind ( this ) }
87
+ hidden = { this . state . hideDialog }
88
+ onDismiss = { this . _onDialogDismiss . bind ( this ) }
89
+ modalProps = { {
90
+ isBlocking : true ,
91
+ containerClassName : styles . dialogContainer
92
+ } }
93
+ dialogContentProps = { {
94
+ type : DialogType . close ,
95
+ showCloseButton : true
96
+ } }
97
+ width = { '570px' }
98
+ height = { '315px' } /> }
99
+ { ! this . state . hideDialog && ! this . state . dispFormUrl && < Dialog
100
+ onDismiss = { this . _onDialogDismiss . bind ( this ) }
101
+ modalProps = { {
102
+ isBlocking : true ,
103
+ containerClassName : styles . dialogContainer
104
+ } }
105
+ dialogContentProps = { {
106
+ type : DialogType . close ,
107
+ showCloseButton : true
108
+ } } >
109
+ < Spinner size = { SpinnerSize . large } />
110
+ </ Dialog > }
111
+ </ div > ) ;
81
112
}
82
113
83
114
private _onClick ( lookup : ISPFieldLookupValue ) : void {
@@ -92,10 +123,32 @@ export class FieldLookupRenderer extends React.Component<IFieldLookupRendererPro
92
123
//
93
124
// showing Display Form in the dialog
94
125
//
95
- this . setState ( {
96
- lookupDispFormUrl : `${ this . props . dispFormUrl } &ID=${ lookup . lookupId } &RootFolder=*&IsDlg=1` ,
97
- hideDialog : false
98
- } ) ;
126
+ if ( this . state . dispFormUrl ) {
127
+ this . setState ( {
128
+ lookupDispFormUrl : `${ this . state . dispFormUrl } &ID=${ lookup . lookupId } &RootFolder=*&IsDlg=1` ,
129
+ hideDialog : false
130
+ } ) ;
131
+ }
132
+ else if ( this . props . fieldId ) {
133
+
134
+ this . setState ( {
135
+ hideDialog : false
136
+ } ) ;
137
+
138
+ SPHelper . getLookupFieldListDispFormUrl ( this . props . fieldId , this . props . context ) . then ( dispFormUrlValue => {
139
+ const dispFormUrl : string = dispFormUrlValue . toString ( ) ;
140
+ this . setState ( ( prevState , props ) => {
141
+ if ( prevState . hideDialog ) {
142
+ return ;
143
+ }
144
+
145
+ return {
146
+ dispFormUrl : dispFormUrl ,
147
+ lookupDispFormUrl : `${ dispFormUrl } &ID=${ lookup . lookupId } &RootFolder=*&IsDlg=1`
148
+ } ;
149
+ } ) ;
150
+ } ) ;
151
+ }
99
152
}
100
153
101
154
private _onIframeLoaded ( iframe : any ) : void {
0 commit comments