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

feat: Send message after update tags on content [FC-0036] #800

Closed

Conversation

ChrisChV
Copy link
Contributor

@ChrisChV ChrisChV commented Jan 17, 2024

Description

Blocked: Check this #800 (comment)

This adds a feature to send tags of a content after the update mutation.

Supporting information

Internal ticket: FAL-3601
Github issue: openedx/modular-learning#167
Related PR: openedx/edx-platform#34059

Testing instructions

@ChrisChV ChrisChV marked this pull request as draft January 17, 2024 18:33
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jan 17, 2024
@openedx-webhooks
Copy link

openedx-webhooks commented Jan 17, 2024

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:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

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.

@openedx-webhooks
Copy link

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:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

This is currently a draft pull request. When it is ready for our review and all tests are green, click "Ready for Review", or remove "WIP" from the title, as appropriate.

@ChrisChV ChrisChV changed the title feat: Send message after update tags on content feat: Send message after update tags on content [FC-0036] Jan 17, 2024
Copy link

codecov bot commented Jan 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0fc0ce0) 89.28% compared to head (076ef75) 89.28%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #800   +/-   ##
=======================================
  Coverage   89.28%   89.28%           
=======================================
  Files         551      551           
  Lines        9740     9744    +4     
  Branches     2101     2101           
=======================================
+ Hits         8696     8700    +4     
  Misses        996      996           
  Partials       48       48           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ChrisChV ChrisChV marked this pull request as ready for review January 18, 2024 16:58
Copy link
Member

@yusuf-musleh yusuf-musleh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM! Great work @ChrisChV ! Just had 1 suggestion

  • I tested this: (I testing by following the steps in the related edx-platform PR)
  • I read through the code
  • I checked for accessibility issues
  • Includes documentation
  • I made sure any change in configuration variables is reflected in the corresponding client's configuration-secure repository.

...data,
};
window.top?.postMessage(
`[Manage tags drawer] Tags updated: ${JSON.stringify(messageJson)}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this new message format, it might make sense to also change the closeManageTagsDrawer message to match the same format to keep things consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to add it when necessary, when it is used. Also, as Braden says, these messages are temporary.

Copy link
Contributor

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 message data is being passed as a string and then processed. You can simply pass JSON data. This is used in a couple of places and it generally follows the format of: window.top?.postMessage({ type: 'authoring.events.tags.updated', payload: data })

Then you can use code like this to handle it on the other side.

getConfig().STUDIO_BASE_URL,
);
});
getContentTaxonomyTagsCountData(contentId).then((data) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be simpler to just send a message that the count has changed, with only the contentId and to let the parent frame call the API to retrieve the updated count if it wants to. That will keep the code here simpler. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have also thought the same thing, but I feel that it is simpler to make and handle the API calls here and just send the data to be displayed in the template. Also I don't think there is much problem with the code here since it is temporary

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I just don't want people to copy this pattern when they move it into the MFE. If we just use React-Query in the MFE it will update without any special code, as long as we do the "query invalidation" correctly.

@@ -142,5 +144,30 @@ export const useContentTaxonomyTagsUpdater = (contentId, taxonomyId) => {
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ['contentTaxonomyTags', contentId] });
},
onSuccess: () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This notification is just temporary. In the future, the course outline page and course unit page will be part of the frontend-app-course-authoring, so there will be no need to send a change notification nor to refresh the counts - React Query will handle that all automatically :)

So: I want to make sure everyone who sees this code understands that. Please add a comment that says something like "In the future, when the Course Outline Page and Unit Page are integrated into this MFE, they should just use React Query to load the tag counts, and React Query will automatically refresh those counts when the mutation invalidates them. So this postMessage is just a temporary feature to support the legacy Django template courseware page."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here: 78db929

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@bradenmacdonald
Copy link
Contributor

@ChrisChV Can this PR merge before the edx-platform PR?

@ChrisChV
Copy link
Contributor Author

ChrisChV commented Jan 22, 2024

@ChrisChV Can this PR merge before the edx-platform PR?

@bradenmacdonald Yes, in this case the order does not matter. Nothing breaks

Copy link
Contributor

@xitij2000 xitij2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code generally looks good, but I don't like the usage of postMessage. You can send JSON data with postmessage, so I don't see a reason to mash it into a string and then use regex on the other side. These are messages that the user will not see so we can use something that's easier to parse.

...data,
};
window.top?.postMessage(
`[Manage tags drawer] Tags updated: ${JSON.stringify(messageJson)}`,
Copy link
Contributor

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 message data is being passed as a string and then processed. You can simply pass JSON data. This is used in a couple of places and it generally follows the format of: window.top?.postMessage({ type: 'authoring.events.tags.updated', payload: data })

Then you can use code like this to handle it on the other side.

@ChrisChV
Copy link
Contributor Author

@xitij2000 Thanks for the review. Yes, you are right, I will make the changes

@ChrisChV
Copy link
Contributor Author

@xitij2000 I made the changes on this commit: 2170664

Also I open this PR with edx-platform changes: openedx/edx-platform#34223

Copy link
Contributor

@xitij2000 xitij2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not working for me on tutor without changes described in openedx/edx-platform#34223

Once that is fixed, this is good to go.

@bradenmacdonald
Copy link
Contributor

Good news/bad news: With the major progress we're making lately on the MFE pages, and the plan to shift focus entirely to the MFEs for now, I think it may make more sense to pause this PR. If the outline/unit MFE pages don't end up being ready for Redwood, we can merge this, but it's looking pretty likely that those will be done by Redwood and we won't need this at all.

@ChrisChV
Copy link
Contributor Author

Good news/bad news: With the major progress we're making lately on the MFE pages, and the plan to shift focus entirely to the MFEs for now, I think it may make more sense to pause this PR. If the outline/unit MFE pages don't end up being ready for Redwood, we can merge this, but it's looking pretty likely that those will be done by Redwood and we won't need this at all.

Ok, make sense 👍

@bradenmacdonald
Copy link
Contributor

Closing this as we're focusing development on the MFE.

@openedx-webhooks
Copy link

@ChrisChV Even though your pull request wasn’t merged, please take a moment to answer a two question survey so we can improve your experience in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants