forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Tagging UX refinements - refresh tag count on edit (openedx#34059)
* style: drawer-cover color updated for all tagging drawers * feat: Update TagList component when a tag is updated on Manage tags drawer * feat: Refactor TagCount to be able to refresh the count * feat: Sync tag count in units
- Loading branch information
1 parent
8942492
commit 534d275
Showing
17 changed files
with
219 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as TagCountView from 'js/views/tag_count'; | ||
import * as TagCountModel from 'js/models/tag_count'; | ||
|
||
// eslint-disable-next-line no-unused-expressions | ||
'use strict'; | ||
export default function TagCountFactory(TagCountJson, el) { | ||
var model = new TagCountModel(TagCountJson, {parse: true}); | ||
var tagCountView = new TagCountView({el, model}); | ||
tagCountView.setupMessageListener(); | ||
tagCountView.render(); | ||
} | ||
|
||
export {TagCountFactory}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
define(['backbone', 'underscore'], function(Backbone, _) { | ||
/** | ||
* Model for Tag count view | ||
*/ | ||
var TagCountModel = Backbone.Model.extend({ | ||
defaults: { | ||
content_id: null, | ||
tags_count: 0, | ||
course_authoring_url: null, | ||
}, | ||
}); | ||
return TagCountModel; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
define(['jquery', 'underscore', 'js/views/baseview', 'edx-ui-toolkit/js/utils/html-utils'], | ||
function($, _, BaseView, HtmlUtils) { | ||
'use strict'; | ||
|
||
/** | ||
* TagCountView displays the tag count of a unit/component | ||
* | ||
* This component is being rendered in this way to allow receiving | ||
* messages from the Manage tags drawer and being able to update the count. | ||
*/ | ||
var TagCountView = BaseView.extend({ | ||
// takes TagCountModel as a model | ||
|
||
initialize: function() { | ||
BaseView.prototype.initialize.call(this); | ||
this.template = this.loadTemplate('tag-count'); | ||
}, | ||
|
||
setupMessageListener: function () { | ||
window.addEventListener( | ||
'message', (event) => { | ||
// Listen any message from Manage tags drawer. | ||
var data = event.data; | ||
var courseAuthoringUrl = this.model.get("course_authoring_url") | ||
if (event.origin == courseAuthoringUrl | ||
&& data.includes('[Manage tags drawer] 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); | ||
this.render(); | ||
} | ||
} | ||
} | ||
); | ||
}, | ||
|
||
render: function() { | ||
HtmlUtils.setHtml( | ||
this.$el, | ||
HtmlUtils.HTML( | ||
this.template({ | ||
tags_count: this.model.get("tags_count"), | ||
}) | ||
) | ||
); | ||
return this; | ||
} | ||
}); | ||
|
||
return TagCountView; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<% if (tags_count && tags_count > 0) { %> | ||
<button data-tooltip="<%- gettext("Manage Tags") %>" class="btn-default action-button manage-tags-button" data-testid="tag-count-button"> | ||
<span class="icon fa fa-tag" aria-hidden="true"></span> | ||
<span><%- tags_count %></span> | ||
<span class="sr action-button-text"><%- gettext("Manage Tags") %></span> | ||
</button> | ||
<% } %> |
Oops, something went wrong.