Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Add an `emoji` property type to workflows

Régis Hanol28fe6724974a
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/field-control-registry.js b/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/field-control-registry.js
index da55117f45c..3e244f8ab3d 100644
--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/field-control-registry.js
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/field-control-registry.js
@@ -78,6 +78,7 @@ const FIELD_CONTROL_REGISTRY = {
},
select: { kind: "field", type: "select", renderer: SelectControl },
icon: { kind: "field", type: "icon", renderer: IconControl },
+ emoji: { kind: "field", type: "emoji", renderer: DefaultInputControl },
color: { kind: "field", type: "color", renderer: DefaultInputControl },
checkbox: { kind: "field", type: "checkbox", renderer: DefaultInputControl },
textarea: { kind: "field", type: "textarea", renderer: DefaultInputControl },
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/property-engine.js b/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/property-engine.js
index f49a6ffd7fc..5276cc50392 100644
--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/property-engine.js
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/property-engine.js
@@ -328,6 +328,7 @@ export function propertyOptionLabel(nodeDefinitionOrType, fieldName, option) {
const TYPE_TO_CONTROL = {
boolean: "boolean",
icon: "icon",
+ emoji: "emoji",
options: "select",
multi_options: "multi_combo_box",
collection: "collection",
@@ -354,7 +355,7 @@ export function fieldSupportsExpression(schema = {}) {
return Boolean(ui.expression);
}
- return ["string", "integer", "number", "float", "icon"].includes(
+ return ["string", "integer", "number", "float", "icon", "emoji"].includes(
fieldType(schema)
);
}
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/property_schema_validator.rb b/plugins/discourse-workflows/lib/discourse_workflows/property_schema_validator.rb
index a197a6e93e3..0fb89db7c87 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/property_schema_validator.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/property_schema_validator.rb
@@ -18,6 +18,7 @@ module DiscourseWorkflows
notice
credential
icon
+ emoji
custom
].freeze
@@ -109,6 +110,7 @@ module DiscourseWorkflows
data_table_condition_builder
data_table_select
date_time
+ emoji
field_path
filter_query
group_select
diff --git a/plugins/discourse-workflows/test/javascripts/integration/components/workflows/property-engine-test.gjs b/plugins/discourse-workflows/test/javascripts/integration/components/workflows/property-engine-test.gjs
index 50a78db510a..153c978867c 100644
--- a/plugins/discourse-workflows/test/javascripts/integration/components/workflows/property-engine-test.gjs
+++ b/plugins/discourse-workflows/test/javascripts/integration/components/workflows/property-engine-test.gjs
@@ -10,8 +10,10 @@ import {
import { module, test } from "qunit";
import sinon from "sinon";
import Form from "discourse/components/form";
+import emojisFixtures from "discourse/tests/fixtures/emojis-fixtures";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
+import emojiPicker from "discourse/tests/helpers/emoji-picker-helper";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { NO_VALUE_OPTION } from "discourse/ui-kit/d-native-select";
import I18n, { i18n } from "discourse-i18n";
@@ -92,6 +94,35 @@ module("Integration | Component | workflows property engine", function (hooks) {
assert.dom("input").isFocused();
});
+ test("picks emojis for emoji fields", async function (assert) {
+ pretender.get("/emojis.json", () =>
+ response(emojisFixtures["/emojis.json"])
+ );
+ pretender.get("/emojis/search-aliases.json", () => response([]));
+
+ this.setProperties({
+ configuration: { reaction: null },
+ formApi: null,
+ nodeType: "action:topic",
+ schema: {
+ reaction: {
+ type: "emoji",
+ no_data_expression: true,
+ },
+ },
+ registerApi: (api) => {
+ this.set("formApi", api);
+ },
+ });
+
+ await renderEngine(this);
+
+ await click(".btn-emoji");
+ await emojiPicker(".emoji-picker").select("grinning");
+
+ assert.strictEqual(this.formApi.get("reaction"), "grinning");
+ });
+
test("validates optional integer fields that do not support expressions", async function (assert) {
this.setProperties({
configuration: { post_number: "" },
diff --git a/plugins/discourse-workflows/test/javascripts/unit/lib/workflows-property-engine-test.js b/plugins/discourse-workflows/test/javascripts/unit/lib/workflows-property-engine-test.js
index 0704267ba2a..6a46d893ae8 100644
--- a/plugins/discourse-workflows/test/javascripts/unit/lib/workflows-property-engine-test.js
+++ b/plugins/discourse-workflows/test/javascripts/unit/lib/workflows-property-engine-test.js
@@ -296,6 +296,7 @@ module("Unit | Utility | workflows property engine", function () {
"textarea"
);
assert.strictEqual(fieldControl({ type: "icon" }), "icon");
+ assert.strictEqual(fieldControl({ type: "emoji" }), "emoji");
assert.strictEqual(
fieldControl({ type: "multi_options" }),
"multi_combo_box"
@@ -317,6 +318,7 @@ module("Unit | Utility | workflows property engine", function () {
);
assert.true(fieldSupportsExpression({ type: "integer" }));
assert.true(fieldSupportsExpression({ type: "icon" }));
+ assert.true(fieldSupportsExpression({ type: "emoji" }));
assert.false(fieldSupportsExpression({ type: "multi_options" }));
assert.false(
fieldSupportsExpression({ type: "string", no_data_expression: true })