@@ -79,11 +79,12 @@ function transformSingleSiteResponse(
7979 * Transforms the WordPress.com sites API response into SyncSite objects.
8080 *
8181 * @param sites - Raw site data from the WordPress.com API
82- * @param connectedSiteIds - IDs of sites already connected to the current local site.
83- * Used to: 1) keep deleted sites in the list if they're connected, and
84- * 2) determine sync support status (already-connected vs syncable)
82+ * @param connectedSiteIds - Optional IDs of sites already connected to the current local site.
83+ * When provided, used to: 1) keep deleted sites in the list if they're connected, and
84+ * 2) determine sync support status (already-connected vs syncable).
85+ * When not provided, no filtering based on connected sites is applied.
8586 */
86- function transformSitesResponse ( sites : unknown [ ] , connectedSiteIds : number [ ] ) : SyncSite [ ] {
87+ function transformSitesResponse ( sites : unknown [ ] , connectedSiteIds ? : number [ ] ) : SyncSite [ ] {
8788 const validatedSites = sites . reduce < SitesEndpointSite [ ] > ( ( acc , rawSite ) => {
8889 try {
8990 const site = sitesEndpointSiteSchema . parse ( rawSite ) ;
@@ -100,12 +101,17 @@ function transformSitesResponse( sites: unknown[], connectedSiteIds: number[] ):
100101
101102 return validatedSites
102103 . filter ( ( site ) => ! site . is_a8c )
103- . filter ( ( site ) => ! site . is_deleted || connectedSiteIds . some ( ( id ) => id === site . ID ) )
104+ . filter (
105+ // Filter out deleted sites, except if they're in the connectedSiteIds list
106+ ( site ) =>
107+ ! site . is_deleted ||
108+ ( connectedSiteIds && connectedSiteIds . some ( ( id ) => id === site . ID ) )
109+ )
104110 . map ( ( site ) => {
105111 // The API returns the wrong value for the `is_wpcom_staging_site` prop while staging sites
106112 // are being created. Hence the check in other sites' `wpcom_staging_blog_ids` arrays.
107113 const isStaging = allStagingSiteIds . includes ( site . ID ) ;
108- const syncSupport = getSyncSupport ( site , connectedSiteIds ) ;
114+ const syncSupport = getSyncSupport ( site , connectedSiteIds ?? [ ] ) ;
109115
110116 return transformSingleSiteResponse ( site , syncSupport , isStaging ) ;
111117 } ) ;
@@ -116,7 +122,7 @@ export const wpcomSitesApi = createApi( {
116122 baseQuery : fetchBaseQuery ( ) ,
117123 tagTypes : [ 'WpComSites' ] ,
118124 endpoints : ( builder ) => ( {
119- getWpComSites : builder . query < SyncSite [ ] , { connectedSiteIds : number [ ] ; userId ?: number } > ( {
125+ getWpComSites : builder . query < SyncSite [ ] , { connectedSiteIds ? : number [ ] ; userId ?: number } > ( {
120126 queryFn : async ( { connectedSiteIds } ) => {
121127 const wpcomClient = getWpcomClient ( ) ;
122128 if ( ! wpcomClient ) {
0 commit comments