Skip to content

Commit

Permalink
Allow deleting inactive projects; add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
abs committed Sep 16, 2024
1 parent a2921be commit 9c43945
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 28 deletions.
9 changes: 8 additions & 1 deletion server/lib/supafana/web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,13 @@ defmodule Supafana.Web.Router do
false ->
forbid(conn, "Project #{project_ref} does not belong to your Supabase organization")

{:ok, _, _} ->
send_resp(
conn,
400,
"Project must be restored to provision"
)

{:ok, service_key} ->
case Supafana.Azure.Api.check_deployment(project_ref) do
{:ok, %{"properties" => %{"provisioningState" => "Failed"}}} ->
Expand Down Expand Up @@ -675,7 +682,7 @@ defmodule Supafana.Web.Router do
false ->
forbid(conn, "Project #{project_ref} does not belong to your Supabase organization")

{:ok, _} ->
_ ->
Supafana.Web.Task.schedule(
operation: :delete_vm,
project_ref: project_ref,
Expand Down
8 changes: 7 additions & 1 deletion server/lib/supafana/web/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ defmodule Supafana.Web.Utils do
{:ok, service_key}

_ ->
false
case Supafana.Supabase.Management.project_health(access_token, project_ref) do
{:ok, health} ->
{:ok, :inactive, health}

_ ->
false
end
end
end
end
78 changes: 52 additions & 26 deletions storefront/src/ui/SupafanaProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,33 @@ const SupafanaProject = ({
{(["Failed"].includes(state) ||
(plan === "Supafana Pro" && ["Deleted"].includes(state))) && (
<td>
<button
onClick={() => {
if (!provisionGrafanaMutation.isPending) {
provisionGrafanaMutation.mutate();
}
}}
className="btn btn-xs btn-primary w-20 text-white"
>
{provisionGrafanaMutation.isPending ? (
<span className="loading loading-ring loading-xs h-3" />
) : (
<span>Provision</span>
)}
</button>
{project.status.startsWith("ACTIVE") ? (
<button
onClick={() => {
if (!provisionGrafanaMutation.isPending) {
provisionGrafanaMutation.mutate();
}
}}
className="btn btn-xs btn-primary w-20 text-white"
>
{provisionGrafanaMutation.isPending ? (
<span className="loading loading-ring loading-xs h-3" />
) : (
<span>Provision</span>
)}
</button>
) : (
<span className="text-zinc-500">
You’ll have to{" "}
<a
className="link link-primary dark:link-secondary"
href={`https://supabase.com/dashboard/project/${project.id}`}
>
restore
</a>{" "}
this project to provision Supafana
</span>
)}
</td>
)}
{plan === "Trial" && trialEnded && state === "Deleted" && (
Expand All @@ -239,18 +252,31 @@ const SupafanaProject = ({
)}
{plan === "Trial" && !trialEnded && state === "Deleted" && (
<td>
<button
onClick={() => {
provisionGrafanaMutation.mutate();
}}
className="btn btn-xs btn-primary w-20 text-white"
>
{provisionGrafanaMutation.isPending ? (
<span className="loading loading-ring loading-xs h-3" />
) : (
<span>Provision</span>
)}
</button>
{project.status.startsWith("ACTIVE") ? (
<button
onClick={() => {
provisionGrafanaMutation.mutate();
}}
className="btn btn-xs btn-primary w-20 text-white"
>
{provisionGrafanaMutation.isPending ? (
<span className="loading loading-ring loading-xs h-3" />
) : (
<span>Provision</span>
)}
</button>
) : (
<span className="text-zinc-500">
You’ll have to{" "}
<a
className="link link-primary dark:link-secondary"
href={`https://supabase.com/dashboard/project/${project.id}`}
>
restore
</a>{" "}
this project to provision Supafana
</span>
)}
</td>
)}
</tr>
Expand Down

0 comments on commit 9c43945

Please sign in to comment.