mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-23 00:24:19 +08:00
Follow up to refactoring the generic utils mixin used in select-kit components in https://github.com/discourse/discourse/pull/32594. This PR follows a different approach as the util functions related to properties here aren't easily extracted without a major change to the interface due to the dependency on `this.selectKit`. These util functions are instead declared on the prototype with a class decorator which ensures the same behaviour is maintained without relying on a mixin. It's largely a lift-and-shift with some minor refactoring of the conditional logic to reduce nesting and improve readability of the functions.
29 lines
754 B
Text
Vendored
29 lines
754 B
Text
Vendored
import Component from "@ember/component";
|
|
import { computed } from "@ember/object";
|
|
import { tagName } from "@ember-decorators/component";
|
|
import { makeArray } from "discourse/lib/helpers";
|
|
import selectKitPropUtils from "select-kit/lib/select-kit-prop-utils";
|
|
|
|
@tagName("")
|
|
@selectKitPropUtils
|
|
export default class FormatSelectedContent extends Component {
|
|
content = null;
|
|
selectKit = null;
|
|
|
|
@computed("content")
|
|
get formattedContent() {
|
|
if (this.content) {
|
|
return makeArray(this.content)
|
|
.map((c) => this.getName(c))
|
|
.join(", ");
|
|
} else {
|
|
return this.getName(this.selectKit.noneItem);
|
|
}
|
|
}
|
|
|
|
<template>
|
|
<span class="formatted-selection">
|
|
{{this.formattedContent}}
|
|
</span>
|
|
</template>
|
|
}
|