-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin Scheduler: Check for file mod capabilities (#88124)
This prevents the plugin scheduler UI from loading if we don't have file mod capabilities.
- Loading branch information
1 parent
9a0e205
commit 52a957f
Showing
7 changed files
with
146 additions
and
37 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
client/blocks/plugins-update-manager/hooks/use-can-create-schedules.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useUpdateScheduleCapabilitiesQuery } from 'calypso/data/plugins/use-update-schedules-capabilities-query'; | ||
|
||
const DEFAULT_FILE_MOD_PERMISSIONS = { | ||
modify_files: false, | ||
autoupdate_files: false, | ||
errors: undefined, | ||
}; | ||
|
||
interface UseCanCreateSchedulesReturn { | ||
canCreateSchedules: boolean; | ||
errors?: { code: string; message: string }[]; | ||
isLoading: boolean; | ||
} | ||
|
||
export function useCanCreateSchedules( siteSlug: string ): UseCanCreateSchedulesReturn { | ||
const { data, isLoading } = useUpdateScheduleCapabilitiesQuery( siteSlug ); | ||
const { | ||
modify_files: modifyFiles, | ||
autoupdate_files: autoUpdateFiles, | ||
errors, | ||
} = data || DEFAULT_FILE_MOD_PERMISSIONS; | ||
|
||
// we assume we can create schedules until the API reports back. | ||
const canCreateSchedules = isLoading ? true : modifyFiles && autoUpdateFiles; | ||
|
||
return { canCreateSchedules, errors, isLoading }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
client/data/plugins/use-update-schedules-capabilities-query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useQuery, UseQueryResult } from '@tanstack/react-query'; | ||
import wpcomRequest from 'wpcom-proxy-request'; | ||
import type { SiteSlug } from 'calypso/types'; | ||
|
||
export type ScheduleUpdatesCapabilities = { | ||
modify_files: boolean; | ||
autoupdate_files: boolean; | ||
errors?: { code: string; message: string }[]; | ||
}; | ||
|
||
export const useUpdateScheduleCapabilitiesQuery = ( | ||
siteSlug: SiteSlug | ||
): UseQueryResult< ScheduleUpdatesCapabilities > => { | ||
return useQuery( { | ||
queryKey: [ 'schedule-updates-capabilities', siteSlug ], | ||
queryFn: () => | ||
wpcomRequest( { | ||
path: `/sites/${ siteSlug }/update-schedules/capabilities`, | ||
apiNamespace: 'wpcom/v2', | ||
method: 'GET', | ||
} ), | ||
meta: { | ||
persist: false, | ||
}, | ||
enabled: !! siteSlug, | ||
retry: false, | ||
refetchOnWindowFocus: false, | ||
} ); | ||
}; |