ServiceabilitySQLInfo.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. 'use strict';
  2. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. /**
  5. * Licensed Materials - Property of IBM
  6. * IBM Business Analytics (C) Copyright IBM Corp. 2020
  7. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['../../../../api/impl/serviceability/nls/StringResources', 'react', 'ca-ui-toolkit', 'react-dom'], function (StringResources, React, UI_TOOLKIT, ReactDOM) {
  10. var Dialog = UI_TOOLKIT.Dialog,
  11. Button = UI_TOOLKIT.Button,
  12. ToggleSwitchSection = UI_TOOLKIT.ToggleSwitchSection,
  13. FlexItem = UI_TOOLKIT.FlexItem,
  14. FlexLayout = UI_TOOLKIT.FlexLayout,
  15. TextArea = UI_TOOLKIT.TextArea,
  16. TruncatedText = UI_TOOLKIT.TruncatedText,
  17. Tabs = UI_TOOLKIT.Tabs,
  18. TabPanel = UI_TOOLKIT.TabPanel;
  19. var useState = React.useState,
  20. useEffect = React.useEffect;
  21. return function () {
  22. function ServiceabilitySQLInfo(visApi, queryExecution) {
  23. _classCallCheck(this, ServiceabilitySQLInfo);
  24. this.visApi = visApi;
  25. this.queryExecution = queryExecution;
  26. this._widgetLastCognosQuery = undefined;
  27. this._widgetLastNativeQuery = undefined;
  28. this._widgetLastMDXQuery = undefined;
  29. this._shouldFetchQuery = false;
  30. this.el$ = undefined;
  31. }
  32. ServiceabilitySQLInfo.prototype.showQueryDialog = function showQueryDialog() {
  33. var _this = this;
  34. this.el$ = document.createElement('div');
  35. this.el$.classList.add('sql-popover-container');
  36. document.body.appendChild(this.el$);
  37. var hasQueryInfo = this.widgetsLastCognosQuery || this.widgetsLastNativeQuery || this.widgetsLastMDXQuery;
  38. var Dialog = this.QueryDialog;
  39. var DialogBody = this.QueryDialogBody;
  40. ReactDOM.render(React.createElement(
  41. Dialog,
  42. {
  43. hasQueryInfo: hasQueryInfo,
  44. onClose: function onClose(evt) {
  45. return _this.removeSQLDialog(evt);
  46. }
  47. },
  48. React.createElement(DialogBody, {
  49. cognosSQL: this.widgetsLastCognosQuery,
  50. nativeSQL: this.widgetsLastNativeQuery,
  51. MDXQuery: this.widgetsLastMDXQuery
  52. })
  53. ), this.el$);
  54. };
  55. ServiceabilitySQLInfo.prototype.removeSQLDialog = function removeSQLDialog(evt) {
  56. if (evt) {
  57. evt.stopPropagation();
  58. }
  59. if (this.el$) {
  60. ReactDOM.unmountComponentAtNode(this.el$);
  61. this.el$.remove();
  62. this.el$ = undefined;
  63. }
  64. };
  65. ServiceabilitySQLInfo.prototype.QueryDialogBody = function QueryDialogBody(props) {
  66. var DialogTextArea = function DialogTextArea(value) {
  67. return React.createElement(TextArea, {
  68. placeholder: StringResources.get('interactToTriggerQuery'),
  69. disabled: false,
  70. rows: 20,
  71. resize: false,
  72. value: value,
  73. style: { width: '100%' },
  74. className: 'sql-textarea'
  75. });
  76. };
  77. var ErrorDialogBody = function ErrorDialogBody() {
  78. return React.createElement(
  79. 'div',
  80. { 'data-id': 's12y-sqlinfo-error' },
  81. StringResources.get('queryInfoNotAvailable')
  82. );
  83. };
  84. var cognosSQL = props.cognosSQL,
  85. nativeSQL = props.nativeSQL,
  86. MDXQuery = props.MDXQuery;
  87. var defaultSelectedTab = void 0;
  88. if (cognosSQL) {
  89. defaultSelectedTab = 'cognossql';
  90. } else if (nativeSQL) {
  91. defaultSelectedTab = 'nativesql';
  92. } else if (MDXQuery) {
  93. defaultSelectedTab = 'mdxquery';
  94. }
  95. var _useState = useState(defaultSelectedTab),
  96. selectedTab = _useState[0],
  97. setSelectedTab = _useState[1];
  98. if (cognosSQL || nativeSQL || MDXQuery) {
  99. return React.createElement(
  100. Tabs,
  101. {
  102. onChange: function onChange(tabId) {
  103. return setSelectedTab(tabId);
  104. },
  105. selected: selectedTab,
  106. vertical: true,
  107. linePosition: 'right'
  108. },
  109. cognosSQL && React.createElement(
  110. TabPanel,
  111. { id: 'cognossql', label: 'Cognos SQL' },
  112. DialogTextArea(cognosSQL)
  113. ),
  114. nativeSQL && React.createElement(
  115. TabPanel,
  116. { id: 'nativesql', label: 'Native SQL' },
  117. DialogTextArea(nativeSQL)
  118. ),
  119. MDXQuery && React.createElement(
  120. TabPanel,
  121. { id: 'mdxquery', label: 'MDX' },
  122. DialogTextArea(MDXQuery)
  123. )
  124. );
  125. } else {
  126. return React.createElement(ErrorDialogBody, null);
  127. }
  128. };
  129. ServiceabilitySQLInfo.prototype.QueryDialog = function QueryDialog(props) {
  130. var onClose = props.onClose,
  131. hasQueryInfo = props.hasQueryInfo,
  132. children = props.children;
  133. return React.createElement(
  134. Dialog,
  135. {
  136. size: 'large',
  137. width: '80%',
  138. className: 'sql-textarea-dialog'
  139. },
  140. React.createElement(
  141. Dialog.Header,
  142. null,
  143. React.createElement(TruncatedText, { value: StringResources.get('SQLMDX') })
  144. ),
  145. React.createElement(
  146. Dialog.Body,
  147. null,
  148. React.createElement(
  149. FlexLayout,
  150. null,
  151. React.createElement(
  152. FlexItem,
  153. { overflow: 'auto', style: { width: '100%' } },
  154. children
  155. )
  156. )
  157. ),
  158. React.createElement(
  159. Dialog.Footer,
  160. null,
  161. hasQueryInfo && React.createElement(Dialog.Button, { label: StringResources.get('copy'), primary: true, className: 'query-dialog-copy-button', onClick: function onClick() {
  162. document.body.querySelector('.sql-textarea textarea').select();
  163. document.execCommand('copy');
  164. }
  165. }),
  166. React.createElement(Dialog.Button, { label: StringResources.get('close'), onClick: function onClick(evt) {
  167. return onClose(evt);
  168. }, className: 'query-dialog-close-button' })
  169. )
  170. );
  171. };
  172. ServiceabilitySQLInfo.prototype.QuerySection = function QuerySection(props) {
  173. var initialToggleState = props.initialToggleState,
  174. onToggle = props.onToggle,
  175. openDialog = props.openDialog;
  176. var _useState2 = useState(initialToggleState),
  177. toggleState = _useState2[0],
  178. setToggleState = _useState2[1];
  179. useEffect(function () {
  180. onToggle(toggleState, setButtonDisabled);
  181. });
  182. var _useState3 = useState(!initialToggleState),
  183. buttonDisabled = _useState3[0],
  184. setButtonDisabled = _useState3[1];
  185. return React.createElement(
  186. FlexLayout,
  187. { direction: 'column' },
  188. React.createElement(
  189. FlexItem,
  190. null,
  191. React.createElement(ToggleSwitchSection, {
  192. label: StringResources.get('fetchQuery'),
  193. rtl: false,
  194. className: 'fetch-sql-toggle',
  195. checked: toggleState,
  196. onChange: function onChange() {
  197. return setToggleState(!toggleState);
  198. }
  199. })
  200. ),
  201. React.createElement(
  202. FlexItem,
  203. null,
  204. React.createElement(Button, {
  205. label: StringResources.get('showSQLMDX'),
  206. disabled: buttonDisabled,
  207. className: 'sql-mdx-dialog-button',
  208. onClick: function onClick() {
  209. return openDialog();
  210. },
  211. intent: 'primary'
  212. })
  213. )
  214. );
  215. };
  216. /**
  217. * @returns {object} The result of this result should be an object which will
  218. * be stringfied later.
  219. * @description this method will fetch the last sql result from the renderSequence
  220. */
  221. ServiceabilitySQLInfo.prototype.toJSON = function toJSON() {
  222. return {
  223. sqlQuery: this.widgetsLastCognosQuery
  224. };
  225. };
  226. /**
  227. * @description this method returns a JSON representation of the query section in the serviceability tab
  228. * @returns {object} The UI spec which will be consumed by ContentInfoAPI
  229. */
  230. ServiceabilitySQLInfo.prototype.toUIJSON = function toUIJSON() {
  231. var _this2 = this;
  232. var SQL = this.QuerySection;
  233. var node = React.createElement(SQL, {
  234. initialToggleState: this.shouldFetchQuery,
  235. onToggle: function onToggle(toggleState, setButtonDisabled) {
  236. _this2.shouldFetchQuery = toggleState;
  237. if (!toggleState) {
  238. _this2.widgetsLastCognosQuery = null;
  239. _this2.widgetsLastNativeQuery = null;
  240. setButtonDisabled(true);
  241. } else {
  242. if (!_this2.widgetsLastNativeQuery && !_this2.widgetsLastCognosQuery) {
  243. var option = { qfbMode: 'validate' };
  244. _this2.queryExecution && _this2.queryExecution.addRequestOptions(option);
  245. _this2.visApi.reRender({ sameQueryValidateMode: true }).then(function () {
  246. _this2.queryExecution && _this2.queryExecution.removeRequestOptions(['qfbMode']);
  247. setButtonDisabled(false);
  248. });
  249. }
  250. }
  251. },
  252. openDialog: function openDialog() {
  253. return _this2.showQueryDialog();
  254. }
  255. });
  256. return [{
  257. sectionName: StringResources.get('query'),
  258. sectionValues: [{
  259. fieldName: StringResources.get('queryInfo'),
  260. node: node,
  261. type: 'ReactNode'
  262. }],
  263. properties: {
  264. open: false
  265. }
  266. }];
  267. };
  268. _createClass(ServiceabilitySQLInfo, [{
  269. key: 'widgetsLastCognosQuery',
  270. set: function set(cognosQuery) {
  271. this._widgetLastCognosQuery = cognosQuery;
  272. },
  273. get: function get() {
  274. return this._widgetLastCognosQuery;
  275. }
  276. }, {
  277. key: 'widgetsLastNativeQuery',
  278. set: function set(nativeQuery) {
  279. this._widgetLastNativeQuery = nativeQuery;
  280. },
  281. get: function get() {
  282. return this._widgetLastNativeQuery;
  283. }
  284. }, {
  285. key: 'widgetsLastMDXQuery',
  286. get: function get() {
  287. return this._widgetLastMDXQuery;
  288. },
  289. set: function set(MDXQuery) {
  290. this._widgetLastMDXQuery = MDXQuery;
  291. }
  292. }, {
  293. key: 'shouldFetchQuery',
  294. get: function get() {
  295. return this._shouldFetchQuery;
  296. },
  297. set: function set(state) {
  298. this._shouldFetchQuery = state;
  299. }
  300. }]);
  301. return ServiceabilitySQLInfo;
  302. }();
  303. });
  304. //# sourceMappingURL=ServiceabilitySQLInfo.js.map