99 excludeDrive ,
1010 getDrivesList ,
1111 getExcludedDrives ,
12- includeDrive
12+ includeDrive ,
13+ mountDrive
1314} from '../requests' ;
1415import { ISignal , Signal } from '@lumino/signaling' ;
1516import { driveBrowserIcon , addIcon , removeIcon } from '../icons' ;
@@ -27,6 +28,8 @@ export interface IDriveInputProps {
2728 onSubmit : ( ) => void ;
2829 isPublic : boolean ;
2930 setIsPublic : ( value : boolean ) => void ;
31+ mountError : string ;
32+ resetMountError : ( ) => void ;
3033}
3134
3235export function DriveInputComponent ( {
@@ -36,7 +39,9 @@ export function DriveInputComponent({
3639 setRegion,
3740 onSubmit,
3841 isPublic,
39- setIsPublic
42+ setIsPublic,
43+ mountError,
44+ resetMountError
4045} : IDriveInputProps ) {
4146 return (
4247 < div >
@@ -45,6 +50,7 @@ export function DriveInputComponent({
4550 className = "drive-search-input"
4651 onInput = { ( event : any ) => {
4752 setPublicDrive ( event . target . value ) ;
53+ resetMountError ( ) ;
4854 } }
4955 placeholder = "Enter drive name"
5056 value = { driveValue }
@@ -69,12 +75,18 @@ export function DriveInputComponent({
6975 className = "drive-region-input"
7076 onInput = { ( event : any ) => {
7177 setRegion ( event . target . value ) ;
78+ resetMountError ( ) ;
7279 } }
7380 placeholder = "Region (e.g.: us-east-1)"
7481 value = { regionValue }
7582 />
7683 ) }
7784 </ div >
85+ { mountError && (
86+ < div className = "add-public-drive-section" >
87+ < p className = "error" > { mountError } </ p >
88+ </ div >
89+ ) }
7890 </ div >
7991 ) ;
8092}
@@ -183,6 +195,7 @@ export function DriveListManagerComponent({ model }: IProps) {
183195 ) ;
184196 const [ isPublic , setIsPublic ] = useState < boolean > ( false ) ;
185197 const [ driveRegion , setDriveRegion ] = useState < string > ( '' ) ;
198+ const [ mountError , setMountError ] = useState < string > ( '' ) ;
186199
187200 // Called after mounting.
188201 React . useEffect ( ( ) => {
@@ -197,14 +210,24 @@ export function DriveListManagerComponent({ model }: IProps) {
197210 } , [ model ] ) ;
198211
199212 const onAddedPublicDrive = async ( ) => {
200- if ( isPublic ) {
201- await addPublicDrive ( publicDrive ) ;
213+ // Check if user has access to drive.
214+ const result = await mountDrive ( publicDrive , {
215+ provider : 's3'
216+ } ) ;
217+ if ( result && result . error ) {
218+ // Show error in case of failure.
219+ setMountError ( result . error . message ) ;
202220 } else {
203- await addExternalDrive ( publicDrive , driveRegion ) ;
221+ // Proceed with adding the drive otherwise.
222+ if ( isPublic ) {
223+ await addPublicDrive ( publicDrive ) ;
224+ } else {
225+ await addExternalDrive ( publicDrive , driveRegion ) ;
226+ setDriveRegion ( '' ) ;
227+ }
204228 setDriveRegion ( '' ) ;
229+ await model . refresh ( ) ;
205230 }
206- setPublicDrive ( '' ) ;
207- await model . refresh ( ) ;
208231 } ;
209232
210233 return (
@@ -239,6 +262,8 @@ export function DriveListManagerComponent({ model }: IProps) {
239262 isPublic = { isPublic }
240263 setIsPublic = { setIsPublic }
241264 onSubmit = { onAddedPublicDrive }
265+ mountError = { mountError }
266+ resetMountError = { ( ) => setMountError ( '' ) }
242267 />
243268 </ div >
244269
0 commit comments