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(hosting-overview-refinements): fix rendering atomic website as simple #93843

Closed
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
10 changes: 10 additions & 0 deletions client/data/sites/use-site-excerpts-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ const fetchSites = (
} );
};

export const queryKeyForAllSitesWithThemeSlug = [
USE_SITE_EXCERPTS_QUERY_KEY,
SITE_EXCERPT_REQUEST_FIELDS,
SITE_EXCERPT_REQUEST_OPTIONS,
[],
'all',
[],
[ 'theme_slug' ],
];

Comment on lines +32 to +41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing the loop: I mentioned on Slack that I think we should replace this with a getUseSiteExcerptsQueryKey function. That function should be used internally in useSiteExcerptsQuery and when invalidating the query.

export const useSiteExcerptsQuery = (
fetchFilter?: string[],
sitesFilterFn?: ( site: SiteExcerptData ) => boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { FEATURE_SFTP, getPlan, PLAN_BUSINESS } from '@automattic/calypso-produc
import page from '@automattic/calypso-router';
import { Dialog } from '@automattic/components';
import { useHasEnTranslation } from '@automattic/i18n-utils';
import { useQueryClient } from '@tanstack/react-query';
import { Button, Spinner } from '@wordpress/components';
import { translate } from 'i18n-calypso';
import { useRef, useState, useEffect } from 'react';
import { AnyAction } from 'redux';
import EligibilityWarnings from 'calypso/blocks/eligibility-warnings';
import { HostingCard } from 'calypso/components/hosting-card';
import InlineSupportLink from 'calypso/components/inline-support-link';
import { queryKeyForAllSitesWithThemeSlug } from 'calypso/data/sites/use-site-excerpts-query';
import { useSiteTransferStatusQuery } from 'calypso/landing/stepper/hooks/use-site-transfer/query';
import { useSelector, useDispatch } from 'calypso/state';
import { recordTracksEvent } from 'calypso/state/analytics/actions';
Expand Down Expand Up @@ -40,6 +42,7 @@ const PromoCard = ( { title, text, supportContext }: PromoCardProps ) => (

const HostingFeatures = () => {
const dispatch = useDispatch();
const queryClient = useQueryClient();
const { searchParams } = new URL( document.location.toString() );
const showActivationModal = searchParams.get( 'activate' ) !== null;
const [ showEligibility, setShowEligibility ] = useState( showActivationModal );
Expand Down Expand Up @@ -91,8 +94,11 @@ const HostingFeatures = () => {

if ( siteTransferData?.status === transferStates.COMPLETED ) {
dispatch( fetchAtomicTransfer( siteId ) as unknown as AnyAction );
queryClient.invalidateQueries( {
queryKey: queryKeyForAllSitesWithThemeSlug,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use getUseSiteExcerptsQueryKey here. @nightnei and I discussed how we can ensure that we target the exact same query key that's used in client/hosting/sites/components/sites-dashboard.tsx, but I think we should consider not doing that.

By specifying a shorter key when invalidating queries, react-query will invalidate all queries with longer keys matching that prefix. For example, if we invalidate the key ['sites'], queries for ['sites', 'all'] will also be invalidated.

This seems like an appropriate case to make use of that. We can invalidate all useSiteExcerptsQuery instances where site_visibility === all and just not specify additional_fields and additional_options.

Thoughts, @nightnei?

} );
}
}, [ siteTransferData?.status, siteId, dispatch ] );
}, [ siteTransferData?.status, siteId, dispatch, queryClient ] );

const upgradeLink = `https://wordpress.com/checkout/${ encodeURIComponent( siteSlug ) }/business`;
const promoCards = [
Expand Down
Loading