-
Notifications
You must be signed in to change notification settings - Fork 0
Feature: auto multisite detection/configurations #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
up1512001
wants to merge
29
commits into
main
Choose a base branch
from
feature/auto-mu-configurations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
94c38bb
feature: created modal for plugins network activation to select gover…
up1512001 0131813
feature: created required rest routes for multisite configurations
up1512001 fbdbe71
feature: auto api key updation and modal markup for governing site se…
up1512001 03fd03f
feature: created required helpers utils functions
up1512001 bb0f98b
chore: enqueue required js files and created constants for options
up1512001 e29b830
feature: created modal for adding multisite brand sites
up1512001 9313c19
chore: make existing pattern/template working consistent
up1512001 cc996b7
chore: remove site options on plugin deletion and updated pot file
up1512001 055e12d
address copilot feedbacks
up1512001 5b8175f
chore: updated governing site selection route and added required styl…
up1512001 c28171a
update: remove plugins script loading from network plugin screen
up1512001 d29c933
update: set api key for multisite governing site selection
up1512001 c5287e9
address copilot feedbacks
up1512001 e67eec7
chore: fix type case issue with id's of multisite
up1512001 ee43d7d
update: health check to allow same multisite requests
up1512001 4922ca8
feature: auto assign brand-site to new created sites in same MU
up1512001 37bd850
update: site details in governing site if its changes any how
up1512001 e60562f
feature: change document title same as modal
up1512001 56a2e83
update: patterns sharing message same as template sharing
up1512001 1b06592
feature: remove all options/posts on plugin network deletion
up1512001 83a3dde
update: translations file
up1512001 28e84f2
fix: patterns site tabs issue
up1512001 ee31113
chore: update brand site patterns tab and refactor code
up1512001 65b886e
fix: site_id type issue
up1512001 892d38a
chore: replace od prefix with onedesign
up1512001 aa99600
update: site_id type to be string only
up1512001 ab37226
fix: type mis-matching issue with id
up1512001 073eb70
address copilot feedbacks
up1512001 7d56343
fix: site type issue in template sharing
up1512001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,169 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useState, useEffect, createRoot, useCallback, useRef } from '@wordpress/element'; | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { Card, CardHeader, CardBody, Notice, Button, SelectControl } from '@wordpress/components'; | ||
|
|
||
| /** | ||
| * Global variable from PHP | ||
| */ | ||
| import { MULTISITES, API_NAMESPACE, NONCE } from '../../js/constants'; | ||
|
|
||
| /** | ||
| * SiteTypeSelector component for selecting site type. | ||
| * | ||
| * @param {Object} props - Component properties. | ||
| * @param {string} props.value - Current selected value. | ||
| * @param {Function} props.setGoverningSite - Function to set governing site. | ||
| * | ||
| * @return {JSX.Element} Rendered component. | ||
| */ | ||
| const SiteTypeSelector = ( { value, setGoverningSite } ) => ( | ||
| <SelectControl | ||
| label={ __( 'Select Governing Site', 'onedesign' ) } | ||
| value={ value } | ||
| help={ __( 'Choose governing site from current multisite network. Other sites will be set as brand sites. This setting cannot be changed later and affects available features and configurations.', 'onedesign' ) } | ||
| onChange={ ( v ) => { | ||
| setGoverningSite( v ); | ||
| } } | ||
| options={ [ | ||
| { label: __( 'Select…', 'onedesign' ), value: '' }, | ||
| ...MULTISITES.map( ( site ) => ( { label: site.name, value: site.id } ) ), | ||
| ] } | ||
| /> | ||
| ); | ||
|
|
||
| /** | ||
| * Site type selection component for OneDesign Multisite setup. | ||
| * | ||
| * @return {JSX.Element} Rendered component. | ||
| */ | ||
| const OneDesignMultisiteGoverningSiteSelection = () => { | ||
| const [ governingSite, setGoverningSite ] = useState( '' ); | ||
| const currentGoverningSiteID = useRef( '' ); | ||
| const [ notice, setNotice ] = useState( null ); | ||
| const [ isSaving, setIsSaving ] = useState( false ); | ||
|
|
||
| const fetchCurrentGoverningSite = useCallback( async () => { | ||
| try { | ||
| const response = await fetch( | ||
| `${ API_NAMESPACE }/multisite/governing-site`, | ||
| { | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| 'X-WP-NONCE': NONCE, | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| if ( ! response.ok ) { | ||
| setNotice( { | ||
| type: 'error', | ||
| message: __( 'Error fetching current governing site.', 'onedesign' ), | ||
| } ); | ||
| return; | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
| if ( data?.governing_site ) { | ||
| setGoverningSite( data.governing_site ); | ||
| currentGoverningSiteID.current = data.governing_site; | ||
| } | ||
| return; | ||
| } catch { | ||
| setNotice( { | ||
| type: 'error', | ||
| message: __( 'Error fetching current governing site.', 'onedesign' ), | ||
| } ); | ||
| } | ||
| }, [] ); | ||
|
|
||
| useEffect( () => { | ||
| fetchCurrentGoverningSite(); | ||
| }, [] ); // eslint-disable-line react-hooks/exhaustive-deps | ||
|
|
||
| const handleGoverningSiteChange = useCallback( async ( value ) => { | ||
| setGoverningSite( value ); | ||
| currentGoverningSiteID.current = value; | ||
| setIsSaving( true ); | ||
|
|
||
| try { | ||
| const response = await fetch( `${ API_NAMESPACE }/multisite/governing-site`, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| 'X-WP-NONCE': NONCE, | ||
| }, | ||
| body: JSON.stringify( { governing_site_id: value } ), | ||
| } ); | ||
|
|
||
| if ( ! response.ok ) { | ||
| setNotice( { | ||
| type: 'error', | ||
| message: __( 'Error setting governing site.', 'onedesign' ), | ||
| } ); | ||
| setIsSaving( false ); | ||
| return; | ||
| } | ||
|
|
||
| setNotice( { | ||
| type: 'success', | ||
| message: __( 'Governing site updated successfully.', 'onedesign' ), | ||
| } ); | ||
|
|
||
| setTimeout( () => { | ||
| setIsSaving( false ); | ||
| window.location.reload(); | ||
| }, 1000 ); | ||
| return; | ||
| } catch { | ||
| setNotice( { | ||
| type: 'error', | ||
| message: __( 'Error setting governing site.', 'onedesign' ), | ||
| } ); | ||
| } finally { | ||
| setIsSaving( false ); | ||
| } | ||
| }, [] ); | ||
|
|
||
| return ( | ||
| <> | ||
| <Card> | ||
| <> | ||
| { notice?.message?.length > 0 && | ||
| <Notice | ||
| status={ notice?.type ?? 'success' } | ||
| isDismissible={ true } | ||
| onRemove={ () => setNotice( null ) } | ||
| > | ||
| { notice?.message } | ||
| </Notice> | ||
| } | ||
| </> | ||
| <CardHeader> | ||
| <h2>{ __( 'OneDesign', 'onedesign' ) }</h2> | ||
| </CardHeader> | ||
| <CardBody> | ||
| <SiteTypeSelector value={ governingSite } setGoverningSite={ setGoverningSite } /> | ||
| <Button | ||
| variant="primary" | ||
| onClick={ () => handleGoverningSiteChange( governingSite ) } | ||
| disabled={ isSaving || governingSite.trim().length === 0 || governingSite === currentGoverningSiteID.current } | ||
| style={ { marginTop: '1.5rem' } } | ||
| isBusy={ isSaving } | ||
| > | ||
| { __( 'Select Governing Site', 'onedesign' ) } | ||
| </Button> | ||
| </CardBody> | ||
| </Card> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| // Render to Gutenberg admin page with ID: onedesign-multisite-selection-modal | ||
| const target = document.getElementById( 'onedesign-multisite-selection-modal' ); | ||
| if ( target ) { | ||
| const root = createRoot( target ); | ||
| root.render( <OneDesignMultisiteGoverningSiteSelection /> ); | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.