@gen3/frontend 0.11.25 → 0.11.27

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.
Files changed (151) hide show
  1. package/dist/cjs/index.js +257 -4
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/dts/components/Buttons/index.d.ts +1 -0
  4. package/dist/dts/components/Buttons/index.d.ts.map +1 -1
  5. package/dist/dts/components/Buttons/index.js +1 -0
  6. package/dist/dts/components/Buttons/index.js.map +1 -1
  7. package/dist/dts/components/Providers/Gen3Provider.d.ts +6 -6
  8. package/dist/dts/components/SegmentedControl.stories.d.ts +374 -0
  9. package/dist/dts/components/SegmentedControl.stories.d.ts.map +1 -0
  10. package/dist/dts/components/SegmentedControl.stories.js +28 -0
  11. package/dist/dts/components/SegmentedControl.stories.js.map +1 -0
  12. package/dist/dts/features/Analysis/AnalysisCardCompact.stories.d.ts +4 -4
  13. package/dist/dts/features/CohortBuilder/ExplorerTable/AccessCellRenderers.d.ts +3 -0
  14. package/dist/dts/features/CohortBuilder/ExplorerTable/AccessCellRenderers.d.ts.map +1 -0
  15. package/dist/dts/features/CohortBuilder/ExplorerTable/AccessCellRenderers.js +46 -0
  16. package/dist/dts/features/CohortBuilder/ExplorerTable/AccessCellRenderers.js.map +1 -0
  17. package/dist/dts/features/CohortBuilder/ExplorerTable/ArrayCellRenderer.d.ts +1 -1
  18. package/dist/dts/features/CohortBuilder/Repository/Repository.d.ts +4 -0
  19. package/dist/dts/features/CohortBuilder/Repository/Repository.d.ts.map +1 -0
  20. package/dist/dts/features/CohortBuilder/Repository/Repository.js +8 -0
  21. package/dist/dts/features/CohortBuilder/Repository/Repository.js.map +1 -0
  22. package/dist/dts/features/CohortBuilder/Repository/index.d.ts +4 -0
  23. package/dist/dts/features/CohortBuilder/Repository/index.d.ts.map +1 -0
  24. package/dist/dts/features/CohortBuilder/Repository/index.js +3 -0
  25. package/dist/dts/features/CohortBuilder/Repository/index.js.map +1 -0
  26. package/dist/dts/features/CohortBuilder/Repository/types.d.ts +12 -0
  27. package/dist/dts/features/CohortBuilder/Repository/types.d.ts.map +1 -0
  28. package/dist/dts/features/CohortBuilder/Repository/types.js.map +1 -0
  29. package/dist/dts/lib/session/session.d.ts.map +1 -1
  30. package/dist/dts/lib/session/session.js +36 -1
  31. package/dist/dts/lib/session/session.js.map +1 -1
  32. package/dist/dts/pages/Repository/Repository.d.ts +4 -0
  33. package/dist/dts/pages/Repository/Repository.d.ts.map +1 -0
  34. package/dist/dts/pages/Repository/Repository.js +24 -0
  35. package/dist/dts/pages/Repository/Repository.js.map +1 -0
  36. package/dist/dts/pages/Repository/data.d.ts +4 -0
  37. package/dist/dts/pages/Repository/data.d.ts.map +1 -0
  38. package/dist/dts/{features/CohortBuilder/CohortManager/cohortActionHooks.js → pages/Repository/data.js} +55 -42
  39. package/dist/dts/pages/Repository/data.js.map +1 -0
  40. package/dist/dts/pages/Repository/index.d.ts +4 -0
  41. package/dist/dts/pages/Repository/index.d.ts.map +1 -0
  42. package/dist/dts/pages/Repository/index.js +4 -0
  43. package/dist/dts/pages/Repository/index.js.map +1 -0
  44. package/dist/dts/pages/Repository/types.d.ts +6 -0
  45. package/dist/dts/pages/Repository/types.d.ts.map +1 -0
  46. package/dist/dts/pages/Repository/types.js +2 -0
  47. package/dist/dts/pages/Repository/types.js.map +1 -0
  48. package/dist/dts/types/icons.d.ts +2 -2
  49. package/dist/dts/types/icons.d.ts.map +1 -1
  50. package/dist/dts/types/icons.js +2 -2
  51. package/dist/dts/types/icons.js.map +1 -1
  52. package/dist/esm/index.js +259 -6
  53. package/dist/esm/index.js.map +1 -1
  54. package/dist/index.d.ts +6 -6
  55. package/dist/tsconfig.tsbuildinfo +1 -1
  56. package/package.json +3 -3
  57. package/dist/dts/components/DropdownMenu/DropdownMenu.d.ts +0 -64
  58. package/dist/dts/components/DropdownMenu/DropdownMenu.d.ts.map +0 -1
  59. package/dist/dts/components/DropdownMenu/DropdownMenu.js +0 -38
  60. package/dist/dts/components/DropdownMenu/DropdownMenu.js.map +0 -1
  61. package/dist/dts/components/DropdownMenu/DropdownMenu.unit.test.d.ts +0 -2
  62. package/dist/dts/components/DropdownMenu/DropdownMenu.unit.test.d.ts.map +0 -1
  63. package/dist/dts/components/DropdownMenu/DropdownMenu.unit.test.js +0 -141
  64. package/dist/dts/components/DropdownMenu/DropdownMenu.unit.test.js.map +0 -1
  65. package/dist/dts/components/DropdownMenu/index.d.ts +0 -3
  66. package/dist/dts/components/DropdownMenu/index.d.ts.map +0 -1
  67. package/dist/dts/components/DropdownMenu/index.js +0 -3
  68. package/dist/dts/components/DropdownMenu/index.js.map +0 -1
  69. package/dist/dts/components/MessageCards/ErrorMessage.d.ts +0 -7
  70. package/dist/dts/components/MessageCards/ErrorMessage.d.ts.map +0 -1
  71. package/dist/dts/components/MessageCards/ErrorMessage.js +0 -8
  72. package/dist/dts/components/MessageCards/ErrorMessage.js.map +0 -1
  73. package/dist/dts/features/CohortBuilder/CohortManager/CohortActions.d.ts +0 -20
  74. package/dist/dts/features/CohortBuilder/CohortManager/CohortActions.d.ts.map +0 -1
  75. package/dist/dts/features/CohortBuilder/CohortManager/CohortActions.js +0 -37
  76. package/dist/dts/features/CohortBuilder/CohortManager/CohortActions.js.map +0 -1
  77. package/dist/dts/features/CohortBuilder/CohortManager/CohortNotificationProvider.d.ts +0 -9
  78. package/dist/dts/features/CohortBuilder/CohortManager/CohortNotificationProvider.d.ts.map +0 -1
  79. package/dist/dts/features/CohortBuilder/CohortManager/CohortNotificationProvider.js +0 -122
  80. package/dist/dts/features/CohortBuilder/CohortManager/CohortNotificationProvider.js.map +0 -1
  81. package/dist/dts/features/CohortBuilder/CohortManager/CohortNotifications.d.ts +0 -19
  82. package/dist/dts/features/CohortBuilder/CohortManager/CohortNotifications.d.ts.map +0 -1
  83. package/dist/dts/features/CohortBuilder/CohortManager/CohortNotifications.js +0 -52
  84. package/dist/dts/features/CohortBuilder/CohortManager/CohortNotifications.js.map +0 -1
  85. package/dist/dts/features/CohortBuilder/CohortManager/CohortSelector.d.ts +0 -10
  86. package/dist/dts/features/CohortBuilder/CohortManager/CohortSelector.d.ts.map +0 -1
  87. package/dist/dts/features/CohortBuilder/CohortManager/CohortSelector.js +0 -37
  88. package/dist/dts/features/CohortBuilder/CohortManager/CohortSelector.js.map +0 -1
  89. package/dist/dts/features/CohortBuilder/CohortManager/CustomCohortSelectItem.d.ts +0 -13
  90. package/dist/dts/features/CohortBuilder/CohortManager/CustomCohortSelectItem.d.ts.map +0 -1
  91. package/dist/dts/features/CohortBuilder/CohortManager/CustomCohortSelectItem.js +0 -33
  92. package/dist/dts/features/CohortBuilder/CohortManager/CustomCohortSelectItem.js.map +0 -1
  93. package/dist/dts/features/CohortBuilder/CohortManager/cohortActionHooks.d.ts +0 -7
  94. package/dist/dts/features/CohortBuilder/CohortManager/cohortActionHooks.d.ts.map +0 -1
  95. package/dist/dts/features/CohortBuilder/CohortManager/cohortActionHooks.js.map +0 -1
  96. package/dist/dts/features/CohortBuilder/CohortManager/commonIcons.d.ts +0 -5
  97. package/dist/dts/features/CohortBuilder/CohortManager/commonIcons.d.ts.map +0 -1
  98. package/dist/dts/features/CohortBuilder/CohortManager/commonIcons.js +0 -5
  99. package/dist/dts/features/CohortBuilder/CohortManager/commonIcons.js.map +0 -1
  100. package/dist/dts/features/CohortBuilder/CohortManager/index.d.ts +0 -5
  101. package/dist/dts/features/CohortBuilder/CohortManager/index.d.ts.map +0 -1
  102. package/dist/dts/features/CohortBuilder/CohortManager/index.js +0 -4
  103. package/dist/dts/features/CohortBuilder/CohortManager/index.js.map +0 -1
  104. package/dist/dts/features/CohortBuilder/CohortManager/modals/GenericCohortModal.d.ts +0 -13
  105. package/dist/dts/features/CohortBuilder/CohortManager/modals/GenericCohortModal.d.ts.map +0 -1
  106. package/dist/dts/features/CohortBuilder/CohortManager/modals/GenericCohortModal.js +0 -15
  107. package/dist/dts/features/CohortBuilder/CohortManager/modals/GenericCohortModal.js.map +0 -1
  108. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveCohortErrorModal.d.ts +0 -4
  109. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveCohortErrorModal.d.ts.map +0 -1
  110. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveCohortErrorModal.js +0 -8
  111. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveCohortErrorModal.js.map +0 -1
  112. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveCohortModal.d.ts +0 -32
  113. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveCohortModal.d.ts.map +0 -1
  114. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveCohortModal.js +0 -190
  115. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveCohortModal.js.map +0 -1
  116. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveCohortModal.unit.test.d.ts +0 -2
  117. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveCohortModal.unit.test.d.ts.map +0 -1
  118. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveCohortModal.unit.test.js +0 -145
  119. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveCohortModal.unit.test.js.map +0 -1
  120. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveOrCreateEntityModal.d.ts +0 -29
  121. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveOrCreateEntityModal.d.ts.map +0 -1
  122. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveOrCreateEntityModal.js +0 -79
  123. package/dist/dts/features/CohortBuilder/CohortManager/modals/SaveOrCreateEntityModal.js.map +0 -1
  124. package/dist/dts/features/CohortBuilder/CohortManager/style.d.ts +0 -5
  125. package/dist/dts/features/CohortBuilder/CohortManager/style.d.ts.map +0 -1
  126. package/dist/dts/features/CohortBuilder/CohortManager/style.js +0 -21
  127. package/dist/dts/features/CohortBuilder/CohortManager/style.js.map +0 -1
  128. package/dist/dts/features/CohortBuilder/CohortManager/types.d.ts +0 -49
  129. package/dist/dts/features/CohortBuilder/CohortManager/types.d.ts.map +0 -1
  130. package/dist/dts/features/CohortBuilder/CohortManager/types.js.map +0 -1
  131. package/dist/dts/features/CohortBuilder/CohortManager.d.ts +0 -6
  132. package/dist/dts/features/CohortBuilder/CohortManager.d.ts.map +0 -1
  133. package/dist/dts/features/CohortBuilder/CohortManager.js +0 -8
  134. package/dist/dts/features/CohortBuilder/CohortManager.js.map +0 -1
  135. package/dist/dts/features/CohortDiscovery/CohortManagment/CohortStorage.d.ts +0 -64
  136. package/dist/dts/features/CohortDiscovery/CohortManagment/CohortStorage.d.ts.map +0 -1
  137. package/dist/dts/features/CohortDiscovery/CohortManagment/CohortStorage.js +0 -572
  138. package/dist/dts/features/CohortDiscovery/CohortManagment/CohortStorage.js.map +0 -1
  139. package/dist/dts/features/CohortDiscovery/CohortSelectors.d.ts +0 -1
  140. package/dist/dts/features/CohortDiscovery/CohortSelectors.d.ts.map +0 -1
  141. package/dist/dts/features/CohortDiscovery/CohortSelectors.js +0 -41
  142. package/dist/dts/features/CohortDiscovery/CohortSelectors.js.map +0 -1
  143. package/dist/dts/features/CohortDiscovery/CohortSlice.d.ts +0 -1
  144. package/dist/dts/features/CohortDiscovery/CohortSlice.d.ts.map +0 -1
  145. package/dist/dts/features/CohortDiscovery/CohortSlice.js +0 -162
  146. package/dist/dts/features/CohortDiscovery/CohortSlice.js.map +0 -1
  147. package/dist/dts/features/CohortDiscovery/SavedCohortManagerSlice.d.ts +0 -1
  148. package/dist/dts/features/CohortDiscovery/SavedCohortManagerSlice.d.ts.map +0 -1
  149. package/dist/dts/features/CohortDiscovery/SavedCohortManagerSlice.js +0 -284
  150. package/dist/dts/features/CohortDiscovery/SavedCohortManagerSlice.js.map +0 -1
  151. /package/dist/dts/features/CohortBuilder/{CohortManager → Repository}/types.js +0 -0
package/dist/cjs/index.js CHANGED
@@ -46,7 +46,7 @@ var MiniSearch = require('minisearch');
46
46
  var uniq = require('lodash/uniq');
47
47
  var sum = require('lodash/sum');
48
48
  var lu = require('react-icons/lu');
49
- require('universal-cookie');
49
+ var Cookies = require('universal-cookie');
50
50
  var GraphiQL = require('graphiql');
51
51
  var fs = require('fs');
52
52
  var path = require('path');
@@ -880,6 +880,7 @@ const workspaceShutdownAlertLimit = 30000; // 5 minutes: 5 * 60 * 1000 TODO Figu
880
880
  }
881
881
  };
882
882
 
883
+ const ACTIVITY_CHANNEL = 'gen3-user-activity';
883
884
  const logoutSession = async ()=>{
884
885
  // logged in using credentials then execute credentials logout first
885
886
  const accessToken = cookiesNext.getCookie('credentials_token');
@@ -963,6 +964,27 @@ const UPDATE_SESSION_LIMIT = MinutesToMilliseconds(5);
963
964
  const [getUserDetails] = core.useLazyFetchUserDetailsQuery(); // Fetch user details
964
965
  const userStatus = core.useCoreSelector((state)=>core.selectUserAuthStatus(state));
965
966
  const [mostRecentActivityTimestamp, setMostRecentActivityTimestamp] = React.useState(Date.now());
967
+ const broadcastChannelRef = React.useRef(null);
968
+ // Initialize BroadcastChannel for cross-tab communication
969
+ // any user event on one tab or window will update mostRecentActivityTimestamp
970
+ React.useEffect(()=>{
971
+ if (typeof window !== 'undefined') {
972
+ broadcastChannelRef.current = new BroadcastChannel(ACTIVITY_CHANNEL);
973
+ // Listen for activity updates from other tabs
974
+ const handleActivityMessage = (event)=>{
975
+ if (event.data.type === 'activity-update') {
976
+ setMostRecentActivityTimestamp(event.data.timestamp);
977
+ }
978
+ };
979
+ broadcastChannelRef.current.addEventListener('message', handleActivityMessage);
980
+ return ()=>{
981
+ if (broadcastChannelRef.current) {
982
+ broadcastChannelRef.current.removeEventListener('message', handleActivityMessage);
983
+ broadcastChannelRef.current.close();
984
+ }
985
+ };
986
+ }
987
+ }, []);
966
988
  const [mostRecentSessionRefreshTimestamp, setMostRecentSessionRefreshTimestamp] = React.useState(Date.now());
967
989
  const inactiveTimeLimitMilliseconds = MinutesToMilliseconds(inactiveTimeLimit);
968
990
  const workspaceInactivityTimeLimitMilliseconds = MinutesToMilliseconds(workspaceInactivityTimeLimit);
@@ -999,15 +1021,28 @@ const UPDATE_SESSION_LIMIT = MinutesToMilliseconds(5);
999
1021
  updateSession();
1000
1022
  if (updateSessionIntervalMilliseconds <= 0) return; // do not poll if updateSessionInterval is 0
1001
1023
  const updateUserActivity = ()=>{
1002
- setMostRecentActivityTimestamp(Date.now());
1024
+ const timestamp = Date.now();
1025
+ setMostRecentActivityTimestamp(timestamp);
1026
+ if (broadcastChannelRef.current) {
1027
+ broadcastChannelRef.current.postMessage({
1028
+ type: 'activity-update',
1029
+ timestamp
1030
+ });
1031
+ }
1003
1032
  };
1004
1033
  window.addEventListener('mousedown', updateUserActivity);
1005
1034
  window.addEventListener('keypress', updateUserActivity);
1006
1035
  window.addEventListener('updateUserActivity', updateUserActivity);
1036
+ window.addEventListener('scroll', updateUserActivity);
1037
+ window.addEventListener('click', updateUserActivity);
1038
+ window.addEventListener('touchstart', updateUserActivity);
1007
1039
  return ()=>{
1008
1040
  window.removeEventListener('mousedown', updateUserActivity);
1009
1041
  window.removeEventListener('keypress', updateUserActivity);
1010
1042
  window.removeEventListener('updateUserActivity', updateUserActivity);
1043
+ window.removeEventListener('scroll', updateUserActivity);
1044
+ window.removeEventListener('click', updateUserActivity);
1045
+ window.removeEventListener('touchstart', updateUserActivity);
1011
1046
  };
1012
1047
  }, []); // only call on mount/dismount
1013
1048
  useInterval(()=>{
@@ -1433,7 +1468,7 @@ const CredentialsLogin = ({ handleLogin })=>{
1433
1468
  };
1434
1469
 
1435
1470
  // separate function for hashing logic
1436
- function hashString(str) {
1471
+ function hashString$1(str) {
1437
1472
  let hash = 0;
1438
1473
  for(let i = 0; i < str.length; i++){
1439
1474
  hash = str.charCodeAt(i) + ((hash << 5) - hash);
@@ -1445,7 +1480,7 @@ function hashCode(str) {
1445
1480
  if (str === null || str === '') {
1446
1481
  return 0;
1447
1482
  }
1448
- return hashString(str);
1483
+ return hashString$1(str);
1449
1484
  }
1450
1485
 
1451
1486
  /**
@@ -11181,6 +11216,22 @@ const CountsValue = ({ label, isSuccess, counts })=>{
11181
11216
  });
11182
11217
  };
11183
11218
 
11219
+ const hashString = (s)=>s.split('').reduce((acc, c)=>(acc << 5) - acc + c.charCodeAt(0), 0);
11220
+ const getBody = (iframe)=>{
11221
+ const document1 = iframe?.contentWindow || iframe?.contentDocument;
11222
+ return document1?.document?.body || document1?.body;
11223
+ };
11224
+ const toHtml = (key, value)=>`<input
11225
+ type="hidden"
11226
+ name="${key}"
11227
+ value="${lodash.isPlainObject(value) ? JSON.stringify(value).replace(/"/g, '&quot;') : value}"
11228
+ />`;
11229
+ const customKeys = [
11230
+ 'expand',
11231
+ 'fields',
11232
+ 'facets'
11233
+ ];
11234
+ const processParamObj = (key, value)=>lodash.includes(customKeys, key) ? [].concat(value).join() : value;
11184
11235
  /**
11185
11236
  * A notification box that is used to alert the user that their
11186
11237
  * selected file downloads are in progress
@@ -11206,6 +11257,136 @@ const CountsValue = ({ label, isSuccess, counts })=>{
11206
11257
  ]
11207
11258
  });
11208
11259
  };
11260
+ /**
11261
+ * Trigger a download by attaching an iFrame to the document with the parameters of the request as fields in a form
11262
+ * @param endpoint - endpoint to be attached with
11263
+ * @param params - body to be attached with post request
11264
+ * @param method - Request Method: GET, PUT, POST
11265
+ * @param dispatch - dispatch send from the parent component to dispatch Modals
11266
+ * @param done - callback function to be called after the download has been initiated
11267
+ * @param Modal400 - Modal for 400 error
11268
+ * @param Modal403 - Modal for 403 error
11269
+ * @param customErrorMessage - custom message to be passed for 400 errors
11270
+ * @param hideNotification - hide the notification
11271
+ */ const download = async ({ endpoint, params, method, dispatch, done, Modal400 = core.Modals.GeneralErrorModal, Modal403 = core.Modals.NoAccessModal, customErrorMessage, hideNotification = false })=>{
11272
+ const cookies = new Cookies();
11273
+ /* Create a cookie with a unique identifier to attach to request. Response from server will use the set-cookie header
11274
+ to remove the cookie when the response is received (aka the download starts). This will only work on when the FE and BE
11275
+ are on the same domain.
11276
+ */ const downloadToken = lodash.uniqueId(`${+new Date()}-`);
11277
+ const cookieKey = navigator.cookieEnabled ? Math.abs(hashString(JSON.stringify(params) + downloadToken)).toString(16) : null;
11278
+ if (cookieKey) {
11279
+ cookies.set(cookieKey, downloadToken);
11280
+ }
11281
+ // place notification in timeout to avoid flicker on fast calls
11282
+ const showNotificationTimeout = setTimeout(()=>notifications.showNotification({
11283
+ message: /*#__PURE__*/ jsxRuntime.jsx(DownloadNotification, {
11284
+ onClick: ()=>{
11285
+ iFrame.remove();
11286
+ notifications.cleanNotifications();
11287
+ if (done) {
11288
+ done();
11289
+ }
11290
+ }
11291
+ }),
11292
+ styles: ()=>({
11293
+ root: {
11294
+ textAlign: 'center',
11295
+ display: hideNotification ? 'none' : 'block'
11296
+ },
11297
+ closeButton: {
11298
+ color: 'black',
11299
+ '&:hover': {
11300
+ backgroundColor: 'lightslategray'
11301
+ }
11302
+ }
11303
+ }),
11304
+ closeButtonProps: {
11305
+ 'aria-label': 'Close notification'
11306
+ }
11307
+ }), 100); // set to 100 as that is perceived as instant
11308
+ const fields = lodash.reduce({
11309
+ ...params,
11310
+ downloadCookieKey: cookieKey,
11311
+ downloadCookiePath: '/',
11312
+ attachment: true,
11313
+ ...params.filename !== undefined ? {
11314
+ download: params.filename
11315
+ } : {}
11316
+ }, (result, value, key)=>{
11317
+ const paramValue = processParamObj(key, value);
11318
+ return result + [].concat(paramValue).reduce((acc, v)=>acc + toHtml(key, v), '');
11319
+ }, '');
11320
+ const iFrame = document.createElement('iframe');
11321
+ iFrame.style.display = 'none';
11322
+ iFrame.src = 'about:blank';
11323
+ // Appending to document body to allow navigation away from the current
11324
+ // page and downloads in the background
11325
+ document.body.appendChild(iFrame);
11326
+ const pollForDownloadResult = async ()=>{
11327
+ const executePoll = async (resolve)=>{
11328
+ // Request has been canceled
11329
+ const body = getBody(iFrame);
11330
+ if (body === undefined) {
11331
+ resolve();
11332
+ return;
11333
+ }
11334
+ const content = body?.textContent;
11335
+ // Download has started
11336
+ if (cookieKey !== null && !cookies.get(cookieKey)) {
11337
+ clearTimeout(showNotificationTimeout);
11338
+ notifications.cleanNotifications();
11339
+ if (done) {
11340
+ done();
11341
+ }
11342
+ resolve();
11343
+ } else {
11344
+ const iFrameHasContent = iFrame.contentWindow?.document.body;
11345
+ const requestError = iFrame.contentWindow?.document.getElementsByTagName('form').length === 0 && content !== '';
11346
+ if (iFrameHasContent && requestError) {
11347
+ clearTimeout(showNotificationTimeout);
11348
+ notifications.cleanNotifications();
11349
+ const errorMessage = /{"(?:message|error)":"([^"]*)"/g.exec(content ?? 'Undefined')?.[1];
11350
+ if (errorMessage === 'internal server error' || errorMessage === undefined) {
11351
+ dispatch(core.showModal({
11352
+ modal: Modal400,
11353
+ message: errorMessage
11354
+ }));
11355
+ } else if (errorMessage === 'Your token is invalid or expired. Please get a new token.') {
11356
+ dispatch(core.showModal({
11357
+ modal: Modal403,
11358
+ message: errorMessage
11359
+ }));
11360
+ } else {
11361
+ dispatch(core.showModal({
11362
+ modal: Modal400,
11363
+ message: customErrorMessage || errorMessage
11364
+ }));
11365
+ }
11366
+ if (done) {
11367
+ done();
11368
+ }
11369
+ resolve();
11370
+ } else {
11371
+ setTimeout(executePoll, 1000, resolve);
11372
+ }
11373
+ }
11374
+ };
11375
+ return new Promise(executePoll);
11376
+ };
11377
+ const addFormAndSubmit = ()=>{
11378
+ //do all of this together for FireFox support
11379
+ const form = document.createElement('form');
11380
+ form.method = method.toUpperCase();
11381
+ form.action = endpoint;
11382
+ form.innerHTML = fields;
11383
+ getBody(iFrame).appendChild(form);
11384
+ form.submit();
11385
+ };
11386
+ addFormAndSubmit();
11387
+ await pollForDownloadResult();
11388
+ iFrame.remove();
11389
+ };
11209
11390
 
11210
11391
  const showErrorMessage = (error)=>{
11211
11392
  notifications.showNotification({
@@ -19739,6 +19920,78 @@ border-solid
19739
19920
  rounded-[7px]
19740
19921
  `;
19741
19922
 
19923
+ /**
19924
+ * A Button component that downloads data from a given endpoint.
19925
+ * The component will handle all download logic including fetching
19926
+ * the data, creating the file, and downloading the file.
19927
+ * @param endpoint - The endpoint to download from.
19928
+ * @param disabled - Whether the button is disabled.
19929
+ * @param inactiveText - The text to display when the button is inactive.
19930
+ * @param activeText - The text to display when the button is active.
19931
+ * @param filename - The name of the file to download.
19932
+ * @param size - The size of the download.
19933
+ * @param format - The format of the download.
19934
+ * @param fields - The fields to download.
19935
+ * @param caseFilters - The case filters to download.
19936
+ * @param filters - The filters to download.
19937
+ * @param extraParams - Any extra parameters to download.
19938
+ * @param method - The method to use for the download.
19939
+ * @param customStyle - Any custom styles to apply to the button.
19940
+ * @param showLoading - Whether to show the loading icon.
19941
+ * @param showIcon - Whether to show the download icon.
19942
+ * @param preventClickEvent - Whether to prevent the default click event.
19943
+ * @param onClick - The function to call when the button is clicked.
19944
+ * @param setActive - The function to call when the button is set active.
19945
+ * @param active - Whether the button is active.
19946
+ * @param Modal403 - The modal to display when a 403 error occurs.
19947
+ * @param Modal400 - The modal to display when a 400 error occurs.
19948
+ * @param toolTip - The tooltip to display.
19949
+ * @category Buttons
19950
+ */ const DownloadButton = /*#__PURE__*/ React.forwardRef(({ endpoint = '', disabled = false, inactiveText, activeText, params = {}, method = 'POST', customStyle, setActive, onClick, showLoading = true, showIcon = true, preventClickEvent = false, active, Modal400 = core.Modals.GeneralErrorModal, Modal403 = core.Modals.NoAccessModal, toolTip, ...buttonProps }, ref)=>{
19951
+ const text = active ? activeText : inactiveText;
19952
+ const dispatch = core.useCoreDispatch();
19953
+ const Icon = active ? /*#__PURE__*/ jsxRuntime.jsx(core$1.Loader, {
19954
+ size: "sm",
19955
+ className: "p-1"
19956
+ }) : /*#__PURE__*/ jsxRuntime.jsx(fi.FiDownload, {
19957
+ title: "download",
19958
+ size: 16
19959
+ });
19960
+ return /*#__PURE__*/ jsxRuntime.jsx(core$1.Tooltip, {
19961
+ disabled: !toolTip,
19962
+ label: toolTip,
19963
+ children: /*#__PURE__*/ jsxRuntime.jsx(core$1.Button, {
19964
+ ref: ref,
19965
+ leftSection: showIcon && inactiveText && /*#__PURE__*/ jsxRuntime.jsx(fi.FiDownload, {}),
19966
+ disabled: disabled,
19967
+ className: customStyle || `text-base-lightest ${disabled ? 'bg-base' : 'bg-primary hover:bg-primary-darker'} `,
19968
+ loading: showLoading && active,
19969
+ onClick: ()=>{
19970
+ if (!preventClickEvent && onClick) {
19971
+ onClick();
19972
+ return;
19973
+ }
19974
+ dispatch(core.hideModal());
19975
+ if (setActive) setActive(true);
19976
+ download({
19977
+ endpoint,
19978
+ params,
19979
+ method,
19980
+ dispatch,
19981
+ done: ()=>{
19982
+ if (setActive) setActive(false);
19983
+ },
19984
+ Modal400,
19985
+ Modal403
19986
+ });
19987
+ },
19988
+ ...buttonProps,
19989
+ children: text || Icon
19990
+ })
19991
+ });
19992
+ });
19993
+ DownloadButton.displayName = 'DownloadButton';
19994
+
19742
19995
  // Define theme for mantine v7
19743
19996
  const createMantineTheme = (fonts, colors)=>{
19744
19997
  const theme = core$1.createTheme({