Skip to content

Added functionality so the GD menu item and select folder are not enabled until oauth token is loaded #2571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export default class FileBrowser extends Component<Args> {
return this.isWBGoogleDrive;
}

get isGoogleAuthorized(): boolean {
return this.googlePickerComponent?.isGFPDisabled || false;
}

@action
registerChild(child: GoogleFilePickerWidget) {
this.googlePickerComponent = child; // Store the child's instance
Expand All @@ -55,7 +59,7 @@ export default class FileBrowser extends Component<Args> {
openGoogleFilePicker(dropdown: any) {
dropdown.close();
if (this.googlePickerComponent) {
this.googlePickerComponent.openPicker();
this.googlePickerComponent.createPicker();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
data-test-add-google-drive
@layout='fake-link'
{{on 'click' (fn this.openGoogleFilePicker dropdown)}}
disabled={{this.isGoogleAuthorized}}
>
{{t 'osf-components.file-browser.add-from-drive'}}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default class GoogleFilePickerWidget extends Component<Args> {
@tracked isFolderPicker = false;
@tracked openGoogleFilePicker = false;
@tracked visible = false;
@tracked isGFPDisabled = true;
pickerInited = false;
selectFolder: any = undefined;
accessToken!: string;
Expand Down Expand Up @@ -120,6 +121,7 @@ export default class GoogleFilePickerWidget extends Component<Args> {
authorizedStorageAccount.serializeOauthToken = true;
const token = await authorizedStorageAccount.save();
this.accessToken = token.oauthToken;
this.isGFPDisabled = this.accessToken ? false : true;
}
}

Expand All @@ -145,14 +147,6 @@ export default class GoogleFilePickerWidget extends Component<Args> {
}
}

@action
openPicker() {
// Logic for opening Google File Picker here
if (this.handleAuthClick) {
this.handleAuthClick();
}
}

@action
registerComponent() {
if (this.args.onRegisterChild) {
Expand All @@ -179,29 +173,15 @@ export default class GoogleFilePickerWidget extends Component<Args> {
*/
async initializePicker() {
this.pickerInited = true;
this.maybeEnableButtons();
}

/**
* Enables user interaction after all libraries are loaded.
*/
maybeEnableButtons() {
if (this.pickerInited && this.isFolderPicker) {
if (this.isFolderPicker) {
this.visible = true;
}
}

/**
* Sign in the user upon button click.
*/
@action
handleAuthClick() {
this.createPicker();
}

/**
* Create and render a Picker object for searching images.
*/
@action
createPicker() {
const googlePickerView = new window.google.picker.DocsView(window.google.picker.ViewId.DOCS);
googlePickerView.setSelectFolderEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ local-class='google-file-picker-container {{if this.isMobile 'mobile'}}'
</div>
<div local-class='action-container'>
<button class='btn btn-primary btn-medium' local-class='authorize-button {{if this.visible 'visible'}}' type='button' id='authorize_button'
{{on 'click' (action this.handleAuthClick)}}
disabled={{this.isGFPDisabled}}
{{on 'click' (action this.createPicker)}}
>
{{t 'addons.configure.google-file-picker.select-root-folder'}}
</button>
</div>
{{/if}}
<script async defer src='https://apis.google.com/js/api.js' onload='window.GoogleFilePickerWidget.gapiLoaded()'></script>
<script async defer src='https://accounts.google.com/gsi/client' onload='window.GoogleFilePickerWidget.gisLoaded()'></script>
</div>