forked from discourse/discourse
-
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.
…rse#26315) Why this change? While working on the tag selector for the theme object editor, I realised that there is an extremely high possibility that users might want to select more than one tag. By supporting the ability to select more than one tag, it also means that we get support for a single tag for free as well. What does this change do? 1. Change `type: tag` to `type: tags` and support `min` and `max` validations for `type: tags`. 2. Fix the `<SchemaThemeSetting::Types::Tags>` component to support the `min` and `max` validations
- Loading branch information
Showing
10 changed files
with
245 additions
and
75 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
26 changes: 0 additions & 26 deletions
26
app/assets/javascripts/admin/addon/components/schema-theme-setting/types/tag.gjs
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
app/assets/javascripts/admin/addon/components/schema-theme-setting/types/tags.gjs
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,65 @@ | ||
import Component from "@glimmer/component"; | ||
import { tracked } from "@glimmer/tracking"; | ||
import { action } from "@ember/object"; | ||
import { and, not } from "truth-helpers"; | ||
import I18n from "discourse-i18n"; | ||
import FieldInputDescription from "admin/components/schema-theme-setting/field-input-description"; | ||
import TagChooser from "select-kit/components/tag-chooser"; | ||
|
||
export default class SchemaThemeSettingTypeTags extends Component { | ||
@tracked touched = false; | ||
@tracked value = this.args.value; | ||
required = this.args.spec.required; | ||
min = this.args.spec.validations?.min; | ||
max = this.args.spec.validations?.max; | ||
|
||
@action | ||
onInput(newVal) { | ||
this.touched = true; | ||
this.value = newVal; | ||
this.args.onChange(newVal); | ||
} | ||
|
||
get tagChooserOption() { | ||
return { | ||
allowAny: false, | ||
maximum: this.max, | ||
}; | ||
} | ||
|
||
get validationErrorMessage() { | ||
if (!this.touched) { | ||
return; | ||
} | ||
|
||
if ( | ||
(this.min && this.value.length < this.min) || | ||
(this.required && (!this.value || this.value.length === 0)) | ||
) { | ||
return I18n.t("admin.customize.theme.schema.fields.tags.at_least_tag", { | ||
count: this.min, | ||
}); | ||
} | ||
} | ||
|
||
<template> | ||
<TagChooser | ||
@tags={{this.value}} | ||
@onChange={{this.onInput}} | ||
@options={{this.tagChooserOption}} | ||
class={{if this.validationErrorMessage "--invalid"}} | ||
/> | ||
|
||
<div class="schema-field__input-supporting-text"> | ||
{{#if (and @description (not this.validationErrorMessage))}} | ||
<FieldInputDescription @description={{@description}} /> | ||
{{/if}} | ||
|
||
{{#if this.validationErrorMessage}} | ||
<div class="schema-field__input-error"> | ||
{{this.validationErrorMessage}} | ||
</div> | ||
{{/if}} | ||
</div> | ||
</template> | ||
} |
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
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
Oops, something went wrong.