Remove discourse constants (#9958)

Remove discourse constants (#9958)

  • DEV: Discourse.baseUri does not exist

This never could have worked - should have been Discourse.BaseUri if anything.

  • DEV: Remove Discourse.Environment

  • DEV: Remove Discourse.disableMissingIconWarning

  • DEV: A bunch more missing environment checks

diff --git a/app/assets/javascripts/admin/components/admin-report.js b/app/assets/javascripts/admin/components/admin-report.js
index b9ce9a6..bacb617 100644
--- a/app/assets/javascripts/admin/components/admin-report.js
+++ b/app/assets/javascripts/admin/components/admin-report.js
@@ -9,8 +9,8 @@ import ReportLoader from "discourse/lib/reports-loader";
 import { exportEntity } from "discourse/lib/export-csv";
 import { outputExportResult } from "discourse/lib/export-result";
 import Report, { SCHEMA_VERSION } from "admin/models/report";
-import ENV from "discourse-common/config/environment";
 import { isPresent } from "@ember/utils";
+import { isTesting } from "discourse-common/config/environment";
 
 const TABLE_OPTIONS = {
   perPage: 8,
@@ -167,8 +167,8 @@ export default Component.extend({
     let reportKey = "reports:";
     reportKey += [
       dataSourceName,
-      ENV.environment === "test" ? "start" : startDate.replace(/-/g, ""),
-      ENV.environment === "test" ? "end" : endDate.replace(/-/g, ""),
+      isTesting() ? "start" : startDate.replace(/-/g, ""),
+      isTesting() ? "end" : endDate.replace(/-/g, ""),
       "[:prev_period]",
       this.get("reportOptions.table.limit"),
       // Convert all filter values to strings to ensure unique serialization
diff --git a/app/assets/javascripts/admin/components/themes-list-item.js b/app/assets/javascripts/admin/components/themes-list-item.js
index c292b80..56db74e 100644
--- a/app/assets/javascripts/admin/components/themes-list-item.js
+++ b/app/assets/javascripts/admin/components/themes-list-item.js
@@ -4,7 +4,7 @@ import Component from "@ember/component";
 import discourseComputed, { observes } from "discourse-common/utils/decorators";
 import { iconHTML } from "discourse-common/lib/icon-library";
 import { escape } from "pretty-text/sanitizer";
-import ENV from "discourse-common/config/environment";
+import { isTesting } from "discourse-common/config/environment";
 
 const MAX_COMPONENTS = 4;
 
@@ -41,7 +41,7 @@ export default Component.extend({
   animate(isInitial) {
     const $container = $(this.element);
     const $list = $(this.element.querySelector(".components-list"));
-    if ($list.length === 0 || ENV.environment === "test") {
+    if ($list.length === 0 || isTesting()) {
       return;
     }
     const duration = 300;
diff --git a/app/assets/javascripts/discourse-common/addon/config/environment.js b/app/assets/javascripts/discourse-common/addon/config/environment.js
index 8d684bf..b580231 100644
--- a/app/assets/javascripts/discourse-common/addon/config/environment.js
+++ b/app/assets/javascripts/discourse-common/addon/config/environment.js
@@ -1,9 +1,23 @@
 export const INPUT_DELAY = 250;
 
-let environment = Ember.testing ? "test" : "development";
+let environment = "unknown";
+
+export function setEnvironment(e) {
+  if (isTesting()) {
+    environment = "testing";
+  } else {
+    environment = e;
+  }
+}
 
 export function isTesting() {
-  return environment === "test";
+  return Ember.testing;
 }
 
-export default { environment };
+export function isDevelopment() {
+  return environment === "development";
+}
+
+export function isProduction() {
+  return environment === "production";
+}
diff --git a/app/assets/javascripts/discourse-common/addon/lib/icon-library.js b/app/assets/javascripts/discourse-common/addon/lib/icon-library.js
index ef60571..8633701 100644
--- a/app/assets/javascripts/discourse-common/addon/lib/icon-library.js
+++ b/app/assets/javascripts/discourse-common/addon/lib/icon-library.js
@@ -1,10 +1,13 @@
 import I18n from "I18n";
 import { h } from "virtual-dom";
 import attributeHook from "discourse-common/lib/attribute-hook";
+import { isDevelopment } from "discourse-common/config/environment";
 
 const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
 let _renderers = [];
 
+let warnMissingIcons = true;
+
 const REPLACEMENTS = {
   "d-tracking": "bell",
   "d-muted": "discourse-bell-slash",
@@ -45,6 +48,14 @@ export function replaceIcon(source, destination) {
   REPLACEMENTS[source] = destination;
 }
 
+export function disableMissingIconWarning() {
+  warnMissingIcons = false;
+}
+
+export function enableMissingIconWarning() {
+  warnMissingIcons = false;
+}
+
 export function renderIcon(renderType, id, params) {
   for (let i = 0; i < _renderers.length; i++) {
     let renderer = _renderers[i];
@@ -105,8 +116,8 @@ function iconClasses(icon, params) {
 function warnIfMissing(id) {
   if (
     typeof Discourse !== "undefined" &&
-    Discourse.Environment === "development" &&
-    !Discourse.disableMissingIconWarning &&
+    isDevelopment() &&
+    warnMissingIcons &&
     Discourse.SvgIconList &&
     Discourse.SvgIconList.indexOf(id) === -1
   ) {
diff --git a/app/assets/javascripts/discourse/app/components/composer-editor.js b/app/assets/javascripts/discourse/app/components/composer-editor.js
index de6fa43..2eb99f4 100644
--- a/app/assets/javascripts/discourse/app/components/composer-editor.js
+++ b/app/assets/javascripts/discourse/app/components/composer-editor.js
@@ -44,7 +44,7 @@ import {
   cacheShortUploadUrl,
   resolveAllShortUrls
 } from "pretty-text/upload-short-url";
-import ENV from "discourse-common/config/environment";
+import { isTesting } from "discourse-common/config/environment";
 
 const REBUILD_SCROLL_MAP_EVENTS = ["composer:resized", "composer:typed-reply"];
 
@@ -847,7 +847,7 @@ export default Component.extend({
       // need to wait a bit for the "slide down" transition of the composer
       later(
         () => this.appEvents.trigger("composer:closed"),
-        ENV.environment === "test" ? 0 : 400
+        isTesting() ? 0 : 400
       );
     });
 
diff --git a/app/assets/javascripts/discourse/app/components/composer-title.js b/app/assets/javascripts/discourse/app/components/composer-title.js
index 7ee2cb5..ed037bd 100644
--- a/app/assets/javascripts/discourse/app/components/composer-title.js
+++ b/app/assets/javascripts/discourse/app/components/composer-title.js
@@ -6,7 +6,7 @@ import discourseComputed, { observes } from "discourse-common/utils/decorators";
 import { load } from "pretty-text/oneboxer";
 import { lookupCache } from "pretty-text/oneboxer-cache";
 import { ajax } from "discourse/lib/ajax";
-import ENV from "discourse-common/config/environment";
+import { isTesting } from "discourse-common/config/environment";
 import EmberObject from "@ember/object";
 import putCursorAtEnd from "discourse/lib/put-cursor-at-end";
 
@@ -76,7 +76,7 @@ export default Component.extend({
       return;
     }
 
-    if (ENV.environment === "test") {
+    if (isTesting()) {
       next(() =>
         // not ideal but we don't want to run this in current
         // runloop to avoid an error in console
diff --git a/app/assets/javascripts/discourse/app/components/d-editor.js b/app/assets/javascripts/discourse/app/components/d-editor.js
index 184b7f9..87cec77 100644
--- a/app/assets/javascripts/discourse/app/components/d-editor.js
+++ b/app/assets/javascripts/discourse/app/components/d-editor.js
@@ -28,7 +28,7 @@ import { emojiSearch, isSkinTonableEmoji } from "pretty-text/emoji";
 import { emojiUrlFor } from "discourse/lib/text";
 import showModal from "discourse/lib/show-modal";
 import { Promise } from "rsvp";
-import ENV from "discourse-common/config/environment";
+import { isTesting } from "discourse-common/config/environment";
 
 // Our head can be a static string or a function that returns a string
 // based on input (like for numbered lists).
@@ -378,7 +378,7 @@ export default Component.extend({
     }
 
     // Debouncing in test mode is complicated
-    if (ENV.environment === "test") {
+    if (isTesting()) {
       this._updatePreview();
     } else {
       debounce(this, this._updatePreview, 30);
diff --git a/app/assets/javascripts/discourse/app/components/emoji-picker.js b/app/assets/javascripts/discourse/app/components/emoji-picker.js
index a77b564..3acf181 100644

[... diff too long, it was truncated ...]

GitHub sha: a95826f6

1 Like

This commit appears in #9958 which was merged by eviltrout.