Skip to content

Commit

Permalink
DEV: Convert a helper to a component getter (#57)
Browse files Browse the repository at this point in the history
(and merge some directories)
  • Loading branch information
CvX authored Aug 21, 2023
1 parent 79bbc58 commit 20109c3
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion javascripts/discourse/components/modal/ucd-warning.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<DModal
@closeModal={{this.closeModal}}
class="modal-ucd-warning"
@title={{(modal-ucd-title)}}
@title={{this.title}}
@inline={{@inline}}
>
<Ucd::Warning @onClose={{this.closeModal}} />
Expand Down
18 changes: 16 additions & 2 deletions javascripts/discourse/components/modal/ucd-warning.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import Component from "@glimmer/component";
import { inject as service } from "@ember/service";
import { action } from "@ember/object";
import { htmlSafe } from "@ember/template";
import I18n from "I18n";
import { emojiUnescape } from "discourse/lib/text";
import { escape } from "pretty-text/sanitizer";
import { randomizeEmojiDiversity } from "../../lib/emoji-diversity";

export default class ModalUcdWarning extends Component {
@service ucdState;

get title() {
return htmlSafe(
[
emojiUnescape(escape(randomizeEmojiDiversity(settings.emoji_icon))),
escape(I18n.t(themePrefix("warning_modal.title"))),
].join(" ")
);
}

@action
closeModal() {
if (this.args.model.ucd_shouldPermanentlyDismiss) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { withPluginApi } from "discourse/lib/plugin-api";
import { detectUnformattedCode, printDebugInfo } from "../core/detect-code";
import { randomizeEmojiDiversity } from "../lib/emoji-diversity";
import { emojiUnescape } from "discourse/lib/text";
import { htmlSafe } from "@ember/template";
import { registerUnbound } from "discourse-common/lib/helpers";
import I18n from "I18n";
import { escape } from "pretty-text/sanitizer";
import ModalUcdWarning from "../../discourse/components/modal/ucd-warning";
import ModalUcdWarning from "../components/modal/ucd-warning";
import { inject as service } from "@ember/service";

const getDisableAtTrustLevel = () =>
Expand All @@ -30,15 +24,6 @@ export default {
}
};

registerUnbound("modal-ucd-title", () => {
return htmlSafe(
[
emojiUnescape(escape(randomizeEmojiDiversity(settings.emoji_icon))),
escape(I18n.t(themePrefix("warning_modal.title"))),
].join(" ")
);
});

api.modifyClass("model:composer", {
ucdState: service("ucd-state"),
pluginId: "unformatted-code-detector",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/unit/detect-code/with-html-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
withFormattedHTML,
withUnformattedCode,
} from "../../fixtures/basic";
import { detectUnformattedCode } from "../../../unformatted-code-detector/core/detect-code";
import { detectUnformattedCode } from "../../../discourse/core/detect-code";

module("With HTML", function (hooks) {
hooks.beforeEach(function () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/detect-code/without-html-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { module } from "qunit";
import { expectAll } from "../../helpers/utils";
import { withBareHTML } from "../../fixtures/basic";
import { detectUnformattedCode } from "../../../unformatted-code-detector/core/detect-code";
import { detectUnformattedCode } from "../../../discourse/core/detect-code";

module("Without HTML", function (hooks) {
hooks.beforeEach(function () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/emoji-diversity-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { module, test } from "qunit";
import { randomizeEmojiGender } from "../../unformatted-code-detector/lib/emoji-diversity";
import { randomizeEmojiGender } from "../../discourse/lib/emoji-diversity";

const originalMathRandom = Math.random;

Expand Down
2 changes: 1 addition & 1 deletion test/unit/from-bug-reports-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { module } from "qunit";
import { expectAll } from "../helpers/utils";
import { falseNegatives, falsePositives } from "../fixtures/bug-reports";
import { detectUnformattedCode } from "../../unformatted-code-detector/core/detect-code";
import { detectUnformattedCode } from "../../discourse/core/detect-code";

module("bug reports", function () {
expectAll(detectUnformattedCode, falseNegatives, true);
Expand Down
5 changes: 2 additions & 3 deletions test/unit/post-length-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { module } from "qunit";
import { expectAll } from "../helpers/utils";

import { withUnformattedCode } from "../fixtures/basic";
import { detectUnformattedCode } from "../../unformatted-code-detector/core/detect-code";
import { module } from "qunit";
import { detectUnformattedCode } from "../../discourse/core/detect-code";

module("ignore if too short", function (hooks) {
hooks.beforeEach(function () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/sensitivity-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { module, test } from "qunit";
import { applySensitivity } from "../../unformatted-code-detector/core/sensitivity";
import { applySensitivity } from "../../discourse/core/sensitivity";

module("apply sensitivity", function () {
test("lowest sensitivity", function (assert) {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/sequential-lines-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { module, test } from "qunit";
import {
getCodeEnergy,
numSequentialLinesWithThresholdCodeEnergy,
} from "../../unformatted-code-detector/core/detect-code";
} from "../../discourse/core/detect-code";
import {
CodeEnergyLevels,
codeEnergyValues,
} from "../../unformatted-code-detector/core/code-energy";
} from "../../discourse/core/code-energy";

module("sequential lines", function (hooks) {
hooks.beforeEach(function () {
Expand Down

0 comments on commit 20109c3

Please sign in to comment.