@@ -10,10 +10,6 @@ import { ILinkFilePickerTabProps, ILinkFilePickerTabState } from '.';
10
10
import { PrimaryButton , DefaultButton } from 'office-ui-fabric-react/lib/components/Button' ;
11
11
import { TextField } from 'office-ui-fabric-react/lib/TextField' ;
12
12
13
- // PnP
14
- //TODO: Remove pnp
15
- import { FetchClient } from "@pnp/common" ;
16
-
17
13
// Localized strings
18
14
import * as strings from 'ControlStrings' ;
19
15
import { GeneralHelper } from '../../../Utilities' ;
@@ -50,9 +46,11 @@ export default class LinkFilePickerTab extends React.Component<ILinkFilePickerTa
50
46
validateOnFocusOut = { false }
51
47
validateOnLoad = { true }
52
48
value = { fileUrl }
53
- onChanged = { ( _event : React . FormEvent < HTMLInputElement | HTMLTextAreaElement > , newValue ? : string ) => this . _handleChange ( newValue ) }
49
+ onChanged = { ( newValue : string ) => this . _handleChange ( newValue ) }
54
50
/>
51
+
55
52
</ div >
53
+
56
54
< div className = { styles . actionButtonsContainer } >
57
55
< div className = { styles . actionButtons } >
58
56
< PrimaryButton
@@ -68,12 +66,12 @@ export default class LinkFilePickerTab extends React.Component<ILinkFilePickerTa
68
66
/**
69
67
* Called as user types in a new value
70
68
*/
71
- private _handleChange = ( fileUrl ? : string ) => {
72
- const filePickerResult : IFilePickerResult = {
69
+ private _handleChange = ( fileUrl : string ) => {
70
+ const filePickerResult : IFilePickerResult = fileUrl && this . _isUrl ( fileUrl ) ? {
73
71
file : null ,
74
72
fileAbsoluteUrl : fileUrl ,
75
73
fileTitle : GeneralHelper . getFileNameWithoutExtension ( fileUrl )
76
- }
74
+ } : null ;
77
75
this . setState ( {
78
76
filePickerResult
79
77
} ) ;
@@ -83,55 +81,30 @@ export default class LinkFilePickerTab extends React.Component<ILinkFilePickerTa
83
81
* Verifies the url that was typed in
84
82
* @param value
85
83
*/
86
- private _getErrorMessagePromise ( value : string ) : Promise < string > {
87
- return new Promise ( resolve => {
88
-
89
- // DOn't give an error for blank or placeholder value, but don't make it a valid entry either
90
- if ( value === undefined || value === 'https://' ) {
91
- this . setState ( { isValid : false } ) ;
92
- resolve ( '' ) ;
93
- return ;
94
- }
95
-
96
- // Make sure that user is typing a valid URL format
97
- if ( ! this . _isUrl ( value ) ) {
98
- this . setState ( { isValid : false } ) ;
99
- resolve ( '' ) ;
100
- return ;
101
- }
102
-
103
- // If we don't allow external links, verify that we're in the same domain
104
- if ( ! this . props . allowExternalTenantLinks && ! this . _isSameDomain ( value ) ) {
105
- this . setState ( { isValid : false } ) ;
106
- resolve ( strings . NoExternalLinksValidationMessage ) ;
107
- return ;
108
- }
109
-
110
- // Verify the file exists by actually getting the item
111
- try {
112
- const client = new FetchClient ( ) ;
113
- client . fetch ( value , { method : "HEAD" } ) . then ( ( response ) => {
114
- if ( ! response . ok ) {
115
- this . setState ( { isValid : false } ) ;
116
- resolve ( strings . CantValidateValidationMessage ) ;
117
- return ;
118
- }
119
- // the file exists
120
- this . setState ( { isValid : true } ) ;
121
- resolve ( '' ) ;
122
- } , ( ) => {
123
- this . setState ( { isValid : false } ) ;
124
- resolve ( strings . CantValidateValidationMessage ) ;
125
- } ) . catch ( ( ) => {
126
- this . setState ( { isValid : false } ) ;
127
- resolve ( strings . CantValidateValidationMessage ) ;
128
- } ) ;
129
- } catch ( error ) {
130
- console . log ( "Error verifying file" , error ) ;
131
- this . setState ( { isValid : false } ) ;
132
- resolve ( strings . CantValidateValidationMessage ) ;
133
- }
134
- } ) ;
84
+ private _getErrorMessagePromise = async ( value : string ) : Promise < string > => {
85
+ // DOn't give an error for blank or placeholder value, but don't make it a valid entry either
86
+ if ( value === undefined || value === 'https://' ) {
87
+ this . setState ( { isValid : false } ) ;
88
+ return '' ;
89
+ }
90
+
91
+ // Make sure that user is typing a valid URL format
92
+ if ( ! this . _isUrl ( value ) ) {
93
+ this . setState ( { isValid : false } ) ;
94
+ return '' ;
95
+ }
96
+
97
+ // If we don't allow external links, verify that we're in the same domain
98
+ if ( ! this . props . allowExternalTenantLinks && ! this . _isSameDomain ( value ) ) {
99
+ this . setState ( { isValid : false } ) ;
100
+ return strings . NoExternalLinksValidationMessage ;
101
+ }
102
+
103
+ const fileExists = await this . props . fileSearchService . fetchFile ( value ) ;
104
+ this . setState ( { isValid : fileExists } ) ;
105
+
106
+ const strResult = fileExists ? '' : strings . ProvidedValueIsInvalid ;
107
+ return strResult ;
135
108
}
136
109
137
110
/**
0 commit comments