Board: fix attribute views for tags (#2046)

* Board: fix attribute views for tags

Signed-off-by: Anna No <anna.no@xored.com>

* Board: fix attribute views for tags

Signed-off-by: Anna No <anna.no@xored.com>

* fix formatting

Signed-off-by: Anna No <anna.no@xored.com>

* fix review comments

Signed-off-by: Anna No <anna.no@xored.com>

* fix review comments

Signed-off-by: Anna No <anna.no@xored.com>

* fix review comments

Signed-off-by: Anna No <anna.no@xored.com>
This commit is contained in:
Anna No 2022-06-09 21:34:35 +07:00 committed by GitHub
parent cbaf13cd72
commit 4e5fc37506
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 11 deletions

View File

@ -88,9 +88,6 @@ export function createModel (builder: Builder): void {
builder.createModel(TTagElement, TTagReference, TTagCategory)
builder.mixin(tags.class.TagReference, core.class.Class, view.mixin.CollectionEditor, {
editor: tags.component.Tags
})
builder.mixin(tags.class.TagReference, core.class.Class, view.mixin.AttributeEditor, {
editor: tags.component.TagsAttributeEditor
})

View File

@ -41,16 +41,24 @@
attribute: AnyAttribute,
presenterClass?: { attrClass: Ref<Class<Doc>>; category: AttributeCategory }
): void {
if (presenterClass?.attrClass !== undefined && presenterClass?.category === 'attribute') {
const typeClass = hierarchy.getClass(presenterClass.attrClass)
const editorMixin = hierarchy.as(typeClass, view.mixin.AttributeEditor)
editor = getResource(editorMixin.editor).catch((cause) => {
console.error(`failed to find editor for ${_class} ${attribute} ${presenterClass.attrClass} cause: ${cause}`)
})
if (presenterClass?.attrClass === undefined) {
return
}
if (presenterClass?.attrClass !== undefined && presenterClass?.category === 'array') {
const category = presenterClass.category
let mixinRef = undefined
if (category === 'attribute') {
mixinRef = view.mixin.AttributeEditor
}
if (category === 'collection') {
mixinRef = view.mixin.CollectionEditor
}
if (category === 'array') {
mixinRef = view.mixin.ArrayEditor
}
if (mixinRef !== undefined) {
const typeClass = hierarchy.getClass(presenterClass.attrClass)
const editorMixin = hierarchy.as(typeClass, view.mixin.ArrayEditor)
const editorMixin = hierarchy.as(typeClass, mixinRef)
editor = getResource(editorMixin.editor).catch((cause) => {
console.error(`failed to find editor for ${_class} ${attribute} ${presenterClass.attrClass} cause: ${cause}`)
})