Skip to content
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-6559] Integrate user download functionality #2413

Open
wants to merge 2 commits into
base: feature/dashboard-b-and-i
Choose a base branch
from
Open
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 @@ -9,6 +9,7 @@ import Intl from 'ember-intl/services/intl';
import InstitutionModel from 'ember-osf-web/models/institution';
import InstitutionDepartmentsModel from 'ember-osf-web/models/institution-department';
import Analytics from 'ember-osf-web/services/analytics';
import { RelationshipWithLinks } from 'osf-api';

interface Column {
key: string;
Expand Down Expand Up @@ -184,6 +185,27 @@ export default class InstitutionalUsersList extends Component<InstitutionalUsers
return query;
}

downloadUrl(format: string) {
const institutionRelationships = this.args.institution.links.relationships;
const usersLink = (institutionRelationships!.user_metrics as RelationshipWithLinks).links.related.href;
const userURL = new URL(usersLink!);
userURL.searchParams.set('format', format);
userURL.searchParams.set('page[size]', '10000');
return userURL.toString();
}

get downloadCsvUrl() {
return this.downloadUrl('csv');
}

get downloadTsvUrl() {
return this.downloadUrl('tsv');
}

get downloadJsonUrl() {
return this.downloadUrl('json');
}

@restartableTask
@waitFor
async searchDepartment(name: string) {
Expand Down Expand Up @@ -237,5 +259,4 @@ export default class InstitutionalUsersList extends Component<InstitutionalUsers
clickToggleOrcidFilter(hasOrcid: boolean) {
this.hasOrcid = !hasOrcid;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
color: $color-select;
}

.download-dropdown-content {
display: flex;
flex-direction: column;
}

.table {
margin-bottom: 45px;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,33 @@
<FaIcon @icon='download' />
</dd.trigger>
<dd.content local-class='download-dropdown-content'>
<Button local-class='download-option' {{on 'click' (queue this.downloadCsv dd.close)}}>
<OsfLink
data-test-csv-download-button
data-analytics-name='Download CSV'
{{on 'click' dd.close}}
@target='_blank'
@href={{this.downloadCsvUrl}}
>
{{t 'institutions.dashboard.format_labels.csv'}}
</Button>
<Button local-class='download-option' {{on 'click' (queue this.downloadTsv dd.close)}}>
</OsfLink>
<OsfLink
data-test-tsv-download-button
data-analytics-name='Download TSV'
{{on 'click' dd.close}}
@target='_blank'
@href={{this.downloadTsvUrl}}
>
{{t 'institutions.dashboard.format_labels.tsv'}}
</Button>
<Button local-class='download-option' {{on 'click' (queue this.downloadJsonTable dd.close)}}>
{{t 'institutions.dashboard.format_labels.json_table'}}
</Button>
<Button local-class='download-option' {{on 'click' (queue this.downloadJsonDirect dd.close)}}>
{{t 'institutions.dashboard.format_labels.json_direct'}}
</Button>
</OsfLink>
<OsfLink
data-test-json-download-button
data-analytics-name='Download JSON'
{{on 'click' dd.close}}
@target='_blank'
@href={{this.downloadJsonUrl}}
>
{{t 'institutions.dashboard.format_labels.json'}}
</OsfLink>
</dd.content>
</ResponsiveDropdown>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ module('Integration | routes | institutions | dashboard | -components | institut

this.set('model', model);
await render(hbs`
<Institutions::Dashboard::-Components::InstitutionalUsersList
@modelTaskInstance={{this.model.taskInstance}}
@institution={{this.model.taskInstance.institution}}
/>
<Institutions::Dashboard::-Components::InstitutionalUsersList
@modelTaskInstance={{this.model.taskInstance}}
@institution={{this.model.taskInstance.institution}}
/>
`);
assert.dom('[data-test-header]')
.exists({ count: 9 }, '9 default headers');
Expand Down Expand Up @@ -70,6 +70,11 @@ module('Integration | routes | institutions | dashboard | -components | institut
.exists({ count: 5 }, '5 in the list with public project');
assert.dom('[data-test-item="privateProjects"]')
.exists({ count: 5 }, '5 in the list with private projects');

// Test download buttons
assert.dom('[data-test-download-csv]').exists('CSV download button');
assert.dom('[data-test-download-tsv]').exists('TSV download button');
assert.dom('[data-test-download-json]').exists('JSON download button');
});

test('it sorts', async function(assert) {
Expand Down Expand Up @@ -105,10 +110,10 @@ module('Integration | routes | institutions | dashboard | -components | institut

this.set('model', model);
await render(hbs`
<Institutions::Dashboard::-Components::InstitutionalUsersList
@modelTaskInstance={{this.model.taskInstance}}
@institution={{this.model.taskInstance.institution}}
/>
<Institutions::Dashboard::-Components::InstitutionalUsersList
@modelTaskInstance={{this.model.taskInstance}}
@institution={{this.model.taskInstance.institution}}
/>
`);
assert.dom('[data-test-item="user_name"]')
.exists({ count: 3 }, '3 users');
Expand Down
1 change: 1 addition & 0 deletions translations/en-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ institutions:
format_labels:
csv: '.csv'
tsv: '.tsv'
json: 'JSON'
json_table: 'JSON (table)'
json_direct: 'JSON (direct)'
download: 'Download'
Expand Down
Loading