Skip to content
Open
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: 8 additions & 5 deletions assets/src/admin/onboarding/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import apiFetch from '@wordpress/api-fetch';
import { __ } from '@wordpress/i18n';
import {
Card,

Check warning on line 11 in assets/src/admin/onboarding/page.tsx

View workflow job for this annotation

GitHub Actions / CSS/JS Lint / JS Lint & TypeScript

Use `Card.Root` from `@wordpress/ui` instead
CardHeader,

Check warning on line 12 in assets/src/admin/onboarding/page.tsx

View workflow job for this annotation

GitHub Actions / CSS/JS Lint / JS Lint & TypeScript

Use `Card.Header` (and optionally `Card.Title`) from `@wordpress/ui` instead
CardBody,

Check warning on line 13 in assets/src/admin/onboarding/page.tsx

View workflow job for this annotation

GitHub Actions / CSS/JS Lint / JS Lint & TypeScript

Use `Card.Content` from `@wordpress/ui` instead
Notice,
Button,
SelectControl,
Expand All @@ -27,8 +27,11 @@
}

// WordPress provides snake_case keys here. Using them intentionally.
// eslint-disable-next-line camelcase
const { nonce, setup_url, site_type } = window.OneUpdateOnboarding;
const {
nonce,
setup_url: setupUrl,
site_type: initialSiteType,
} = window.OneUpdateOnboarding;

/**
* Create NONCE middleware for apiFetch
Expand Down Expand Up @@ -65,7 +68,7 @@

const OnboardingScreen = () => {
const [ siteType, setSiteType ] = useState< SiteType | '' >(
site_type || ''
initialSiteType || ''
);
const [ notice, setNotice ] = useState< NoticeState | null >( null );
const [ isSaving, setIsSaving ] = useState( false );
Expand Down Expand Up @@ -105,8 +108,8 @@
setSiteType( settings.oneupdate_site_type );

// Redirect user to setup page.
if ( setup_url ) {
window.location.href = setup_url;
if ( setupUrl ) {
window.location.href = setupUrl;
}
} );
} catch {
Expand Down
15 changes: 8 additions & 7 deletions assets/src/admin/plugin-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
SelectControl,
Spinner,
TextControl,
Card,

Check warning on line 17 in assets/src/admin/plugin-manager/index.js

View workflow job for this annotation

GitHub Actions / CSS/JS Lint / JS Lint & TypeScript

Use `Card.Root` from `@wordpress/ui` instead
CardBody,

Check warning on line 18 in assets/src/admin/plugin-manager/index.js

View workflow job for this annotation

GitHub Actions / CSS/JS Lint / JS Lint & TypeScript

Use `Card.Content` from `@wordpress/ui` instead
Flex,
FlexBlock,
FlexItem,
Expand All @@ -26,10 +26,10 @@
MenuGroup,
MenuItem,
__experimentalSpacer as Spacer,
Tooltip,

Check warning on line 29 in assets/src/admin/plugin-manager/index.js

View workflow job for this annotation

GitHub Actions / CSS/JS Lint / JS Lint & TypeScript

Use `Tooltip` from `@wordpress/ui` instead
CheckboxControl,
__experimentalVStack as VStack,

Check warning on line 31 in assets/src/admin/plugin-manager/index.js

View workflow job for this annotation

GitHub Actions / CSS/JS Lint / JS Lint & TypeScript

Use `Stack` from `@wordpress/ui` instead
__experimentalHStack as HStack,

Check warning on line 32 in assets/src/admin/plugin-manager/index.js

View workflow job for this annotation

GitHub Actions / CSS/JS Lint / JS Lint & TypeScript

Use `Stack` from `@wordpress/ui` instead
Notice,
Snackbar,
} from '@wordpress/components';
Expand Down Expand Up @@ -108,14 +108,14 @@
} else {
setIsValidS3Credentials( false );
}
} catch ( error ) {
} catch {
setIsValidS3Credentials( false );
}
}, [] );

useEffect( () => {
performHealthCheckOnS3Credentials();
}, [] );
}, [ performHealthCheckOnS3Credentials ] );

const fetchSitesWithPluginLoader = useCallback( async () => {
try {
Expand All @@ -139,7 +139,7 @@
const data = await response.json();
setAllAvailableSites( data.shared_sites || [] ); // Store all available sites for later use
return data.success ? data.shared_sites : [];
} catch ( error ) {
} catch {
return [];
}
}, [] );
Expand Down Expand Up @@ -170,7 +170,7 @@

const data = await response.json();
return data.success ? data.plugins : {};
} catch ( error ) {
} catch {
return {};
}
}, [] );
Expand Down Expand Up @@ -588,6 +588,7 @@
typeFilter,
updateFilter,
siteFilter,
allAvailableSites.length,
] );

const getUpdateTooltipText = ( plugin ) => {
Expand Down Expand Up @@ -946,7 +947,7 @@

// Refresh plugins data
await fetchRealTimePluginsData();
} catch ( error ) {
} catch {
setGlobalNotice( {
status: 'error',
message: sprintf(
Expand Down Expand Up @@ -1098,7 +1099,7 @@
status: 'success',
message: noticeMessage,
} );
} catch ( error ) {
} catch {
setGlobalNotice( {
status: 'error',
message: __( 'Failed to update plugins.', 'oneupdate' ),
Expand All @@ -1114,7 +1115,7 @@
setSelectedSites( ( prev ) => [ ...prev, url ] );
} else {
setSelectedSites( ( prev ) =>
prev.filter( ( url ) => url !== url )
prev.filter( ( siteUrl ) => siteUrl !== url )
);
}
};
Expand Down
2 changes: 1 addition & 1 deletion assets/src/admin/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const SettingsPage = () => {
if ( SITE_TYPE === 'governing-site' ) {
fetchAllAvailableGitHubRepos();
}
}, [ SITE_TYPE ] );
}, [ fetchAllAvailableGitHubRepos ] );

useEffect( () => {
apiFetch< { shared_sites?: BrandSite[] } >( {
Expand Down
87 changes: 47 additions & 40 deletions assets/src/components/GitHubRepoToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const GitHubRepoToken = ( {
} );

if ( ! response.ok ) {
// eslint-disable-next-line no-console
console.error(
'Error fetching GitHub token:',
response.statusText
Expand All @@ -52,50 +53,56 @@ const GitHubRepoToken = ( {

useEffect( () => {
getRepoToken();
}, [] );

const setGitHubRepoToken = useCallback( async ( token: string ) => {
const response = await fetch( `${ API_NAMESPACE }/github-token`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-WP-NONCE': NONCE,
},
body: JSON.stringify( { token } ),
} );
}, [ getRepoToken ] );

if ( response.ok === false || response.status === 400 ) {
setNotice( {
type: 'error',
message: __(
'Please enter valid GitHub PAT token.',
'oneupdate'
),
const setGitHubRepoToken = useCallback(
async ( token: string ) => {
const response = await fetch( `${ API_NAMESPACE }/github-token`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-WP-NONCE': NONCE,
},
body: JSON.stringify( { token } ),
} );
return;
}
const data = await response.json();

if ( data?.status === '400' ) {
setNotice( {
type: 'error',
message:
data?.message ||
__( 'Enter valid PAT token.', 'oneupdate' ),
} );
return;
}
if ( response.ok === false || response.status === 400 ) {
setNotice( {
type: 'error',
message: __(
'Please enter valid GitHub PAT token.',
'oneupdate'
),
} );
return;
}
const data = await response.json();

if ( data?.success ) {
setNotice( {
type: 'success',
message: __( 'GitHub token saved successfully.', 'oneupdate' ),
} );
await fetchAllAvailableGitHubRepos();
} else {
console.error( 'Error setting GitHub token:', data ); // eslint-disable-line no-console
}
}, [] );
if ( data?.status === '400' ) {
setNotice( {
type: 'error',
message:
data?.message ||
__( 'Enter valid PAT token.', 'oneupdate' ),
} );
return;
}

if ( data?.success ) {
setNotice( {
type: 'success',
message: __(
'GitHub token saved successfully.',
'oneupdate'
),
} );
await fetchAllAvailableGitHubRepos();
} else {
console.error( 'Error setting GitHub token:', data ); // eslint-disable-line no-console
}
},
[ fetchAllAvailableGitHubRepos, setNotice ]
);

return (
<Card style={ { marginTop: '20px' } }>
Expand Down
8 changes: 4 additions & 4 deletions assets/src/components/PluginGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
*/
import PluginCard from './PluginCard';

const API_NAMESPACE = OneUpdatePlugins.restUrl + '/oneupdate/v1';
const API_KEY = OneUpdatePlugins.api_key;
const API_NAMESPACE = window.OneUpdatePlugins.restUrl + '/oneupdate/v1';
const API_KEY = window.OneUpdatePlugins.api_key;

const PluginGrid = () => {
const [ page, setPage ] = useState( 1 );
Expand Down Expand Up @@ -105,7 +105,7 @@ const PluginGrid = () => {

useEffect( () => {
fetchSharedSitesData();
}, [] );
}, [ fetchSharedSitesData ] );

const handleSearchSubmit = () => {
setPage( 1 );
Expand Down Expand Up @@ -355,7 +355,7 @@ const ApplyPluginsModal = ( {
),
} );
}
} catch ( error ) {
} catch {
setIsNoticeVisible( true );
setNoticeMessage( {
type: 'error',
Expand Down
10 changes: 5 additions & 5 deletions assets/src/components/PluginsSharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
} from '@wordpress/components';
import { decodeEntities } from '@wordpress/html-entities';

const API_NAMESPACE = OneUpdatePlugins.restUrl + '/oneupdate/v1';
const RestNonce = OneUpdatePlugins.restNonce;
const API_NAMESPACE = window.OneUpdatePlugins.restUrl + '/oneupdate/v1';
const RestNonce = window.OneUpdatePlugins.restNonce;

const PluginCard = ( {
plugin,
Expand Down Expand Up @@ -315,7 +315,7 @@ const PluginGrid = () => {
if ( searchQuery ) {
fetchPlugins();
}
}, [ fetchPlugins ] );
}, [ fetchPlugins, searchQuery ] );

const handleRetry = () => fetchPlugins();

Expand Down Expand Up @@ -358,7 +358,7 @@ const PluginGrid = () => {

useEffect( () => {
fetchSharedSitesData();
}, [] );
}, [ fetchSharedSitesData ] );

const handleSearchSubmit = () => {
if ( ! searchInput.trim() ) {
Expand Down Expand Up @@ -749,7 +749,7 @@ const ApplyPluginsModal = ( {
),
} );
}
} catch ( error ) {
} catch {
setIsNoticeVisible( true );
setNoticeMessage( {
type: 'error',
Expand Down
4 changes: 2 additions & 2 deletions assets/src/components/S3Credentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ const S3Credentials = ( {
setS3Credentials( data.s3_credentials );
}
setIsLoading( false );
}, [] );
}, [ setNotice ] );

useEffect( () => {
getS3Credentials();
}, [] );
}, [ getS3Credentials ] );

const saveS3Credentials = useCallback( async () => {
setIsSaving( true );
Expand Down
13 changes: 7 additions & 6 deletions assets/src/components/S3ZipUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ const ApplyPluginsModal = ( {

useEffect( () => {
fetchSharedSitesData();
}, [] );
}, [ fetchSharedSitesData ] );

const applySelectedPlugins = useCallback( async () => {
setApplyingPlugins( true );
Expand Down Expand Up @@ -665,7 +665,7 @@ const ApplyPluginsModal = ( {
data.message,
} );
}
} catch ( error ) {
} catch {
setCurrentNotice( {
status: 'error',
message: __(
Expand All @@ -681,6 +681,7 @@ const ApplyPluginsModal = ( {
setShowApplyPluginsModal,
selectedSiteInfo,
setCurrentNotice,
setApplyingPlugins,
] );

const handleClose = () => {
Expand Down Expand Up @@ -788,13 +789,13 @@ const S3ZipUploader = () => {
} else {
setSharedSites( [] );
}
} catch ( error ) {
} catch {
setSharedSites( [] );
}
}, [] );

// Fetch upload history
const fetchHistory = () => {
const fetchHistory = useCallback( () => {
setLoadingHistory( true );
apiFetch( { path: '/oneupdate/v1/history' } )
.then( ( data ) => {
Expand All @@ -813,12 +814,12 @@ const S3ZipUploader = () => {
.catch( () => {
setLoadingHistory( false );
} );
};
}, [] );

useEffect( () => {
fetchHistory();
fetchSharedSitesData();
}, [] );
}, [ fetchHistory, fetchSharedSitesData ] );

// Handle file selection
const handleFileChange = ( event ) => {
Expand Down
2 changes: 1 addition & 1 deletion assets/src/components/SiteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const SiteModal = ( {
} );
setShowNotice( true );
}
} catch ( error ) {
} catch {
setErrors( {
...newErrors,
message: __(
Expand Down
Loading
Loading