@gen3/workspaces 0.12.66 → 0.12.67

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.
@@ -10,6 +10,7 @@ var core$1 = require('@gen3/core');
10
10
  var useDeepCompare = require('use-deep-compare');
11
11
  var notifications = require('@mantine/notifications');
12
12
  var md = require('react-icons/md');
13
+ var fa = require('react-icons/fa');
13
14
  var io5 = require('react-icons/io5');
14
15
  var bs = require('react-icons/bs');
15
16
  var lodash = require('lodash');
@@ -2427,11 +2428,239 @@ const SettingsPanel = ({ showKernels, expanded, setExpanded, width = 380 })=>{
2427
2428
  });
2428
2429
  };
2429
2430
 
2431
+ const PaymentNumberToString = (x, undefinedValue = 'N/A', precision = 2)=>{
2432
+ if (typeof x !== 'number' || Number.isNaN(x)) return undefinedValue;
2433
+ return x.toFixed(precision);
2434
+ };
2435
+ const isNoPayModelError = (error)=>{
2436
+ return 'status' in error && error.status === 'PARSING_ERROR' && error.originalStatus === 404;
2437
+ };
2438
+ const NoPayModel = ()=>{
2439
+ return /*#__PURE__*/ jsxRuntime.jsx(core.Group, {
2440
+ className: "p-2 border-1 border-l-0 border-r-0 border-base-lighter w-full h-16",
2441
+ justify: "space-between",
2442
+ children: /*#__PURE__*/ jsxRuntime.jsx(core.Text, {
2443
+ className: "pl-4",
2444
+ size: "md",
2445
+ classNames: {
2446
+ root: 'font-heading text-utility-warning'
2447
+ },
2448
+ children: "No pay model defined"
2449
+ })
2450
+ });
2451
+ };
2452
+ const CostTracker = ({ workspaceAccountManagerTarget = '' })=>{
2453
+ const { data, isLoading, isFetching, isError, error } = core$1.useGetWorkspacePayModelsQuery(undefined, {
2454
+ pollingInterval: 120000,
2455
+ refetchOnMountOrArgChange: true
2456
+ });
2457
+ const [setWorkspacePayModel] = core$1.useSetCurrentPayModelMutation();
2458
+ const [selectedPayModel, setSelectedPayModel] = React.useState(null);
2459
+ const [opened, setOpened] = React.useState(false);
2460
+ useDeepCompare.useDeepCompareCallback((id)=>{
2461
+ void setWorkspacePayModel(id); // triggers the call to the service to select the pay model
2462
+ setSelectedPayModel(id); // set the paymodel value for the select component
2463
+ }, [
2464
+ setWorkspacePayModel,
2465
+ selectedPayModel
2466
+ ]);
2467
+ const { usersPayModels, workspaceName, hardLimit, totalUsage } = useDeepCompare.useDeepCompareMemo(()=>{
2468
+ if (!data) return {
2469
+ usersPayModels: [],
2470
+ selectedPayModel: [],
2471
+ workspaceName: 'Not Set',
2472
+ totalUsage: undefined,
2473
+ hardLimit: undefined
2474
+ };
2475
+ const usersPayModels = data.allPayModels.map((payModel)=>{
2476
+ return {
2477
+ value: payModel.bmh_workspace_id ?? payModel.workspace_type,
2478
+ label: payModel.workspace_type,
2479
+ totalUsage: payModel['total-usage'],
2480
+ currentPayModel: payModel['current_pay_model'],
2481
+ icon: payModel.request_status === 'active' ? /*#__PURE__*/ jsxRuntime.jsx(fa.FaUser, {}) : /*#__PURE__*/ jsxRuntime.jsx(fa.FaExclamationCircle, {})
2482
+ };
2483
+ });
2484
+ setSelectedPayModel(data.currentPayModel.bmh_workspace_id ?? data.currentPayModel.workspace_type);
2485
+ return {
2486
+ usersPayModels,
2487
+ workspaceName: data.currentPayModel.bmh_workspace_id.length > 0 ? data.currentPayModel.bmh_workspace_id : data.currentPayModel.workspace_type,
2488
+ totalUsage: data.currentPayModel['total-usage'],
2489
+ hardLimit: data.currentPayModel['hard-limit']
2490
+ };
2491
+ }, [
2492
+ data
2493
+ ]);
2494
+ if (isLoading && isFetching) return /*#__PURE__*/ jsxRuntime.jsx("div", {
2495
+ className: "flex justify-center p-2 border-1 border-l-0 border-r-0 border-base-lighter w-full h-14",
2496
+ children: /*#__PURE__*/ jsxRuntime.jsx(core.Loader, {})
2497
+ });
2498
+ if (isError) {
2499
+ if (isNoPayModelError(error)) {
2500
+ return /*#__PURE__*/ jsxRuntime.jsx(NoPayModel, {});
2501
+ } else return /*#__PURE__*/ jsxRuntime.jsx(core.Center, {
2502
+ children: "Unable to get Payment information"
2503
+ });
2504
+ }
2505
+ const ProgressBar = (className = '')=>/*#__PURE__*/ jsxRuntime.jsx(core.Progress, {
2506
+ size: "sm",
2507
+ radius: "xl",
2508
+ "aria-label": "Monthly Workflow Limit",
2509
+ value: !hardLimit ? 100 : hardLimit / totalUsage * 100,
2510
+ color: !hardLimit || totalUsage >= hardLimit ? 'red.5' : 'green.1',
2511
+ className: className
2512
+ });
2513
+ return /*#__PURE__*/ jsxRuntime.jsxs(core.Popover, {
2514
+ width: "target",
2515
+ position: "bottom",
2516
+ shadow: "lg",
2517
+ trapFocus: true,
2518
+ opened: opened,
2519
+ onChange: setOpened,
2520
+ children: [
2521
+ /*#__PURE__*/ jsxRuntime.jsx(core.Popover.Target, {
2522
+ children: /*#__PURE__*/ jsxRuntime.jsxs(core.Button, {
2523
+ onClick: ()=>setOpened((o)=>!o),
2524
+ size: "xs",
2525
+ radius: "xl",
2526
+ variant: "default",
2527
+ className: "h-[--badge-height]",
2528
+ rightSection: /*#__PURE__*/ jsxRuntime.jsx(md.MdExpandMore, {
2529
+ className: "text-accent",
2530
+ size: "1.5em",
2531
+ "aria-label": opened ? 'close' : 'open',
2532
+ style: {
2533
+ transform: opened ? 'rotate(180deg)' : 'rotate(0deg)',
2534
+ transition: 'transform 200ms ease'
2535
+ }
2536
+ }),
2537
+ children: [
2538
+ ProgressBar('w-[110px]'),
2539
+ /*#__PURE__*/ jsxRuntime.jsxs("span", {
2540
+ className: "font-black pl-3 pr-2",
2541
+ children: [
2542
+ "$",
2543
+ PaymentNumberToString(totalUsage)
2544
+ ]
2545
+ }),
2546
+ /*#__PURE__*/ jsxRuntime.jsxs("span", {
2547
+ className: "font-normal",
2548
+ children: [
2549
+ "/$",
2550
+ PaymentNumberToString(hardLimit)
2551
+ ]
2552
+ })
2553
+ ]
2554
+ })
2555
+ }),
2556
+ /*#__PURE__*/ jsxRuntime.jsxs(core.Popover.Dropdown, {
2557
+ className: "px-2",
2558
+ children: [
2559
+ workspaceAccountManagerTarget && /*#__PURE__*/ jsxRuntime.jsx(core.Button, {
2560
+ component: "a",
2561
+ href: workspaceAccountManagerTarget,
2562
+ target: "_blank",
2563
+ variant: "outline",
2564
+ leftSection: /*#__PURE__*/ jsxRuntime.jsx(md.MdOpenInNew, {
2565
+ size: "1.1em",
2566
+ "aria-label": "external"
2567
+ }),
2568
+ size: "xs",
2569
+ className: "w-full mb-4",
2570
+ children: "Workspace Account Manager"
2571
+ }),
2572
+ /*#__PURE__*/ jsxRuntime.jsxs(core.Text, {
2573
+ size: "sm",
2574
+ className: "uppercase pb-2 px-2",
2575
+ children: [
2576
+ "Limit ",
2577
+ /*#__PURE__*/ jsxRuntime.jsxs("span", {
2578
+ className: "font-black pl-1",
2579
+ children: [
2580
+ "$",
2581
+ PaymentNumberToString(hardLimit)
2582
+ ]
2583
+ })
2584
+ ]
2585
+ }),
2586
+ ProgressBar('mx-2'),
2587
+ /*#__PURE__*/ jsxRuntime.jsx(core.Divider, {
2588
+ my: "sm"
2589
+ }),
2590
+ /*#__PURE__*/ jsxRuntime.jsx(core.Text, {
2591
+ size: "sm",
2592
+ className: "uppercase pb-2 px-2",
2593
+ children: "Account & Charges"
2594
+ }),
2595
+ /*#__PURE__*/ jsxRuntime.jsx(core.Accordion, {
2596
+ variant: "unstyled",
2597
+ classNames: {
2598
+ root: '',
2599
+ control: 'p-0 px-2',
2600
+ label: 'p-0',
2601
+ chevron: 'text-accent',
2602
+ panel: 'p-0',
2603
+ content: 'p-0'
2604
+ },
2605
+ children: /*#__PURE__*/ jsxRuntime.jsxs(core.Accordion.Item, {
2606
+ value: "accountInformation",
2607
+ children: [
2608
+ /*#__PURE__*/ jsxRuntime.jsx(core.Accordion.Control, {
2609
+ children: /*#__PURE__*/ jsxRuntime.jsxs(core.Text, {
2610
+ size: "sm",
2611
+ className: "font-black",
2612
+ children: [
2613
+ workspaceName,
2614
+ " - $",
2615
+ PaymentNumberToString(totalUsage)
2616
+ ]
2617
+ })
2618
+ }),
2619
+ /*#__PURE__*/ jsxRuntime.jsx(core.Accordion.Panel, {
2620
+ children: /*#__PURE__*/ jsxRuntime.jsx(core.Radio.Group, {
2621
+ className: "pt-2",
2622
+ children: usersPayModels.map((obj)=>/*#__PURE__*/ jsxRuntime.jsx(core.Radio.Card, {
2623
+ checked: obj.currentPayModel,
2624
+ disabled: true,
2625
+ className: "p-2 border-none data-checked:bg-primary-lightest data-checked:border-primary-darker data-checked:font-black hover:bg-primary-max ",
2626
+ children: /*#__PURE__*/ jsxRuntime.jsxs(core.Group, {
2627
+ wrap: "nowrap",
2628
+ align: "flex-start",
2629
+ children: [
2630
+ /*#__PURE__*/ jsxRuntime.jsx(core.Text, {
2631
+ size: "sm",
2632
+ className: "grow",
2633
+ children: obj.label
2634
+ }),
2635
+ /*#__PURE__*/ jsxRuntime.jsxs(core.Text, {
2636
+ size: "sm",
2637
+ children: [
2638
+ "$",
2639
+ PaymentNumberToString(obj.totalUsage)
2640
+ ]
2641
+ }),
2642
+ /*#__PURE__*/ jsxRuntime.jsx(core.Radio.Indicator, {
2643
+ color: "accent"
2644
+ })
2645
+ ]
2646
+ })
2647
+ }, obj.value))
2648
+ })
2649
+ })
2650
+ ]
2651
+ })
2652
+ })
2653
+ ]
2654
+ })
2655
+ ]
2656
+ });
2657
+ };
2658
+
2430
2659
  const WorkspaceToolbar = /*#__PURE__*/ React.forwardRef(({ toolbarConfiguration }, ref)=>{
2431
2660
  const workspaceTier = core$1.useCoreSelector((state)=>core$1.selectWorkspaceTier(state));
2432
2661
  const workspaceStatus = core$1.useCoreSelector((state)=>core$1.selectJEGActiveWorkspaceStatus(state));
2433
2662
  const isFullscreen = core$1.useCoreSelector((state)=>core$1.selectWorkspaceFullscreen(state));
2434
- const { showStatus, showStop, tierLabel } = toolbarConfiguration || {};
2663
+ const { showStatus, showStop, tierLabel, requirePayModel, workspaceAccountManagerTarget } = toolbarConfiguration || {};
2435
2664
  const coreDispatch = core$1.useCoreDispatch();
2436
2665
  const toggleFullscreen = React.useCallback(()=>{
2437
2666
  coreDispatch(core$1.setWorkspaceFullscreen(!isFullscreen));
@@ -2486,6 +2715,9 @@ const WorkspaceToolbar = /*#__PURE__*/ React.forwardRef(({ toolbarConfiguration
2486
2715
  /*#__PURE__*/ jsxRuntime.jsx(core.Badge, {
2487
2716
  "aria-label": `Workspace tier: ${tierLabel ?? workspaceTier}`,
2488
2717
  children: tierLabel ?? workspaceTier
2718
+ }),
2719
+ requirePayModel && /*#__PURE__*/ jsxRuntime.jsx(CostTracker, {
2720
+ workspaceAccountManagerTarget: workspaceAccountManagerTarget
2489
2721
  })
2490
2722
  ]
2491
2723
  })