Files
firefox/devtools/client/shared/components/reps/long-string.js
T
Nicolas Chevobbe f3047054a0 Bug 1302982 - Add Rep for LongString; r=Honza
Display a longString with what is available on the grip.
Straight from the server, a longString grip has a "initial"
property, which contains the first 10000 chars of the string.
The grip can also contains a "fullText" property that should
be set when the user want to display the full text of the string.
For example, in the DOM Panel, it would be when the user click on
the expand arrow.
The fullText needs to be computed with the result of the
LongStringClient.substring function, but it's not the responsability
of the Reps to do such thing.

In rep-utils, we extract the logic that replace non-printable
characters in its own function and export it, so we can use it outside
the cropString function.

Add some test to make sure LongString are displayed as expected in the
several modes.

MozReview-Commit-ID: 3P9fPBixm2v
2016-11-03 18:08:16 +01:00

72 lines
1.7 KiB
JavaScript

/* 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/. */
"use strict";
// Make this available to both AMD and CJS environments
define(function (require, exports, module) {
// Dependencies
const React = require("devtools/client/shared/vendor/react");
const { sanitizeString, isGrip } = require("./rep-utils");
// Shortcuts
const { span } = React.DOM;
/**
* Renders a long string grip.
*/
const LongStringRep = React.createClass({
displayName: "LongStringRep",
propTypes: {
useQuotes: React.PropTypes.bool,
style: React.PropTypes.object,
},
getDefaultProps: function () {
return {
useQuotes: true,
};
},
render: function () {
let {
cropLimit,
member,
object,
style,
useQuotes
} = this.props;
let {fullText, initial, length} = object;
let config = {className: "objectBox objectBox-string"};
if (style) {
config.style = style;
}
let string = member && member.open
? fullText || initial
: initial.substring(0, cropLimit);
if (string.length < length) {
string += "\u2026";
}
let formattedString = useQuotes ? `"${string}"` : string;
return span(config, sanitizeString(formattedString));
},
});
function supportsObject(object, type) {
if (!isGrip(object)) {
return false;
}
return object.type === "longString";
}
// Exports from this module
exports.LongStringRep = {
rep: LongStringRep,
supportsObject: supportsObject,
};
});