From 8b97a5c486633e73002c2df1119eb38cb0c9ed3d Mon Sep 17 00:00:00 2001 From: Carlos Cano Date: Thu, 9 Jan 2025 18:54:07 +0100 Subject: [PATCH] Fix Sidebar list of spaces not refreshing after subspace delete --- .../space/pages/SpaceSettings/SpaceSettingsView.tsx | 13 +++++++++++-- .../space/pages/SpaceSubspaces/SubspaceListView.tsx | 9 +++++++++ .../useSpaceDashboardNavigation.ts | 12 +++++++++--- .../admin/opportunity/pages/OpportunityList.tsx | 13 +++++++++++-- .../OpportunitySettings/OpportunitySettingsView.tsx | 5 +++++ 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/domain/journey/space/pages/SpaceSettings/SpaceSettingsView.tsx b/src/domain/journey/space/pages/SpaceSettings/SpaceSettingsView.tsx index 2afb618cdc..24b7bd902b 100644 --- a/src/domain/journey/space/pages/SpaceSettings/SpaceSettingsView.tsx +++ b/src/domain/journey/space/pages/SpaceSettings/SpaceSettingsView.tsx @@ -4,6 +4,8 @@ import { useNavigate } from 'react-router-dom'; import scrollToTop from '@/core/ui/utils/scrollToTop'; import { refetchAdminSpaceSubspacesPageQuery, + refetchSpaceDashboardNavigationChallengesQuery, + refetchSubspacesInSpaceQuery, useDeleteSpaceMutation, useSpaceHostQuery, useSpacePrivilegesQuery, @@ -76,7 +78,7 @@ export const SpaceSettingsView = ({ journeyId, journeyTypeName }: SpaceSettingsV const isSubspace = journeyTypeName !== 'space'; const { subspaceId } = useSubSpace(); - const { spaceNameId } = useSpace(); + const { spaceId, spaceNameId } = useSpace(); const [saveAsTemplateDialogOpen, setSaveAsTemplateDialogOpen] = useState(false); const [openDeleteDialog, setOpenDeleteDialog] = useState(false); @@ -85,9 +87,16 @@ export const SpaceSettingsView = ({ journeyId, journeyTypeName }: SpaceSettingsV const [deleteSpace] = useDeleteSpaceMutation({ refetchQueries: [ + refetchSubspacesInSpaceQuery({ + spaceId, + }), refetchAdminSpaceSubspacesPageQuery({ - spaceId: spaceNameId, + spaceId, + }), + refetchSpaceDashboardNavigationChallengesQuery({ + spaceId, }), + 'SpaceDashboardNavigationOpportunities', ], awaitRefetchQueries: true, onCompleted: data => { diff --git a/src/domain/journey/space/pages/SpaceSubspaces/SubspaceListView.tsx b/src/domain/journey/space/pages/SpaceSubspaces/SubspaceListView.tsx index 06de8a5cc2..e9824aaf1b 100644 --- a/src/domain/journey/space/pages/SpaceSubspaces/SubspaceListView.tsx +++ b/src/domain/journey/space/pages/SpaceSubspaces/SubspaceListView.tsx @@ -7,6 +7,8 @@ import AddOutlinedIcon from '@mui/icons-material/AddOutlined'; import { refetchAdminSpaceSubspacesPageQuery, refetchDashboardWithMembershipsQuery, + refetchSpaceDashboardNavigationChallengesQuery, + refetchSubspacesInSpaceQuery, useAdminSpaceSubspacesPageQuery, useDeleteSpaceMutation, useSpaceCollaborationIdLazyQuery, @@ -81,9 +83,16 @@ export const SubspaceListView = () => { const [deleteSubspace] = useDeleteSpaceMutation({ refetchQueries: [ + refetchSubspacesInSpaceQuery({ + spaceId, + }), refetchAdminSpaceSubspacesPageQuery({ spaceId, }), + refetchSpaceDashboardNavigationChallengesQuery({ + spaceId, + }), + 'SpaceDashboardNavigationOpportunities', ], awaitRefetchQueries: true, onCompleted: () => notify(t('pages.admin.subspace.notifications.subspace-removed'), 'success'), diff --git a/src/domain/journey/space/spaceDashboardNavigation/useSpaceDashboardNavigation.ts b/src/domain/journey/space/spaceDashboardNavigation/useSpaceDashboardNavigation.ts index b28749c18b..5bfe8e7183 100644 --- a/src/domain/journey/space/spaceDashboardNavigation/useSpaceDashboardNavigation.ts +++ b/src/domain/journey/space/spaceDashboardNavigation/useSpaceDashboardNavigation.ts @@ -10,7 +10,7 @@ import { SpaceDashboardNavigationProfileFragment, } from '@/core/apollo/generated/graphql-schema'; import { keyBy } from 'lodash'; -import { useCallback, useMemo } from 'react'; +import { useCallback, useEffect, useMemo } from 'react'; interface UseSpaceDashboardNavigationProps { spaceId: string | undefined; @@ -78,7 +78,7 @@ const useSpaceDashboardNavigation = ({ const space = challengesQueryData?.lookup.space; - const readableChallengeIds = space?.subspaces.filter(isReadable).map(({ id }) => id); + const readableChallengeIds = space?.subspaces.filter(isReadable).map(({ id }) => id) ?? []; const { data: opportunitiesQueryData, @@ -89,9 +89,15 @@ const useSpaceDashboardNavigation = ({ spaceId: spaceId!, challengeIds: readableChallengeIds!, }, - skip: !readableChallengeIds || skip, + skip: !readableChallengeIds.length || skip, }); + useEffect(() => { + if (readableChallengeIds.length > 0) { + refetchOpportunities(); + } + }, readableChallengeIds); + const challengesWithOpportunitiesById = useMemo( () => keyBy(opportunitiesQueryData?.lookup.space?.subspaces, 'id'), [opportunitiesQueryData] diff --git a/src/domain/platform/admin/opportunity/pages/OpportunityList.tsx b/src/domain/platform/admin/opportunity/pages/OpportunityList.tsx index 27471bf092..eb096ff0f7 100644 --- a/src/domain/platform/admin/opportunity/pages/OpportunityList.tsx +++ b/src/domain/platform/admin/opportunity/pages/OpportunityList.tsx @@ -14,6 +14,8 @@ import { buildSettingsUrl } from '@/main/routing/urlBuilders'; import { JourneyFormValues } from '@/domain/shared/components/JourneyCreationDialog/JourneyCreationForm'; import { OpportunityIcon } from '@/domain/journey/opportunity/icon/OpportunityIcon'; import { + refetchAdminSpaceSubspacesPageQuery, + refetchSpaceDashboardNavigationChallengesQuery, refetchSubspacesInSpaceQuery, useDeleteSpaceMutation, useSpaceCollaborationIdLazyQuery, @@ -34,7 +36,7 @@ import { useSubspaceCreation } from '@/domain/shared/utils/useSubspaceCreation/u export const OpportunityList: FC = () => { const { t } = useTranslation(); const notify = useNotification(); - const { spaceNameId } = useSpace(); + const { spaceId, spaceNameId } = useSpace(); const { subspaceId } = useSubSpace(); const navigate = useNavigate(); const [open, setOpen] = useState(false); @@ -63,8 +65,15 @@ export const OpportunityList: FC = () => { const [deleteOpportunity] = useDeleteSpaceMutation({ refetchQueries: [ refetchSubspacesInSpaceQuery({ - spaceId: subspaceId, + spaceId, }), + refetchAdminSpaceSubspacesPageQuery({ + spaceId, + }), + refetchSpaceDashboardNavigationChallengesQuery({ + spaceId, + }), + 'SpaceDashboardNavigationOpportunities', ], awaitRefetchQueries: true, onCompleted: () => notify(t('pages.admin.subsubspace.notifications.subsubspace-removed'), 'success'), diff --git a/src/domain/platform/admin/opportunity/pages/OpportunitySettings/OpportunitySettingsView.tsx b/src/domain/platform/admin/opportunity/pages/OpportunitySettings/OpportunitySettingsView.tsx index 32f8342c31..089f1e6641 100644 --- a/src/domain/platform/admin/opportunity/pages/OpportunitySettings/OpportunitySettingsView.tsx +++ b/src/domain/platform/admin/opportunity/pages/OpportunitySettings/OpportunitySettingsView.tsx @@ -7,6 +7,7 @@ import PageContentBlockHeader from '@/core/ui/content/PageContentBlockHeader'; import { Caption } from '@/core/ui/typography'; import { useNotification } from '@/core/ui/notifications/useNotification'; import { + refetchAdminSpaceSubspacesPageQuery, refetchSpaceDashboardNavigationChallengesQuery, refetchSubspacesInSpaceQuery, useDeleteSpaceMutation, @@ -37,9 +38,13 @@ const OpportunitySettingsView = () => { refetchSubspacesInSpaceQuery({ spaceId, }), + refetchAdminSpaceSubspacesPageQuery({ + spaceId, + }), refetchSpaceDashboardNavigationChallengesQuery({ spaceId, }), + 'SpaceDashboardNavigationOpportunities', ], onCompleted: data => { notify(t('pages.admin.space.notifications.space-removed', { name: data.deleteSpace.nameID }), 'success');