From 8a0109522b3acb6c51146e3ea7d2468ef7fac27f Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Mon, 12 Aug 2024 00:33:08 -0700 Subject: [PATCH] fix remove recents on delete --- bin/core/src/resource/mod.rs | 18 +++++++++++------- frontend/src/pages/home/dashboard.tsx | 10 +++++++--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/bin/core/src/resource/mod.rs b/bin/core/src/resource/mod.rs index 736dd0bb7..8ed82c7a5 100644 --- a/bin/core/src/resource/mod.rs +++ b/bin/core/src/resource/mod.rs @@ -780,13 +780,17 @@ where { let resource: ResourceTarget = resource.into(); let (recent_field, id) = match resource { - ResourceTarget::Server(id) => ("recent_servers", id), - ResourceTarget::Deployment(id) => ("recent_deployments", id), - ResourceTarget::Build(id) => ("recent_builds", id), - ResourceTarget::Repo(id) => ("recent_repos", id), - ResourceTarget::Procedure(id) => ("recent_procedures", id), - // Don't need to do anything for others - _ => return, + ResourceTarget::Server(id) => ("recents.Server", id), + ResourceTarget::Deployment(id) => ("recents.Deployment", id), + ResourceTarget::Build(id) => ("recents.Build", id), + ResourceTarget::Repo(id) => ("recents.Repo", id), + ResourceTarget::Procedure(id) => ("recents.Procedure", id), + ResourceTarget::Stack(id) => ("recents.Stack", id), + ResourceTarget::Builder(id) => ("recents.Builder", id), + ResourceTarget::Alerter(id) => ("recents.Alerter", id), + ResourceTarget::ServerTemplate(id) => ("recents.ServerTemplate", id), + ResourceTarget::ResourceSync(id) => ("recents.ResourceSync", id), + ResourceTarget::System(_) => return }; if let Err(e) = db_client() .await diff --git a/frontend/src/pages/home/dashboard.tsx b/frontend/src/pages/home/dashboard.tsx index 7c017057b..0db95bc19 100644 --- a/frontend/src/pages/home/dashboard.tsx +++ b/frontend/src/pages/home/dashboard.tsx @@ -51,9 +51,13 @@ export const Dashboard = () => { }; const ResourceRow = ({ type }: { type: UsableResource }) => { - const recents = useUser().data?.recents?.[type]?.slice(0, 6); - const resources = useRead(`List${type}s`, {}) - .data?.filter((r) => !recents?.includes(r.id)) + const _recents = useUser().data?.recents?.[type]?.slice(0, 6); + const _resources = useRead(`List${type}s`, {}).data; + const recents = _recents?.filter( + (recent) => !_resources?.every((resource) => resource.id !== recent) + ); + const resources = _resources + ?.filter((r) => !recents?.includes(r.id)) .map((r) => r.id); const ids = [ ...(recents ?? []),