Skip to content

FEATURE: Add upload type to schema settings #33802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import GroupsField from "admin/components/schema-setting/types/groups";
import IntegerField from "admin/components/schema-setting/types/integer";
import StringField from "admin/components/schema-setting/types/string";
import TagsField from "admin/components/schema-setting/types/tags";
import UploadField from "admin/components/schema-setting/types/upload";

export default class SchemaSettingField extends Component {
get component() {
Expand All @@ -31,6 +32,8 @@ export default class SchemaSettingField extends Component {
return TagsField;
case "groups":
return GroupsField;
case "upload":
return UploadField;
default:
throw new Error(`unknown type ${type}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { tracked } from "@glimmer/tracking";
import { fn } from "@ember/helper";
import { action } from "@ember/object";
import { and, not } from "truth-helpers";
import UppyImageUploader from "discourse/components/uppy-image-uploader";
import FieldInputDescription from "admin/components/schema-setting/field-input-description";
import SchemaSettingTypeModels from "admin/components/schema-setting/types/models";

export default class SchemaSettingTypeUpload extends SchemaSettingTypeModels {
@tracked value = this.args.value || null;
type = "upload";

@action
onChange(upload) {
return upload.id;
}

<template>

<UppyImageUploader
@imageUrl={{this.value}}
@placeholderUrl={{@setting.placeholder}}
@onUploadDone={{this.onInput}}
@onUploadDeleted={{fn (mut this.value) null}}
@type={{this.type}}
@id={{@setting.schema.name}}
/>

<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>
}
Loading