-
Notifications
You must be signed in to change notification settings - Fork 80
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
Changes from 2 commits
55276c8
786a04e
78db929
04f5bf9
e60c559
32a5f9f
2170664
076ef75
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// @ts-check | ||
import { useMemo } from 'react'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
import { | ||
useQuery, | ||
useQueries, | ||
|
@@ -9,6 +10,7 @@ | |
import { | ||
getTaxonomyTagsData, | ||
getContentTaxonomyTagsData, | ||
getContentTaxonomyTagsCountData, | ||
getContentData, | ||
updateContentTaxonomyTags, | ||
} from './api'; | ||
|
@@ -142,5 +144,30 @@ | |
onSettled: () => { | ||
queryClient.invalidateQueries({ queryKey: ['contentTaxonomyTags', contentId] }); | ||
}, | ||
onSuccess: () => { | ||
if (window.top != null) { | ||
// Sends content tags to the parent page if is called from a iframe. | ||
getContentTaxonomyTagsData(contentId).then((data) => { | ||
const messageJson = { | ||
contentId, | ||
...data, | ||
}; | ||
window.top?.postMessage( | ||
`[Manage tags drawer] Tags updated: ${JSON.stringify(messageJson)}`, | ||
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. I like this new message format, it might make sense to also change the 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. I think it would be better to add it when necessary, when it is used. Also, as Braden says, these messages are temporary. 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. 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: Then you can use code like this to handle it on the other side. |
||
getConfig().STUDIO_BASE_URL, | ||
); | ||
}); | ||
getContentTaxonomyTagsCountData(contentId).then((data) => { | ||
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. It would be simpler to just send a message that the count has changed, with only the 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. 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 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. 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. |
||
const messageJson = { | ||
contentId, | ||
count: data, | ||
}; | ||
window.top?.postMessage( | ||
`[Manage tags drawer] Count updated: ${JSON.stringify(messageJson)}`, | ||
getConfig().STUDIO_BASE_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.
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."
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 here: 78db929
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.
Nice, thanks!