@bydata/react-supertabs 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +257 -0
- package/dist/ClickOutsideListener.js +72 -0
- package/dist/Constants.js +20 -0
- package/dist/NotAvailable.js +29 -0
- package/dist/NotAvailable.scss +30 -0
- package/dist/Readme.md +258 -0
- package/dist/SuperLink.js +36 -0
- package/dist/SuperTabs.js +1196 -0
- package/dist/SuperTabs.scss +892 -0
- package/dist/TabContext.js +1895 -0
- package/dist/TabList.js +234 -0
- package/dist/TabList.scss +274 -0
- package/dist/TabStack.js +98 -0
- package/dist/Utils.js +336 -0
- package/dist/eventEmitter.js +116 -0
- package/dist/images/Icon-open-arrow-top.svg +3 -0
- package/dist/images/icon-chevron-right.svg +1 -0
- package/dist/images/icon-close-lite.svg +3 -0
- package/dist/images/icon-search.svg +10 -0
- package/dist/images/icon-stack.svg +6 -0
- package/dist/index.js +20 -0
- package/dist/usePrevious.js +37 -0
- package/package.json +33 -0
|
@@ -0,0 +1,1895 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.TabContext = void 0;
|
|
8
|
+
exports.TabProvider = TabProvider;
|
|
9
|
+
exports.getUniqueIdentifier = void 0;
|
|
10
|
+
exports.useTabContext = useTabContext;
|
|
11
|
+
var _react = require("react");
|
|
12
|
+
var _reactRouterDom = require("react-router-dom");
|
|
13
|
+
var _usePrevious = _interopRequireDefault(require("./usePrevious"));
|
|
14
|
+
var _Utils = require("./Utils");
|
|
15
|
+
var _Constants = require("./Constants");
|
|
16
|
+
var _excluded = ["subTabs", "level", "order", "tabId", "unique_identifier", "parent_tab_id", "width", "elementWidth"],
|
|
17
|
+
_excluded2 = ["tab_info"],
|
|
18
|
+
_excluded3 = ["subTabs", "level", "order", "tabId", "unique_identifier", "parent_tab_id", "width", "elementWidth"],
|
|
19
|
+
_excluded4 = ["tab_info"],
|
|
20
|
+
_excluded5 = ["tab_info"],
|
|
21
|
+
_excluded6 = ["tab_info"],
|
|
22
|
+
_excluded7 = ["tab_info"];
|
|
23
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
24
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
25
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
26
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
27
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
28
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
29
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
30
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
31
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
32
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
33
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
34
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
35
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
36
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
37
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
38
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
39
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
40
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
41
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
42
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
43
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
44
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
45
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } // hooks
|
|
46
|
+
// utils and constants
|
|
47
|
+
function sortSubTabs(tab) {
|
|
48
|
+
if (tab.subTabs.length > 0) {
|
|
49
|
+
tab.subTabs.sort(_Utils.sortByOrder);
|
|
50
|
+
tab.subTabs.forEach(sortSubTabs); // Recursively sort each subTab's subTabs
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
var getUniqueIdentifier = exports.getUniqueIdentifier = function getUniqueIdentifier(user) {
|
|
54
|
+
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
55
|
+
var ignoreUniqueID = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
56
|
+
var entityIdentifierKey = arguments.length > 3 ? arguments[3] : undefined;
|
|
57
|
+
var id = user.id;
|
|
58
|
+
var orgValue = user === null || user === void 0 ? void 0 : user[entityIdentifierKey];
|
|
59
|
+
var uniqueId = null;
|
|
60
|
+
if (!ignoreUniqueID) {
|
|
61
|
+
var storageKey = "".concat(prefix, "unique_identifier");
|
|
62
|
+
uniqueId = localStorage.getItem(storageKey);
|
|
63
|
+
if (!uniqueId) {
|
|
64
|
+
uniqueId = (0, _Utils.getUniqueId)();
|
|
65
|
+
localStorage.setItem(storageKey, uniqueId);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return [id, orgValue, uniqueId].filter(Boolean).join('_');
|
|
69
|
+
};
|
|
70
|
+
// to use in SuperTabsAPI.js
|
|
71
|
+
|
|
72
|
+
var maxOrder = 9;
|
|
73
|
+
var TabContext = exports.TabContext = /*#__PURE__*/(0, _react.createContext)({
|
|
74
|
+
activeTab: {},
|
|
75
|
+
activeSubTab: {},
|
|
76
|
+
lastOpenedUrl: {
|
|
77
|
+
current: {}
|
|
78
|
+
},
|
|
79
|
+
isTabDataLoaded: false,
|
|
80
|
+
isTabDataLoadFailed: false,
|
|
81
|
+
tabs: [],
|
|
82
|
+
currentEntityId: null,
|
|
83
|
+
getUserDetails: function getUserDetails() {},
|
|
84
|
+
hasPrivilege: function hasPrivilege(privilege) {},
|
|
85
|
+
updateCurrentTab: function updateCurrentTab() {
|
|
86
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
87
|
+
tab = _ref.tab,
|
|
88
|
+
_ref$ignoreActiveTabU = _ref.ignoreActiveTabUpdate,
|
|
89
|
+
ignoreActiveTabUpdate = _ref$ignoreActiveTabU === void 0 ? false : _ref$ignoreActiveTabU,
|
|
90
|
+
parentId = _ref.parentId,
|
|
91
|
+
_ref$isHomeTab = _ref.isHomeTab,
|
|
92
|
+
isHomeTab = _ref$isHomeTab === void 0 ? false : _ref$isHomeTab,
|
|
93
|
+
_ref$isSubTab = _ref.isSubTab,
|
|
94
|
+
isSubTab = _ref$isSubTab === void 0 ? false : _ref$isSubTab,
|
|
95
|
+
_ref$sort = _ref.sort,
|
|
96
|
+
sort = _ref$sort === void 0 ? false : _ref$sort;
|
|
97
|
+
},
|
|
98
|
+
openTab: function openTab(_ref2) {
|
|
99
|
+
var tab = _ref2.tab,
|
|
100
|
+
_ref2$isHomeTab = _ref2.isHomeTab,
|
|
101
|
+
isHomeTab = _ref2$isHomeTab === void 0 ? false : _ref2$isHomeTab,
|
|
102
|
+
_ref2$isSubTab = _ref2.isSubTab,
|
|
103
|
+
isSubTab = _ref2$isSubTab === void 0 ? false : _ref2$isSubTab;
|
|
104
|
+
},
|
|
105
|
+
openSubTab: function openSubTab(_ref3) {
|
|
106
|
+
var tab = _ref3.tab,
|
|
107
|
+
parentId = _ref3.parentId;
|
|
108
|
+
},
|
|
109
|
+
modifyTab: function modifyTab(_ref4) {
|
|
110
|
+
var oldTab = _ref4.oldTab,
|
|
111
|
+
newTab = _ref4.newTab,
|
|
112
|
+
_ref4$isSubTab = _ref4.isSubTab,
|
|
113
|
+
isSubTab = _ref4$isSubTab === void 0 ? false : _ref4$isSubTab;
|
|
114
|
+
},
|
|
115
|
+
openSuperTabOnRowClick: function openSuperTabOnRowClick(_ref5) {
|
|
116
|
+
var tab = _ref5.tab,
|
|
117
|
+
_ref5$isSubTab = _ref5.isSubTab,
|
|
118
|
+
isSubTab = _ref5$isSubTab === void 0 ? true : _ref5$isSubTab;
|
|
119
|
+
},
|
|
120
|
+
closeTab: function closeTab(_ref6) {
|
|
121
|
+
var tab = _ref6.tab,
|
|
122
|
+
_ref6$isSubTab = _ref6.isSubTab,
|
|
123
|
+
isSubTab = _ref6$isSubTab === void 0 ? false : _ref6$isSubTab;
|
|
124
|
+
},
|
|
125
|
+
reorderTabs: function reorderTabs(_ref7) {
|
|
126
|
+
var tab = _ref7.tab,
|
|
127
|
+
order = _ref7.order;
|
|
128
|
+
},
|
|
129
|
+
updateCurrentEntityId: function updateCurrentEntityId(entityId) {},
|
|
130
|
+
handleTabModeChange: function handleTabModeChange() {},
|
|
131
|
+
updateActiveTab: function updateActiveTab(tab) {},
|
|
132
|
+
updateActiveSubTab: function updateActiveSubTab(tab) {},
|
|
133
|
+
updateTabProperty: function updateTabProperty(_ref8) {
|
|
134
|
+
var propertyToUpdate = _ref8.propertyToUpdate,
|
|
135
|
+
newValue = _ref8.newValue,
|
|
136
|
+
entityIdentifierKey = _ref8.entityIdentifierKey,
|
|
137
|
+
identifierValue = _ref8.identifierValue;
|
|
138
|
+
},
|
|
139
|
+
updateTabs: function updateTabs(tabs) {},
|
|
140
|
+
hiddenExternalToolbars: {},
|
|
141
|
+
showExternalToolbar: function showExternalToolbar(id) {},
|
|
142
|
+
hideExternalToolbar: function hideExternalToolbar(id) {},
|
|
143
|
+
alertService: {
|
|
144
|
+
alert: function alert() {},
|
|
145
|
+
error: function error() {},
|
|
146
|
+
info: function info() {},
|
|
147
|
+
success: function success() {},
|
|
148
|
+
warning: function warning() {}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
function TabProvider(_ref9) {
|
|
152
|
+
var children = _ref9.children,
|
|
153
|
+
SITE_PREFIX = _ref9.SITE_PREFIX,
|
|
154
|
+
SITE_PAGES = _ref9.SITE_PAGES,
|
|
155
|
+
_ref9$homeUrl = _ref9.homeUrl,
|
|
156
|
+
homeUrl = _ref9$homeUrl === void 0 ? '/' : _ref9$homeUrl,
|
|
157
|
+
_ref9$entityIdentifie = _ref9.entityIdentifierKey,
|
|
158
|
+
entityIdentifierKey = _ref9$entityIdentifie === void 0 ? 'organization_id' : _ref9$entityIdentifie,
|
|
159
|
+
_ref9$persistTabsAfte = _ref9.persistTabsAfterLogin,
|
|
160
|
+
persistTabsAfterLogin = _ref9$persistTabsAfte === void 0 ? false : _ref9$persistTabsAfte,
|
|
161
|
+
_ref9$preventHomeRedi = _ref9.preventHomeRedirect,
|
|
162
|
+
preventHomeRedirect = _ref9$preventHomeRedi === void 0 ? false : _ref9$preventHomeRedi,
|
|
163
|
+
_ref9$getUserDetails = _ref9.getUserDetails,
|
|
164
|
+
getUserDetails = _ref9$getUserDetails === void 0 ? function () {} : _ref9$getUserDetails,
|
|
165
|
+
_ref9$hasPrivilege = _ref9.hasPrivilege,
|
|
166
|
+
hasPrivilege = _ref9$hasPrivilege === void 0 ? function (privilege) {} : _ref9$hasPrivilege,
|
|
167
|
+
_ref9$handleOpenTab = _ref9.handleOpenTab,
|
|
168
|
+
handleOpenTab = _ref9$handleOpenTab === void 0 ? /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
169
|
+
return _regenerator().w(function (_context) {
|
|
170
|
+
while (1) switch (_context.n) {
|
|
171
|
+
case 0:
|
|
172
|
+
return _context.a(2);
|
|
173
|
+
}
|
|
174
|
+
}, _callee);
|
|
175
|
+
})) : _ref9$handleOpenTab,
|
|
176
|
+
_ref9$handleCloseTab = _ref9.handleCloseTab,
|
|
177
|
+
handleCloseTab = _ref9$handleCloseTab === void 0 ? /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
178
|
+
return _regenerator().w(function (_context2) {
|
|
179
|
+
while (1) switch (_context2.n) {
|
|
180
|
+
case 0:
|
|
181
|
+
return _context2.a(2);
|
|
182
|
+
}
|
|
183
|
+
}, _callee2);
|
|
184
|
+
})) : _ref9$handleCloseTab,
|
|
185
|
+
_ref9$handleReorderTa = _ref9.handleReorderTabs,
|
|
186
|
+
handleReorderTabs = _ref9$handleReorderTa === void 0 ? /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
187
|
+
return _regenerator().w(function (_context3) {
|
|
188
|
+
while (1) switch (_context3.n) {
|
|
189
|
+
case 0:
|
|
190
|
+
return _context3.a(2);
|
|
191
|
+
}
|
|
192
|
+
}, _callee3);
|
|
193
|
+
})) : _ref9$handleReorderTa,
|
|
194
|
+
_ref9$getTabs = _ref9.getTabs,
|
|
195
|
+
getTabs = _ref9$getTabs === void 0 ? /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
|
|
196
|
+
return _regenerator().w(function (_context4) {
|
|
197
|
+
while (1) switch (_context4.n) {
|
|
198
|
+
case 0:
|
|
199
|
+
return _context4.a(2);
|
|
200
|
+
}
|
|
201
|
+
}, _callee4);
|
|
202
|
+
})) : _ref9$getTabs,
|
|
203
|
+
_ref9$retainTabsAfter = _ref9.retainTabsAfterEntityChange,
|
|
204
|
+
retainTabsAfterEntityChange = _ref9$retainTabsAfter === void 0 ? false : _ref9$retainTabsAfter,
|
|
205
|
+
_ref9$shouldRedirectT = _ref9.shouldRedirectToSubTab,
|
|
206
|
+
shouldRedirectToSubTab = _ref9$shouldRedirectT === void 0 ? true : _ref9$shouldRedirectT,
|
|
207
|
+
_ref9$isMobileView = _ref9.isMobileView,
|
|
208
|
+
isMobileView = _ref9$isMobileView === void 0 ? false : _ref9$isMobileView,
|
|
209
|
+
_ref9$isDefaultExpand = _ref9.isDefaultExpanded,
|
|
210
|
+
isDefaultExpanded = _ref9$isDefaultExpand === void 0 ? false : _ref9$isDefaultExpand,
|
|
211
|
+
_ref9$alertService = _ref9.alertService,
|
|
212
|
+
alertService = _ref9$alertService === void 0 ? {} : _ref9$alertService;
|
|
213
|
+
var history = (0, _reactRouterDom.useHistory)();
|
|
214
|
+
var location = (0, _reactRouterDom.useLocation)();
|
|
215
|
+
var homeTabIdRef = (0, _react.useRef)(null);
|
|
216
|
+
var superTabsWrapperElemRef = (0, _react.useRef)(null);
|
|
217
|
+
var _useState = (0, _react.useState)(false),
|
|
218
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
219
|
+
isTabDataLoaded = _useState2[0],
|
|
220
|
+
setIsTabDataLoaded = _useState2[1];
|
|
221
|
+
var _useState3 = (0, _react.useState)(false),
|
|
222
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
223
|
+
isTabDataLoadFailed = _useState4[0],
|
|
224
|
+
setIsTabDataLoadFailed = _useState4[1];
|
|
225
|
+
var _useState5 = (0, _react.useState)(false),
|
|
226
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
227
|
+
openingUnexpandedSubTab = _useState6[0],
|
|
228
|
+
setOpeningUnexpandedSubTab = _useState6[1];
|
|
229
|
+
var _useState7 = (0, _react.useState)(false),
|
|
230
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
231
|
+
closingUnexpandedSubTab = _useState8[0],
|
|
232
|
+
setClosingUnexpandedSubTab = _useState8[1];
|
|
233
|
+
var _useState9 = (0, _react.useState)(null),
|
|
234
|
+
_useState0 = _slicedToArray(_useState9, 2),
|
|
235
|
+
subTabChange = _useState0[0],
|
|
236
|
+
setSubTabChange = _useState0[1];
|
|
237
|
+
var _useState1 = (0, _react.useState)(function () {
|
|
238
|
+
var _JSON$parse;
|
|
239
|
+
return ((_JSON$parse = JSON.parse(sessionStorage.getItem("".concat(SITE_PREFIX, "expandedIds")))) === null || _JSON$parse === void 0 || (_JSON$parse = _JSON$parse.find(function (item) {
|
|
240
|
+
return item.active;
|
|
241
|
+
})) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse.id) || null;
|
|
242
|
+
}),
|
|
243
|
+
_useState10 = _slicedToArray(_useState1, 2),
|
|
244
|
+
expandedTabID = _useState10[0],
|
|
245
|
+
setExpandedTabID = _useState10[1];
|
|
246
|
+
var expandedTabIDRef = (0, _react.useRef)(expandedTabID);
|
|
247
|
+
var expandedTabIDTimeoutRef = (0, _react.useRef)(null);
|
|
248
|
+
var currentOpenTabCallerRef = (0, _react.useRef)(null);
|
|
249
|
+
var _useState11 = (0, _react.useState)({}),
|
|
250
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
251
|
+
subTabWrapperWidth = _useState12[0],
|
|
252
|
+
setSubTabWrapperWidth = _useState12[1];
|
|
253
|
+
var _useState13 = (0, _react.useState)(function () {
|
|
254
|
+
var _getUserDetails;
|
|
255
|
+
return ((_getUserDetails = getUserDetails()) === null || _getUserDetails === void 0 ? void 0 : _getUserDetails[entityIdentifierKey]) || null;
|
|
256
|
+
}),
|
|
257
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
258
|
+
currentEntityId = _useState14[0],
|
|
259
|
+
setCurrentEntityId = _useState14[1];
|
|
260
|
+
var _useState15 = (0, _react.useState)(null),
|
|
261
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
262
|
+
maxWidth = _useState16[0],
|
|
263
|
+
setMaxWidth = _useState16[1];
|
|
264
|
+
var openingUnexpandedSubTabTimeoutRef = (0, _react.useRef)(null);
|
|
265
|
+
var closingUnexpandedSubTabTimeoutRef = (0, _react.useRef)(null);
|
|
266
|
+
var _useState17 = (0, _react.useState)([]),
|
|
267
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
|
268
|
+
tabs = _useState18[0],
|
|
269
|
+
setTabs = _useState18[1];
|
|
270
|
+
var tabsRef = (0, _react.useRef)(tabs);
|
|
271
|
+
var _useState19 = (0, _react.useState)({}),
|
|
272
|
+
_useState20 = _slicedToArray(_useState19, 2),
|
|
273
|
+
activeTab = _useState20[0],
|
|
274
|
+
setActiveTab = _useState20[1];
|
|
275
|
+
var _useState21 = (0, _react.useState)({}),
|
|
276
|
+
_useState22 = _slicedToArray(_useState21, 2),
|
|
277
|
+
activeSubTab = _useState22[0],
|
|
278
|
+
setActiveSubTab = _useState22[1];
|
|
279
|
+
var activeTabRef = (0, _react.useRef)(null);
|
|
280
|
+
var activeSubTabRef = (0, _react.useRef)(null);
|
|
281
|
+
var lastOpenedUrl = (0, _react.useRef)({});
|
|
282
|
+
var updateCurrentTabRef = (0, _react.useRef)(new AbortController());
|
|
283
|
+
var _useState23 = (0, _react.useState)({}),
|
|
284
|
+
_useState24 = _slicedToArray(_useState23, 2),
|
|
285
|
+
hiddenExternalToolbars = _useState24[0],
|
|
286
|
+
setHiddenExternalToolbars = _useState24[1]; // {id: true} means this toolbar is hidden
|
|
287
|
+
var _useState25 = (0, _react.useState)(function () {
|
|
288
|
+
return JSON.parse(localStorage.getItem(SITE_PREFIX + "tab_mode_preference") || "[]");
|
|
289
|
+
}),
|
|
290
|
+
_useState26 = _slicedToArray(_useState25, 2),
|
|
291
|
+
tabModePreference = _useState26[0],
|
|
292
|
+
setTabModePreference = _useState26[1];
|
|
293
|
+
var previousEntityId = (0, _usePrevious["default"])(currentEntityId);
|
|
294
|
+
var closeTabFailedRequestsRef = (0, _react.useRef)({});
|
|
295
|
+
(0, _react.useEffect)(function () {
|
|
296
|
+
localStorage.setItem(SITE_PREFIX + "tab_mode_preference", JSON.stringify(tabModePreference));
|
|
297
|
+
}, [tabModePreference]);
|
|
298
|
+
var discardSubTabWrapperWidth = (0, _react.useCallback)(function () {
|
|
299
|
+
setSubTabWrapperWidth(function (prev) {
|
|
300
|
+
var updated = _objectSpread({}, prev);
|
|
301
|
+
delete updated[currentEntityId + '_' + activeTabRef.current.id];
|
|
302
|
+
return updated;
|
|
303
|
+
});
|
|
304
|
+
}, [currentEntityId]);
|
|
305
|
+
var showExternalToolbar = (0, _react.useCallback)(function (id) {
|
|
306
|
+
setHiddenExternalToolbars(function (prev) {
|
|
307
|
+
var updated = _objectSpread({}, prev);
|
|
308
|
+
delete updated[id];
|
|
309
|
+
return updated;
|
|
310
|
+
});
|
|
311
|
+
discardSubTabWrapperWidth();
|
|
312
|
+
}, []);
|
|
313
|
+
var hideExternalToolbar = (0, _react.useCallback)(function (id) {
|
|
314
|
+
setHiddenExternalToolbars(function (prev) {
|
|
315
|
+
return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, id, true));
|
|
316
|
+
});
|
|
317
|
+
discardSubTabWrapperWidth();
|
|
318
|
+
}, []);
|
|
319
|
+
var updateCurrentEntityId = (0, _react.useCallback)(function (entityId) {
|
|
320
|
+
setCurrentEntityId(entityId);
|
|
321
|
+
}, []);
|
|
322
|
+
var updateTabs = (0, _react.useCallback)(function (tabs) {
|
|
323
|
+
if (typeof tabs === 'function') {
|
|
324
|
+
tabsRef.current = tabs(tabsRef.current);
|
|
325
|
+
} else {
|
|
326
|
+
tabsRef.current = tabs;
|
|
327
|
+
}
|
|
328
|
+
setTabs(tabsRef.current);
|
|
329
|
+
}, []);
|
|
330
|
+
var updateExpandedID = (0, _react.useCallback)(function (val) {
|
|
331
|
+
setExpandedTabID(val);
|
|
332
|
+
expandedTabIDRef.current = val;
|
|
333
|
+
var storedExpandedIds = JSON.parse(sessionStorage.getItem("".concat(SITE_PREFIX, "expandedIds"))) || [];
|
|
334
|
+
if (val) {
|
|
335
|
+
var isIDPresent = storedExpandedIds.some(function (_ref12) {
|
|
336
|
+
var id = _ref12.id;
|
|
337
|
+
return id === val;
|
|
338
|
+
});
|
|
339
|
+
if (!isIDPresent) {
|
|
340
|
+
storedExpandedIds = storedExpandedIds.map(function (item) {
|
|
341
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
342
|
+
active: false
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
storedExpandedIds.push({
|
|
346
|
+
id: val,
|
|
347
|
+
active: true
|
|
348
|
+
});
|
|
349
|
+
} else {
|
|
350
|
+
storedExpandedIds.map(function (item) {
|
|
351
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
352
|
+
active: item.id === val
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
sessionStorage.setItem("".concat(SITE_PREFIX, "expandedIds"), JSON.stringify(storedExpandedIds));
|
|
358
|
+
}, [SITE_PREFIX]);
|
|
359
|
+
var updateSubTabChange = (0, _react.useCallback)(function (val) {
|
|
360
|
+
clearTimeout(expandedTabIDTimeoutRef.current);
|
|
361
|
+
setSubTabChange(val);
|
|
362
|
+
if (val) {
|
|
363
|
+
expandedTabIDTimeoutRef.current = setTimeout(function () {
|
|
364
|
+
setSubTabChange(null);
|
|
365
|
+
}, 1000);
|
|
366
|
+
}
|
|
367
|
+
}, []);
|
|
368
|
+
var updateActiveTab = (0, _react.useCallback)(function (tab) {
|
|
369
|
+
setActiveTab(tab);
|
|
370
|
+
activeTabRef.current = tab;
|
|
371
|
+
}, []);
|
|
372
|
+
var updateActiveSubTab = (0, _react.useCallback)(function (tab) {
|
|
373
|
+
setActiveSubTab(tab);
|
|
374
|
+
activeSubTabRef.current = tab;
|
|
375
|
+
}, []);
|
|
376
|
+
var updateMaxWidth = (0, _react.useCallback)(function () {
|
|
377
|
+
var _data$parentIndex, _superTabsWrapperElem;
|
|
378
|
+
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : tabsRef.current;
|
|
379
|
+
if (data.length === 0) return;
|
|
380
|
+
var openParentTabsLength = data.length;
|
|
381
|
+
var parentIndex = data.findIndex(function (elem) {
|
|
382
|
+
var _activeTabRef$current;
|
|
383
|
+
return elem.id === ((_activeTabRef$current = activeTabRef.current) === null || _activeTabRef$current === void 0 ? void 0 : _activeTabRef$current.id);
|
|
384
|
+
});
|
|
385
|
+
var subTabs = ((_data$parentIndex = data[parentIndex]) === null || _data$parentIndex === void 0 ? void 0 : _data$parentIndex.subTabs) || [];
|
|
386
|
+
var subTabWithOpenOrderOne = subTabs === null || subTabs === void 0 ? void 0 : subTabs.find(function (t) {
|
|
387
|
+
return t.open_order === 1;
|
|
388
|
+
});
|
|
389
|
+
var openedSubTabsLength = subTabs.filter(function (t) {
|
|
390
|
+
return t.order !== 0;
|
|
391
|
+
}).length;
|
|
392
|
+
var totalTabs = openParentTabsLength + (expandedTabIDRef.current ? openedSubTabsLength : subTabWithOpenOrderOne ? 1 : 0);
|
|
393
|
+
var containerWidth = ((_superTabsWrapperElem = superTabsWrapperElemRef.current) === null || _superTabsWrapperElem === void 0 ? void 0 : _superTabsWrapperElem.offsetWidth) - (_Constants.HomeTabWidth + _Constants.MainTabGap * openParentTabsLength + openedSubTabsLength * _Constants.MarginLeft + _Constants.StackButtonWidth + _Constants.SubTabWrapperPadding);
|
|
394
|
+
var maxWidth = Math.ceil(containerWidth / totalTabs * 100) / 100;
|
|
395
|
+
var totalMinWidth = 0;
|
|
396
|
+
var numElementsNeedingSpace = 0;
|
|
397
|
+
|
|
398
|
+
// Calculate the total width and minimum width of all elements
|
|
399
|
+
var activeTabWidth = activeTabRef.current ? (0, _Utils.getTextWidth)((0, _Utils.getTitle)(activeTabRef.current), _Constants.fontStyle) + 42 : 0;
|
|
400
|
+
var tabLengthWithoutActiveTab = totalTabs - 1;
|
|
401
|
+
maxWidth = maxWidth - (activeTabWidth - maxWidth) / tabLengthWithoutActiveTab;
|
|
402
|
+
setMaxWidth(maxWidth);
|
|
403
|
+
var newData = data.map(function (tab) {
|
|
404
|
+
var _activeTabRef$current2;
|
|
405
|
+
var title = (0, _Utils.getTitle)(tab);
|
|
406
|
+
var isActiveTab = tab.id === ((_activeTabRef$current2 = activeTabRef.current) === null || _activeTabRef$current2 === void 0 ? void 0 : _activeTabRef$current2.id);
|
|
407
|
+
var elementWidth = (0, _Utils.getTextWidth)(title, _Constants.fontStyle) + 42;
|
|
408
|
+
var minWidth = isActiveTab ? elementWidth : Math.min(elementWidth, maxWidth);
|
|
409
|
+
totalMinWidth += minWidth - (isActiveTab ? 10 : 0);
|
|
410
|
+
if (elementWidth > maxWidth) numElementsNeedingSpace++;
|
|
411
|
+
return _objectSpread(_objectSpread({}, tab), {}, {
|
|
412
|
+
elementWidth: elementWidth,
|
|
413
|
+
width: minWidth
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
if (expandedTabIDRef.current && parentIndex !== -1) {
|
|
417
|
+
newData[parentIndex].subTabs = subTabs.map(function (tab) {
|
|
418
|
+
if (tab.order === 0) {
|
|
419
|
+
return _objectSpread(_objectSpread({}, tab), {}, {
|
|
420
|
+
width: 0
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
var title = (0, _Utils.getTitle)(tab);
|
|
424
|
+
var elementWidth = Math.ceil((0, _Utils.calculateWidth)({
|
|
425
|
+
text: title,
|
|
426
|
+
hasAvatar: tab.showAvatar,
|
|
427
|
+
addMargin: false
|
|
428
|
+
}) * 100) / 100;
|
|
429
|
+
var minWidth = Math.min(elementWidth, maxWidth);
|
|
430
|
+
totalMinWidth += minWidth;
|
|
431
|
+
if (elementWidth > maxWidth) numElementsNeedingSpace++;
|
|
432
|
+
return _objectSpread(_objectSpread({}, tab), {}, {
|
|
433
|
+
elementWidth: elementWidth,
|
|
434
|
+
width: minWidth
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
} else if (subTabWithOpenOrderOne && parentIndex !== -1) {
|
|
438
|
+
newData[parentIndex].subTabs = newData[parentIndex].subTabs.map(function (tab) {
|
|
439
|
+
if (tab.open_order === 1) {
|
|
440
|
+
var title = (0, _Utils.getTitle)(tab);
|
|
441
|
+
var elementWidth = Math.ceil((0, _Utils.calculateWidth)({
|
|
442
|
+
text: title,
|
|
443
|
+
hasAvatar: tab.showAvatar,
|
|
444
|
+
addMargin: false
|
|
445
|
+
}) * 100) / 100;
|
|
446
|
+
var minWidth = Math.min(elementWidth, maxWidth);
|
|
447
|
+
totalMinWidth += minWidth;
|
|
448
|
+
if (elementWidth > maxWidth) numElementsNeedingSpace++;
|
|
449
|
+
return _objectSpread(_objectSpread({}, tab), {}, {
|
|
450
|
+
elementWidth: elementWidth,
|
|
451
|
+
width: elementWidth
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
return _objectSpread(_objectSpread({}, tab), {}, {
|
|
455
|
+
width: 0
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
var remainingSpace = Math.ceil(containerWidth - totalMinWidth);
|
|
460
|
+
|
|
461
|
+
// Identify elements that need extra space
|
|
462
|
+
// Distribute remaining space among elements that need extra width
|
|
463
|
+
if (remainingSpace > 0 && numElementsNeedingSpace > 0) {
|
|
464
|
+
newData = newData.map(function (tab) {
|
|
465
|
+
var spaceNeeded = tab.elementWidth - tab.width;
|
|
466
|
+
var spaceAllocated = remainingSpace > spaceNeeded ? spaceNeeded : remainingSpace;
|
|
467
|
+
remainingSpace -= spaceAllocated;
|
|
468
|
+
return _objectSpread(_objectSpread({}, tab), {}, {
|
|
469
|
+
width: tab.width + spaceAllocated
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
if (remainingSpace > 0) {
|
|
473
|
+
newData[parentIndex].subTabs = newData[parentIndex].subTabs.map(function (tab) {
|
|
474
|
+
var spaceNeeded = tab.elementWidth - tab.width;
|
|
475
|
+
var spaceAllocated = remainingSpace > spaceNeeded ? spaceNeeded : remainingSpace;
|
|
476
|
+
remainingSpace -= spaceAllocated;
|
|
477
|
+
return _objectSpread(_objectSpread({}, tab), {}, {
|
|
478
|
+
width: tab.width + spaceAllocated
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
updateTabs(newData);
|
|
484
|
+
}, [updateTabs]);
|
|
485
|
+
var resetMaxWidth = function resetMaxWidth() {
|
|
486
|
+
setMaxWidth(null);
|
|
487
|
+
};
|
|
488
|
+
var updateTabProperty = (0, _react.useCallback)(function () {
|
|
489
|
+
var _ref13 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
490
|
+
propertyToUpdate = _ref13.propertyToUpdate,
|
|
491
|
+
newValue = _ref13.newValue,
|
|
492
|
+
entityIdentifierKey = _ref13.entityIdentifierKey,
|
|
493
|
+
identifierValue = _ref13.identifierValue;
|
|
494
|
+
setTabs(function (tabs) {
|
|
495
|
+
var updatedTabs = tabs.map(function (tab) {
|
|
496
|
+
if (tab[entityIdentifierKey] === identifierValue) {
|
|
497
|
+
return _objectSpread(_objectSpread({}, tab), {}, _defineProperty({}, propertyToUpdate, newValue));
|
|
498
|
+
}
|
|
499
|
+
return tab;
|
|
500
|
+
});
|
|
501
|
+
tabsRef.current = updatedTabs;
|
|
502
|
+
return updatedTabs;
|
|
503
|
+
});
|
|
504
|
+
}, []);
|
|
505
|
+
var handleTabModeChange = function handleTabModeChange() {
|
|
506
|
+
var _activeSubTabRef$curr, _activeTabRef$current3;
|
|
507
|
+
var tabId = ((_activeSubTabRef$curr = activeSubTabRef.current) === null || _activeSubTabRef$curr === void 0 ? void 0 : _activeSubTabRef$curr.tabId) || ((_activeTabRef$current3 = activeTabRef.current) === null || _activeTabRef$current3 === void 0 ? void 0 : _activeTabRef$current3.tabId);
|
|
508
|
+
var searchParams = new URLSearchParams(location.search);
|
|
509
|
+
var isEditMode = searchParams.get("edit") === "true";
|
|
510
|
+
var updatedTabModePreference = _toConsumableArray(tabModePreference);
|
|
511
|
+
if (isEditMode) {
|
|
512
|
+
searchParams["delete"]("edit");
|
|
513
|
+
updatedTabModePreference = updatedTabModePreference.filter(function (id) {
|
|
514
|
+
return id !== tabId;
|
|
515
|
+
});
|
|
516
|
+
} else {
|
|
517
|
+
searchParams.set("edit", "true");
|
|
518
|
+
if (!updatedTabModePreference.includes(tabId)) {
|
|
519
|
+
updatedTabModePreference = [].concat(_toConsumableArray(updatedTabModePreference), [tabId]);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
setTabModePreference(updatedTabModePreference);
|
|
523
|
+
history.replace({
|
|
524
|
+
pathname: location.pathname,
|
|
525
|
+
search: "?".concat(searchParams.toString())
|
|
526
|
+
});
|
|
527
|
+
};
|
|
528
|
+
var openSuperTabOnRowClick = function openSuperTabOnRowClick() {
|
|
529
|
+
var _ref14 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
530
|
+
tab = _ref14.tab,
|
|
531
|
+
_ref14$isSubTab = _ref14.isSubTab,
|
|
532
|
+
isSubTab = _ref14$isSubTab === void 0 ? true : _ref14$isSubTab;
|
|
533
|
+
if (tab.isExternal) {
|
|
534
|
+
window.open(tab.url, '_blank'); // open link in new tab if it is external
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
var isTabOpen = !isSubTab && tabsRef.current.some(function (t) {
|
|
538
|
+
return t.url === tab.url;
|
|
539
|
+
});
|
|
540
|
+
history.push(tab.url);
|
|
541
|
+
// if (!isSubTab && tab.skipAPICall) return;
|
|
542
|
+
isSubTab ? openSubTab({
|
|
543
|
+
tab: tab
|
|
544
|
+
}) : !isTabOpen ? openTab({
|
|
545
|
+
tab: tab
|
|
546
|
+
}) : updateCurrentTab({
|
|
547
|
+
tab: tab
|
|
548
|
+
});
|
|
549
|
+
};
|
|
550
|
+
var openTab = (0, _react.useCallback)(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
|
|
551
|
+
var _ref16,
|
|
552
|
+
tab,
|
|
553
|
+
_ref16$isHomeTab,
|
|
554
|
+
isHomeTab,
|
|
555
|
+
_ref16$isSubTab,
|
|
556
|
+
isSubTab,
|
|
557
|
+
_ref16$keepInactive,
|
|
558
|
+
keepInactive,
|
|
559
|
+
_payload$tab_info,
|
|
560
|
+
isEditMode,
|
|
561
|
+
unique_identifier,
|
|
562
|
+
activeTabId,
|
|
563
|
+
subTabs,
|
|
564
|
+
level,
|
|
565
|
+
order,
|
|
566
|
+
tabId,
|
|
567
|
+
tabUniqueId,
|
|
568
|
+
parent_tab_id,
|
|
569
|
+
width,
|
|
570
|
+
elementWidth,
|
|
571
|
+
filteredTab,
|
|
572
|
+
payload,
|
|
573
|
+
storedExpandedIds,
|
|
574
|
+
isExpanded,
|
|
575
|
+
response,
|
|
576
|
+
_tabId,
|
|
577
|
+
newTab,
|
|
578
|
+
_args5 = arguments,
|
|
579
|
+
_t;
|
|
580
|
+
return _regenerator().w(function (_context5) {
|
|
581
|
+
while (1) switch (_context5.p = _context5.n) {
|
|
582
|
+
case 0:
|
|
583
|
+
_ref16 = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {}, tab = _ref16.tab, _ref16$isHomeTab = _ref16.isHomeTab, isHomeTab = _ref16$isHomeTab === void 0 ? false : _ref16$isHomeTab, _ref16$isSubTab = _ref16.isSubTab, isSubTab = _ref16$isSubTab === void 0 ? false : _ref16$isSubTab, _ref16$keepInactive = _ref16.keepInactive, keepInactive = _ref16$keepInactive === void 0 ? false : _ref16$keepInactive;
|
|
584
|
+
_context5.p = 1;
|
|
585
|
+
if (!isSubTab) {
|
|
586
|
+
updateActiveTab(tab);
|
|
587
|
+
lastOpenedUrl.current[currentEntityId + '_' + tab.id] = tab;
|
|
588
|
+
}
|
|
589
|
+
if (!(!isHomeTab && (isSubTab ? !activeTabRef.current.tabId : !homeTabIdRef.current))) {
|
|
590
|
+
_context5.n = 2;
|
|
591
|
+
break;
|
|
592
|
+
}
|
|
593
|
+
console.log('Parent id not found', tab, activeTabRef.current.tabId);
|
|
594
|
+
return _context5.a(2);
|
|
595
|
+
case 2:
|
|
596
|
+
isEditMode = tab.url.includes('?edit=true');
|
|
597
|
+
unique_identifier = getUniqueIdentifier(getUserDetails(), SITE_PREFIX, persistTabsAfterLogin, entityIdentifierKey);
|
|
598
|
+
activeTabId = activeTabRef.current.id;
|
|
599
|
+
subTabs = tab.subTabs, level = tab.level, order = tab.order, tabId = tab.tabId, tabUniqueId = tab.unique_identifier, parent_tab_id = tab.parent_tab_id, width = tab.width, elementWidth = tab.elementWidth, filteredTab = _objectWithoutProperties(tab, _excluded);
|
|
600
|
+
payload = {
|
|
601
|
+
unique_identifier: unique_identifier,
|
|
602
|
+
created_by: unique_identifier.split('_')[0],
|
|
603
|
+
tab_info: _objectSpread(_objectSpread({}, filteredTab), isSubTab && {
|
|
604
|
+
parent_id: activeTabId
|
|
605
|
+
})
|
|
606
|
+
};
|
|
607
|
+
if (isEditMode) {
|
|
608
|
+
payload.tab_info.url = tab.url.replace('?edit=true', '');
|
|
609
|
+
}
|
|
610
|
+
if (!isHomeTab) {
|
|
611
|
+
payload.parent_tab_id = isSubTab ? activeTabRef.current.tabId : homeTabIdRef.current;
|
|
612
|
+
}
|
|
613
|
+
if (closeTabFailedRequestsRef.current[filteredTab.id]) {
|
|
614
|
+
payload.tab_id = closeTabFailedRequestsRef.current[filteredTab.id].tabId;
|
|
615
|
+
delete closeTabFailedRequestsRef.current[filteredTab.id];
|
|
616
|
+
}
|
|
617
|
+
if (!isSubTab) {
|
|
618
|
+
storedExpandedIds = JSON.parse(sessionStorage.getItem("".concat(SITE_PREFIX, "expandedIds"))) || [];
|
|
619
|
+
isExpanded = storedExpandedIds.some(function (_ref17) {
|
|
620
|
+
var id = _ref17.id;
|
|
621
|
+
return id === tab.id;
|
|
622
|
+
});
|
|
623
|
+
if (isExpanded) {
|
|
624
|
+
updateExpandedID(tab.id);
|
|
625
|
+
requestAnimationFrame(function () {
|
|
626
|
+
var _superTabsWrapperElem2;
|
|
627
|
+
(_superTabsWrapperElem2 = superTabsWrapperElemRef.current) === null || _superTabsWrapperElem2 === void 0 || (_superTabsWrapperElem2 = _superTabsWrapperElem2.classList) === null || _superTabsWrapperElem2 === void 0 || _superTabsWrapperElem2.add('nested-tabs-visible');
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
(_payload$tab_info = payload.tab_info) === null || _payload$tab_info === void 0 || delete _payload$tab_info.isClientChanged;
|
|
632
|
+
// return;
|
|
633
|
+
currentOpenTabCallerRef.current = payload.tab_info;
|
|
634
|
+
_context5.n = 3;
|
|
635
|
+
return handleOpenTab(payload);
|
|
636
|
+
case 3:
|
|
637
|
+
response = _context5.v;
|
|
638
|
+
if (!(response.status === 1)) {
|
|
639
|
+
_context5.n = 6;
|
|
640
|
+
break;
|
|
641
|
+
}
|
|
642
|
+
_tabId = response.tabId;
|
|
643
|
+
if (isEditMode) {
|
|
644
|
+
if (!tabModePreference.includes(_tabId)) {
|
|
645
|
+
setTabModePreference([].concat(_toConsumableArray(tabModePreference), [_tabId]));
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (!isHomeTab) {
|
|
649
|
+
_context5.n = 4;
|
|
650
|
+
break;
|
|
651
|
+
}
|
|
652
|
+
homeTabIdRef.current = _tabId;
|
|
653
|
+
return _context5.a(2, {
|
|
654
|
+
tab_info: tab,
|
|
655
|
+
tabId: _tabId,
|
|
656
|
+
level: 0
|
|
657
|
+
});
|
|
658
|
+
case 4:
|
|
659
|
+
newTab = _objectSpread(_objectSpread({}, tab), {}, {
|
|
660
|
+
tabId: _tabId
|
|
661
|
+
});
|
|
662
|
+
updateTabs(function (prev) {
|
|
663
|
+
var tabsCopy = structuredClone(prev);
|
|
664
|
+
if (isSubTab) {
|
|
665
|
+
var parentIndex = tabsCopy.findIndex(function (t) {
|
|
666
|
+
return t.id === activeTabRef.current.id;
|
|
667
|
+
});
|
|
668
|
+
if (parentIndex !== -1 && tabsCopy[parentIndex].subTabs) {
|
|
669
|
+
var currentSubTabExists = tabsCopy[parentIndex].subTabs.find(function (t) {
|
|
670
|
+
return t.id === tab.id;
|
|
671
|
+
});
|
|
672
|
+
if (!currentSubTabExists) {
|
|
673
|
+
tabsCopy[parentIndex].subTabs.push(newTab);
|
|
674
|
+
} else {
|
|
675
|
+
tabsCopy[parentIndex].subTabs = tabsCopy[parentIndex].subTabs.map(function (t) {
|
|
676
|
+
return t.id === tab.id ? _objectSpread(_objectSpread({}, t), {}, {
|
|
677
|
+
tabId: _tabId
|
|
678
|
+
}) : t;
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
if (!keepInactive) {
|
|
683
|
+
updateActiveSubTab(newTab);
|
|
684
|
+
lastOpenedUrl.current[currentEntityId + '_' + activeTabRef.current.id] = newTab;
|
|
685
|
+
}
|
|
686
|
+
} else {
|
|
687
|
+
// when calling sight open tab we are setting subTabs array empty
|
|
688
|
+
var _subTabs = response.children ? response.children.map(function (t, index) {
|
|
689
|
+
var tab_info = t.tab_info,
|
|
690
|
+
rest = _objectWithoutProperties(t, _excluded2);
|
|
691
|
+
var flattenedSubTab = _objectSpread(_objectSpread(_objectSpread({}, rest), tab_info), {}, {
|
|
692
|
+
tabId: rest.id,
|
|
693
|
+
open_order: index + 1
|
|
694
|
+
});
|
|
695
|
+
return flattenedSubTab;
|
|
696
|
+
}) : [];
|
|
697
|
+
tabsCopy = tabsCopy.map(function (t) {
|
|
698
|
+
return t.id === tab.id ? _objectSpread(_objectSpread({}, t), {}, {
|
|
699
|
+
tabId: _tabId,
|
|
700
|
+
subTabs: _subTabs.sort(_Utils.sortByOrder)
|
|
701
|
+
}) : t;
|
|
702
|
+
});
|
|
703
|
+
var pathName = window.location.pathname;
|
|
704
|
+
var isSubTabActive = _subTabs.find(function (t) {
|
|
705
|
+
return t.url === pathName;
|
|
706
|
+
});
|
|
707
|
+
if (isSubTabActive) updateActiveSubTab(isSubTabActive);
|
|
708
|
+
updateActiveTab(newTab);
|
|
709
|
+
}
|
|
710
|
+
return tabsCopy;
|
|
711
|
+
});
|
|
712
|
+
isSubTab ? !keepInactive && updateActiveSubTab(newTab) : updateActiveTab(newTab);
|
|
713
|
+
return _context5.a(2, {
|
|
714
|
+
tab_info: tab,
|
|
715
|
+
id: _tabId,
|
|
716
|
+
level: isSubTab ? 2 : 1,
|
|
717
|
+
parent_tab_id: isSubTab ? activeTabRef.current.tabId : homeTabIdRef.current
|
|
718
|
+
});
|
|
719
|
+
case 5:
|
|
720
|
+
_context5.n = 8;
|
|
721
|
+
break;
|
|
722
|
+
case 6:
|
|
723
|
+
if (!(response instanceof DOMException && response.name === 'AbortError')) {
|
|
724
|
+
_context5.n = 7;
|
|
725
|
+
break;
|
|
726
|
+
}
|
|
727
|
+
return _context5.a(2);
|
|
728
|
+
case 7:
|
|
729
|
+
if (window.isDebugOn) {
|
|
730
|
+
alertService === null || alertService === void 0 || alertService.error(response.msg ? response.msg : 'Error in opening tab!');
|
|
731
|
+
}
|
|
732
|
+
case 8:
|
|
733
|
+
_context5.n = 10;
|
|
734
|
+
break;
|
|
735
|
+
case 9:
|
|
736
|
+
_context5.p = 9;
|
|
737
|
+
_t = _context5.v;
|
|
738
|
+
if (window.isDebugOn) {
|
|
739
|
+
alertService === null || alertService === void 0 || alertService.error(_t.message ? _t.message : 'Error in opening tab!');
|
|
740
|
+
}
|
|
741
|
+
console.log("openTab - error", _t);
|
|
742
|
+
case 10:
|
|
743
|
+
_context5.p = 10;
|
|
744
|
+
currentOpenTabCallerRef.current = null;
|
|
745
|
+
return _context5.f(10);
|
|
746
|
+
case 11:
|
|
747
|
+
return _context5.a(2);
|
|
748
|
+
}
|
|
749
|
+
}, _callee5, null, [[1, 9, 10, 11]]);
|
|
750
|
+
})), [handleOpenTab, currentEntityId, tabModePreference]);
|
|
751
|
+
var updateCurrentTab = (0, _react.useCallback)(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
|
|
752
|
+
var _ref19,
|
|
753
|
+
tab,
|
|
754
|
+
_ref19$ignoreActiveTa,
|
|
755
|
+
ignoreActiveTabUpdate,
|
|
756
|
+
parentId,
|
|
757
|
+
_ref19$isHomeTab,
|
|
758
|
+
isHomeTab,
|
|
759
|
+
_ref19$isSubTab,
|
|
760
|
+
isSubTab,
|
|
761
|
+
_ref19$sort,
|
|
762
|
+
sort,
|
|
763
|
+
_activeSubTabRef$curr2,
|
|
764
|
+
tabId,
|
|
765
|
+
_tabDetails$subTabs,
|
|
766
|
+
_activeSubTabRef$curr3,
|
|
767
|
+
tabDetails,
|
|
768
|
+
subTabDetails,
|
|
769
|
+
_activeTabRef$current5,
|
|
770
|
+
_tabDetails,
|
|
771
|
+
unique_identifier,
|
|
772
|
+
activeTabId,
|
|
773
|
+
subTabs,
|
|
774
|
+
level,
|
|
775
|
+
order,
|
|
776
|
+
tabIdFromTab,
|
|
777
|
+
tabUniqueId,
|
|
778
|
+
parent_tab_id,
|
|
779
|
+
width,
|
|
780
|
+
elementWidth,
|
|
781
|
+
filteredTab,
|
|
782
|
+
payload,
|
|
783
|
+
_tabsRef$current$find,
|
|
784
|
+
storedExpandedIds,
|
|
785
|
+
isExpanded,
|
|
786
|
+
hasSubTabs,
|
|
787
|
+
subTabsWrapperElem,
|
|
788
|
+
response,
|
|
789
|
+
_args6 = arguments,
|
|
790
|
+
_t2;
|
|
791
|
+
return _regenerator().w(function (_context6) {
|
|
792
|
+
while (1) switch (_context6.p = _context6.n) {
|
|
793
|
+
case 0:
|
|
794
|
+
_ref19 = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : {}, tab = _ref19.tab, _ref19$ignoreActiveTa = _ref19.ignoreActiveTabUpdate, ignoreActiveTabUpdate = _ref19$ignoreActiveTa === void 0 ? false : _ref19$ignoreActiveTa, parentId = _ref19.parentId, _ref19$isHomeTab = _ref19.isHomeTab, isHomeTab = _ref19$isHomeTab === void 0 ? false : _ref19$isHomeTab, _ref19$isSubTab = _ref19.isSubTab, isSubTab = _ref19$isSubTab === void 0 ? false : _ref19$isSubTab, _ref19$sort = _ref19.sort, sort = _ref19$sort === void 0 ? false : _ref19$sort;
|
|
795
|
+
_context6.p = 1;
|
|
796
|
+
if (isSubTab) {
|
|
797
|
+
lastOpenedUrl.current[currentEntityId + '_' + parentId] = tab;
|
|
798
|
+
updateActiveSubTab(tab);
|
|
799
|
+
updateTabs(function (prev) {
|
|
800
|
+
var updatedData = prev.map(function (t) {
|
|
801
|
+
return t.url === activeTabRef.current.url ? _objectSpread(_objectSpread({}, t), {}, {
|
|
802
|
+
subTabs: (0, _Utils.addOrUpdateSubTab)({
|
|
803
|
+
array: t.subTabs,
|
|
804
|
+
newTab: tab,
|
|
805
|
+
maxOrder: maxOrder,
|
|
806
|
+
sort: sort
|
|
807
|
+
})
|
|
808
|
+
}) : t;
|
|
809
|
+
});
|
|
810
|
+
// console.log('updateCurrentTab - tabsCopy', updatedData.find(t => t.id === parentId).subTabs.map(t => t.firstName + '_' + t.open_order + '_O-' + t.order));
|
|
811
|
+
return updatedData;
|
|
812
|
+
});
|
|
813
|
+
// setLastOpenedSubTabs((prev) => {
|
|
814
|
+
// const updated = { ...prev };
|
|
815
|
+
// updated[parentId] = isSubTab ? tab : null;
|
|
816
|
+
// return updated;
|
|
817
|
+
// });
|
|
818
|
+
} else {
|
|
819
|
+
if (!ignoreActiveTabUpdate) {
|
|
820
|
+
lastOpenedUrl.current[currentEntityId + '_' + tab.id] = tab;
|
|
821
|
+
updateActiveTab(tab);
|
|
822
|
+
if ((_activeSubTabRef$curr2 = activeSubTabRef.current) !== null && _activeSubTabRef$curr2 !== void 0 && _activeSubTabRef$curr2.url && (0, _Utils.isChildPath)(tab.url, activeSubTabRef.current.url)) {
|
|
823
|
+
updateActiveSubTab({});
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
// updateActiveSubTab({});
|
|
827
|
+
// setLastOpenedSubTabs((prev) => {
|
|
828
|
+
// const updated = { ...prev };
|
|
829
|
+
// updated[tab.id] = null;
|
|
830
|
+
// return updated;
|
|
831
|
+
// });
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// if (tab.skipAPICall) return;
|
|
835
|
+
if (updateCurrentTabRef.current) {
|
|
836
|
+
updateCurrentTabRef.current.abort();
|
|
837
|
+
updateCurrentTabRef.current = new AbortController();
|
|
838
|
+
}
|
|
839
|
+
tabId = null;
|
|
840
|
+
if (isHomeTab) {
|
|
841
|
+
tabId = homeTabIdRef.current;
|
|
842
|
+
} else if (isSubTab) {
|
|
843
|
+
tabDetails = tabsRef.current.find(function (item) {
|
|
844
|
+
var _activeTabRef$current4;
|
|
845
|
+
return item.tabId == (parentId || ((_activeTabRef$current4 = activeTabRef.current) === null || _activeTabRef$current4 === void 0 ? void 0 : _activeTabRef$current4.id));
|
|
846
|
+
});
|
|
847
|
+
subTabDetails = tabDetails === null || tabDetails === void 0 || (_tabDetails$subTabs = tabDetails.subTabs) === null || _tabDetails$subTabs === void 0 ? void 0 : _tabDetails$subTabs.find(function (item) {
|
|
848
|
+
return item.id == tab.id || item.url && tab.url && item.url.split('?')[0] === tab.url.split('?')[0];
|
|
849
|
+
});
|
|
850
|
+
tabId = ((_activeSubTabRef$curr3 = activeSubTabRef.current) === null || _activeSubTabRef$curr3 === void 0 ? void 0 : _activeSubTabRef$curr3.tabId) || (subTabDetails === null || subTabDetails === void 0 ? void 0 : subTabDetails.tabId);
|
|
851
|
+
} else {
|
|
852
|
+
_tabDetails = tabsRef.current.find(function (item) {
|
|
853
|
+
return item.id == tab.id || item.url && tab.url && item.url.split('?')[0] === tab.url.split('?')[0];
|
|
854
|
+
});
|
|
855
|
+
tabId = ((_activeTabRef$current5 = activeTabRef.current) === null || _activeTabRef$current5 === void 0 ? void 0 : _activeTabRef$current5.tabId) || (_tabDetails === null || _tabDetails === void 0 ? void 0 : _tabDetails.tabId);
|
|
856
|
+
}
|
|
857
|
+
if (tabId) {
|
|
858
|
+
_context6.n = 2;
|
|
859
|
+
break;
|
|
860
|
+
}
|
|
861
|
+
// if (!isHomeTab && !homeTabIdRef.current && isSubTab ? !activeTabRef.current.tabId : false) {
|
|
862
|
+
console.log('Tab not found opening a new tab');
|
|
863
|
+
openTab({
|
|
864
|
+
tab: tab,
|
|
865
|
+
isHomeTab: isHomeTab,
|
|
866
|
+
isSubTab: isSubTab
|
|
867
|
+
});
|
|
868
|
+
return _context6.a(2);
|
|
869
|
+
case 2:
|
|
870
|
+
unique_identifier = getUniqueIdentifier(getUserDetails(), SITE_PREFIX, persistTabsAfterLogin, entityIdentifierKey);
|
|
871
|
+
activeTabId = activeTabRef.current.id;
|
|
872
|
+
subTabs = tab.subTabs, level = tab.level, order = tab.order, tabIdFromTab = tab.tabId, tabUniqueId = tab.unique_identifier, parent_tab_id = tab.parent_tab_id, width = tab.width, elementWidth = tab.elementWidth, filteredTab = _objectWithoutProperties(tab, _excluded3);
|
|
873
|
+
payload = {
|
|
874
|
+
unique_identifier: unique_identifier,
|
|
875
|
+
tab_id: tabId,
|
|
876
|
+
created_by: unique_identifier.split('_')[0],
|
|
877
|
+
tab_info: _objectSpread(_objectSpread({}, filteredTab), isSubTab && {
|
|
878
|
+
parent_id: tab.parent_id || activeTabId
|
|
879
|
+
})
|
|
880
|
+
};
|
|
881
|
+
if (!isHomeTab) {
|
|
882
|
+
payload.parent_tab_id = parent_tab_id || (isSubTab ? activeTabRef.current.tabId : homeTabIdRef.current);
|
|
883
|
+
}
|
|
884
|
+
if (!(!isHomeTab && !payload.parent_tab_id)) {
|
|
885
|
+
_context6.n = 3;
|
|
886
|
+
break;
|
|
887
|
+
}
|
|
888
|
+
if (window.isDebugOn) {
|
|
889
|
+
alertService === null || alertService === void 0 || alertService.error('Parent id not found for updating current tab');
|
|
890
|
+
}
|
|
891
|
+
console.log('Parent id not found for updating current tab', tab, activeTabRef.current.tabId);
|
|
892
|
+
return _context6.a(2);
|
|
893
|
+
case 3:
|
|
894
|
+
if (!isSubTab) {
|
|
895
|
+
storedExpandedIds = JSON.parse(sessionStorage.getItem("".concat(SITE_PREFIX, "expandedIds"))) || [];
|
|
896
|
+
isExpanded = storedExpandedIds.some(function (_ref20) {
|
|
897
|
+
var id = _ref20.id;
|
|
898
|
+
return id === tab.id;
|
|
899
|
+
});
|
|
900
|
+
hasSubTabs = ((_tabsRef$current$find = tabsRef.current.find(function (t) {
|
|
901
|
+
return t.id === tab.id;
|
|
902
|
+
})) === null || _tabsRef$current$find === void 0 || (_tabsRef$current$find = _tabsRef$current$find.subTabs) === null || _tabsRef$current$find === void 0 ? void 0 : _tabsRef$current$find.length) > 0;
|
|
903
|
+
if (isExpanded) {
|
|
904
|
+
updateExpandedID(tab.id);
|
|
905
|
+
requestAnimationFrame(function () {
|
|
906
|
+
var _superTabsWrapperElem3;
|
|
907
|
+
(_superTabsWrapperElem3 = superTabsWrapperElemRef.current) === null || _superTabsWrapperElem3 === void 0 || (_superTabsWrapperElem3 = _superTabsWrapperElem3.classList) === null || _superTabsWrapperElem3 === void 0 || _superTabsWrapperElem3.add('nested-tabs-visible');
|
|
908
|
+
});
|
|
909
|
+
} else if (hasSubTabs) {
|
|
910
|
+
requestAnimationFrame(function () {
|
|
911
|
+
var _superTabsWrapperElem4;
|
|
912
|
+
(_superTabsWrapperElem4 = superTabsWrapperElemRef.current) === null || _superTabsWrapperElem4 === void 0 || (_superTabsWrapperElem4 = _superTabsWrapperElem4.classList) === null || _superTabsWrapperElem4 === void 0 || _superTabsWrapperElem4.add('nested-tabs-visible');
|
|
913
|
+
});
|
|
914
|
+
subTabsWrapperElem = document.querySelectorAll('.sub-tabs-wrapper');
|
|
915
|
+
subTabsWrapperElem.forEach(function (elem) {
|
|
916
|
+
elem.style.transition = "width ease-out ".concat(_Constants.transitionDuration, "ms");
|
|
917
|
+
});
|
|
918
|
+
setTimeout(function () {
|
|
919
|
+
subTabsWrapperElem.forEach(function (elem) {
|
|
920
|
+
elem.style.removeProperty('transition');
|
|
921
|
+
});
|
|
922
|
+
}, _Constants.transitionDuration + 50);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
_context6.n = 4;
|
|
926
|
+
return handleOpenTab(payload, updateCurrentTabRef.current);
|
|
927
|
+
case 4:
|
|
928
|
+
response = _context6.v;
|
|
929
|
+
if (!(response.status !== 1)) {
|
|
930
|
+
_context6.n = 6;
|
|
931
|
+
break;
|
|
932
|
+
}
|
|
933
|
+
if (!(response instanceof DOMException && response.name === 'AbortError')) {
|
|
934
|
+
_context6.n = 5;
|
|
935
|
+
break;
|
|
936
|
+
}
|
|
937
|
+
return _context6.a(2);
|
|
938
|
+
case 5:
|
|
939
|
+
if (window.isDebugOn) {
|
|
940
|
+
alertService === null || alertService === void 0 || alertService.error(response.msg ? response.msg : 'Error in updating current tab!');
|
|
941
|
+
}
|
|
942
|
+
case 6:
|
|
943
|
+
_context6.n = 8;
|
|
944
|
+
break;
|
|
945
|
+
case 7:
|
|
946
|
+
_context6.p = 7;
|
|
947
|
+
_t2 = _context6.v;
|
|
948
|
+
if (window.isDebugOn) {
|
|
949
|
+
alertService === null || alertService === void 0 || alertService.error(_t2.message ? _t2.message : 'Error in updating current tab!');
|
|
950
|
+
}
|
|
951
|
+
console.log("updateCurrentTab - error", _t2);
|
|
952
|
+
case 8:
|
|
953
|
+
return _context6.a(2);
|
|
954
|
+
}
|
|
955
|
+
}, _callee6, null, [[1, 7]]);
|
|
956
|
+
})), [handleOpenTab, openTab, currentEntityId]);
|
|
957
|
+
var openSubTab = (0, _react.useCallback)(/*#__PURE__*/function () {
|
|
958
|
+
var _ref22 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(_ref21) {
|
|
959
|
+
var _parentTab, _parentTab2, _parentTab3, _parentTab4;
|
|
960
|
+
var tab, parentId, _ref21$keepInactive, keepInactive, isSubTabOpen, parentTab, tabsCopy, subTabWithOpenOrderOne, _superTabsWrapperElem5;
|
|
961
|
+
return _regenerator().w(function (_context7) {
|
|
962
|
+
while (1) switch (_context7.n) {
|
|
963
|
+
case 0:
|
|
964
|
+
tab = _ref21.tab, parentId = _ref21.parentId, _ref21$keepInactive = _ref21.keepInactive, keepInactive = _ref21$keepInactive === void 0 ? false : _ref21$keepInactive;
|
|
965
|
+
isSubTabOpen = false;
|
|
966
|
+
parentTab = null;
|
|
967
|
+
tabsCopy = structuredClone(tabsRef.current);
|
|
968
|
+
parentTab = tabsCopy.find(function (t) {
|
|
969
|
+
var _activeTabRef$current6;
|
|
970
|
+
return t.id === ((_activeTabRef$current6 = activeTabRef.current) === null || _activeTabRef$current6 === void 0 ? void 0 : _activeTabRef$current6.id);
|
|
971
|
+
});
|
|
972
|
+
subTabWithOpenOrderOne = (_parentTab = parentTab) === null || _parentTab === void 0 || (_parentTab = _parentTab.subTabs) === null || _parentTab === void 0 ? void 0 : _parentTab.find(function (t) {
|
|
973
|
+
return t.open_order === 1;
|
|
974
|
+
}); // Check if subTab already exists by URL or ID to prevent duplicates
|
|
975
|
+
isSubTabOpen = (_parentTab2 = parentTab) === null || _parentTab2 === void 0 || (_parentTab2 = _parentTab2.subTabs) === null || _parentTab2 === void 0 ? void 0 : _parentTab2.find(function (t) {
|
|
976
|
+
return t.url && tab.url && t.url.split('?')[0] === tab.url.split('?')[0] || t.id === tab.id;
|
|
977
|
+
});
|
|
978
|
+
// Ensure sub tabs are expanded if there is only one sub tab
|
|
979
|
+
if (isDefaultExpanded && ((_parentTab3 = parentTab) === null || _parentTab3 === void 0 || (_parentTab3 = _parentTab3.subTabs) === null || _parentTab3 === void 0 ? void 0 : _parentTab3.length) === 1) {
|
|
980
|
+
updateExpandedID(parentTab.id);
|
|
981
|
+
(_superTabsWrapperElem5 = superTabsWrapperElemRef.current) === null || _superTabsWrapperElem5 === void 0 || _superTabsWrapperElem5.classList.add('nested-tabs-visible');
|
|
982
|
+
}
|
|
983
|
+
updateTabs(function () {
|
|
984
|
+
return tabsCopy.map(function (t) {
|
|
985
|
+
var _activeTabRef$current7;
|
|
986
|
+
return t.url === ((_activeTabRef$current7 = activeTabRef.current) === null || _activeTabRef$current7 === void 0 ? void 0 : _activeTabRef$current7.url) ? _objectSpread(_objectSpread({}, t), {}, {
|
|
987
|
+
subTabs: (0, _Utils.addOrUpdateSubTab)({
|
|
988
|
+
array: t.subTabs,
|
|
989
|
+
newTab: tab,
|
|
990
|
+
maxOrder: maxOrder
|
|
991
|
+
})
|
|
992
|
+
}) : t;
|
|
993
|
+
});
|
|
994
|
+
});
|
|
995
|
+
if (!keepInactive) {
|
|
996
|
+
lastOpenedUrl.current[currentEntityId + '_' + parentTab.id] = tab;
|
|
997
|
+
setActiveSubTab(tab);
|
|
998
|
+
activeSubTabRef.current = tab;
|
|
999
|
+
}
|
|
1000
|
+
clearTimeout(openingUnexpandedSubTabTimeoutRef.current);
|
|
1001
|
+
setOpeningUnexpandedSubTab(true);
|
|
1002
|
+
openingUnexpandedSubTabTimeoutRef.current = setTimeout(function () {
|
|
1003
|
+
setOpeningUnexpandedSubTab(false);
|
|
1004
|
+
}, 300);
|
|
1005
|
+
updateMaxWidth();
|
|
1006
|
+
updateSubTabChange({
|
|
1007
|
+
parentTabId: activeTabRef.current.id,
|
|
1008
|
+
oldTab: subTabWithOpenOrderOne,
|
|
1009
|
+
newTab: tab
|
|
1010
|
+
});
|
|
1011
|
+
// if (!isSubTabOpen && !tab.skipAPICall) openTab({ tab, parentId, isSubTab: true, keepInactive });
|
|
1012
|
+
if (!isSubTabOpen) openTab({
|
|
1013
|
+
tab: tab,
|
|
1014
|
+
parentId: parentId,
|
|
1015
|
+
isSubTab: true,
|
|
1016
|
+
keepInactive: keepInactive
|
|
1017
|
+
});
|
|
1018
|
+
if (subTabWrapperWidth[currentEntityId + '_' + ((_parentTab4 = parentTab) === null || _parentTab4 === void 0 ? void 0 : _parentTab4.id)]) {
|
|
1019
|
+
setSubTabWrapperWidth(function (prev) {
|
|
1020
|
+
var updated = _objectSpread({}, prev);
|
|
1021
|
+
delete updated[currentEntityId + '_' + parentTab.id];
|
|
1022
|
+
return updated;
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
case 1:
|
|
1026
|
+
return _context7.a(2);
|
|
1027
|
+
}
|
|
1028
|
+
}, _callee7);
|
|
1029
|
+
}));
|
|
1030
|
+
return function (_x) {
|
|
1031
|
+
return _ref22.apply(this, arguments);
|
|
1032
|
+
};
|
|
1033
|
+
}(), [updateTabs, updateMaxWidth, updateSubTabChange, openTab, subTabWrapperWidth, currentEntityId]);
|
|
1034
|
+
var modifyTab = (0, _react.useCallback)(function (_ref23) {
|
|
1035
|
+
var oldTab = _ref23.oldTab,
|
|
1036
|
+
newTab = _ref23.newTab,
|
|
1037
|
+
_ref23$isSubTab = _ref23.isSubTab,
|
|
1038
|
+
isSubTab = _ref23$isSubTab === void 0 ? false : _ref23$isSubTab;
|
|
1039
|
+
var tab = _objectSpread(_objectSpread({}, newTab), {}, {
|
|
1040
|
+
tabId: oldTab.tabId || null
|
|
1041
|
+
});
|
|
1042
|
+
updateTabs(function (prev) {
|
|
1043
|
+
var tabsCopy = structuredClone(prev);
|
|
1044
|
+
var parentIndex = tabsCopy.findIndex(function (t) {
|
|
1045
|
+
return t.id === activeTabRef.current.id;
|
|
1046
|
+
});
|
|
1047
|
+
if (isSubTab) {
|
|
1048
|
+
var childIndex = tabsCopy[parentIndex].subTabs.findIndex(function (t) {
|
|
1049
|
+
return t.id === oldTab.id || t.url && newTab.url && t.url.split('?')[0] === newTab.url.split('?')[0];
|
|
1050
|
+
});
|
|
1051
|
+
if (childIndex !== -1) {
|
|
1052
|
+
tabsCopy[parentIndex].subTabs[childIndex] = tab;
|
|
1053
|
+
} else {
|
|
1054
|
+
tabsCopy[parentIndex].subTabs.push(tab);
|
|
1055
|
+
}
|
|
1056
|
+
lastOpenedUrl.current[currentEntityId + '_' + activeTabRef.current.id] = newTab;
|
|
1057
|
+
updateActiveSubTab(newTab);
|
|
1058
|
+
} else {
|
|
1059
|
+
tabsCopy = tabsCopy.map(function (t) {
|
|
1060
|
+
return t.id === oldTab.id ? newTab : t;
|
|
1061
|
+
});
|
|
1062
|
+
updateActiveTab(newTab);
|
|
1063
|
+
}
|
|
1064
|
+
return tabsCopy;
|
|
1065
|
+
});
|
|
1066
|
+
// openTab({ tab, isSubTab });
|
|
1067
|
+
updateCurrentTab({
|
|
1068
|
+
tab: tab,
|
|
1069
|
+
isSubTab: isSubTab,
|
|
1070
|
+
parentId: activeTabRef.current.id
|
|
1071
|
+
});
|
|
1072
|
+
}, [updateCurrentTab, updateActiveSubTab, updateActiveTab, updateTabs, currentEntityId]);
|
|
1073
|
+
var closeTab = (0, _react.useCallback)(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
|
|
1074
|
+
var _ref25,
|
|
1075
|
+
tab,
|
|
1076
|
+
_ref25$isSubTab,
|
|
1077
|
+
isSubTab,
|
|
1078
|
+
response,
|
|
1079
|
+
_activeSubTabRef$curr5,
|
|
1080
|
+
tabId,
|
|
1081
|
+
updatedTabModePreference,
|
|
1082
|
+
_args8 = arguments,
|
|
1083
|
+
_t3;
|
|
1084
|
+
return _regenerator().w(function (_context8) {
|
|
1085
|
+
while (1) switch (_context8.p = _context8.n) {
|
|
1086
|
+
case 0:
|
|
1087
|
+
_ref25 = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {}, tab = _ref25.tab, _ref25$isSubTab = _ref25.isSubTab, isSubTab = _ref25$isSubTab === void 0 ? false : _ref25$isSubTab;
|
|
1088
|
+
_context8.p = 1;
|
|
1089
|
+
if (isSubTab) {
|
|
1090
|
+
clearTimeout(closingUnexpandedSubTabTimeoutRef.current);
|
|
1091
|
+
setClosingUnexpandedSubTab(true);
|
|
1092
|
+
closingUnexpandedSubTabTimeoutRef.current = setTimeout(function () {
|
|
1093
|
+
setClosingUnexpandedSubTab(false);
|
|
1094
|
+
}, 300);
|
|
1095
|
+
}
|
|
1096
|
+
updateTabs(function (prev) {
|
|
1097
|
+
var newTabs = structuredClone(prev);
|
|
1098
|
+
if (prev.length === 0) return newTabs;
|
|
1099
|
+
if (isSubTab) {
|
|
1100
|
+
var _newTabs, _newTabs2, _newTabs3, _newTabs4, _newTabs5, _activeSubTabRef$curr4;
|
|
1101
|
+
var parentTabIndex = (_newTabs = newTabs) === null || _newTabs === void 0 ? void 0 : _newTabs.findIndex(function (data) {
|
|
1102
|
+
return data.id === activeTabRef.current.id;
|
|
1103
|
+
});
|
|
1104
|
+
var subTabIndex = (_newTabs2 = newTabs) === null || _newTabs2 === void 0 || (_newTabs2 = _newTabs2[parentTabIndex]) === null || _newTabs2 === void 0 ? void 0 : _newTabs2.subTabs.findIndex(function (data) {
|
|
1105
|
+
return data.id === tab.id;
|
|
1106
|
+
});
|
|
1107
|
+
var tabOrder = tab.order,
|
|
1108
|
+
tabOpenOrder = tab.open_order;
|
|
1109
|
+
var subTabsLength = (_newTabs3 = newTabs) === null || _newTabs3 === void 0 || (_newTabs3 = _newTabs3[parentTabIndex]) === null || _newTabs3 === void 0 ? void 0 : _newTabs3.subTabs.length;
|
|
1110
|
+
newTabs[parentTabIndex].subTabs = (_newTabs4 = newTabs) === null || _newTabs4 === void 0 || (_newTabs4 = _newTabs4[parentTabIndex]) === null || _newTabs4 === void 0 ? void 0 : _newTabs4.subTabs.filter(function (subTab) {
|
|
1111
|
+
return subTab.id !== tab.id;
|
|
1112
|
+
});
|
|
1113
|
+
var _splitSubTabs = (0, _Utils.splitSubTabs)((_newTabs5 = newTabs) === null || _newTabs5 === void 0 || (_newTabs5 = _newTabs5[parentTabIndex]) === null || _newTabs5 === void 0 ? void 0 : _newTabs5.subTabs),
|
|
1114
|
+
itemsWithOrderZero = _splitSubTabs.itemsWithOrderZero;
|
|
1115
|
+
var nextNonZeroOrderObj = subTabsLength > maxOrder && itemsWithOrderZero.length > 0 ? itemsWithOrderZero.reduce(function (prev, curr) {
|
|
1116
|
+
return prev.open_order < curr.open_order ? prev : curr;
|
|
1117
|
+
}) : null;
|
|
1118
|
+
if (tab.id === ((_activeSubTabRef$curr4 = activeSubTabRef.current) === null || _activeSubTabRef$curr4 === void 0 ? void 0 : _activeSubTabRef$curr4.id)) {
|
|
1119
|
+
if (newTabs[parentTabIndex].subTabs.length > 0) {
|
|
1120
|
+
var _newActiveSubTab$orde, _newActiveSubTab$open;
|
|
1121
|
+
var nextSubTab = newTabs[parentTabIndex].subTabs[subTabIndex];
|
|
1122
|
+
var newActiveSubTab = nextSubTab !== null && nextSubTab !== void 0 ? nextSubTab : newTabs[parentTabIndex].subTabs[subTabIndex - 1];
|
|
1123
|
+
// const newActiveSubTab = nextSubTab ?? newTabs[parentTabIndex].subTabs.find(subTab => subTab.open_order === tab.open_order + 1);
|
|
1124
|
+
var _tabOrder = (_newActiveSubTab$orde = newActiveSubTab === null || newActiveSubTab === void 0 ? void 0 : newActiveSubTab.order) !== null && _newActiveSubTab$orde !== void 0 ? _newActiveSubTab$orde : 0;
|
|
1125
|
+
var _tabOpenOrder = (_newActiveSubTab$open = newActiveSubTab === null || newActiveSubTab === void 0 ? void 0 : newActiveSubTab.open_order) !== null && _newActiveSubTab$open !== void 0 ? _newActiveSubTab$open : 0;
|
|
1126
|
+
newTabs[parentTabIndex].subTabs = newTabs[parentTabIndex].subTabs.map(function (subTab) {
|
|
1127
|
+
if (subTab.id === newActiveSubTab.id) {
|
|
1128
|
+
var order = nextSubTab ? subTab.order - 1 : subTab.order;
|
|
1129
|
+
return _objectSpread(_objectSpread({}, subTab), {}, {
|
|
1130
|
+
order: order,
|
|
1131
|
+
open_order: 1
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
if (nextNonZeroOrderObj && subTab.id === nextNonZeroOrderObj.id) {
|
|
1135
|
+
return _objectSpread(_objectSpread({}, subTab), {}, {
|
|
1136
|
+
order: maxOrder,
|
|
1137
|
+
open_order: subTab.open_order - 1
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
return _objectSpread(_objectSpread({}, subTab), {}, {
|
|
1141
|
+
order: subTab.order > _tabOrder ? subTab.order - 1 : subTab.order,
|
|
1142
|
+
open_order: subTab.open_order > _tabOpenOrder ? subTab.open_order - 1 : subTab.open_order
|
|
1143
|
+
});
|
|
1144
|
+
});
|
|
1145
|
+
updateActiveSubTab(newActiveSubTab);
|
|
1146
|
+
lastOpenedUrl.current[currentEntityId + '_' + activeTabRef.current.id] = newActiveSubTab;
|
|
1147
|
+
var url = newActiveSubTab.url;
|
|
1148
|
+
if (tabModePreference.includes(newActiveSubTab.tabId)) {
|
|
1149
|
+
url += "?edit=true";
|
|
1150
|
+
}
|
|
1151
|
+
history.replace(url);
|
|
1152
|
+
} else {
|
|
1153
|
+
updateActiveSubTab({});
|
|
1154
|
+
lastOpenedUrl.current[currentEntityId + '_' + activeTabRef.current.id] = null;
|
|
1155
|
+
var _url = activeTabRef.current.url;
|
|
1156
|
+
if (tabModePreference.includes(activeTabRef.current.tabId)) {
|
|
1157
|
+
_url += "?edit=true";
|
|
1158
|
+
}
|
|
1159
|
+
history.replace(_url);
|
|
1160
|
+
}
|
|
1161
|
+
} else {
|
|
1162
|
+
newTabs[parentTabIndex].subTabs = newTabs[parentTabIndex].subTabs.map(function (subTab) {
|
|
1163
|
+
if (tabOrder === 0) {
|
|
1164
|
+
return _objectSpread(_objectSpread({}, subTab), {}, {
|
|
1165
|
+
open_order: subTab.open_order > tabOpenOrder ? subTab.open_order - 1 : subTab.open_order
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
if (nextNonZeroOrderObj && subTab.id === nextNonZeroOrderObj.id) {
|
|
1169
|
+
return _objectSpread(_objectSpread({}, subTab), {}, {
|
|
1170
|
+
order: maxOrder,
|
|
1171
|
+
open_order: subTab.open_order - 1
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
1174
|
+
return _objectSpread(_objectSpread({}, subTab), {}, {
|
|
1175
|
+
order: subTab.order > tabOrder ? subTab.order - 1 : subTab.order,
|
|
1176
|
+
open_order: subTab.open_order > tabOpenOrder ? subTab.open_order - 1 : subTab.open_order
|
|
1177
|
+
});
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
newTabs[parentTabIndex].subTabs.sort(_Utils.sortByOrder);
|
|
1181
|
+
} else {
|
|
1182
|
+
var _activeTabRef$current8;
|
|
1183
|
+
if (tab.id === ((_activeTabRef$current8 = activeTabRef.current) === null || _activeTabRef$current8 === void 0 ? void 0 : _activeTabRef$current8.id)) {
|
|
1184
|
+
var tabIndex = newTabs.findIndex(function (data) {
|
|
1185
|
+
return data.id === tab.id;
|
|
1186
|
+
});
|
|
1187
|
+
if (newTabs.length > 1) {
|
|
1188
|
+
var nextTab = newTabs[tabIndex + 1];
|
|
1189
|
+
var newActiveTab = nextTab !== null && nextTab !== void 0 ? nextTab : newTabs[tabIndex - 1];
|
|
1190
|
+
updateActiveTab(newActiveTab);
|
|
1191
|
+
lastOpenedUrl.current[currentEntityId + '_' + activeTabRef.current.id] = newActiveTab;
|
|
1192
|
+
history.replace(newActiveTab.url);
|
|
1193
|
+
} else {
|
|
1194
|
+
lastOpenedUrl.current[currentEntityId + '_' + activeTabRef.current.id] = null;
|
|
1195
|
+
updateActiveTab({});
|
|
1196
|
+
history.replace("/");
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
newTabs = newTabs.filter(function (t) {
|
|
1200
|
+
return t.id !== tab.id;
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
return newTabs;
|
|
1204
|
+
});
|
|
1205
|
+
if (isSubTab) {
|
|
1206
|
+
updateMaxWidth();
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
// if (tab.skipAPICall) return;
|
|
1210
|
+
if (tab.tabId) {
|
|
1211
|
+
_context8.n = 2;
|
|
1212
|
+
break;
|
|
1213
|
+
}
|
|
1214
|
+
console.log('Tab id not found', tab);
|
|
1215
|
+
history.replace("/");
|
|
1216
|
+
return _context8.a(2);
|
|
1217
|
+
case 2:
|
|
1218
|
+
_context8.n = 3;
|
|
1219
|
+
return handleCloseTab(tab.tabId);
|
|
1220
|
+
case 3:
|
|
1221
|
+
response = _context8.v;
|
|
1222
|
+
if (!(response.status === 1)) {
|
|
1223
|
+
_context8.n = 4;
|
|
1224
|
+
break;
|
|
1225
|
+
}
|
|
1226
|
+
console.log('closeTab - response.current_tab_id', response.current_tab_id, activeSubTabRef.current);
|
|
1227
|
+
// if (isSubTab && response.current_tab_id !== activeSubTabRef.current?.tabId ) {
|
|
1228
|
+
if (isSubTab && activeSubTabRef.current) {
|
|
1229
|
+
if (isSubTab && ((_activeSubTabRef$curr5 = activeSubTabRef.current) === null || _activeSubTabRef$curr5 === void 0 ? void 0 : _activeSubTabRef$curr5.open_order) > 2) {
|
|
1230
|
+
updateCurrentTab({
|
|
1231
|
+
tab: activeSubTabRef.current,
|
|
1232
|
+
isSubTab: true,
|
|
1233
|
+
parentId: activeTabRef.current.id
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
activeSubTabRef.current.open_order = 1;
|
|
1237
|
+
}
|
|
1238
|
+
tabId = tab.tabId;
|
|
1239
|
+
updatedTabModePreference = _toConsumableArray(tabModePreference);
|
|
1240
|
+
if (updatedTabModePreference.includes(tabId)) {
|
|
1241
|
+
updatedTabModePreference = updatedTabModePreference.filter(function (id) {
|
|
1242
|
+
return id !== tabId;
|
|
1243
|
+
});
|
|
1244
|
+
setTabModePreference(updatedTabModePreference);
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
// console.log('response', response);
|
|
1248
|
+
_context8.n = 6;
|
|
1249
|
+
break;
|
|
1250
|
+
case 4:
|
|
1251
|
+
if (!(response instanceof DOMException && response.name === 'AbortError')) {
|
|
1252
|
+
_context8.n = 5;
|
|
1253
|
+
break;
|
|
1254
|
+
}
|
|
1255
|
+
return _context8.a(2);
|
|
1256
|
+
case 5:
|
|
1257
|
+
if (window.isDebugOn) {
|
|
1258
|
+
alertService === null || alertService === void 0 || alertService.error(response.msg ? response.msg : 'Error in closing tab!');
|
|
1259
|
+
}
|
|
1260
|
+
closeTabFailedRequestsRef.current[tab.id] = tab;
|
|
1261
|
+
case 6:
|
|
1262
|
+
_context8.n = 8;
|
|
1263
|
+
break;
|
|
1264
|
+
case 7:
|
|
1265
|
+
_context8.p = 7;
|
|
1266
|
+
_t3 = _context8.v;
|
|
1267
|
+
if (window.isDebugOn) {
|
|
1268
|
+
alertService === null || alertService === void 0 || alertService.error(_t3.message ? _t3.message : 'Error in closing tab!');
|
|
1269
|
+
}
|
|
1270
|
+
console.log("closeTab - error", _t3);
|
|
1271
|
+
closeTabFailedRequestsRef.current[tab.id] = tab;
|
|
1272
|
+
case 8:
|
|
1273
|
+
return _context8.a(2);
|
|
1274
|
+
}
|
|
1275
|
+
}, _callee8, null, [[1, 7]]);
|
|
1276
|
+
})), [handleCloseTab, updateCurrentTab, currentEntityId, tabModePreference]);
|
|
1277
|
+
var reorderTabs = (0, _react.useCallback)(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() {
|
|
1278
|
+
var _ref27,
|
|
1279
|
+
tab,
|
|
1280
|
+
order,
|
|
1281
|
+
payload,
|
|
1282
|
+
response,
|
|
1283
|
+
_args9 = arguments,
|
|
1284
|
+
_t4;
|
|
1285
|
+
return _regenerator().w(function (_context9) {
|
|
1286
|
+
while (1) switch (_context9.p = _context9.n) {
|
|
1287
|
+
case 0:
|
|
1288
|
+
_ref27 = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {}, tab = _ref27.tab, order = _ref27.order;
|
|
1289
|
+
_context9.p = 1;
|
|
1290
|
+
if (tab.tabId) {
|
|
1291
|
+
_context9.n = 2;
|
|
1292
|
+
break;
|
|
1293
|
+
}
|
|
1294
|
+
// alertService?.error('Tab id not found');
|
|
1295
|
+
console.log('Tab id not found', tab);
|
|
1296
|
+
return _context9.a(2);
|
|
1297
|
+
case 2:
|
|
1298
|
+
payload = {
|
|
1299
|
+
tab_id: tab.tabId.toString(),
|
|
1300
|
+
new_order: order
|
|
1301
|
+
};
|
|
1302
|
+
_context9.n = 3;
|
|
1303
|
+
return handleReorderTabs(payload);
|
|
1304
|
+
case 3:
|
|
1305
|
+
response = _context9.v;
|
|
1306
|
+
if (!(response.status !== 1)) {
|
|
1307
|
+
_context9.n = 5;
|
|
1308
|
+
break;
|
|
1309
|
+
}
|
|
1310
|
+
if (!(response instanceof DOMException && response.name === 'AbortError')) {
|
|
1311
|
+
_context9.n = 4;
|
|
1312
|
+
break;
|
|
1313
|
+
}
|
|
1314
|
+
return _context9.a(2);
|
|
1315
|
+
case 4:
|
|
1316
|
+
if (window.isDebugOn) {
|
|
1317
|
+
alertService === null || alertService === void 0 || alertService.error(response.msg ? response.msg : 'Error in reordering tabs!');
|
|
1318
|
+
}
|
|
1319
|
+
case 5:
|
|
1320
|
+
_context9.n = 7;
|
|
1321
|
+
break;
|
|
1322
|
+
case 6:
|
|
1323
|
+
_context9.p = 6;
|
|
1324
|
+
_t4 = _context9.v;
|
|
1325
|
+
if (window.isDebugOn) {
|
|
1326
|
+
alertService === null || alertService === void 0 || alertService.error(_t4.message ? _t4.message : 'Error in reordering tabs!');
|
|
1327
|
+
}
|
|
1328
|
+
console.log("reorderTabs - error", _t4);
|
|
1329
|
+
case 7:
|
|
1330
|
+
return _context9.a(2);
|
|
1331
|
+
}
|
|
1332
|
+
}, _callee9, null, [[1, 6]]);
|
|
1333
|
+
})), [handleReorderTabs]);
|
|
1334
|
+
|
|
1335
|
+
/*
|
|
1336
|
+
* Closing level 1 tabs whose access is removed on backend and filtering level 2 tabs related to closed level 1 tabs.
|
|
1337
|
+
*/
|
|
1338
|
+
var removeTabsWithoutAccess = (0, _react.useCallback)(function (tabs) {
|
|
1339
|
+
var tabsWithAccess = [];
|
|
1340
|
+
var tabIdsWithoutAccess = [];
|
|
1341
|
+
tabs.forEach(function (tab) {
|
|
1342
|
+
var _tab$tab_info;
|
|
1343
|
+
if (tab.level === 1 && !hasPrivilege((_tab$tab_info = tab.tab_info) === null || _tab$tab_info === void 0 ? void 0 : _tab$tab_info.privilege)) {
|
|
1344
|
+
// Here we are closing only level 1 tabs only subtabs will be automatically closed on backend
|
|
1345
|
+
tabIdsWithoutAccess.push(tab.id);
|
|
1346
|
+
closeTab({
|
|
1347
|
+
tab: _objectSpread(_objectSpread({}, tab), {}, {
|
|
1348
|
+
tabId: tab.id
|
|
1349
|
+
}),
|
|
1350
|
+
isSubTab: tab.level === 2
|
|
1351
|
+
});
|
|
1352
|
+
} else {
|
|
1353
|
+
tabsWithAccess.push(tab);
|
|
1354
|
+
}
|
|
1355
|
+
});
|
|
1356
|
+
return tabsWithAccess.filter(function (tab) {
|
|
1357
|
+
return !tabIdsWithoutAccess.includes(tab.parent_tab_id);
|
|
1358
|
+
}); // Here we are filtering out subtabs (level 2) of no access tabs (level 1)
|
|
1359
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1360
|
+
}, [closeTab]);
|
|
1361
|
+
/**
|
|
1362
|
+
* Identifies and closes duplicate tabs based on their URLs
|
|
1363
|
+
*
|
|
1364
|
+
* @param {Array} data - Array of tab objects to check for duplicates
|
|
1365
|
+
* @returns {Array} - Array of tabs with duplicates removed
|
|
1366
|
+
*/
|
|
1367
|
+
var findDuplicateEntriesAndCloseTab = (0, _react.useCallback)(/*#__PURE__*/function () {
|
|
1368
|
+
var _ref28 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(data) {
|
|
1369
|
+
var urlMap, uniqueTabs, _iterator, _step, _step$value, url, tabsWithSameUrl, i, _t5, _t6, _t7;
|
|
1370
|
+
return _regenerator().w(function (_context0) {
|
|
1371
|
+
while (1) switch (_context0.p = _context0.n) {
|
|
1372
|
+
case 0:
|
|
1373
|
+
_context0.p = 0;
|
|
1374
|
+
// Track URLs we've seen and tabs we'll keep
|
|
1375
|
+
urlMap = new Map();
|
|
1376
|
+
uniqueTabs = []; // First pass - identify duplicates while preserving original order
|
|
1377
|
+
data.forEach(function (element) {
|
|
1378
|
+
if (!element || !element.tab_info) return;
|
|
1379
|
+
var url = element.tab_info.url;
|
|
1380
|
+
if (!url) return;
|
|
1381
|
+
var normalizedUrl = (0, _Utils.normalizeUrl)(url);
|
|
1382
|
+
if (urlMap.has(normalizedUrl)) {
|
|
1383
|
+
// Add to existing entry's list
|
|
1384
|
+
urlMap.get(normalizedUrl).push(element);
|
|
1385
|
+
} else {
|
|
1386
|
+
// Create new entry
|
|
1387
|
+
urlMap.set(normalizedUrl, [element]);
|
|
1388
|
+
uniqueTabs.push(element);
|
|
1389
|
+
}
|
|
1390
|
+
});
|
|
1391
|
+
|
|
1392
|
+
// Second pass - close duplicates sequentially
|
|
1393
|
+
_iterator = _createForOfIteratorHelper(urlMap.entries());
|
|
1394
|
+
_context0.p = 1;
|
|
1395
|
+
_iterator.s();
|
|
1396
|
+
case 2:
|
|
1397
|
+
if ((_step = _iterator.n()).done) {
|
|
1398
|
+
_context0.n = 10;
|
|
1399
|
+
break;
|
|
1400
|
+
}
|
|
1401
|
+
_step$value = _slicedToArray(_step.value, 2), url = _step$value[0], tabsWithSameUrl = _step$value[1];
|
|
1402
|
+
if (!(tabsWithSameUrl.length <= 1)) {
|
|
1403
|
+
_context0.n = 3;
|
|
1404
|
+
break;
|
|
1405
|
+
}
|
|
1406
|
+
return _context0.a(3, 9);
|
|
1407
|
+
case 3:
|
|
1408
|
+
i = 1;
|
|
1409
|
+
case 4:
|
|
1410
|
+
if (!(i < tabsWithSameUrl.length)) {
|
|
1411
|
+
_context0.n = 9;
|
|
1412
|
+
break;
|
|
1413
|
+
}
|
|
1414
|
+
_context0.p = 5;
|
|
1415
|
+
_context0.n = 6;
|
|
1416
|
+
return closeTab({
|
|
1417
|
+
tab: _objectSpread(_objectSpread({}, tabsWithSameUrl[i]), {}, {
|
|
1418
|
+
tabId: tabsWithSameUrl[i].id
|
|
1419
|
+
}),
|
|
1420
|
+
isSubTab: tabsWithSameUrl[i].level === 2
|
|
1421
|
+
});
|
|
1422
|
+
case 6:
|
|
1423
|
+
_context0.n = 8;
|
|
1424
|
+
break;
|
|
1425
|
+
case 7:
|
|
1426
|
+
_context0.p = 7;
|
|
1427
|
+
_t5 = _context0.v;
|
|
1428
|
+
console.error("Error closing duplicate tab:", _t5);
|
|
1429
|
+
case 8:
|
|
1430
|
+
i++;
|
|
1431
|
+
_context0.n = 4;
|
|
1432
|
+
break;
|
|
1433
|
+
case 9:
|
|
1434
|
+
_context0.n = 2;
|
|
1435
|
+
break;
|
|
1436
|
+
case 10:
|
|
1437
|
+
_context0.n = 12;
|
|
1438
|
+
break;
|
|
1439
|
+
case 11:
|
|
1440
|
+
_context0.p = 11;
|
|
1441
|
+
_t6 = _context0.v;
|
|
1442
|
+
_iterator.e(_t6);
|
|
1443
|
+
case 12:
|
|
1444
|
+
_context0.p = 12;
|
|
1445
|
+
_iterator.f();
|
|
1446
|
+
return _context0.f(12);
|
|
1447
|
+
case 13:
|
|
1448
|
+
return _context0.a(2, uniqueTabs);
|
|
1449
|
+
case 14:
|
|
1450
|
+
_context0.p = 14;
|
|
1451
|
+
_t7 = _context0.v;
|
|
1452
|
+
console.error("Error in findDuplicateEntriesAndCloseTab:", _t7);
|
|
1453
|
+
return _context0.a(2, data);
|
|
1454
|
+
}
|
|
1455
|
+
}, _callee0, null, [[5, 7], [1, 11, 12, 13], [0, 14]]);
|
|
1456
|
+
}));
|
|
1457
|
+
return function (_x2) {
|
|
1458
|
+
return _ref28.apply(this, arguments);
|
|
1459
|
+
};
|
|
1460
|
+
}(), [closeTab]);
|
|
1461
|
+
(0, _react.useEffect)(function () {
|
|
1462
|
+
// only run actual logic when currentEntityId changes
|
|
1463
|
+
if (previousEntityId == currentEntityId) {
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
var controller = new AbortController();
|
|
1467
|
+
if (currentEntityId != null && currentEntityId != undefined) {
|
|
1468
|
+
var fetchTabDetails = /*#__PURE__*/function () {
|
|
1469
|
+
var _ref29 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10() {
|
|
1470
|
+
var href, orgId, payload, response, _response$current_tab, _response$current_tab2, _response$current_tab4, pathName, isHomeTab, tabsOutputWithoutDuplicates, tabsOutput, _activeTab, _activeSubTab, currentActiveTab, _activeTab2, _response$current_tab3, tab_info, rest, flattenedObj, isCurrentTabOpen, openedParentTab, updatedParentTab, flattenedParentObj, parentTab, _activeSubTabRef$curr6, parentTabFromData, _flattenedParentObj, _tab_info, _rest, _flattenedObj, isSubTab, parent, parentTabInfo, parentRest, _flattenedParentObj2, tabsMap, restTabs, id, _tabsMap$id, _activeSubTab$tabId, _activeSubTab2, _activeTab3, tabId, isEditMode, tempTabModePreference, updated, _t8;
|
|
1471
|
+
return _regenerator().w(function (_context10) {
|
|
1472
|
+
while (1) switch (_context10.p = _context10.n) {
|
|
1473
|
+
case 0:
|
|
1474
|
+
_context10.p = 0;
|
|
1475
|
+
href = new URL(window.location.href);
|
|
1476
|
+
orgId = href.searchParams.get('org_id');
|
|
1477
|
+
if (!(orgId && +orgId !== currentEntityId)) {
|
|
1478
|
+
_context10.n = 1;
|
|
1479
|
+
break;
|
|
1480
|
+
}
|
|
1481
|
+
return _context10.a(2);
|
|
1482
|
+
case 1:
|
|
1483
|
+
payload = {
|
|
1484
|
+
unique_identifier: getUniqueIdentifier(getUserDetails(), SITE_PREFIX, persistTabsAfterLogin, entityIdentifierKey)
|
|
1485
|
+
};
|
|
1486
|
+
_context10.n = 2;
|
|
1487
|
+
return getTabs({
|
|
1488
|
+
payload: payload,
|
|
1489
|
+
controller: controller
|
|
1490
|
+
});
|
|
1491
|
+
case 2:
|
|
1492
|
+
response = _context10.v;
|
|
1493
|
+
if (!(response.status === 1)) {
|
|
1494
|
+
_context10.n = 13;
|
|
1495
|
+
break;
|
|
1496
|
+
}
|
|
1497
|
+
pathName = window.location.pathname;
|
|
1498
|
+
isHomeTab = pathName === homeUrl;
|
|
1499
|
+
_context10.n = 3;
|
|
1500
|
+
return findDuplicateEntriesAndCloseTab(response.tabs);
|
|
1501
|
+
case 3:
|
|
1502
|
+
tabsOutputWithoutDuplicates = _context10.v;
|
|
1503
|
+
tabsOutput = removeTabsWithoutAccess(tabsOutputWithoutDuplicates);
|
|
1504
|
+
_activeTab = null;
|
|
1505
|
+
_activeSubTab = null;
|
|
1506
|
+
currentActiveTab = null;
|
|
1507
|
+
homeTabIdRef.current = tabsOutput.find(function (tab) {
|
|
1508
|
+
return tab.level === 0;
|
|
1509
|
+
}).id;
|
|
1510
|
+
|
|
1511
|
+
// This needs to be handled with props as optional as should we redirect to subtab on not
|
|
1512
|
+
if (shouldRedirectToSubTab && isHomeTab && response !== null && response !== void 0 && (_response$current_tab = response.current_tab) !== null && _response$current_tab !== void 0 && _response$current_tab.level && ((_response$current_tab2 = response.current_tab) === null || _response$current_tab2 === void 0 ? void 0 : _response$current_tab2.level) !== 0) {
|
|
1513
|
+
_response$current_tab3 = response.current_tab, tab_info = _response$current_tab3.tab_info, rest = _objectWithoutProperties(_response$current_tab3, _excluded4);
|
|
1514
|
+
flattenedObj = _objectSpread(_objectSpread(_objectSpread({}, rest), tab_info), {}, {
|
|
1515
|
+
tabId: rest.id,
|
|
1516
|
+
subTabs: []
|
|
1517
|
+
});
|
|
1518
|
+
_activeTab = flattenedObj;
|
|
1519
|
+
// lastOpenedUrl.current[activeTab.id] = activeTab.url;
|
|
1520
|
+
pathName = (_activeTab2 = _activeTab) === null || _activeTab2 === void 0 ? void 0 : _activeTab2.url;
|
|
1521
|
+
if (_activeTab.level > 1) {
|
|
1522
|
+
_activeSubTab = _activeTab;
|
|
1523
|
+
// lastOpenedUrl.current[activeTab.id] = activeSubTab.url;
|
|
1524
|
+
}
|
|
1525
|
+
isHomeTab = false;
|
|
1526
|
+
history.replace(pathName);
|
|
1527
|
+
}
|
|
1528
|
+
isCurrentTabOpen = !isHomeTab && tabsOutput.find(function (tab) {
|
|
1529
|
+
var _tab$tab_info$url;
|
|
1530
|
+
return ((_tab$tab_info$url = tab.tab_info.url) === null || _tab$tab_info$url === void 0 || (_tab$tab_info$url = _tab$tab_info$url.split('?')) === null || _tab$tab_info$url === void 0 ? void 0 : _tab$tab_info$url[0]) === pathName;
|
|
1531
|
+
});
|
|
1532
|
+
if (isCurrentTabOpen) {
|
|
1533
|
+
_context10.n = 11;
|
|
1534
|
+
break;
|
|
1535
|
+
}
|
|
1536
|
+
openedParentTab = SITE_PAGES.find(function (page) {
|
|
1537
|
+
return page.url === pathName;
|
|
1538
|
+
});
|
|
1539
|
+
if (!openedParentTab) {
|
|
1540
|
+
_context10.n = 7;
|
|
1541
|
+
break;
|
|
1542
|
+
}
|
|
1543
|
+
if (!hasPrivilege(openedParentTab.privilege)) {
|
|
1544
|
+
_context10.n = 5;
|
|
1545
|
+
break;
|
|
1546
|
+
}
|
|
1547
|
+
_context10.n = 4;
|
|
1548
|
+
return openTab({
|
|
1549
|
+
tab: openedParentTab
|
|
1550
|
+
});
|
|
1551
|
+
case 4:
|
|
1552
|
+
updatedParentTab = _context10.v;
|
|
1553
|
+
flattenedParentObj = _objectSpread(_objectSpread(_objectSpread({}, updatedParentTab), updatedParentTab.tab_info), {}, {
|
|
1554
|
+
tabId: updatedParentTab.id
|
|
1555
|
+
});
|
|
1556
|
+
_activeTab = flattenedParentObj;
|
|
1557
|
+
tabsOutput.push(updatedParentTab);
|
|
1558
|
+
_context10.n = 6;
|
|
1559
|
+
break;
|
|
1560
|
+
case 5:
|
|
1561
|
+
history.push(homeUrl);
|
|
1562
|
+
case 6:
|
|
1563
|
+
_context10.n = 10;
|
|
1564
|
+
break;
|
|
1565
|
+
case 7:
|
|
1566
|
+
if (isHomeTab) {
|
|
1567
|
+
_context10.n = 10;
|
|
1568
|
+
break;
|
|
1569
|
+
}
|
|
1570
|
+
parentTab = (0, _Utils.findBestMatchFromPages)([(0, _Utils.getHomeTab)(homeUrl)].concat(_toConsumableArray(SITE_PAGES)), pathName);
|
|
1571
|
+
if (!parentTab) {
|
|
1572
|
+
_context10.n = 10;
|
|
1573
|
+
break;
|
|
1574
|
+
}
|
|
1575
|
+
parentTabFromData = tabsOutput.find(function (tab) {
|
|
1576
|
+
return tab.tab_info.id === parentTab.id;
|
|
1577
|
+
});
|
|
1578
|
+
if (parentTabFromData) {
|
|
1579
|
+
_context10.n = 9;
|
|
1580
|
+
break;
|
|
1581
|
+
}
|
|
1582
|
+
_context10.n = 8;
|
|
1583
|
+
return openTab({
|
|
1584
|
+
tab: parentTab
|
|
1585
|
+
});
|
|
1586
|
+
case 8:
|
|
1587
|
+
parentTabFromData = _context10.v;
|
|
1588
|
+
tabsOutput.push(parentTabFromData);
|
|
1589
|
+
case 9:
|
|
1590
|
+
_flattenedParentObj = parentTabFromData ? _objectSpread(_objectSpread(_objectSpread({}, parentTabFromData), parentTabFromData.tab_info), {}, {
|
|
1591
|
+
tabId: parentTabFromData.id
|
|
1592
|
+
}) : null;
|
|
1593
|
+
delete _flattenedParentObj.tab_info;
|
|
1594
|
+
_activeTab = _flattenedParentObj !== null && _flattenedParentObj !== void 0 ? _flattenedParentObj : parentTab;
|
|
1595
|
+
_activeSubTab = _objectSpread(_objectSpread({}, parentTab), {}, {
|
|
1596
|
+
id: "sub_".concat(parentTab.id),
|
|
1597
|
+
url: pathName,
|
|
1598
|
+
name: 'Loading...',
|
|
1599
|
+
title: ''
|
|
1600
|
+
});
|
|
1601
|
+
if ((_activeSubTabRef$curr6 = activeSubTabRef.current) !== null && _activeSubTabRef$curr6 !== void 0 && _activeSubTabRef$curr6.tabId) _activeSubTab.tabId = activeSubTabRef.current.tabId;
|
|
1602
|
+
case 10:
|
|
1603
|
+
_context10.n = 12;
|
|
1604
|
+
break;
|
|
1605
|
+
case 11:
|
|
1606
|
+
_tab_info = isCurrentTabOpen.tab_info, _rest = _objectWithoutProperties(isCurrentTabOpen, _excluded5);
|
|
1607
|
+
_flattenedObj = _objectSpread(_objectSpread(_objectSpread({}, _rest), _tab_info), {}, {
|
|
1608
|
+
tabId: _rest.id
|
|
1609
|
+
});
|
|
1610
|
+
isSubTab = isCurrentTabOpen.level !== 1;
|
|
1611
|
+
if (isSubTab) {
|
|
1612
|
+
parent = tabsOutput.find(function (tab) {
|
|
1613
|
+
return tab.id === _flattenedObj.parent_tab_id;
|
|
1614
|
+
});
|
|
1615
|
+
parentTabInfo = parent.tab_info, parentRest = _objectWithoutProperties(parent, _excluded6);
|
|
1616
|
+
_flattenedParentObj2 = _objectSpread(_objectSpread(_objectSpread({}, parentRest), parentTabInfo), {}, {
|
|
1617
|
+
tabId: parentRest.id
|
|
1618
|
+
});
|
|
1619
|
+
_activeTab = _flattenedParentObj2;
|
|
1620
|
+
_activeSubTab = _flattenedObj;
|
|
1621
|
+
} else {
|
|
1622
|
+
_activeTab = _flattenedObj;
|
|
1623
|
+
}
|
|
1624
|
+
currentActiveTab = {
|
|
1625
|
+
tab: _flattenedObj,
|
|
1626
|
+
isSubTab: isSubTab,
|
|
1627
|
+
parentId: _flattenedObj.parent_tab_id
|
|
1628
|
+
};
|
|
1629
|
+
case 12:
|
|
1630
|
+
tabsMap = {};
|
|
1631
|
+
restTabs = [];
|
|
1632
|
+
tabsOutput.sort(function (a, b) {
|
|
1633
|
+
return a.level - b.level;
|
|
1634
|
+
}).forEach(function (obj) {
|
|
1635
|
+
var tab_info = obj.tab_info,
|
|
1636
|
+
rest = _objectWithoutProperties(obj, _excluded7);
|
|
1637
|
+
var flattenedObj = _objectSpread(_objectSpread(_objectSpread({}, rest), tab_info), {}, {
|
|
1638
|
+
tabId: rest.id,
|
|
1639
|
+
subTabs: []
|
|
1640
|
+
});
|
|
1641
|
+
tabsMap[flattenedObj.tabId] = flattenedObj;
|
|
1642
|
+
if (flattenedObj.level !== 0) {
|
|
1643
|
+
if (flattenedObj.parent_tab_id in tabsMap) {
|
|
1644
|
+
tabsMap[flattenedObj.parent_tab_id].subTabs.push(flattenedObj);
|
|
1645
|
+
} else {
|
|
1646
|
+
tabsMap[flattenedObj.parent_tab_id] = {
|
|
1647
|
+
subTabs: [flattenedObj]
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
});
|
|
1652
|
+
|
|
1653
|
+
// Collect top-level tabs that have children
|
|
1654
|
+
for (id in tabsMap) {
|
|
1655
|
+
if (tabsMap[id].level === 0 && tabsMap[id].subTabs.length > 0) {
|
|
1656
|
+
tabsMap[id].subTabs = (_tabsMap$id = tabsMap[id]) === null || _tabsMap$id === void 0 || (_tabsMap$id = _tabsMap$id.subTabs) === null || _tabsMap$id === void 0 ? void 0 : _tabsMap$id.map(function (tab) {
|
|
1657
|
+
var _tab$subTabs;
|
|
1658
|
+
if ((tab === null || tab === void 0 || (_tab$subTabs = tab.subTabs) === null || _tab$subTabs === void 0 ? void 0 : _tab$subTabs.length) > 0) {
|
|
1659
|
+
var level2Tabs = tab.subTabs.filter(function (subTab) {
|
|
1660
|
+
return subTab.level === 2;
|
|
1661
|
+
});
|
|
1662
|
+
// level2Tabs.sort((a, b) => a.order - b.order); // Sort by the existing order
|
|
1663
|
+
tab.subTabs = level2Tabs.map(function (subTab, index) {
|
|
1664
|
+
subTab.open_order = index + 1;
|
|
1665
|
+
return subTab;
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
return tab;
|
|
1669
|
+
});
|
|
1670
|
+
sortSubTabs(tabsMap[id]);
|
|
1671
|
+
restTabs.push.apply(restTabs, _toConsumableArray(tabsMap[id].subTabs));
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
if (!isHomeTab) {
|
|
1675
|
+
// Update the tab mode preference in localStorage
|
|
1676
|
+
tabId = (_activeSubTab$tabId = (_activeSubTab2 = _activeSubTab) === null || _activeSubTab2 === void 0 ? void 0 : _activeSubTab2.tabId) !== null && _activeSubTab$tabId !== void 0 ? _activeSubTab$tabId : (_activeTab3 = _activeTab) === null || _activeTab3 === void 0 ? void 0 : _activeTab3.tabId;
|
|
1677
|
+
if (tabId) {
|
|
1678
|
+
isEditMode = new URLSearchParams(location.search).get("edit") === "true";
|
|
1679
|
+
tempTabModePreference = JSON.parse(localStorage.getItem(SITE_PREFIX + "tab_mode_preference") || "[]"); // Here we are using localStorage to avoid re-rendering the component when tabModePreference is updated ( Do not use tabModePreference directly here as it will cause memory leak )
|
|
1680
|
+
if (isEditMode) {
|
|
1681
|
+
if (!tempTabModePreference.includes(tabId)) {
|
|
1682
|
+
setTabModePreference([].concat(_toConsumableArray(tempTabModePreference), [tabId]));
|
|
1683
|
+
}
|
|
1684
|
+
} else {
|
|
1685
|
+
updated = tempTabModePreference.filter(function (id) {
|
|
1686
|
+
return id !== tabId;
|
|
1687
|
+
});
|
|
1688
|
+
if (updated.length !== tempTabModePreference.length) {
|
|
1689
|
+
setTabModePreference(updated);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
updateTabs(restTabs);
|
|
1695
|
+
// if (!activeTab) {
|
|
1696
|
+
// if (SITE_PAGES.find(page => page.url === formattedPathname)) { // add hasPrivilege
|
|
1697
|
+
// console.log('activeTab if', activeTab, formattedPathname);
|
|
1698
|
+
// // check privilege and open tab if found and make sure to replace the tab with latest info
|
|
1699
|
+
// activeTab = SITE_PAGES.find(page => page.url === formattedPathname);
|
|
1700
|
+
// }
|
|
1701
|
+
// }
|
|
1702
|
+
|
|
1703
|
+
if (_activeTab) {
|
|
1704
|
+
setActiveTab(_activeTab);
|
|
1705
|
+
activeTabRef.current = _activeTab;
|
|
1706
|
+
lastOpenedUrl.current[currentEntityId + '_' + _activeTab.id] = _activeTab;
|
|
1707
|
+
// if (isDefaultExpanded) updateExpandedID(activeTab.id);
|
|
1708
|
+
}
|
|
1709
|
+
if (_activeSubTab) {
|
|
1710
|
+
setActiveSubTab(_activeSubTab);
|
|
1711
|
+
activeSubTabRef.current = _activeSubTab;
|
|
1712
|
+
lastOpenedUrl.current[currentEntityId + '_' + _activeTab.id] = _activeSubTab;
|
|
1713
|
+
}
|
|
1714
|
+
if (currentActiveTab && currentActiveTab.tab.url !== ((_response$current_tab4 = response.current_tab) === null || _response$current_tab4 === void 0 || (_response$current_tab4 = _response$current_tab4.tab_info) === null || _response$current_tab4 === void 0 ? void 0 : _response$current_tab4.url)) {
|
|
1715
|
+
updateCurrentTab(currentActiveTab);
|
|
1716
|
+
}
|
|
1717
|
+
setIsTabDataLoaded(true);
|
|
1718
|
+
_context10.n = 17;
|
|
1719
|
+
break;
|
|
1720
|
+
case 13:
|
|
1721
|
+
if (!(response !== null && response !== void 0 && response.hasNoTabs)) {
|
|
1722
|
+
_context10.n = 15;
|
|
1723
|
+
break;
|
|
1724
|
+
}
|
|
1725
|
+
_context10.n = 14;
|
|
1726
|
+
return openTab({
|
|
1727
|
+
tab: (0, _Utils.getHomeTab)(homeUrl),
|
|
1728
|
+
isHomeTab: true
|
|
1729
|
+
});
|
|
1730
|
+
case 14:
|
|
1731
|
+
if (retainTabsAfterEntityChange) {
|
|
1732
|
+
if (tabsRef.current.length > 0) {
|
|
1733
|
+
tabsRef.current.forEach(/*#__PURE__*/function () {
|
|
1734
|
+
var _ref30 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(retainedTab) {
|
|
1735
|
+
return _regenerator().w(function (_context1) {
|
|
1736
|
+
while (1) switch (_context1.n) {
|
|
1737
|
+
case 0:
|
|
1738
|
+
_context1.n = 1;
|
|
1739
|
+
return openTab({
|
|
1740
|
+
tab: retainedTab,
|
|
1741
|
+
isHomeTab: false,
|
|
1742
|
+
isSubTab: false
|
|
1743
|
+
});
|
|
1744
|
+
case 1:
|
|
1745
|
+
return _context1.a(2);
|
|
1746
|
+
}
|
|
1747
|
+
}, _callee1);
|
|
1748
|
+
}));
|
|
1749
|
+
return function (_x3) {
|
|
1750
|
+
return _ref30.apply(this, arguments);
|
|
1751
|
+
};
|
|
1752
|
+
}());
|
|
1753
|
+
if (activeTab.url) {
|
|
1754
|
+
history.push(activeTab.url);
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
setIsTabDataLoaded(true);
|
|
1759
|
+
return _context10.a(2);
|
|
1760
|
+
case 15:
|
|
1761
|
+
if (!(response instanceof DOMException && response.name === 'AbortError')) {
|
|
1762
|
+
_context10.n = 16;
|
|
1763
|
+
break;
|
|
1764
|
+
}
|
|
1765
|
+
return _context10.a(2);
|
|
1766
|
+
case 16:
|
|
1767
|
+
throw new Error((response === null || response === void 0 ? void 0 : response.msg) || (response === null || response === void 0 ? void 0 : response.message) || 'Error fetching tabs');
|
|
1768
|
+
case 17:
|
|
1769
|
+
_context10.n = 19;
|
|
1770
|
+
break;
|
|
1771
|
+
case 18:
|
|
1772
|
+
_context10.p = 18;
|
|
1773
|
+
_t8 = _context10.v;
|
|
1774
|
+
if (window.isDebugOn) {
|
|
1775
|
+
alertService === null || alertService === void 0 || alertService.error(_t8.message ? _t8.message : 'Error in fetching tabs!');
|
|
1776
|
+
}
|
|
1777
|
+
console.log("fetchTabDetails - error", _t8);
|
|
1778
|
+
setIsTabDataLoadFailed(true);
|
|
1779
|
+
case 19:
|
|
1780
|
+
_context10.p = 19;
|
|
1781
|
+
tabsRef.current = tabsRef.current.map(function (tab) {
|
|
1782
|
+
return _objectSpread(_objectSpread({}, tab), {}, {
|
|
1783
|
+
isClientChanged: false
|
|
1784
|
+
});
|
|
1785
|
+
});
|
|
1786
|
+
return _context10.f(19);
|
|
1787
|
+
case 20:
|
|
1788
|
+
return _context10.a(2);
|
|
1789
|
+
}
|
|
1790
|
+
}, _callee10, null, [[0, 18, 19, 20]]);
|
|
1791
|
+
}));
|
|
1792
|
+
return function fetchTabDetails() {
|
|
1793
|
+
return _ref29.apply(this, arguments);
|
|
1794
|
+
};
|
|
1795
|
+
}();
|
|
1796
|
+
fetchTabDetails({
|
|
1797
|
+
controller: controller
|
|
1798
|
+
});
|
|
1799
|
+
}
|
|
1800
|
+
return function () {
|
|
1801
|
+
return controller.abort();
|
|
1802
|
+
};
|
|
1803
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1804
|
+
}, [getTabs, openTab, updateCurrentTab, currentEntityId, removeTabsWithoutAccess]);
|
|
1805
|
+
(0, _react.useEffect)(function () {
|
|
1806
|
+
return function () {
|
|
1807
|
+
homeTabIdRef.current = null;
|
|
1808
|
+
//remove all subtabs on client change but retain level 1 tab
|
|
1809
|
+
if (retainTabsAfterEntityChange) {
|
|
1810
|
+
setTabs(function (prev) {
|
|
1811
|
+
return prev.map(function (tab) {
|
|
1812
|
+
return _objectSpread(_objectSpread({}, tab), {}, {
|
|
1813
|
+
subTabs: []
|
|
1814
|
+
});
|
|
1815
|
+
});
|
|
1816
|
+
});
|
|
1817
|
+
tabsRef.current = tabsRef.current.map(function (tab) {
|
|
1818
|
+
return _objectSpread(_objectSpread({}, tab), {}, {
|
|
1819
|
+
subTabs: [],
|
|
1820
|
+
isClientChanged: true
|
|
1821
|
+
});
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
};
|
|
1825
|
+
}, [currentEntityId]);
|
|
1826
|
+
(0, _react.useEffect)(function () {
|
|
1827
|
+
return function () {
|
|
1828
|
+
clearTimeout(expandedTabIDTimeoutRef.current);
|
|
1829
|
+
clearTimeout(closingUnexpandedSubTabTimeoutRef.current);
|
|
1830
|
+
clearTimeout(openingUnexpandedSubTabTimeoutRef.current);
|
|
1831
|
+
};
|
|
1832
|
+
}, []);
|
|
1833
|
+
return /*#__PURE__*/React.createElement(TabContext.Provider, {
|
|
1834
|
+
value: {
|
|
1835
|
+
activeTab: activeTab,
|
|
1836
|
+
activeTabRef: activeTabRef,
|
|
1837
|
+
activeSubTab: activeSubTab,
|
|
1838
|
+
activeSubTabRef: activeSubTabRef,
|
|
1839
|
+
closingUnexpandedSubTab: closingUnexpandedSubTab,
|
|
1840
|
+
setClosingUnexpandedSubTab: setClosingUnexpandedSubTab,
|
|
1841
|
+
closingUnexpandedSubTabTimeoutRef: closingUnexpandedSubTabTimeoutRef,
|
|
1842
|
+
openingUnexpandedSubTab: openingUnexpandedSubTab,
|
|
1843
|
+
setOpeningUnexpandedSubTab: setOpeningUnexpandedSubTab,
|
|
1844
|
+
openingUnexpandedSubTabTimeoutRef: openingUnexpandedSubTabTimeoutRef,
|
|
1845
|
+
tabsRef: tabsRef,
|
|
1846
|
+
currentOpenTabCallerRef: currentOpenTabCallerRef,
|
|
1847
|
+
isTabDataLoaded: isTabDataLoaded,
|
|
1848
|
+
isTabDataLoadFailed: isTabDataLoadFailed,
|
|
1849
|
+
lastOpenedUrl: lastOpenedUrl,
|
|
1850
|
+
SITE_PAGES: SITE_PAGES,
|
|
1851
|
+
SITE_PREFIX: SITE_PREFIX,
|
|
1852
|
+
tabs: tabs,
|
|
1853
|
+
currentEntityId: currentEntityId,
|
|
1854
|
+
superTabsWrapperElemRef: superTabsWrapperElemRef,
|
|
1855
|
+
maxWidth: maxWidth,
|
|
1856
|
+
subTabChange: subTabChange,
|
|
1857
|
+
expandedTabID: expandedTabID,
|
|
1858
|
+
updateExpandedID: updateExpandedID,
|
|
1859
|
+
subTabWrapperWidth: subTabWrapperWidth,
|
|
1860
|
+
setSubTabWrapperWidth: setSubTabWrapperWidth,
|
|
1861
|
+
expandedTabIDRef: expandedTabIDRef,
|
|
1862
|
+
updateMaxWidth: updateMaxWidth,
|
|
1863
|
+
setSubTabChange: setSubTabChange,
|
|
1864
|
+
updateSubTabChange: updateSubTabChange,
|
|
1865
|
+
resetMaxWidth: resetMaxWidth,
|
|
1866
|
+
updateCurrentTab: updateCurrentTab,
|
|
1867
|
+
closeTab: closeTab,
|
|
1868
|
+
reorderTabs: reorderTabs,
|
|
1869
|
+
openTab: openTab,
|
|
1870
|
+
openSubTab: openSubTab,
|
|
1871
|
+
modifyTab: modifyTab,
|
|
1872
|
+
openSuperTabOnRowClick: openSuperTabOnRowClick,
|
|
1873
|
+
updateCurrentEntityId: updateCurrentEntityId,
|
|
1874
|
+
handleTabModeChange: handleTabModeChange,
|
|
1875
|
+
getUserDetails: getUserDetails,
|
|
1876
|
+
hasPrivilege: hasPrivilege,
|
|
1877
|
+
updateActiveTab: updateActiveTab,
|
|
1878
|
+
updateActiveSubTab: updateActiveSubTab,
|
|
1879
|
+
updateTabProperty: updateTabProperty,
|
|
1880
|
+
updateTabs: updateTabs,
|
|
1881
|
+
homeUrl: homeUrl,
|
|
1882
|
+
preventHomeRedirect: preventHomeRedirect,
|
|
1883
|
+
hiddenExternalToolbars: hiddenExternalToolbars,
|
|
1884
|
+
showExternalToolbar: showExternalToolbar,
|
|
1885
|
+
hideExternalToolbar: hideExternalToolbar,
|
|
1886
|
+
tabModePreference: tabModePreference,
|
|
1887
|
+
discardSubTabWrapperWidth: discardSubTabWrapperWidth,
|
|
1888
|
+
isMobileView: isMobileView,
|
|
1889
|
+
isDefaultExpanded: isDefaultExpanded
|
|
1890
|
+
}
|
|
1891
|
+
}, children);
|
|
1892
|
+
}
|
|
1893
|
+
function useTabContext() {
|
|
1894
|
+
return (0, _react.useContext)(TabContext);
|
|
1895
|
+
}
|