0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Added error message when trying to add zero tags in bulk action

refs https://github.com/TryGhost/Team/issues/2922
This commit is contained in:
Simon Backx 2023-04-13 17:44:26 +02:00
parent 788aa34c8b
commit 0cf41171b8
2 changed files with 37 additions and 15 deletions

View file

@ -6,19 +6,22 @@
<div class="modal-body">
<p>
<GhTokenInput
@extra={{hash
tokenComponent=(component "gh-token-input/tag-token")
}}
@onChange={{this.handleChange}}
@onCreate={{this.handleCreate}}
@options={{this.availableTags}}
@renderInPlace={{true}}
@selected={{this.selectedTags}}
@showCreateWhen={{this.shouldAllowCreate}}
@triggerId={{this.triggerId}}
@placeholder="Select one or more tags"
/>
<GhFormGroup @errors={{this.errors}} @hasValidated={{this.hasValidated}} @property="tags">
<GhTokenInput
@extra={{hash
tokenComponent=(component "gh-token-input/tag-token")
}}
@onChange={{this.handleChange}}
@onCreate={{this.handleCreate}}
@options={{this.availableTags}}
@renderInPlace={{true}}
@selected={{this.selectedTags}}
@showCreateWhen={{this.shouldAllowCreate}}
@triggerId={{this.triggerId}}
@placeholder="Select one or more tags"
/>
<GhErrorMessage @errors={{this.errors}} @property="tags" />
</GhFormGroup>
</p>
</div>
@ -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"
/>

View file

@ -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();