Bug 1327756 - Netmonitor divides js files into 2 groups when I sort by type. r?honza draft
authorLocke Chen <locke12456@gmail.com>
Sat, 15 Apr 2017 11:14:26 +0800
changeset 563121 318200e6b36715490e9d5efbf8aa76d8f7abd7fc
parent 563120 9379831bb9c3d9abfea7dbf8dd06dbdab1d81dc4
child 624400 01c91f3569401cc9d98d93a4a1184e241af1aa4c
push id54216
push userbmo:locke12456@gmail.com
push dateSat, 15 Apr 2017 03:14:55 +0000
reviewershonza
bugs1327756
milestone55.0a1
Bug 1327756 - Netmonitor divides js files into 2 groups when I sort by type. r?honza MozReview-Commit-ID: EuuCBXyhYvr
devtools/client/netmonitor/src/components/request-list-item.js
devtools/client/netmonitor/src/utils/request-utils.js
--- a/devtools/client/netmonitor/src/components/request-list-item.js
+++ b/devtools/client/netmonitor/src/components/request-list-item.js
@@ -391,39 +391,32 @@ const CauseColumn = createFactory(create
           onClick: onCauseBadgeClick,
         }, "JS"),
         span({ className: "subitem-label" }, causeType),
       )
     );
   }
 }));
 
-const CONTENT_MIME_TYPE_ABBREVIATIONS = {
-  "ecmascript": "js",
-  "javascript": "js",
-  "x-javascript": "js"
-};
-
 const TypeColumn = createFactory(createClass({
   displayName: "TypeColumn",
 
   propTypes: {
     item: PropTypes.object.isRequired,
   },
 
   shouldComponentUpdate(nextProps) {
     return this.props.item.mimeType !== nextProps.item.mimeType;
   },
 
   render() {
     const { mimeType } = this.props.item;
     let abbrevType;
     if (mimeType) {
       abbrevType = getAbbreviatedMimeType(mimeType);
-      abbrevType = CONTENT_MIME_TYPE_ABBREVIATIONS[abbrevType] || abbrevType;
     }
 
     return (
       div({
         className: "requests-list-subitem requests-list-type",
         title: mimeType,
       },
         span({ className: "subitem-label" }, abbrevType),
--- a/devtools/client/netmonitor/src/utils/request-utils.js
+++ b/devtools/client/netmonitor/src/utils/request-utils.js
@@ -1,16 +1,22 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* eslint-disable mozilla/reject-some-requires */
 
 "use strict";
 
+const CONTENT_MIME_TYPE_ABBREVIATIONS = {
+  "ecmascript": "js",
+  "javascript": "js",
+  "x-javascript": "js"
+};
+
 /**
  * Extracts any urlencoded form data sections (e.g. "?foo=bar&baz=42") from a
  * POST request.
  *
  * @param {object} headers - the "requestHeaders".
  * @param {object} uploadHeaders - the "requestHeadersFromUploadStream".
  * @param {object} postData - the "requestPostData".
  * @return {array} a promise list that is resolved with the extracted form data.
@@ -107,17 +113,18 @@ function decodeUnicodeUrl(string) {
  *
  * @param {string} mimeType - mime type
  * @return {string} abbreviated mime type
  */
 function getAbbreviatedMimeType(mimeType) {
   if (!mimeType) {
     return "";
   }
-  return (mimeType.split(";")[0].split("/")[1] || "").split("+")[0];
+  let abbrevType = (mimeType.split(";")[0].split("/")[1] || "").split("+")[0];
+  return CONTENT_MIME_TYPE_ABBREVIATIONS[abbrevType] || abbrevType;
 }
 
 /**
  * Helpers for getting the last portion of a url.
  * For example helper returns "basename" from http://domain.com/path/basename
  * If basename portion is empty, it returns the url pathname.
  *
  * @param {string} url - url string