discourse/app/assets/javascripts/admin/addon/components/schema-theme-setting/field.gjs
Alan Guo Xiang Tan 86b2e3aa3e
DEV: Change tag type to tags type for theme object schema (#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
2024-03-22 15:32:00 +08:00

66 lines
1.7 KiB
Plaintext

import Component from "@glimmer/component";
import { cached } from "@glimmer/tracking";
import htmlSafe from "discourse-common/helpers/html-safe";
import BooleanField from "./types/boolean";
import CategoryField from "./types/category";
import EnumField from "./types/enum";
import FloatField from "./types/float";
import GroupField from "./types/group";
import IntegerField from "./types/integer";
import StringField from "./types/string";
import TagsField from "./types/tags";
export default class SchemaThemeSettingField extends Component {
get component() {
const type = this.args.spec.type;
switch (this.args.spec.type) {
case "string":
return StringField;
case "integer":
return IntegerField;
case "float":
return FloatField;
case "boolean":
return BooleanField;
case "enum":
return EnumField;
case "category":
return CategoryField;
case "tags":
return TagsField;
case "group":
return GroupField;
default:
throw new Error(`unknown type ${type}`);
}
}
@cached
get description() {
if (!this.args.description) {
return;
}
return htmlSafe(this.args.description.trim().replace(/\n/g, "<br>"));
}
<template>
<div class="schema-field" data-name={{@name}}>
<label class="schema-field__label">{{@name}}{{if
@spec.required
"*"
}}</label>
<div class="schema-field__input">
<this.component
@value={{@value}}
@spec={{@spec}}
@onChange={{@onValueChange}}
@description={{this.description}}
/>
</div>
</div>
</template>
}