This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from studiopress/feature/detect-local-environ…
…ment [GF-3828] Detect Local Environment, Add Dismissible Notice
- Loading branch information
Showing
16 changed files
with
356 additions
and
26 deletions.
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
wp-modules/app/js/src/components/Notices/EnvironmentNotice/index.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,51 @@ | ||
// WP dependencies | ||
import { __ } from '@wordpress/i18n'; | ||
import { createInterpolateElement } from '@wordpress/element'; | ||
import { Notice, Dashicon } from '@wordpress/components'; | ||
|
||
type Props = { | ||
isVisible: boolean; | ||
handleDismiss: () => void; | ||
}; | ||
|
||
/** Display a notice if no version control is detected in the theme. */ | ||
export default function EnvironmentNotice( { | ||
isVisible, | ||
handleDismiss, | ||
}: Props ) { | ||
return isVisible ? ( | ||
<Notice | ||
className="patternmanager-notice" | ||
isDismissible | ||
status="error" | ||
onRemove={ handleDismiss } | ||
> | ||
{ createInterpolateElement( | ||
__( | ||
'A local development environment was not detected. Pattern Manager is not intended for use on a live site. <div></div>Download <a></a>.', | ||
'pattern-manager' | ||
), | ||
{ | ||
div: <div style={ { marginTop: '1rem' } }></div>, | ||
a: ( | ||
<a | ||
href="https://localwp.com/?modal=download" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
aria-label="Download Local by WP Engine (opens in new tab)" | ||
> | ||
{ __( 'Local by WP Engine', 'pattern-manager' ) } | ||
<span className="screen-reader-text"> | ||
{ __( | ||
'(opens in a new tab)', | ||
'pattern-manager' | ||
) } | ||
</span> | ||
<Dashicon icon={ 'external' } /> | ||
</a> | ||
), | ||
} | ||
) } | ||
</Notice> | ||
) : null; | ||
} |
47 changes: 47 additions & 0 deletions
47
wp-modules/app/js/src/components/Notices/EnvironmentNotice/test/index.spec.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,47 @@ | ||
import { create, act } from 'react-test-renderer'; | ||
import EnvironmentNotice from '..'; | ||
|
||
it( 'EnvironmentNotice is not visible when passed falsy isVisible', () => { | ||
const testRenderer = create( | ||
<EnvironmentNotice isVisible={ false } handleDismiss={ () => {} } /> | ||
); | ||
|
||
expect( testRenderer.toJSON() ).toBeNull(); | ||
|
||
testRenderer.unmount(); | ||
} ); | ||
|
||
it( 'EnvironmentNotice is visible when passed truthy isVisible', () => { | ||
const testRenderer = create( | ||
<EnvironmentNotice isVisible={ true } handleDismiss={ () => {} } /> | ||
); | ||
|
||
expect( testRenderer.toJSON() ).toMatchObject( { | ||
props: { | ||
className: | ||
'patternmanager-notice components-notice is-error is-dismissible', | ||
}, | ||
type: 'div', | ||
} ); | ||
|
||
testRenderer.unmount(); | ||
} ); | ||
|
||
it( 'EnvironmentNotice is dismissible', () => { | ||
const handleDismissSpy = jest.fn(); | ||
const testRenderer = create( | ||
<EnvironmentNotice | ||
isVisible={ true } | ||
handleDismiss={ handleDismissSpy } | ||
/> | ||
); | ||
|
||
// Dismiss the notice. | ||
act( () => { | ||
testRenderer.root.findByProps( { type: 'button' } ).props.onClick(); | ||
} ); | ||
|
||
expect( handleDismissSpy ).toHaveBeenCalled(); | ||
|
||
testRenderer.unmount(); | ||
} ); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as EnvironmentNotice } from './EnvironmentNotice'; | ||
export { default as VersionControlNotice } from './VersionControlNotice'; |
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,25 @@ | ||
import { useState } from '@wordpress/element'; | ||
import { patternManager } from '../globals'; | ||
import getHeaders from '../utils/getHeaders'; | ||
|
||
export default function useEnvironment( initialEnvironmentNotice: boolean ) { | ||
const [ displayNotice, setDisplayNotice ] = useState( | ||
initialEnvironmentNotice | ||
); | ||
|
||
function updateDismissedSites() { | ||
setDisplayNotice( false ); | ||
return fetch( | ||
patternManager.apiEndpoints.updateDismissedSitesEndpoint, | ||
{ | ||
method: 'POST', | ||
headers: getHeaders(), | ||
} | ||
); | ||
} | ||
|
||
return { | ||
displayNotice, | ||
updateDismissedSites, | ||
}; | ||
} |
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
Oops, something went wrong.