From becd39cc2353ecc5c261daef19de445afa974b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Mon, 5 Feb 2024 12:03:43 +0800 Subject: [PATCH] feat: revamped instance size selection (#20765) --- .../Subscription/DowngradeModal.tsx | 53 ++- .../Subscription/PlanUpdateSidePanel.tsx | 7 + .../interfaces/Settings/Addons/Addons.tsx | 62 ++- .../Addons/ComputeInstanceSidePanel.tsx | 394 +++++++++--------- .../Infrastructure/InfrastructureActivity.tsx | 22 +- apps/studio/data/api.d.ts | 2 + apps/studio/lib/constants/infrastructure.ts | 30 ++ 7 files changed, 326 insertions(+), 244 deletions(-) diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/DowngradeModal.tsx b/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/DowngradeModal.tsx index 1b8e7a9f729..32b384ba0bf 100644 --- a/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/DowngradeModal.tsx +++ b/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/DowngradeModal.tsx @@ -1,3 +1,4 @@ +import { ProjectInfo } from 'data/projects/projects-query' import { OrgSubscription, ProjectAddon } from 'data/subscriptions/types' import { PricingInformation } from 'shared-data' import { Alert, IconAlertOctagon, IconMinusCircle, IconPauseCircle, Modal } from 'ui' @@ -8,6 +9,7 @@ export interface DowngradeModalProps { subscription?: OrgSubscription onClose: () => void onConfirm: () => void + projects: ProjectInfo[] } const ProjectDowngradeListItem = ({ projectAddon }: { projectAddon: ProjectAddon }) => { @@ -39,7 +41,26 @@ const DowngradeModal = ({ subscription, onClose, onConfirm, + projects, }: DowngradeModalProps) => { + // Filter out the micro addon as we're dealing with that separately + const previousProjectAddons = + subscription?.project_addons.flatMap((projectAddons) => { + const addons = projectAddons.addons.filter((it) => it.variant.identifier !== 'ci_micro') + if (!addons.length) { + return [] + } else { + return { + ...projectAddons, + // Overwrite addons, filtered out the micro addon + addons, + } + } + }) || [] + + const hasInstancesOnMicro = projects.some((project) => project.infra_compute_size === 'micro') + const downgradingToNano = subscription?.nano_enabled === true + return ( - {(subscription?.project_addons.length ?? 0) > 0 && ( - -
    - {subscription?.project_addons.map((project) => ( - - ))} -
-
- )} + {(previousProjectAddons.length ?? 0) > 0 || + (hasInstancesOnMicro && downgradingToNano && ( + +
    + {previousProjectAddons.map((project) => ( + + ))} + + {projects + .filter((it) => it.infra_compute_size === 'micro') + .map((project) => ( +
  • + {project.name}: Compute will be downgraded. Project will also{' '} + need to be restarted. +
  • + ))} +
+
+ ))}