Bug 1474836 - (Part 1) Externalize font editor empty state warning message to Redux store. r=gl draft
authorRazvan Caliman <rcaliman@mozilla.com>
Wed, 11 Jul 2018 11:19:34 +0200
changeset 816425 66b013138ccdea5136a936718e8bd7809c093658
parent 815985 a675c5d7eb76887a3e4b24548d621c9cc05a1545
child 816426 011c09eeb7260d665b6a86b58671b58e82dd1a18
push id115847
push userbmo:rcaliman@mozilla.com
push dateWed, 11 Jul 2018 09:21:52 +0000
reviewersgl
bugs1474836
milestone63.0a1
Bug 1474836 - (Part 1) Externalize font editor empty state warning message to Redux store. r=gl MozReview-Commit-ID: AsVkZz5x0VC
devtools/client/inspector/fonts/actions/font-editor.js
devtools/client/inspector/fonts/actions/index.js
devtools/client/inspector/fonts/components/FontEditor.js
devtools/client/inspector/fonts/reducers/font-editor.js
--- a/devtools/client/inspector/fonts/actions/font-editor.js
+++ b/devtools/client/inspector/fonts/actions/font-editor.js
@@ -6,16 +6,17 @@
 
 const {
   APPLY_FONT_VARIATION_INSTANCE,
   RESET_EDITOR,
   UPDATE_AXIS_VALUE,
   UPDATE_CUSTOM_INSTANCE,
   UPDATE_EDITOR_STATE,
   UPDATE_PROPERTY_VALUE,
+  UPDATE_WARNING_MESSAGE,
 } = require("./index");
 
 module.exports = {
 
   resetFontEditor() {
     return {
       type: RESET_EDITOR,
     };
@@ -55,9 +56,16 @@ module.exports = {
   updateFontProperty(property, value) {
     return {
       type: UPDATE_PROPERTY_VALUE,
       property,
       value,
     };
   },
 
+  updateWarningMessage(warning) {
+    return {
+      type: UPDATE_WARNING_MESSAGE,
+      warning,
+    };
+  },
+
 };
--- a/devtools/client/inspector/fonts/actions/index.js
+++ b/devtools/client/inspector/fonts/actions/index.js
@@ -30,9 +30,12 @@ createEnum([
   "UPDATE_FONTS",
 
   // Update the preview text.
   "UPDATE_PREVIEW_TEXT",
 
   // Update the value of a CSS font property
   "UPDATE_PROPERTY_VALUE",
 
+  // Update the warning message with the reason for not showing the font editor
+  "UPDATE_WARNING_MESSAGE",
+
 ], module.exports);
--- a/devtools/client/inspector/fonts/components/FontEditor.js
+++ b/devtools/client/inspector/fonts/components/FontEditor.js
@@ -274,48 +274,48 @@ class FontEditor extends PureComponent {
           className: "font-control-label",
         },
         getStr("fontinspector.fontInstanceLabel")
       ),
       instanceSelect
     );
   }
 
-  renderWarning() {
+  renderWarning(warning) {
     return dom.div(
       {
         id: "font-editor"
       },
       dom.div(
         {
           className: "devtools-sidepanel-no-result"
         },
-        getStr("fontinspector.noFontsOnSelectedElement")
+        warning
       )
     );
   }
 
   render() {
     const { fontEditor } = this.props;
-    const { fonts, families, axes, instance, properties } = fontEditor;
+    const { fonts, families, axes, instance, properties, warning } = fontEditor;
     // Pick the first font to show editor controls regardless of how many fonts are used.
     const font = fonts[0];
     const hasFontAxes = font && font.variationAxes;
     const hasFontInstances = font && font.variationInstances
       && font.variationInstances.length > 0;
     const hasSlantOrItalicAxis = hasFontAxes && font.variationAxes.find(axis => {
       return axis.tag === "slnt" || axis.tag === "ital";
     });
     const hasWeightAxis = hasFontAxes && font.variationAxes.find(axis => {
       return axis.tag === "wght";
     });
 
-    // Render empty state message for nodes that don't have a used font.
+    // Show the empty state with a warning message when a used font was not found.
     if (!font) {
-      return this.renderWarning();
+      return this.renderWarning(warning);
     }
 
     return dom.div(
       {
         id: "font-editor"
       },
       // Always render UI for font family, format and font file URL.
       this.renderFontFamily(fonts, families),
--- a/devtools/client/inspector/fonts/reducers/font-editor.js
+++ b/devtools/client/inspector/fonts/reducers/font-editor.js
@@ -9,16 +9,17 @@ const { parseFontVariationAxes } = requi
 
 const {
   APPLY_FONT_VARIATION_INSTANCE,
   RESET_EDITOR,
   UPDATE_AXIS_VALUE,
   UPDATE_CUSTOM_INSTANCE,
   UPDATE_EDITOR_STATE,
   UPDATE_PROPERTY_VALUE,
+  UPDATE_WARNING_MESSAGE,
 } = require("../actions/index");
 
 const INITIAL_STATE = {
   // Variable font axes.
   axes: {},
   // Copy of the most recent axes values. Used to revert from a named instance.
   customInstanceValues: [],
   // Font families declared on the selected element
@@ -33,16 +34,19 @@ const INITIAL_STATE = {
   fonts: [],
   // Current selected font variation instance.
   instance: {
     name: getStr("fontinspector.customInstanceName"),
     values: [],
   },
   // CSS font properties defined on the selected rule.
   properties: {},
+
+  // Warning message with the reason why the font editor cannot be shown.
+  warning: getStr("fontinspector.noFontsOnSelectedElement"),
 };
 
 const reducers = {
 
   // Update font editor with the axes and values defined by a font variation instance.
   [APPLY_FONT_VARIATION_INSTANCE](state, { name, values }) {
     const newState = { ...state };
     newState.instance.name = name;
@@ -100,17 +104,21 @@ const reducers = {
 
     return { ...state, axes, fonts, families, properties };
   },
 
   [UPDATE_PROPERTY_VALUE](state, { property, value }) {
     const newState = { ...state };
     newState.properties[property] = value;
     return newState;
-  }
+  },
+
+  [UPDATE_WARNING_MESSAGE](state, { warning }) {
+    return { ...state, warning };
+  },
 
 };
 
 module.exports = function(state = INITIAL_STATE, action) {
   const reducer = reducers[action.type];
   if (!reducer) {
     return state;
   }