From 0cf41171b87faa11359b98d57964238aed7952af Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Thu, 13 Apr 2023 17:44:26 +0200 Subject: [PATCH] Added error message when trying to add zero tags in bulk action refs https://github.com/TryGhost/Team/issues/2922 --- .../components/posts-list/modals/add-tag.hbs | 32 ++++++++++--------- .../components/posts-list/modals/add-tag.js | 20 ++++++++++++ 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/ghost/admin/app/components/posts-list/modals/add-tag.hbs b/ghost/admin/app/components/posts-list/modals/add-tag.hbs index 45fb235d21..8d82cc343e 100644 --- a/ghost/admin/app/components/posts-list/modals/add-tag.hbs +++ b/ghost/admin/app/components/posts-list/modals/add-tag.hbs @@ -6,19 +6,22 @@ @@ -29,8 +32,7 @@ @buttonText="Add" @runningText="Adding" @showSuccess={{false}} - @task={{@data.confirm}} - @taskArgs={{this.selectedTags}} + @task={{this.confirm}} @class="gh-btn gh-btn-green gh-btn-icon" data-test-button="confirm" /> diff --git a/ghost/admin/app/components/posts-list/modals/add-tag.js b/ghost/admin/app/components/posts-list/modals/add-tag.js index 50f888a0eb..6f125acb47 100644 --- a/ghost/admin/app/components/posts-list/modals/add-tag.js +++ b/ghost/admin/app/components/posts-list/modals/add-tag.js @@ -1,7 +1,10 @@ import Component from '@glimmer/component'; +import DS from 'ember-data'; // eslint-disable-line import {action} from '@ember/object'; import {inject as service} from '@ember/service'; +import {task} from 'ember-concurrency'; import {tracked} from '@glimmer/tracking'; +const {Errors} = DS; export default class AddTag extends Component { @service store; @@ -11,10 +14,17 @@ export default class AddTag extends Component { @tracked selectedTags = []; + @tracked + errors = Errors.create(); + get availableTags() { return this.#availableTags || []; } + get hasValidated() { + return ['tags']; + } + constructor() { super(...arguments); // perform a background query to fetch all users and set `availableTags` @@ -41,6 +51,16 @@ export default class AddTag extends Component { this.selectedTags = newTags; } + @task + *confirm() { + if (this.selectedTags.length === 0) { + this.errors.add('tags', 'Select at least one tag'); + return; + } + this.errors.clear(); + yield this.args.data.confirm.perform(this.selectedTags); + } + @action handleCreate(nameInput) { let potentialTagName = nameInput.trim();