From b9da8969e635a9e2e34df6a097a726f71ebade8b Mon Sep 17 00:00:00 2001 From: XnpioChV Date: Mon, 12 Feb 2024 16:36:17 -0500 Subject: [PATCH] fix: Update tag counts when changes are saved in the tag drawer * fix: courseAuthoringUrl on message listener --- cms/static/js/views/pages/container_subviews.js | 11 +++++------ cms/static/js/views/tag_count.js | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cms/static/js/views/pages/container_subviews.js b/cms/static/js/views/pages/container_subviews.js index 2fe33df88eee..b32c86ae8dec 100644 --- a/cms/static/js/views/pages/container_subviews.js +++ b/cms/static/js/views/pages/container_subviews.js @@ -376,15 +376,14 @@ function($, _, gettext, BaseView, ViewUtils, XBlockViewUtils, MoveXBlockUtils, H "message", (event) => { // Listen any message from Manage tags drawer. var data = event.data; - var courseAuthoringUrl = this.model.get("course_authoring_url") + var courseAuthoringUrl = new URL(this.model.get("course_authoring_url")).origin; if (event.origin == courseAuthoringUrl - && data.includes('[Manage tags drawer] Tags updated:')) { + && data.type == 'authoring.events.tags.updated') { // This message arrives when there is a change in the tag list. // The message contains the new list of tags. - let jsonData = data.replace(/\[Manage tags drawer\] Tags updated: /g, ""); - jsonData = JSON.parse(jsonData); - if (jsonData.contentId == this.model.id) { - this.model.set('tags', this.buildTaxonomyTree(jsonData)); + data = data.data + if (data.contentId == this.model.id) { + this.model.set('tags', this.buildTaxonomyTree(data)); this.render(); } } diff --git a/cms/static/js/views/tag_count.js b/cms/static/js/views/tag_count.js index c7ba4d79e5ed..b95df3abeb7b 100644 --- a/cms/static/js/views/tag_count.js +++ b/cms/static/js/views/tag_count.js @@ -21,15 +21,14 @@ function($, _, BaseView, HtmlUtils) { 'message', (event) => { // Listen any message from Manage tags drawer. var data = event.data; - var courseAuthoringUrl = this.model.get("course_authoring_url") + var courseAuthoringUrl = new URL(this.model.get("course_authoring_url")).origin; if (event.origin == courseAuthoringUrl - && data.includes('[Manage tags drawer] Count updated:')) { + && data.type == 'authoring.events.tags.count.updated') { // This message arrives when there is a change in the tag list. // The message contains the new count of tags. - let jsonData = data.replace(/\[Manage tags drawer\] Count updated: /g, ""); - jsonData = JSON.parse(jsonData); - if (jsonData.contentId == this.model.get("content_id")) { - this.model.set('tags_count', jsonData.count); + data = data.data + if (data.contentId == this.model.get("content_id")) { + this.model.set('tags_count', data.count); this.render(); } }