Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Sidebar list of spaces not refreshing after subspace delete #7418

Merged
merged 5 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/domain/journey/space/pages/SpaceSettings/SpaceSettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useNavigate } from 'react-router-dom';
import scrollToTop from '@/core/ui/utils/scrollToTop';
import {
refetchAdminSpaceSubspacesPageQuery,
refetchSpaceDashboardNavigationChallengesQuery,
refetchSubspacesInSpaceQuery,
useDeleteSpaceMutation,
useSpaceHostQuery,
useSpacePrivilegesQuery,
Expand Down Expand Up @@ -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<boolean>(false);
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
Expand All @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import AddOutlinedIcon from '@mui/icons-material/AddOutlined';
import {
refetchAdminSpaceSubspacesPageQuery,
refetchDashboardWithMembershipsQuery,
refetchSpaceDashboardNavigationChallengesQuery,
refetchSubspacesInSpaceQuery,
useAdminSpaceSubspacesPageQuery,
useDeleteSpaceMutation,
useSpaceCollaborationIdLazyQuery,
Expand Down Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -89,9 +89,15 @@ const useSpaceDashboardNavigation = ({
spaceId: spaceId!,
challengeIds: readableChallengeIds!,
},
skip: !readableChallengeIds || skip,
skip: !readableChallengeIds.length || skip,
});

useEffect(() => {
if (readableChallengeIds.length > 0) {
refetchOpportunities();
}
}, readableChallengeIds);
ccanos marked this conversation as resolved.
Show resolved Hide resolved

const challengesWithOpportunitiesById = useMemo(
() => keyBy(opportunitiesQueryData?.lookup.space?.subspaces, 'id'),
[opportunitiesQueryData]
Expand Down
13 changes: 11 additions & 2 deletions src/domain/platform/admin/opportunity/pages/OpportunityList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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');
Expand Down