@gen3/workspaces 0.12.78 → 0.12.80

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.
@@ -4,7 +4,7 @@ import { mergeDefaultTailwindClassnames, ACTIVITY_CHANNEL, convertSecondsToMilli
4
4
  import { Card, Stack, Badge, Text, List, Group, Tooltip, Button, Container, SimpleGrid, LoadingOverlay, Loader, Alert, Select, Divider, ActionIcon, Popover, Accordion, Radio, Progress, TextInput, Textarea, Table, Scroller, Tabs, Center } from '@mantine/core';
5
5
  import { Icon } from '@iconify-icon/react';
6
6
  import { useInterval, useElementSize, useDisclosure, useResizeObserver } from '@mantine/hooks';
7
- import { GEN3_API, GEN3_WORKSPACE_API, gen3Api, useCoreSelector, selectJEGActiveWorkspaceStatus, useCoreDispatch, setJEGActiveWorkspaceStatus, WorkspaceStatus, setJEGRequestedWorkspaceStatus, RequestedWorkspaceStatus, setJEGActiveWorkspaceId, isFetchBaseQueryError, selectJEGRequestedWorkspaceStatus, selectJEGRequestedWorkspaceStatusTimestamp, isTimeGreaterThan, formatUptimeInMinutes, selectJEGKernelIds, removeManyJEGActiveKernels, upsertManyJEGActiveKernels, normalizeRtkError, selectAllJEGKernels, addJEGActiveKernel, selectWorkspaceTier, setWorkspaceTier, useGetWorkspacePayModelsQuery, useSetCurrentPayModelMutation, selectWorkspaceFullscreen, setWorkspaceFullscreen, useGetDictionaryFromUrlQuery, useUserAuth, GEN3_COMMONS_NAME } from '@gen3/core';
7
+ import { GEN3_API, GEN3_WORKSPACE_API, gen3Api, useCoreSelector, selectJEGActiveWorkspaceStatus, useCoreDispatch, setJEGActiveWorkspaceStatus, WorkspaceStatus, setJEGRequestedWorkspaceStatus, RequestedWorkspaceStatus, setJEGActiveWorkspaceId, isFetchBaseQueryError, selectJEGRequestedWorkspaceStatus, selectJEGRequestedWorkspaceStatusTimestamp, isTimeGreaterThan, formatUptimeInMinutes, selectJEGKernelIds, removeManyJEGActiveKernels, upsertManyJEGActiveKernels, normalizeRtkError, selectAllJEGKernels, addJEGActiveKernel, selectWorkspaceTier, setWorkspaceTier, useGetWorkspacePayModelsQuery, useGetActivePayModelQuery, useSetCurrentPayModelMutation, selectWorkspaceFullscreen, setWorkspaceFullscreen, useGetDictionaryFromUrlQuery, useUserAuth, GEN3_COMMONS_NAME } from '@gen3/core';
8
8
  import { useDeepCompareEffect, useDeepCompareCallback, useDeepCompareMemo } from 'use-deep-compare';
9
9
  import { notifications } from '@mantine/notifications';
10
10
  import { MdExpandMore, MdOpenInNew, MdKeyboardArrowDown, MdKeyboardArrowRight } from 'react-icons/md';
@@ -2426,30 +2426,66 @@ const SettingsPanel = ({ showKernels, expanded, setExpanded, width = 380 })=>{
2426
2426
  });
2427
2427
  };
2428
2428
 
2429
- const PaymentNumberToString = (x, undefinedValue = 'N/A', precision = 2)=>{
2429
+ // TODO rework once requirements are made
2430
+ const usdFormatter = new Intl.NumberFormat('en-US', {
2431
+ style: 'currency',
2432
+ currency: 'USD'
2433
+ });
2434
+ const paymentNumberToString = (x, undefinedValue = 'N/A', precision = 2)=>{
2430
2435
  if (typeof x !== 'number' || Number.isNaN(x)) return undefinedValue;
2431
- return x.toFixed(precision);
2436
+ return usdFormatter.format(x);
2432
2437
  };
2433
2438
  const isNoPayModelError = (error)=>{
2434
2439
  return 'status' in error && error.status === 'PARSING_ERROR' && error.originalStatus === 404;
2435
2440
  };
2436
2441
  const CostTracker = ({ workspaceAccountManagerTarget = '' })=>{
2437
- const { data, isLoading, isFetching, isError, error } = useGetWorkspacePayModelsQuery(undefined, {
2442
+ const { data, isLoading, isFetching, isError, error, isSuccess } = useGetWorkspacePayModelsQuery(undefined, {
2438
2443
  pollingInterval: 120000,
2439
2444
  refetchOnMountOrArgChange: true
2440
2445
  });
2441
- const [setWorkspacePayModel] = useSetCurrentPayModelMutation();
2446
+ const { data: currentPaymodelData, isFetching: isCurrentPayModelFetching } = useGetActivePayModelQuery();
2447
+ const [setWorkspacePayModel, result] = useSetCurrentPayModelMutation();
2442
2448
  const [selectedPayModel, setSelectedPayModel] = useState(null);
2443
2449
  const [opened, setOpened] = useState(false);
2444
- useDeepCompareCallback((id)=>{
2445
- void setWorkspacePayModel(id); // triggers the call to the service to select the pay model
2450
+ const setPayModel = useDeepCompareCallback((id)=>{
2451
+ void setWorkspacePayModel(id).unwrap(); // triggers the call to the service to select the pay model
2446
2452
  setSelectedPayModel(id); // set the paymodel value for the select component
2447
2453
  }, [
2448
2454
  setWorkspacePayModel,
2449
2455
  selectedPayModel
2450
2456
  ]);
2451
2457
  const { usersPayModels, workspaceName, hardLimit, totalUsage } = useDeepCompareMemo(()=>{
2452
- if (!(data && data.currentPayModel !== null)) {
2458
+ if (isSuccess && data) {
2459
+ const usersPayModels = data?.allPayModels.map((payModel)=>{
2460
+ return {
2461
+ value: payModel.bmh_workspace_id ?? payModel.workspace_type,
2462
+ label: payModel.workspace_type,
2463
+ totalUsage: payModel['total-usage'],
2464
+ currentPayModel: payModel.current_pay_model ?? null,
2465
+ icon: payModel.request_status === 'active' ? /*#__PURE__*/ jsx(FaUser, {}) : /*#__PURE__*/ jsx(FaExclamationCircle, {})
2466
+ };
2467
+ });
2468
+ let currentPayModel = null;
2469
+ if (data?.currentPayModel) {
2470
+ currentPayModel = data?.currentPayModel.bmh_workspace_id ?? data?.currentPayModel.workspace_type;
2471
+ }
2472
+ setSelectedPayModel(currentPayModel);
2473
+ let workspaceName = 'Not Set';
2474
+ let totalUsage = undefined;
2475
+ let hardLimit = undefined;
2476
+ if (data.currentPayModel !== null) {
2477
+ workspaceName = data.currentPayModel.bmh_workspace_id.length > 0 ? data.currentPayModel.bmh_workspace_id : data.currentPayModel.workspace_type;
2478
+ totalUsage = data.currentPayModel?.['total-usage'];
2479
+ hardLimit = data.currentPayModel?.['hard-limit'];
2480
+ }
2481
+ return {
2482
+ usersPayModels,
2483
+ workspaceName,
2484
+ selectedPayModel,
2485
+ totalUsage,
2486
+ hardLimit
2487
+ };
2488
+ } else {
2453
2489
  return {
2454
2490
  usersPayModels: [],
2455
2491
  selectedPayModel: [],
@@ -2458,22 +2494,6 @@ const CostTracker = ({ workspaceAccountManagerTarget = '' })=>{
2458
2494
  hardLimit: undefined
2459
2495
  };
2460
2496
  }
2461
- const usersPayModels = data.allPayModels.map((payModel)=>{
2462
- return {
2463
- value: payModel.bmh_workspace_id ?? payModel.workspace_type,
2464
- label: payModel.workspace_type,
2465
- totalUsage: payModel['total-usage'],
2466
- currentPayModel: payModel['current_pay_model'],
2467
- icon: payModel.request_status === 'active' ? /*#__PURE__*/ jsx(FaUser, {}) : /*#__PURE__*/ jsx(FaExclamationCircle, {})
2468
- };
2469
- });
2470
- setSelectedPayModel(data.currentPayModel.bmh_workspace_id ?? data.currentPayModel.workspace_type);
2471
- return {
2472
- usersPayModels,
2473
- workspaceName: data.currentPayModel.bmh_workspace_id.length > 0 ? data.currentPayModel.bmh_workspace_id : data.currentPayModel.workspace_type,
2474
- totalUsage: data.currentPayModel['total-usage'],
2475
- hardLimit: data.currentPayModel['hard-limit']
2476
- };
2477
2497
  }, [
2478
2498
  data
2479
2499
  ]);
@@ -2553,8 +2573,8 @@ const CostTracker = ({ workspaceAccountManagerTarget = '' })=>{
2553
2573
  size: "sm",
2554
2574
  radius: "xl",
2555
2575
  "aria-label": "Monthly Workflow Limit",
2556
- value: !hardLimit ? 100 : hardLimit / totalUsage * 100,
2557
- color: !hardLimit || totalUsage >= hardLimit ? 'red.5' : 'green.1',
2576
+ value: !hardLimit || !totalUsage ? 100 : hardLimit / totalUsage * 100,
2577
+ color: !hardLimit || totalUsage && totalUsage >= hardLimit ? 'red.5' : 'green.1',
2558
2578
  className: className
2559
2579
  });
2560
2580
  return /*#__PURE__*/ jsxs(Popover, {
@@ -2583,18 +2603,15 @@ const CostTracker = ({ workspaceAccountManagerTarget = '' })=>{
2583
2603
  }),
2584
2604
  children: [
2585
2605
  ProgressBar('w-[110px]'),
2586
- /*#__PURE__*/ jsxs("span", {
2587
- className: "font-black pl-3 pr-2",
2588
- children: [
2589
- "$",
2590
- PaymentNumberToString(totalUsage)
2591
- ]
2606
+ /*#__PURE__*/ jsx("span", {
2607
+ className: "font-black pl-3 pr-1",
2608
+ children: paymentNumberToString(totalUsage)
2592
2609
  }),
2593
2610
  /*#__PURE__*/ jsxs("span", {
2594
2611
  className: "font-normal",
2595
2612
  children: [
2596
- "/$",
2597
- PaymentNumberToString(hardLimit)
2613
+ "/",
2614
+ paymentNumberToString(hardLimit)
2598
2615
  ]
2599
2616
  })
2600
2617
  ]
@@ -2620,13 +2637,11 @@ const CostTracker = ({ workspaceAccountManagerTarget = '' })=>{
2620
2637
  size: "sm",
2621
2638
  className: "uppercase pb-2 px-2",
2622
2639
  children: [
2623
- "Limit ",
2624
- /*#__PURE__*/ jsxs("span", {
2640
+ "Limit",
2641
+ ' ',
2642
+ /*#__PURE__*/ jsx("span", {
2625
2643
  className: "font-black pl-1",
2626
- children: [
2627
- "$",
2628
- PaymentNumberToString(hardLimit)
2629
- ]
2644
+ children: paymentNumberToString(hardLimit)
2630
2645
  })
2631
2646
  ]
2632
2647
  }),
@@ -2653,22 +2668,19 @@ const CostTracker = ({ workspaceAccountManagerTarget = '' })=>{
2653
2668
  value: "accountInformation",
2654
2669
  children: [
2655
2670
  /*#__PURE__*/ jsx(Accordion.Control, {
2656
- children: /*#__PURE__*/ jsxs(Text, {
2671
+ children: /*#__PURE__*/ jsx(Text, {
2657
2672
  size: "sm",
2658
2673
  className: "font-black",
2659
- children: [
2660
- workspaceName,
2661
- " - $",
2662
- PaymentNumberToString(totalUsage)
2663
- ]
2674
+ children: `${workspaceName} - ${paymentNumberToString(totalUsage)}`
2664
2675
  })
2665
2676
  }),
2666
2677
  /*#__PURE__*/ jsx(Accordion.Panel, {
2667
2678
  children: /*#__PURE__*/ jsx(Radio.Group, {
2668
2679
  className: "pt-2",
2680
+ onChange: setPayModel,
2681
+ value: selectedPayModel,
2669
2682
  children: usersPayModels.map((obj)=>/*#__PURE__*/ jsx(Radio.Card, {
2670
- checked: obj.currentPayModel,
2671
- disabled: true,
2683
+ value: obj.value,
2672
2684
  className: "p-2 border-none data-checked:bg-primary-lightest data-checked:border-primary-darker data-checked:font-black hover:bg-primary-max ",
2673
2685
  children: /*#__PURE__*/ jsxs(Group, {
2674
2686
  wrap: "nowrap",
@@ -2679,12 +2691,9 @@ const CostTracker = ({ workspaceAccountManagerTarget = '' })=>{
2679
2691
  className: "grow",
2680
2692
  children: obj.label
2681
2693
  }),
2682
- /*#__PURE__*/ jsxs(Text, {
2694
+ /*#__PURE__*/ jsx(Text, {
2683
2695
  size: "sm",
2684
- children: [
2685
- "$",
2686
- PaymentNumberToString(obj.totalUsage)
2687
- ]
2696
+ children: `${paymentNumberToString(obj.totalUsage)}`
2688
2697
  }),
2689
2698
  /*#__PURE__*/ jsx(Radio.Indicator, {
2690
2699
  color: "accent"
@@ -4487,5 +4496,5 @@ const WorkspacesCenterPageGetServerSideProps = async ()=>{
4487
4496
  }
4488
4497
  };
4489
4498
 
4490
- export { WorkspacesCenterPage, WorkspacesCenterPageGetServerSideProps };
4499
+ export { CostTracker, WorkspacesCenterPage, WorkspacesCenterPageGetServerSideProps };
4491
4500
  //# sourceMappingURL=index.js.map