Skip to content

Commit 58c650c

Browse files
chore: addredd PR feedback
Co-authored-by: Utsav Patel <[email protected]> Co-authored-by: Vishal Kakadiya <[email protected]>
1 parent 3518cc2 commit 58c650c

File tree

13 files changed

+207
-159
lines changed

13 files changed

+207
-159
lines changed

assets/src/admin/patterns/components/PatternModal.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ import { cog } from '@wordpress/icons';
2525
import BasePatternsTab from './BasePatternsTab';
2626
import AppliedPatternsTab from './AppliedPatternsTab';
2727
import Category from './Category';
28-
29-
/**
30-
* Global data
31-
*/
32-
const SettingLink = patternSyncData?.settingsLink;
28+
import { SETTINGS_LINK as SettingLink } from '../../../js/constants';
3329

3430
/**
3531
* Fetch all brand site patterns

assets/src/admin/patterns/pattern-event.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { __ } from '@wordpress/i18n';
5+
16
/**
27
* This File contains the code to add the Design Library Button.
38
*/
@@ -46,7 +51,7 @@ window.addEventListener( 'DOMContentLoaded', function() {
4651
this.libraryCache.switchModeButton.addEventListener( 'click', () => {
4752
window.console.log( 'Firing Custom Event' );
4853
const designLibraryModalOpenEvent = new CustomEvent( 'designLibraryModalOpen', {
49-
detail: { message: 'Open the Design Library Modal!' },
54+
detail: { message: __( 'Open the Design Library Modal!', 'onedesign' ) },
5055
} );
5156

5257
document.dispatchEvent( designLibraryModalOpenEvent );

assets/src/admin/plugin/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import { __ } from '@wordpress/i18n';
66
import { Card, CardHeader, CardBody, Notice, Button, SelectControl } from '@wordpress/components';
77

88
/**
9-
* Global variable from PHP
9+
* Internal dependencies
1010
*/
11-
const API_NAMESPACE = OneDesignSettings.restUrl + '/onedesign/v1';
12-
const NONCE = OneDesignSettings.restNonce;
13-
const API_KEY = OneDesignSettings.apiKey;
11+
import { API_NAMESPACE, NONCE, API_KEY, SETTINGS_LINK } from '../../js/constants';
1412

1513
/**
1614
* SiteTypeSelector component for selecting site type.
@@ -106,7 +104,7 @@ const OneDesignSiteTypeSelection = () => {
106104
setSiteType( data.site_type );
107105

108106
// redirect user to setup page.
109-
window.location.href = OneDesignSettings.setupUrl;
107+
window.location.href = SETTINGS_LINK;
110108
}
111109
} catch {
112110
setNotice( {

assets/src/admin/settings/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ import { Snackbar } from '@wordpress/components';
1111
import SiteTable from '../../components/SiteTable';
1212
import SiteModal from '../../components/SiteModal';
1313
import SiteSettings from '../../components/SiteSettings';
14-
15-
/**
16-
* Global variable from PHP
17-
*/
18-
const API_NAMESPACE = OneDesignSettings.restUrl + '/onedesign/v1';
19-
const NONCE = OneDesignSettings.restNonce;
14+
import { API_NAMESPACE, NONCE } from '../../js/constants';
2015

2116
/**
2217
* Settings page component for OneDesign plugin.

assets/src/admin/templates/components/BrandSiteTemplates.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ import { useCallback, useState } from '@wordpress/element';
1313
* Internal dependencies
1414
*/
1515
import MemoizedTemplatePreview from './MemoizedTemplatePreview';
16-
17-
// Global variable from PHP
18-
const REST_NAMESPACE = TemplateLibraryData?.restUrl;
19-
const NONCE = TemplateLibraryData?.nonce;
16+
import { API_NAMESPACE as REST_NAMESPACE, NONCE } from '../../../js/constants';
2017

2118
/**
2219
* BrandSiteTemplates component.
@@ -61,17 +58,20 @@ const BrandSiteTemplates = ( { filteredTemplates, currentPage, PER_PAGE, selecte
6158
const data = await response.json();
6259
if ( data.success ) {
6360
fetchConnectedSitesTemplates();
61+
62+
const count = selectedTemplates.length;
63+
6464
setNotice( {
6565
type: 'success',
6666
message: sprintf(
6767
/* translators: %d: Number of templates removed. */
6868
_n(
6969
'%d template removed successfully.',
7070
'%d templates removed successfully.',
71-
selectedTemplates.length,
71+
count,
7272
'onedesign',
7373
),
74-
selectedTemplates.length,
74+
count,
7575
),
7676
} );
7777
setSelectedTemplates( [] );
@@ -168,7 +168,7 @@ const BrandSiteTemplates = ( { filteredTemplates, currentPage, PER_PAGE, selecte
168168
{ renderPagination() }
169169
{ isRemoveModalOpen && (
170170
<Modal
171-
title={ __( 'Remove Template' ) }
171+
title={ __( 'Remove Template', 'onedesign' ) }
172172
onRequestClose={ () => {
173173
setIsRemoveModalOpen( false );
174174
} }

assets/src/admin/templates/components/MemoizedTemplatePreview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const MemoizedTemplatePreview = memo(
102102
role="button"
103103
tabIndex={ 0 }
104104
onKeyDown={ ( e ) => {
105-
if ( e.key === 'Enter' || e.key === ' ' ) {
105+
if ( e.code === 'Enter' || e.code === 'Space' ) {
106106
e.preventDefault();
107107
onSelect( template );
108108
}

assets/src/admin/templates/components/TemplateModal.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ import { cog } from '@wordpress/icons';
1818
import BaseSiteTemplates from './BaseSiteTemplates';
1919
import SiteSelection from './SiteSelection';
2020
import BrandSiteTemplates from './BrandSiteTemplates';
21-
22-
// Global variable from PHP
23-
const REST_NAMESPACE = TemplateLibraryData?.restUrl;
24-
const NONCE = TemplateLibraryData?.nonce;
25-
const SettingLink = TemplateLibraryData?.settingsLink;
26-
const PER_PAGE = 9;
21+
import { API_NAMESPACE as REST_NAMESPACE, NONCE, SETTINGS_LINK as SettingLink, PER_PAGE } from '../../../js/constants';
2722

2823
/**
2924
* TemplateModal component.

assets/src/admin/templates/template-event.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { __ } from '@wordpress/i18n';
5+
16
/**
27
* This File contains the code to add the Design Library Button.
38
*/
@@ -46,7 +51,7 @@ window.addEventListener( 'DOMContentLoaded', function() {
4651
this.libraryCache.switchModeButton.addEventListener( 'click', () => {
4752
window.console.log( 'Template event fired...' );
4853
const TemplateLibraryOpenEvent = new CustomEvent( 'TemplateLibraryOpen', {
49-
detail: { message: 'Open the Design Library Modal!' },
54+
detail: { message: __( 'Open the Design Library Modal!', 'onedesign' ) },
5055
} );
5156

5257
document.dispatchEvent( TemplateLibraryOpenEvent );

assets/src/components/SiteSettings.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ import {
1616
import { __ } from '@wordpress/i18n';
1717

1818
/**
19-
* Global variable from PHP
19+
* internal dependencies
2020
*/
21-
const API_NAMESPACE = OneDesignSettings.restUrl + '/onedesign/v1';
22-
const NONCE = OneDesignSettings.restNonce;
23-
const API_KEY = OneDesignSettings.apiKey;
21+
import { API_NAMESPACE, NONCE, API_KEY } from '../js/constants';
2422

2523
/**
2624
* SiteSettings component for managing API key and governing site connection.

assets/src/js/constants.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* PHP consts for JS usage.
3+
*
4+
* @package
5+
*/
6+
7+
let settings = {};
8+
9+
if ( typeof window.OneDesignSettings !== 'undefined' ) {
10+
settings = window.OneDesignSettings;
11+
} else if ( typeof window.patternSyncData !== 'undefined' ) {
12+
settings = window.patternSyncData;
13+
} else if ( typeof window.TemplateLibraryData !== 'undefined' ) {
14+
settings = window.TemplateLibraryData;
15+
}
16+
17+
const ONEDESIGN_REST_NAME = 'onedesign';
18+
const ONEDESIGN_REST_VERSION = 'v1';
19+
20+
const API_NAMESPACE = settings?.restUrl ? settings.restUrl + `/${ ONEDESIGN_REST_NAME }/${ ONEDESIGN_REST_VERSION }` : '';
21+
const NONCE = settings?.restNonce ? settings.restNonce : '';
22+
const API_KEY = settings?.apiKey ? settings.apiKey : '';
23+
const SETTINGS_LINK = settings?.settingsLink ? settings.settingsLink : '';
24+
const PER_PAGE = 9;
25+
26+
export {
27+
API_NAMESPACE,
28+
NONCE,
29+
API_KEY,
30+
SETTINGS_LINK,
31+
PER_PAGE,
32+
};

0 commit comments

Comments
 (0)