ServiceabilityContent.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. /*
  6. *+------------------------------------------------------------------------+
  7. *| Licensed Materials - Property of IBM
  8. *| IBM Cognos Products: Content Explorer
  9. *| (C) Copyright IBM Corp. 2019
  10. *|
  11. *| US Government Users Restricted Rights - Use, duplication or disclosure
  12. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  13. *+------------------------------------------------------------------------+
  14. */
  15. define(['react', 'ca-ui-toolkit', 'prop-types', '../../../../app/ui/dialogs/EditableDialog', '../nls/StringResources'], function (React, UI_TOOLKIT, PropTypes, EditableDialog, StringResources) {
  16. /**
  17. * @description This class provides all of the contents inside a serviceability panel.
  18. * The UI is a two-level hierarchy. The first level is Section, and the second level is Field.
  19. *
  20. * For each Section, it has an attribute called "open" to control if this section should be
  21. * opened in default. It also has an attribute called "sectionName" which should be a string.
  22. * If "sectionName" is an empty string, the section name component will not be rendered.
  23. *
  24. * For each Field, it has attributes which are "fieldName", "fieldValue", and "type". They are all
  25. * strings. The values of "fieldName" and "fieldValue" could be any string. If "fieldName" is an
  26. * empty string, the field name component will not be rendered. "type" is also a string and its
  27. * value should be one of ['SimpleTable', 'Default', 'ReactNode']. If "type" is not specified, we will render
  28. * it in a default way.
  29. *
  30. * If the "type" is 'SimpleTable', the "fieldValues" should be an object which has the following properties:
  31. * - columnLength: how many columns you want to display
  32. * - rowLength: how many rows you want to display
  33. * - headerValue: (col) => {return value;}, where "col" is an integer represents the column number, and "value"
  34. * is a string.
  35. * - cellValue: (row, col) => {return value;}, where "row" and "col" are row number and col number which both
  36. * are integers. The "value" should be a string.
  37. *
  38. * A object should be provided to tell this class how to render Sections and Fields. It should looks like:
  39. * [
  40. * {
  41. * sectionName: 'section A',
  42. * sectionValues: [{
  43. * fieldName: 'field a1',
  44. * fieldValue: 'field value of a1',
  45. * type: 'SimpleTable'
  46. * },
  47. * {
  48. * fieldName: 'field a2',
  49. * fieldValue: 'field value of a2'
  50. * }
  51. * ],
  52. * properties: {
  53. * open: true | false
  54. * }
  55. * },
  56. * {
  57. * sectionName: 'section B',
  58. * sectionValues: [],
  59. * properties: {}
  60. * }
  61. * ]
  62. * Content has all components on a serviceability panel.
  63. * It consists of many sections, which consists of many fields.
  64. */
  65. var Label = UI_TOOLKIT.Label;
  66. var Container = UI_TOOLKIT.Container;
  67. var Button = UI_TOOLKIT.Button;
  68. var ToggleSwitchSection = UI_TOOLKIT.ToggleSwitchSection;
  69. var CollapsibleSection = UI_TOOLKIT.CollapsibleSection;
  70. var Paragraph = UI_TOOLKIT.Paragraph;
  71. var Separator = UI_TOOLKIT.Separator;
  72. var SimpleTable = UI_TOOLKIT.SimpleTable;
  73. var FIELD_TITLE_CLASS = 's12yFieldTitle';
  74. var FIELD_VALUE_CLASS = 's12yFieldValue';
  75. var SHOW_INFO_ON_ALL_CONTENTS = StringResources.get('showInfoForAll');
  76. var HIDE_INFO_ON_ALL_CONTENTS = StringResources.get('hideInfoForAll');
  77. var Content = function (_React$Component) {
  78. _inherits(Content, _React$Component);
  79. function Content(props) {
  80. _classCallCheck(this, Content);
  81. var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
  82. _this._dashboardS12yFeature = _this.props.dashboardApi.getFeature('Serviceability');
  83. _this.state = {
  84. infoIsVisible: _this._dashboardS12yFeature.isInfoVisible()
  85. };
  86. _this._onClickSpec = _this._onClickSpec.bind(_this);
  87. _this._onClickShowInfo = _this._onClickShowInfo.bind(_this);
  88. _this._fieldContentGenerators = {
  89. 'SimpleTable': _this._createSimpleTable.bind(_this),
  90. 'Default': _this._createParagraph.bind(_this),
  91. 'ReactNode': function ReactNode(fieldSpec) {
  92. return fieldSpec.node;
  93. }
  94. };
  95. return _this;
  96. }
  97. Content.prototype._onClickSpec = function _onClickSpec() {
  98. var allSpec = { 'widget spec': this.props.widgetInfo.getSpec(), 'dashboard spec': this.props.dashboardApi.getSpec() };
  99. var buttons = [{
  100. type: 's12yDialogCopyButton',
  101. text: StringResources.get('copyButton'),
  102. handler: function handler() {
  103. document.execCommand('copy');
  104. },
  105. defaultId: 's12yDialogCopyButton'
  106. }, {
  107. text: StringResources.get('closeButton'),
  108. type: 'secondary s12yDialogCloseButton',
  109. defaultId: 'close'
  110. }];
  111. var options = {
  112. sType: 'editableInfo',
  113. sTitle: StringResources.get('specification'),
  114. sValue: JSON.stringify(allSpec, null, 4),
  115. updateable: false,
  116. showCloseX: true,
  117. buttons: buttons
  118. };
  119. var boardModelDialog = new EditableDialog(options);
  120. boardModelDialog.open();
  121. };
  122. Content.prototype._onClickShowInfo = function _onClickShowInfo(willShowInfo) {
  123. if (willShowInfo === true) {
  124. this._dashboardS12yFeature.showInfo();
  125. } else {
  126. this._dashboardS12yFeature.hideInfo();
  127. }
  128. this.setState({ infoIsVisible: willShowInfo });
  129. };
  130. Content.prototype.render = function render() {
  131. var _this2 = this;
  132. var sections = this.props.UISpec.map(function (sectionSpec) {
  133. return _this2._createSection(sectionSpec);
  134. });
  135. var showInfoToggle = !this.props.showButtons ? null : React.createElement(ToggleSwitchSection, {
  136. label: this.state.infoIsVisible ? HIDE_INFO_ON_ALL_CONTENTS : SHOW_INFO_ON_ALL_CONTENTS,
  137. rtl: false,
  138. className: 'showInfoToggle',
  139. checked: this.state.infoIsVisible,
  140. onChange: this._onClickShowInfo
  141. });
  142. var specButton = !this.props.showButtons ? null : React.createElement(Button, {
  143. label: StringResources.get('showDetails'),
  144. className: 'specDialogButton',
  145. onClick: this._onClickSpec,
  146. intent: 'primary'
  147. });
  148. this.container = React.createElement(
  149. Container,
  150. { width: 'auto', className: 's12yContent' },
  151. sections,
  152. showInfoToggle,
  153. specButton
  154. );
  155. return this.container;
  156. };
  157. Content.prototype._createSection = function _createSection(sectionSpec) {
  158. var _this3 = this;
  159. var fields = sectionSpec.sectionValues.map(function (fieldSpec, fieldIndex) {
  160. var isLastField = fieldIndex + 1 === sectionSpec.sectionValues.length;
  161. return _this3._createField(fieldSpec, isLastField);
  162. });
  163. var section = void 0;
  164. if (sectionSpec.sectionName === '') {
  165. section = React.createElement(
  166. React.Fragment,
  167. null,
  168. fields
  169. );
  170. } else {
  171. // Take section name, convert to lower case, and get rid of any spaces if any
  172. var id = 'serviceability_section_' + sectionSpec.sectionName.toLowerCase().replace(/\s/g, '');
  173. section = React.createElement(
  174. CollapsibleSection,
  175. {
  176. id: id,
  177. 'aria-controls': id,
  178. label: sectionSpec.sectionName,
  179. defaultOpen: sectionSpec.properties.open,
  180. labelStyle: {
  181. 'font-size': '16px',
  182. 'font-weight': 'bold',
  183. 'padding-left': '8px'
  184. },
  185. className: 's12ySection' },
  186. fields,
  187. React.createElement(Separator, { className: 'sectionSeparator' })
  188. );
  189. }
  190. return section;
  191. };
  192. Content.prototype._createField = function _createField(fieldSpec, isLastField) {
  193. var fieldContent = void 0;
  194. var fieldContentGenerator = this._fieldContentGenerators[fieldSpec.type];
  195. if (!fieldContentGenerator) {
  196. fieldContentGenerator = this._fieldContentGenerators['Default'];
  197. }
  198. fieldContent = fieldContentGenerator(fieldSpec);
  199. // Take field name, convert to lower case, and get rid of any spaces if any
  200. var id = 'serviceability_field_' + fieldSpec.fieldName.toLowerCase().replace(/\s/g, '');
  201. return React.createElement(
  202. Container,
  203. { id: id, 'aria-controls': id, className: 's12yField' },
  204. fieldContent,
  205. isLastField ? null : React.createElement(Separator, { className: 'fieldSeparator' })
  206. );
  207. };
  208. Content.prototype._createParagraph = function _createParagraph(fieldSpec) {
  209. return React.createElement(
  210. Container,
  211. { className: 'Default' },
  212. React.createElement(Label, { className: FIELD_TITLE_CLASS, label: fieldSpec.fieldName, type: 'caption' }),
  213. React.createElement(
  214. Paragraph,
  215. { className: FIELD_VALUE_CLASS },
  216. ' ',
  217. fieldSpec.fieldValue,
  218. ' '
  219. )
  220. );
  221. };
  222. Content.prototype._createSimpleTable = function _createSimpleTable(fieldSpec) {
  223. return React.createElement(
  224. Container,
  225. { className: 'SimpleTable' },
  226. fieldSpec.fieldName === '' ? null : React.createElement(Label, { className: FIELD_TITLE_CLASS, label: fieldSpec.fieldName, type: 'caption' }),
  227. React.createElement(SimpleTable, {
  228. className: 's12ySimpleTable',
  229. colLength: fieldSpec.fieldValue.columnLength,
  230. rowLength: fieldSpec.fieldValue.rowLength,
  231. headerRenderer: function headerRenderer(col) {
  232. var header = void 0;
  233. if (typeof fieldSpec.fieldValue.headerValue === 'function') {
  234. header = React.createElement(
  235. Paragraph,
  236. { className: FIELD_VALUE_CLASS + ' s12ySimpleTableHeader s12ySimpleTableHeader_' + col },
  237. fieldSpec.fieldValue.headerValue(col)
  238. );
  239. } else {
  240. header = null;
  241. }
  242. return header;
  243. },
  244. cellRenderer: function cellRenderer(row, col) {
  245. return React.createElement(
  246. Paragraph,
  247. { className: FIELD_VALUE_CLASS + ' s12ySimpleTableCell s12ySimpleTableCell_' + row + '_' + col },
  248. fieldSpec.fieldValue.cellValue(row, col)
  249. );
  250. } })
  251. );
  252. };
  253. return Content;
  254. }(React.Component);
  255. Content.propTypes = {
  256. widgetInfo: PropTypes.shape({
  257. getSpec: PropTypes.func
  258. }),
  259. dashboardApi: PropTypes.any,
  260. UISpec: PropTypes.array,
  261. showButtons: PropTypes.bool
  262. };
  263. return Content;
  264. });
  265. //# sourceMappingURL=ServiceabilityContent.js.map