Skip to content

Commit 5da6d77

Browse files
Merge pull request #6 from rtCamp/fix/change-settings-page-position
fix: change settings page position
2 parents 4c41ae9 + 17ce57e commit 5da6d77

File tree

3 files changed

+79
-42
lines changed

3 files changed

+79
-42
lines changed

assets/src/css/editor.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@
114114
animation: fadeIn 0.3s ease;
115115
}
116116

117+
.onedesign-modal-tabs {
118+
position: relative;
119+
120+
.onedesign-settings-button {
121+
position: absolute;
122+
top: 0;
123+
right: 0;
124+
background-color: #fff;
125+
height: 45px;
126+
width: 55px;
127+
}
128+
}
129+
117130
.onedesign-tabs {
118131

119132
.components-tab-panel__tabs {

assets/src/patterns-popover/components/LibraryModal.js

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* WordPress dependencies
33
*/
44
import { useState, useEffect, useCallback, useMemo } from '@wordpress/element';
5-
import { Modal, SearchControl, TabPanel, Spinner } from '@wordpress/components';
5+
import { Modal, SearchControl, TabPanel, Spinner, IconButton } from '@wordpress/components';
66
import { __ } from '@wordpress/i18n';
77
import { useSelect, useDispatch } from '@wordpress/data';
88
import apiFetch from '@wordpress/api-fetch';
@@ -453,47 +453,58 @@ const LibraryModal = () => {
453453
{ renderSearchResults() }
454454
</div>
455455

456-
<TabPanel
457-
className="onedesign-tabs"
458-
activeClass="active-tab"
459-
tabs={ tabs }
460-
onSelect={ handleTabSelect }
461-
>
462-
{ ( tab ) => {
463-
if ( tab.name === 'basePatterns' ) {
456+
<div className="onedesign-modal-tabs">
457+
<TabPanel
458+
className="onedesign-tabs"
459+
activeClass="active-tab"
460+
tabs={ tabs }
461+
onSelect={ handleTabSelect }
462+
>
463+
{ ( tab ) => {
464+
if ( tab.name === 'basePatterns' ) {
465+
return (
466+
<BasePatternsTab
467+
isLoading={ isLoading }
468+
basePatterns={ filteredBasePatterns }
469+
visibleCount={ visibleCount }
470+
handlePatternSelection={ handlePatternSelection }
471+
hasMorePatterns={ hasMorePatterns }
472+
loadMorePatterns={ loadMorePatterns }
473+
searchTerm={ searchTerm }
474+
setSelectedPatterns={ setSelectedPatterns }
475+
selectedPatterns={ selectedPatterns }
476+
applySelectedPatterns={ applySelectedPatterns }
477+
consumerSites={ consumerSites }
478+
sitePatterns={ allConsumerSitePatterns }
479+
/>
480+
);
481+
}
482+
// based on tab name show applied patterns
464483
return (
465-
<BasePatternsTab
466-
isLoading={ isLoading }
467-
basePatterns={ filteredBasePatterns }
468-
visibleCount={ visibleCount }
469-
handlePatternSelection={ handlePatternSelection }
470-
hasMorePatterns={ hasMorePatterns }
471-
loadMorePatterns={ loadMorePatterns }
472-
searchTerm={ searchTerm }
473-
setSelectedPatterns={ setSelectedPatterns }
484+
<AppliedPatternsTab
485+
isLoadingApplied={ isLoadingApplied }
486+
appliedPatterns={ getFilteredPatterns( tab ) }
487+
visibleAppliedCount={ visibleAppliedCount }
474488
selectedPatterns={ selectedPatterns }
475-
applySelectedPatterns={ applySelectedPatterns }
476-
consumerSites={ consumerSites }
477-
sitePatterns={ allConsumerSitePatterns }
489+
hasMoreAppliedPatterns={ hasMoreAppliedPatterns }
490+
loadMoreAppliedPatterns={ loadMoreAppliedPatterns }
491+
applySelectedPatterns={ removeSelectedPatterns }
492+
setVisibleAppliedCount={ setVisibleAppliedCount }
493+
siteInfo={ tab }
478494
/>
479495
);
480-
}
481-
// based on tab name show applied patterns
482-
return (
483-
<AppliedPatternsTab
484-
isLoadingApplied={ isLoadingApplied }
485-
appliedPatterns={ getFilteredPatterns( tab ) }
486-
visibleAppliedCount={ visibleAppliedCount }
487-
selectedPatterns={ selectedPatterns }
488-
hasMoreAppliedPatterns={ hasMoreAppliedPatterns }
489-
loadMoreAppliedPatterns={ loadMoreAppliedPatterns }
490-
applySelectedPatterns={ removeSelectedPatterns }
491-
setVisibleAppliedCount={ setVisibleAppliedCount }
492-
siteInfo={ tab }
493-
/>
494-
);
495-
} }
496-
</TabPanel>
496+
} }
497+
</TabPanel>
498+
{ /* Add icon button to redirect user to onedesign-settings page */ }
499+
<IconButton
500+
icon="admin-generic"
501+
label={ __( 'Go to OneDesign Settings', 'onedesign' ) }
502+
onClick={ () => {
503+
window.location.href = '/wp-admin/admin.php?page=onedesign-settings';
504+
} }
505+
className="onedesign-settings-button"
506+
/>
507+
</div>
497508
</div>
498509
</div>
499510
</Modal>

inc/classes/class-settings.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Settings {
2323
*
2424
* @var string
2525
*/
26-
const PAGE_SLUG = 'onedesign-settings';
26+
const PAGE_SLUG = 'onedesign';
2727

2828
/**
2929
* Option name for site type.
@@ -81,7 +81,7 @@ public function add_settings_page(): void {
8181
__( 'OneDesign', 'onedesign' ),
8282
'manage_options',
8383
self::PAGE_SLUG,
84-
array( $this, 'settings_page_content' ),
84+
'__return_null',
8585
'dashicons-admin-generic',
8686
100
8787
);
@@ -98,6 +98,17 @@ public function add_settings_page(): void {
9898
'__return_null'
9999
);
100100
}
101+
102+
add_submenu_page(
103+
self::PAGE_SLUG,
104+
__( 'Settings', 'onedesign' ),
105+
__( 'Settings', 'onedesign' ),
106+
'manage_options',
107+
'onedesign-settings',
108+
array( $this, 'settings_page_content' )
109+
);
110+
111+
remove_submenu_page( 'onedesign', 'onedesign' );
101112
}
102113

103114
/**
@@ -109,8 +120,10 @@ public function add_settings_page(): void {
109120
* @return void
110121
*/
111122
public function handle_design_library_redirect(): void {
123+
$pages = array( 'design-library', 'onedesign' );
124+
112125
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
113-
if ( ! isset( $_GET['page'] ) || 'design-library' !== $_GET['page'] ) {
126+
if ( ! isset( $_GET['page'] ) || ! in_array( $_GET['page'], $pages, true ) ) {
114127
return;
115128
}
116129

@@ -379,7 +392,7 @@ public function api_key_regenerated_notice(): void {
379392
* @return void
380393
*/
381394
public function enqueue_admin_scripts( string $hook ): void {
382-
if ( ( 'toplevel_page_' . self::PAGE_SLUG ) !== $hook && 'onedesign_page_design-library' !== $hook ) {
395+
if ( ! str_contains( $hook, self::PAGE_SLUG ) ) {
383396
return;
384397
}
385398

0 commit comments

Comments
 (0)