forked from CenterForOpenScience/ember-osf-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENG-4642] Boa Add-on Project PR - Ember Part (CenterForOpenScience#2046
) * [WIP] first stab at Boa addon ux * make boa modal findable * save WIP on dataset select * futa wisdom attained/accepted * add action; fetch parents properly * enabled addons enabled * cleanups; fix closemodal * Add mirage support for BoA files * Type updates * authenticate addon endpoint request * Add a bit of error handling to mirage * Change logic to populate a node addons * Disable submit to boa if no dataset selected * Add qp to boa upload link * Add placeholder message to dataset select * Update toast messages * CR feedback * Boa bugs (CenterForOpenScience#2047) * Add file size to boa request * Allow checked out boa file to be submitted * Use sizeInt * Circumvent promise-induced bugs (CenterForOpenScience#2049) --------- Co-authored-by: Fitz Elliott <[email protected]> Co-authored-by: Futa Ikeda <[email protected]> Co-authored-by: futa-ikeda <[email protected]>
- Loading branch information
Showing
18 changed files
with
324 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
lib/osf-components/addon/components/file-actions-menu/submit-to-boa-modal/component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { inject as service } from '@ember/service'; | ||
import { waitFor } from '@ember/test-waiters'; | ||
import Component from '@glimmer/component'; | ||
import { task } from 'ember-concurrency'; | ||
import IntlService from 'ember-intl/services/intl'; | ||
import File from 'ember-osf-web/packages/files/file'; | ||
import captureException, { getApiErrorMessage } from 'ember-osf-web/utils/capture-exception'; | ||
import config from 'ember-osf-web/config/environment'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
|
||
interface Args { | ||
file: File; | ||
isOpen: boolean; | ||
closeModal: () => {}; | ||
} | ||
|
||
export default class SubmitToBoaModal extends Component<Args> { | ||
@service toast!: Toastr; | ||
@service intl!: IntlService; | ||
@tracked selectedDataset?: string; | ||
|
||
datasets = [ | ||
'2022 Jan/Java', | ||
'2022 Feb/Python', | ||
'2021 Method Chains', | ||
'2021 Aug/Python', | ||
'2021 Aug/Kotlin (small)', | ||
'2021 Aug/Kotlin', | ||
'2021 Jan/ML-Verse', | ||
'2020 August/Python-DS', | ||
'2019 October/GitHub (small)', | ||
'2019 October/GitHub (medium)', | ||
'2019 October/GitHub', | ||
'2015 September/GitHub', | ||
'2013 September/SF (small)', | ||
'2013 September/SF (medium)', | ||
'2013 September/SF', | ||
'2013 May/SF', | ||
'2013 February/SF', | ||
'2012 July/SF', | ||
]; | ||
|
||
@action | ||
onDatasetChange(newDataset: string) { | ||
this.selectedDataset = newDataset; | ||
} | ||
|
||
@task | ||
@waitFor | ||
async confirmSubmitToBoa() { | ||
try { | ||
const file = this.args.file; | ||
const fileModel = file.fileModel; | ||
const parentFolder = await fileModel.get('parentFolder'); | ||
const grandparentFolder = await parentFolder.get('parentFolder'); | ||
const endpoint = config.OSF.url + 'api/v1/project/' + fileModel.target.get('id') + '/boa/submit-job/'; | ||
const uploadLink = new URL(parentFolder.get('links').upload as string); | ||
uploadLink.searchParams.set('kind', 'file'); | ||
const payload = { | ||
data: { | ||
nodeId: fileModel.target.get('id'), | ||
name: file.name, | ||
materialized: fileModel.materializedPath, | ||
sizeInt: fileModel.size, | ||
links: { | ||
download: file.links.download, | ||
upload: file.links.upload, | ||
}, | ||
}, | ||
parent: { | ||
links: { | ||
upload: uploadLink.toString(), | ||
}, | ||
isAddonRoot: !grandparentFolder, | ||
}, | ||
dataset: this.selectedDataset, | ||
}; | ||
await this.args.file.currentUser.authenticatedAJAX({ | ||
url: endpoint, | ||
type: 'POST', | ||
data: JSON.stringify(payload), | ||
xhrFields: { withCredentials: true }, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
|
||
this.args.closeModal(); | ||
} catch (e) { | ||
captureException(e); | ||
const errorMessageKey = this.intl.t('osf-components.file-browser.submit_to_boa_fail', | ||
{ fileName: this.args.file.name, htmlSafe: true }) as string; | ||
this.toast.error(getApiErrorMessage(e), errorMessageKey); | ||
return; | ||
} | ||
|
||
this.toast.success( | ||
this.intl.t('osf-components.file-browser.submit_to_boa_success', { fileName: this.args.file.name }), | ||
); | ||
} | ||
} |
Empty file.
34 changes: 34 additions & 0 deletions
34
lib/osf-components/addon/components/file-actions-menu/submit-to-boa-modal/template.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<OsfDialog @isOpen={{@isOpen}} @onClose={{@closeModal}} as |dialog|> | ||
<dialog.heading> | ||
{{t 'osf-components.file-browser.submit_to_boa'}} | ||
</dialog.heading> | ||
<dialog.main> | ||
|
||
<p>{{t 'osf-components.file-browser.boa_dataset_spiel'}}</p> | ||
<PowerSelect | ||
@options={{this.datasets}} | ||
@selected={{this.selectedDataset}} | ||
@placeholder={{t 'osf-components.file-browser.boa_dataset_select_placeholder'}} | ||
@onChange={{this.onDatasetChange}} | ||
as |dataset| | ||
> | ||
{{dataset}} | ||
</PowerSelect> | ||
<p>{{t 'osf-components.file-browser.confirm_submit_to_boa' fileName=@file.name}}</p> | ||
|
||
</dialog.main> | ||
<dialog.footer> | ||
<Button | ||
{{on 'click' (fn (mut @isOpen) false)}} | ||
> | ||
{{t 'general.cancel'}} | ||
</Button> | ||
<Button | ||
@type='primary' | ||
disabled={{or this.confirmSubmitToBoa.isRunning (not this.selectedDataset)}} | ||
{{on 'click' (perform this.confirmSubmitToBoa)}} | ||
> | ||
{{t 'osf-components.file-browser.confirm_submit_to_boa_yes'}} | ||
</Button> | ||
</dialog.footer> | ||
</OsfDialog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
lib/osf-components/app/components/file-actions-menu/submit-to-boa-modal/component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'osf-components/components/file-actions-menu/submit-to-boa-modal/component'; |
1 change: 1 addition & 0 deletions
1
lib/osf-components/app/components/file-actions-menu/submit-to-boa-modal/template.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'osf-components/components/file-actions-menu/submit-to-boa-modal/template'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.