-
Notifications
You must be signed in to change notification settings - Fork 87
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: Show toast when exporting course tags #995
feat: Show toast when exporting course tags #995
Conversation
Thanks for the pull request, @ChrisChV! 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 #995 +/- ##
==========================================
+ Coverage 92.29% 92.31% +0.01%
==========================================
Files 708 708
Lines 12505 12527 +22
Branches 2686 2689 +3
==========================================
+ Hits 11542 11564 +22
Misses 926 926
Partials 37 37 ☔ View full report in Codecov by Sentry. |
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 this PR @ChrisChV ! It solves the issue, and the code looks great.
I left a few comments, but they're just suggestions.
- I tested this on my tutor dev stack using the PR test instructions.
- I read through the code
- I checked for accessibility issues by using my keyboard to navigate.
- Includes code documentation
- User-facing strings are extracted for translation
src/course-outline/CourseOutline.jsx
Outdated
if (location.hash === '#export') { | ||
setToastMessage(intl.formatMessage(messages.exportTagsToastMessage)); | ||
getTagsExportFile(courseId, courseName).finally(() => { | ||
setToastMessage(null); |
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.
Is there any way to make the Toast appear for some minimum amount of time? When the export is quick, it flickers and disappears so fast I can't read it.
This wasn't mentioned as part of the issue, so no worries if paragon's Toast doesn't support this.
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.
Do we need to show a failure message if the export fails?
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.
@pomegranited @bradenmacdonald By default the toast has a delay of 5 seconds before closing. I left the default value and I added success/error toast messages when the export is done; to avoid to close a toast quickly
Commit: 449251b
src/course-outline/data/api.js
Outdated
// Gets exported tags and builds the blob to download CSV file. | ||
// This can be done with this code: | ||
// `window.location.href = exportTags(contentId);` | ||
// but it is done in this way to known when the operation ends to close the toast. |
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.
nit:
// but it is done in this way to known when the operation ends to close the toast. | |
// but it is done in this way so we know when the operation ends to close the toast. |
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.
Updated: 79368d7
a.click(); | ||
|
||
window.URL.revokeObjectURL(url); | ||
} |
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.
There's a weird side effect of this change, where after I select "Export Tags", the #export
stays in the URL, and so the "Export Tags" menu item stays selected, so I can't re-select it and export again unless I navigate somewhere else first.
I don't think this is important -- people are unlikely to want to export tags multiple times -- it's just annoying, so not a blocker for this PR.
export_tags.mp4
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.
Fixed: 6ccf705
b7e98a0
to
bc63bfc
Compare
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.
I'm not sure I understand why the url is being used the way it is but other than that it is working.
const [toastMessage, setToastMessage] = useState(/** @type{null|string} */ (null)); | ||
|
||
useEffect(() => { | ||
if (location.hash === '#export-tags') { | ||
setToastMessage(intl.formatMessage(messages.exportTagsCreatingToastMessage)); | ||
getTagsExportFile(courseId, courseName).then(() => { | ||
setToastMessage(intl.formatMessage(messages.exportTagsSuccessToastMessage)); | ||
}).catch(() => { | ||
setToastMessage(intl.formatMessage(messages.exportTagsErrorToastMessage)); | ||
}); | ||
|
||
// Delete `#export-tags` from location | ||
window.location.href = '#'; | ||
} | ||
}, [location]); |
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.
I'm not sure why this URL change is being used as an indicator of this state.
I think whatever triggers the tag exporting should set the toastMessage or some flag that an export is in progress.
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 Export Tags
button is on the StudioHeader (frontend-component-header). This component only receives as parameters the text of the button and the link to where that button should redirect.
There is no way to send an onClick
function or know when the user clicked the button or add some flag to know if the export is in progress, this is necessary to display the toast. The component logic is closed in the link that is passed as a parameter.
My workaroun is to use an internal MFE route instead the edx-platform API. The detail is that there should be no redirection. To achieve this I have used the url fragment. The useEffect
of this code is to verify the fragment and execute the export code we want with the respective toasts.
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.
Sounds good!
I think another mechanism could be to use postMessage, but I guess if all you can do is inject a link this is a good solutions.
src/course-outline/messages.js
Outdated
}, | ||
exportTagsSuccessToastMessage: { | ||
id: 'course-authoring.course-outline.export-tags.toast.success.message', | ||
defaultMessage: 'File created successfully', |
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.
I'm assuming this message will change later, but it's too unspecific. This is specifically a message about tags being exported from a particular course and that being successful, so the message can be more tailored tot hat.
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.
Sure 👍 Updated: 1d37c84
@ChrisChV 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future. |
Description
In progress
toast when exporting course tagsSupporting information
Technical Details
The
Export Tags
button is on the StudioHeader (frontend-component-header). This component only receives as parameters the text of the button and the link to where that button should redirect.There is no way to send an
onClick
function or know when the user clicked the button or add some flag to know if the export is in progress, this is necessary to display the toast. The component logic is closed in the link that is passed as a parameter.The workaroun used on this PR is to use an internal MFE route instead the edx-platform API. The detail is that there should be no redirection. To achieve this I have used the url fragment. The useEffect of this code is to verify the fragment and execute the export code we want with the respective toasts.
Testing instructions
contentstore.new_studio_mfe.use_new_course_outline_page
.Tools
>Export Tags
.