-
Notifications
You must be signed in to change notification settings - Fork 384
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
Highlight AMP-compatible themes and plugins in admin #6597
Merged
westonruter
merged 110 commits into
develop
from
enhancement/2313-highlight-amp-compatible-theme-plugin
Nov 3, 2021
Merged
Changes from 108 commits
Commits
Show all changes
110 commits
Select commit
Hold shift + click to select a range
1e8de3b
Add skeleton for new tab in plugin install screen
dhaval-parekh 34ae487
Add skeleton for new tab in theme install screen
dhaval-parekh dda5938
Add script for generate json file for plugins and themes
dhaval-parekh 5deff42
update script for plugin and theme json data
dhaval-parekh 68b73ac
Update json file for plugin
dhaval-parekh 1dc1f8d
Add basic markup for AMP tab in plugin install screen
dhaval-parekh 19f3e15
Change the content of amp tab in install plugin page
dhaval-parekh c1ed08c
Add AMP icon in PX Enhancing tab
dhaval-parekh 0afc726
Add PX enahacing tab in theme install screen
dhaval-parekh f7cc67d
Add PX enahacing tab in theme install screen
dhaval-parekh 5cc29a6
Add New tab in theme install page for PX enhanced themes
dhaval-parekh dac1640
Add tooltip in AMP compatible message in install plugin/theme page
dhaval-parekh efd0253
Add AMP compatiable message in plugin card on install plugin page
dhaval-parekh 31f36ff
Add plugin meta for AMP compatibility in plugin listing page
dhaval-parekh e235fe2
Add AMP compatiable message for compatiable themes in installed theme…
dhaval-parekh 89514c7
Remove rating info for none wporg plugins
dhaval-parekh b088689
Rename the class names
dhaval-parekh d5e095e
Add unit test cases
dhaval-parekh 6ef834a
Add PX enhanced message in on borading wizard
dhaval-parekh e36e7a1
Fix markup on search plugin page
dhaval-parekh 1c5de0a
Add AMP message in add plugin screen after search result comes in
dhaval-parekh 87ee462
Update package-lock.json
dhaval-parekh 041e779
Update package-lock.json
dhaval-parekh 3f5242e
Merge branch 'develop' into enhancement/2313-highlight-amp-compatible…
dhaval-parekh ceacbd7
Use wp_filesystem instead of php function to read files
dhaval-parekh ca47dcf
Add function docs
dhaval-parekh 83421e1
Update plugin and theme json data and remove unused functions
dhaval-parekh f0c7712
Remove duplicate css and update tooltip message
dhaval-parekh 08f4163
Remove the usage of jquery and udpate package.json
dhaval-parekh 639796d
Remove AMP Compatible message for themes in AMP onboarding screen
dhaval-parekh bd562c0
Increase the limit to fetch data from API.
dhaval-parekh 2be96cd
Fix JS issue and revert changes of OnboardingWizardSubmenuPage.php
dhaval-parekh 34a5162
Apply suggestion from PR
dhaval-parekh 6c301df
fetch AMP plugin and theme data when it needed
dhaval-parekh 49b368c
Store AMP plugins/themes data into php files instead of JSON
dhaval-parekh b12e572
Update function docs
dhaval-parekh f386e29
Omit the empty field for the plugin/theme data, and fill it in when n…
dhaval-parekh 6359f2d
Merge branch 'develop' into enhancement/2313-highlight-amp-compatible…
dhaval-parekh 04ac429
Fix unit test cases
dhaval-parekh 097ac8d
Rename the command and file that update AMP extension files
dhaval-parekh 7ecf415
Replace single quote with double quote while converting object to php…
dhaval-parekh 91cf776
Prevent to store plugin description in php file
dhaval-parekh 68bbb9c
Use innerText instead of innerHTML
dhaval-parekh d8ac7dc
Add unit test case for get_plugins() and get_themes()
dhaval-parekh 55faed3
Update the logic to covernt JS object into PHP array
dhaval-parekh de077b4
Update Gruntfile.js to add auto-generated files
dhaval-parekh fe7d4bb
Add multiple attempt to fetch data from wp.org API
dhaval-parekh 89839bf
Fix unit test cases
dhaval-parekh 6558ab5
Add a check for if an auto-generated file is exists
dhaval-parekh de2bd9e
Merge branch 'develop' into enhancement/2313-highlight-amp-compatible…
dhaval-parekh d99b7a3
Remove unwanted eslint ignore comments
dhaval-parekh 85247dd
Add logging to indicate what is going on
westonruter d032f72
Simplify conditional
westonruter 088b805
Abort update-extension-files when files exist
westonruter 599d1f3
Opt to commit amp-plugins and amp-themes data to repo
westonruter ce93a3f
Exclude phpcs rules for exported data
westonruter 231749e
Fix lintstaged pattern to match 'amp-' prefixed files in includes dir…
westonruter 8ef0ec3
Move theme/plugin files into includes/ecosystem-data directory
westonruter 1a10ded
Remove update-extension-files from running as part of build
westonruter b82cf95
Add notice for how files were generated
westonruter 888a639
Mark ecosystem data files as being generated files
westonruter 4d02116
Update script to fetch AMP extension data,
dhaval-parekh 08861f9
Remove the usage of tmp file to convert JS object into PHP array
dhaval-parekh e240f44
Prevent rectangular images from being stretched into a square plugin …
westonruter cbd8cab
Remove AMP logo from theme/plugin directory tabs
westonruter 2514c1c
Add AMP Compatible tab to end instead of beginning
westonruter 6d923e7
Remove additional info from plugin card in AMP Compatible tab
dhaval-parekh 65bfa8b
Omit extra field being stored for AMP plugins and themes.
dhaval-parekh 112a772
Prevent showing AMP compatibility message in AMP compatible tab
dhaval-parekh a0514dd
Speed up update-extension-files by requesting ecosystem data with lin…
westonruter 9171748
Regenerate ecosystem data after data entry fixes on amp-wp.org
westonruter 5318ec1
Move AMP compatible message from bottom to top left corner
dhaval-parekh 2fbad0e
Update package-lock.json
dhaval-parekh c0cf8c5
Merge branch 'develop' into enhancement/2313-highlight-amp-compatible…
dhaval-parekh 7a93019
Merge branch 'develop' of github.com:ampproject/amp-wp into enhanceme…
westonruter a266f25
Revert "Update package-lock.json"
westonruter 47ebc63
Replace extension-card-px-message with amp-extension-card-message
westonruter 3082968
Replace 'AMP' with 'Amp' for symbol readability
westonruter b2a3dc4
Replace references to PX with AMP for now
westonruter 7e9331d
Utilize URLSearchParams for parsing query params
westonruter 78fcfd2
Improve tooltip text
westonruter 6630e71
Remove AMP icon from plugin row meta
westonruter 46cf134
Exclude ecosystem-data from codecov
westonruter afbbcd4
Sort imports
westonruter f0e5cee
Update package-lock with latest for version 1
westonruter 7d07c70
Improve method name for filtering themes_api
westonruter ee71030
Add missing link text for AMP Compatible tab on Themes screen
westonruter 3edc227
Add amp_compatible_ecosystem_shown filter to disable integration
westonruter ec437c5
Add PhpUnusedParameterInspection ignorance
westonruter 03171f8
Account for plugins and themes variables always being arrays
westonruter 08743c6
Sort themes and plugins alphabetically
westonruter 16735e3
Add includes/ecosystem-data to PHP exclusion list
westonruter 6e552c1
Utilize MutationObserver to watch for card updates
westonruter 15e6199
Only run code for plugin search results setup once
westonruter 25b83eb
Improve placement of isAmpCompatibleTab conditionals
westonruter c64ff0e
Simplify logic considering once events
westonruter 7a8487f
Remove extraneous spaces and improve child manipulation
westonruter 46db0a2
Prevent showing AMP badge icon on AMP Compatible themes tab
westonruter f47398b
Remove fs and child_process packages since built-in to Node
westonruter 760ae35
Regenerate ecosystem data
westonruter 53a85b7
Prevent adding assets needlessly to plugin list table
westonruter 9cfc78c
Fix AmpPlugin::register test and remove unused is_file_exists vars
westonruter 46fc670
Try fixing AmpThemesTest::test_is_needed
westonruter 0981169
Define 'amp-compatible' in constants
westonruter 326b603
Fix import order
westonruter 496a134
Add noopener and noreferrer to ecosystem links
westonruter 83c6d3c
Show all AMP-compatible plugins since pagination is not working
westonruter b7f8e6e
Improve method names in AmpPlugins
westonruter 7ee0295
Improve methods in AmpThemes
westonruter 49b37fa
Use more int casting
westonruter 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
.plugin-icon { | ||
object-fit: contain; /* Account for non-square icons being used. */ | ||
} | ||
|
||
.plugin-card { | ||
position: relative; | ||
} | ||
|
||
.amp-extension-card-message { | ||
text-align: center; | ||
padding: 0; | ||
clear: both; | ||
background-color: #fff; | ||
color: #3c434a; | ||
position: absolute; | ||
top: -10px; | ||
left: -10px; | ||
border-radius: 15px; | ||
} | ||
|
||
.amp-logo-icon { | ||
background-image: url("../images/amp-logo-icon.svg"); | ||
background-color: transparent; | ||
background-size: 30px; | ||
height: 30px; | ||
width: 30px; | ||
display: inline-block; | ||
vertical-align: middle; | ||
cursor: pointer; | ||
} | ||
|
||
.amp-logo-icon.small { | ||
background-size: 15px 15px; | ||
height: 15px; | ||
width: 15px; | ||
} | ||
|
||
.theme-browser .theme { | ||
float: none; | ||
display: inline-block; | ||
vertical-align: top; | ||
} | ||
|
||
.plugin-install-tab-amp-compatible .plugin-card-bottom { | ||
display: none; | ||
} | ||
|
||
.amp-extension-card-message .tooltiptext { | ||
visibility: hidden; | ||
width: 60%; | ||
background-color: rgba(0, 0, 0, 0.8); | ||
color: #fff; | ||
text-align: center; | ||
border-radius: 6px; | ||
padding: 5px; | ||
position: absolute; | ||
z-index: 1; | ||
left: 40px; | ||
min-width: 200px; | ||
} | ||
|
||
.tooltiptext::after { | ||
content: ""; | ||
position: absolute; | ||
top: 10px; | ||
right: 100%; | ||
border-width: 7px; | ||
border-style: solid; | ||
border-color: transparent rgba(0, 0, 0, 0.8) transparent transparent; | ||
} | ||
|
||
.amp-extension-card-message:hover .tooltiptext { | ||
visibility: visible; | ||
} |
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,115 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import domReady from '@wordpress/dom-ready'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { AMP_PLUGINS, AMP_COMPATIBLE } from 'amp-plugins'; // From WP inline script. | ||
import { debounce } from 'lodash'; | ||
|
||
const ampPluginInstall = { | ||
|
||
/** | ||
* Init function. | ||
*/ | ||
init() { | ||
if ( this.isAmpCompatibleTab() ) { | ||
this.removeAdditionalInfo(); | ||
} else { | ||
this.addAmpMessage(); | ||
} | ||
this.addAmpMessageInSearchResult(); | ||
}, | ||
|
||
/** | ||
* Check if "AMP Compatible" tab is open or not. | ||
* | ||
* @return {boolean} Is AMP-compatible tab. | ||
*/ | ||
isAmpCompatibleTab() { | ||
const queryParams = new URLSearchParams( window.location.search.substr( 1 ) ); | ||
return queryParams.get( 'tab' ) === AMP_COMPATIBLE; | ||
}, | ||
|
||
/** | ||
* Add message for AMP Compatibility in AMP-compatible plugins card after search result comes in. | ||
*/ | ||
addAmpMessageInSearchResult() { | ||
const pluginFilterForm = document.getElementById( 'plugin-filter' ); | ||
const pluginInstallSearch = document.querySelector( '.plugin-install-php .wp-filter-search' ); | ||
if ( ! pluginFilterForm || ! pluginInstallSearch ) { | ||
return; | ||
} | ||
|
||
const startSearchResults = debounce( () => { | ||
pluginInstallSearch.removeEventListener( 'input', startSearchResults, { once: true } ); // For IE 11 which doesn't support once events. | ||
|
||
// Replace the class for our custom AMP-compatible tab once doing a search. | ||
const wrap = document.querySelector( '.plugin-install-tab-amp-compatible' ); | ||
if ( wrap ) { | ||
wrap.classList.remove( 'plugin-install-tab-amp-compatible' ); | ||
wrap.classList.add( 'plugin-install-tab-search-result' ); | ||
} | ||
|
||
// Start watching for changes the first time a search is being made. | ||
const mutationObserver = new MutationObserver( () => { | ||
this.addAmpMessage(); | ||
} ); | ||
mutationObserver.observe( pluginFilterForm, { childList: true } ); | ||
}, 1000 ); // See timeout in core: <https://github.com/WordPress/WordPress/blob/b87617e2719d114d123a88ed7e489170f0204735/wp-admin/js/updates.js#L2578> | ||
|
||
pluginInstallSearch.addEventListener( 'input', startSearchResults, { once: true } ); | ||
}, | ||
|
||
/** | ||
* Add message for AMP Compatibility in AMP-compatible plugins card. | ||
*/ | ||
addAmpMessage() { | ||
for ( const pluginSlug of AMP_PLUGINS ) { | ||
const pluginCardElement = document.querySelector( `.plugin-card.plugin-card-${ pluginSlug }` ); | ||
|
||
if ( ! pluginCardElement ) { | ||
continue; | ||
} | ||
|
||
// Skip cards that have already been processed. | ||
if ( pluginCardElement.classList.contains( 'amp-extension-card-message' ) ) { | ||
continue; | ||
} | ||
|
||
const messageElement = document.createElement( 'div' ); | ||
const iconElement = document.createElement( 'span' ); | ||
const tooltipElement = document.createElement( 'span' ); | ||
|
||
messageElement.classList.add( 'amp-extension-card-message' ); | ||
iconElement.classList.add( 'amp-logo-icon' ); | ||
tooltipElement.classList.add( 'tooltiptext' ); | ||
|
||
tooltipElement.append( | ||
__( 'This is known to work well with the AMP plugin.', 'amp' ), | ||
); | ||
|
||
messageElement.append( iconElement ); | ||
messageElement.append( tooltipElement ); | ||
|
||
pluginCardElement.appendChild( messageElement ); | ||
} | ||
}, | ||
|
||
/** | ||
* Remove the additional info from the plugin card in the "AMP Compatible" tab. | ||
*/ | ||
removeAdditionalInfo() { | ||
const pluginCardBottom = document.querySelectorAll( '.plugin-install-tab-amp-compatible .plugin-card-bottom' ); | ||
for ( const elementNode of pluginCardBottom ) { | ||
elementNode.remove(); | ||
} | ||
}, | ||
}; | ||
|
||
domReady( () => { | ||
ampPluginInstall.init(); | ||
} ); |
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,59 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import domReady from '@wordpress/dom-ready'; | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { AMP_COMPATIBLE } from 'amp-themes'; // From WP inline script. | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ampViewTheme from './theme-install/view/theme'; | ||
|
||
const ampThemeInstall = { | ||
|
||
/** | ||
* Init function. | ||
*/ | ||
init() { | ||
this.addTab(); | ||
this.overrideViews(); | ||
}, | ||
|
||
/** | ||
* Add a new tab for AMP-compatible themes on theme install page. | ||
*/ | ||
addTab() { | ||
const filterLinks = document.querySelector( '.filter-links' ); | ||
if ( ! filterLinks ) { | ||
return; | ||
} | ||
|
||
const listItem = document.createElement( 'li' ); | ||
const anchorElement = document.createElement( 'a' ); | ||
|
||
anchorElement.setAttribute( 'href', '#' ); | ||
anchorElement.setAttribute( 'data-sort', AMP_COMPATIBLE ); | ||
anchorElement.append( __( 'AMP Compatible', 'amp' ) ); | ||
|
||
listItem.appendChild( anchorElement ); | ||
|
||
filterLinks.appendChild( listItem ); | ||
}, | ||
|
||
/** | ||
* Override theme view. | ||
*/ | ||
overrideViews() { | ||
wp.themes.view.Theme = ampViewTheme; | ||
}, | ||
|
||
}; | ||
|
||
domReady( () => { | ||
ampThemeInstall.init(); | ||
} ); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something we may need to look out for here: what if another plugin is also doing a similar thing? Will their overrides get lost? I suppose not if they are also extending
wp.themes.view.Theme
because if they do so then they would be extending our extension, or vice-versa. Still, something to look out for.