REFACTOR: changes from tag synonym feedback

This commit is contained in:
Neil Lalonde 2019-12-06 15:42:06 -05:00
parent 68124caae2
commit d0e191a9d5
4 changed files with 76 additions and 82 deletions

View File

@ -1,10 +1,7 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error"; import { popupAjaxError } from "discourse/lib/ajax-error";
import showModal from "discourse/lib/show-modal"; import showModal from "discourse/lib/show-modal";
import { import { default as discourseComputed } from "discourse-common/utils/decorators";
default as discourseComputed,
observes
} from "discourse-common/utils/decorators";
import Component from "@ember/component"; import Component from "@ember/component";
import { reads, and } from "@ember/object/computed"; import { reads, and } from "@ember/object/computed";
import { isEmpty } from "@ember/utils"; import { isEmpty } from "@ember/utils";
@ -43,11 +40,9 @@ export default Component.extend({
return isEmpty(tagGroupNames) && isEmpty(categories) && isEmpty(synonyms); return isEmpty(tagGroupNames) && isEmpty(categories) && isEmpty(synonyms);
}, },
@observes("expanded") didInsertElement() {
toggleExpanded() { this._super(...arguments);
if (this.expanded && !this.tagInfo) {
this.loadTagInfo(); this.loadTagInfo();
}
}, },
loadTagInfo() { loadTagInfo() {
@ -68,7 +63,8 @@ export default Component.extend({
result.category_ids.map(id => Category.findById(id)) result.category_ids.map(id => Category.findById(id))
); );
}) })
.finally(() => this.set("loading", false)); .finally(() => this.set("loading", false))
.catch(popupAjaxError);
}, },
actions: { actions: {
@ -89,7 +85,7 @@ export default Component.extend({
type: "DELETE" type: "DELETE"
}) })
.then(() => this.tagInfo.synonyms.removeObject(tag)) .then(() => this.tagInfo.synonyms.removeObject(tag))
.catch(() => bootbox.alert(I18n.t("generic_error"))); .catch(popupAjaxError);
}, },
deleteSynonym(tag) { deleteSynonym(tag) {
@ -101,7 +97,7 @@ export default Component.extend({
tag tag
.destroyRecord() .destroyRecord()
.then(() => this.tagInfo.synonyms.removeObject(tag)) .then(() => this.tagInfo.synonyms.removeObject(tag))
.catch(() => bootbox.alert(I18n.t("generic_error"))); .catch(popupAjaxError);
} }
); );
}, },

View File

@ -1,4 +1,3 @@
{{#if expanded}}
<section class="tag-info"> <section class="tag-info">
{{#if tagInfo}} {{#if tagInfo}}
<div class="tag-name"> <div class="tag-name">
@ -45,7 +44,6 @@
</div> </div>
{{/each}} {{/each}}
</div> </div>
<div class="clearfix" />
</div> </div>
{{/if}} {{/if}}
{{#if editSynonymsMode}} {{#if editSynonymsMode}}
@ -70,4 +68,3 @@
<div>{{i18n 'loading'}}</div> <div>{{i18n 'loading'}}</div>
{{/if}} {{/if}}
</section> </section>
{{/if}}

View File

@ -46,8 +46,8 @@
</div> </div>
</div> </div>
{{#if showToggleInfo}} {{#if showInfo}}
{{tag-info tag=tag expanded=showInfo list=list deleteAction=(action "deleteTag")}} {{tag-info tag=tag list=list deleteAction=(action "deleteTag")}}
{{/if}} {{/if}}
{{plugin-outlet name="discovery-list-container-top"}} {{plugin-outlet name="discovery-list-container-top"}}

View File

@ -280,6 +280,7 @@ header .discourse-tag {
.add-synonyms, .add-synonyms,
.tag-associations { .tag-associations {
margin-top: 1em; margin-top: 1em;
clear: both;
} }
.tag-list { .tag-list {
border: none; border: none;