-
Notifications
You must be signed in to change notification settings - Fork 76
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
feat: add download template button to taxonomy list [FC-0036] #674
feat: add download template button to taxonomy list [FC-0036] #674
Conversation
Thanks for the pull request, @rpenido! Please note that it may take us up to several weeks or months to complete a review and merge your PR. Feel free to add as much of the following information to the ticket as you can:
All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here. Please let us know once your PR is ready for our review and all tests are green. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #674 +/- ##
=======================================
Coverage 88.96% 88.96%
=======================================
Files 472 472
Lines 7376 7378 +2
Branches 1573 1573
=======================================
+ Hits 6562 6564 +2
Misses 787 787
Partials 27 27 ☔ View full report in Codecov by Sentry. |
7b6d7ad
to
80d737b
Compare
80d737b
to
5381f15
Compare
193cf98
to
a9414cb
Compare
@rpenido I think you're missing some style changes from the original PR? I'm seeing this when I run this branch: |
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.
👍 Looks great @rpenido !
Could you also please update the PR description and un-draft this to get it ready for upstream/CC review?
- I tested this on my devstack
- I read through the code
- I checked for accessibility issues by using only my keyboard to navigate
- Includes documentation
- User-facing strings are extracted for translation
Fixed! |
@bradenmacdonald This PR is ready for upstream review -- who should we ask? |
@jristau1984 has offered to coordinate reviews for us for now. @jristau1984 could you please line up a review for this small PR? Or if you folks don't have much capacity for the near future, let me know and I can find a reviewer from Axim or an OpenCraft Core Contributor (as we did on e.g. #645). |
I've created issue TNL-11202 in the private 2U Jira. |
@rpenido could you add "[FC-0036]" to the PR title here? Thanks :) |
Hi, @jristau1984! 😃 The same here: do we have an estimated due date for this review? Thank you! 😃 |
Due to heavy focus on internal goal delivery before the end of the year, I cannot promise any reviews before January. Tagging @cablaa77 and @jimjohnson8 in case they are able to prioritize this earlier. |
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.
The code looks good. Just some minor suggestions.
await act(async () => { | ||
fireEvent.click(importMenu); | ||
}); |
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.
These don't need to be wrapped in act since the library itself wraps them "act" internally.
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.
Done 7f6319e!
it('downloads the taxonomy template json', async () => { | ||
useIsTaxonomyListDataLoaded.mockReturnValue(true); | ||
useTaxonomyListDataResponse.mockReturnValue({ | ||
results: [{ | ||
id: 1, | ||
name: 'Taxonomy', | ||
description: 'This is a description', | ||
}], | ||
}); | ||
const { getByTestId } = render(<RootWrapper />); | ||
const importMenu = getByTestId('taxonomy-download-template'); | ||
expect(importMenu).toBeInTheDocument(); | ||
await act(async () => { | ||
fireEvent.click(importMenu); | ||
}); | ||
|
||
const importButton = getByTestId('taxonomy-download-template-json'); | ||
expect(importButton).toBeInTheDocument(); | ||
await act(async () => { | ||
fireEvent.click(importButton); | ||
}); | ||
expect(getTaxonomyTemplateFile).toHaveBeenCalled(); | ||
}); |
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.
This and the above test seem to be exactly the same with very minor differences, so we can use parametrisation here as well.
it('downloads the taxonomy template json', async () => { | |
useIsTaxonomyListDataLoaded.mockReturnValue(true); | |
useTaxonomyListDataResponse.mockReturnValue({ | |
results: [{ | |
id: 1, | |
name: 'Taxonomy', | |
description: 'This is a description', | |
}], | |
}); | |
const { getByTestId } = render(<RootWrapper />); | |
const importMenu = getByTestId('taxonomy-download-template'); | |
expect(importMenu).toBeInTheDocument(); | |
await act(async () => { | |
fireEvent.click(importMenu); | |
}); | |
const importButton = getByTestId('taxonomy-download-template-json'); | |
expect(importButton).toBeInTheDocument(); | |
await act(async () => { | |
fireEvent.click(importButton); | |
}); | |
expect(getTaxonomyTemplateFile).toHaveBeenCalled(); | |
}); | |
it.each(['CSV', 'JSON'])('downloads the taxonomy template %s', async (fileFormat) => { | |
useIsTaxonomyListDataLoaded.mockReturnValue(true); | |
useTaxonomyListDataResponse.mockReturnValue({ | |
results: [{ | |
id: 1, | |
name: 'Taxonomy', | |
description: 'This is a description', | |
}], | |
}); | |
const { findByRole } = render(<RootWrapper />); | |
const importMenu = await findByRole('button', {name: /download template/i}); | |
fireEvent.click(importMenu); | |
const importButton = await findByRole('button', {name: `${fileFormat} template` }); | |
fireEvent.click(importButton); | |
expect(getTaxonomyTemplateFile).toHaveBeenCalled(); | |
}); |
Note that I've simplified the test somewhat.
- Using findByRole etc is preferred to finding by test id.
- No need for act around fireEvent
- No need to assert the presence of a component in the document, if the component is missing for some reason then the findByRole will still cause the test to fail.
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.
Thank you for the explanation @xitij2000!
Done 7f6319e!
But I didn't manage to find a way to check that the download really started.
src/taxonomy/data/api.js
Outdated
|
||
/** | ||
* Downloads the template file for import taxonomies | ||
* @param {('json'|'csv')} format | ||
* @returns {void} | ||
*/ | ||
export function getTaxonomyTemplateFile(format) { | ||
window.location.href = getTaxonomyTemplateApiUrl(format); | ||
} |
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.
Instead of doing this, I think you can just add this URL as a link direct using the download property.
i.e.
<a href={getTaxonomyTemplateApiUrl(format)} download=
taxonomy-template.${format}>
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.
Done! I skipped the download
attribute: the download file name is set in the backend API.
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.
Looks good! Just one small nit.
<Dropdown.Item | ||
href={getTaxonomyTemplateApiUrl('csv')} | ||
data-testid="taxonomy-download-template-csv" | ||
> | ||
{intl.formatMessage(messages.downloadTemplateButtonCSVLabel)} | ||
</Dropdown.Item> | ||
<Dropdown.Item | ||
href={getTaxonomyTemplateApiUrl('json')} | ||
data-testid="taxonomy-download-template-json" | ||
> | ||
{intl.formatMessage(messages.downloadTemplateButtonJSONLabel)} | ||
</Dropdown.Item> |
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.
Adding download=template.json/.csv
or just download will also enforce that the browser will downlod the file instead of opening it in a tab.
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.
Thank you for the review @xitij2000 !
We are doing it in the backend here: https://github.com/openedx/openedx-learning/blob/3e2d6a497efddfae7a1c24b361ddfd36704dbb80/openedx_tagging/core/tagging/rest_api/v1/views_import.py#L47 using Content-Disposition
. Should we also do it here?
@rpenido 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future. |
This commit adds a new button in the Taxonomy List to allow users to download a sample taxonomy template in the format used to import taxonomies.
Description
This PR adds a new button in the Taxonomy List to allow users to download a sample taxonomy template in the format used to import taxonomies.
Supporting Information
Testing instructions
Download template
and then on theCSV template
optiontemplate.csv
is correctly saved.Download template
and then on theJSON template
optiontemplate.json
is correctly saved.Private-ref: FAL-3532