-
Notifications
You must be signed in to change notification settings - Fork 56
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
[ENG-4671] Implement submit-to-boa flow for file list and file detail page #2034
Changes from 10 commits
f5d1b93
de8b28b
d4fde0e
ff4b06f
9888b8e
1e327c8
e312dd0
613d7cc
ebf1b4c
90c7468
0c0e306
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
datasets?: string[]; | ||
@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', | ||
]; | ||
Comment on lines
+24
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is less than ideal, but I see it's been discussed already as part of the scope. Let's never update this list, and if it ever needs to change, we should use an endpoint to get the current list of datasets. |
||
|
||
@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/'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sadly true, it uses the existing add-on routes, might be something that will be totally refactored in the new add-on service? |
||
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, | ||
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 }), | ||
); | ||
} | ||
} |
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,9 +110,35 @@ | |
</Button> | ||
{{/if}} | ||
{{/if}} | ||
{{#if @item.currentUserCanDelete}} | ||
{{#if @item.providerIsOsfstorage}} | ||
{{#if @item.isBoaFile}} | ||
{{#if this.isBoaEnabled}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a lot of nested ifs. Probably fine, though might be better as a getter in the component ts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! I will distill this down to a getter on the component |
||
<Button | ||
@layout='fake-link' | ||
data-test-submit-to-boa | ||
data-analytics-name='Submit to Boa' | ||
local-class='DropdownItem' | ||
{{on 'click' (queue | ||
dropdown.close | ||
this.openSubmitToBoaModal | ||
)}} | ||
> | ||
<FaIcon @icon='upload' /> | ||
{{t 'file_actions_menu.submit_to_boa'}} | ||
</Button> | ||
{{/if}} | ||
{{/if}} | ||
{{/if}} | ||
{{/if}} | ||
</dropdown.content> | ||
</ResponsiveDropdown> | ||
<FileActionsMenu::DeleteModal @file={{@item}} @isOpen={{this.isDeleteModalOpen}} @closeModal={{this.closeDeleteModal}} @onDelete={{@onDelete}} /> | ||
<FileActionsMenu::SubmitToBoaModal | ||
@file={{@item}} | ||
@isOpen={{this.isSubmitToBoaModalOpen}} | ||
@closeModal={{this.closeSubmitToBoaModal}} | ||
/> | ||
{{#if @manager}} | ||
<MoveFileModal | ||
@isOpen={{this.moveModalOpen}} | ||
|
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'; |
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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will hard-code this list for now, and if/when Boa adds anything to this list, we will update it or fetch it from somewhere.