Skip to content
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
Merged
Show file tree
Hide file tree
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 Sep 1, 2021
34ae487
Add skeleton for new tab in theme install screen
dhaval-parekh Sep 1, 2021
dda5938
Add script for generate json file for plugins and themes
dhaval-parekh Sep 3, 2021
5deff42
update script for plugin and theme json data
dhaval-parekh Sep 3, 2021
68b73ac
Update json file for plugin
dhaval-parekh Sep 4, 2021
1dc1f8d
Add basic markup for AMP tab in plugin install screen
dhaval-parekh Sep 4, 2021
19f3e15
Change the content of amp tab in install plugin page
dhaval-parekh Sep 6, 2021
c1ed08c
Add AMP icon in PX Enhancing tab
dhaval-parekh Sep 6, 2021
0afc726
Add PX enahacing tab in theme install screen
dhaval-parekh Sep 7, 2021
f7cc67d
Add PX enahacing tab in theme install screen
dhaval-parekh Sep 7, 2021
5cc29a6
Add New tab in theme install page for PX enhanced themes
dhaval-parekh Sep 7, 2021
dac1640
Add tooltip in AMP compatible message in install plugin/theme page
dhaval-parekh Sep 7, 2021
efd0253
Add AMP compatiable message in plugin card on install plugin page
dhaval-parekh Sep 7, 2021
31f36ff
Add plugin meta for AMP compatibility in plugin listing page
dhaval-parekh Sep 8, 2021
e235fe2
Add AMP compatiable message for compatiable themes in installed theme…
dhaval-parekh Sep 8, 2021
89514c7
Remove rating info for none wporg plugins
dhaval-parekh Sep 8, 2021
b088689
Rename the class names
dhaval-parekh Sep 8, 2021
d5e095e
Add unit test cases
dhaval-parekh Sep 8, 2021
6ef834a
Add PX enhanced message in on borading wizard
dhaval-parekh Sep 9, 2021
e36e7a1
Fix markup on search plugin page
dhaval-parekh Sep 10, 2021
1c5de0a
Add AMP message in add plugin screen after search result comes in
dhaval-parekh Sep 10, 2021
87ee462
Update package-lock.json
dhaval-parekh Oct 5, 2021
041e779
Update package-lock.json
dhaval-parekh Oct 5, 2021
3f5242e
Merge branch 'develop' into enhancement/2313-highlight-amp-compatible…
dhaval-parekh Oct 11, 2021
ceacbd7
Use wp_filesystem instead of php function to read files
dhaval-parekh Oct 11, 2021
ca47dcf
Add function docs
dhaval-parekh Oct 11, 2021
83421e1
Update plugin and theme json data and remove unused functions
dhaval-parekh Oct 11, 2021
f0c7712
Remove duplicate css and update tooltip message
dhaval-parekh Oct 11, 2021
08f4163
Remove the usage of jquery and udpate package.json
dhaval-parekh Oct 12, 2021
639796d
Remove AMP Compatible message for themes in AMP onboarding screen
dhaval-parekh Oct 12, 2021
bd562c0
Increase the limit to fetch data from API.
dhaval-parekh Oct 12, 2021
2be96cd
Fix JS issue and revert changes of OnboardingWizardSubmenuPage.php
dhaval-parekh Oct 12, 2021
34a5162
Apply suggestion from PR
dhaval-parekh Oct 12, 2021
6c301df
fetch AMP plugin and theme data when it needed
dhaval-parekh Oct 12, 2021
49b368c
Store AMP plugins/themes data into php files instead of JSON
dhaval-parekh Oct 12, 2021
b12e572
Update function docs
dhaval-parekh Oct 12, 2021
f386e29
Omit the empty field for the plugin/theme data, and fill it in when n…
dhaval-parekh Oct 12, 2021
6359f2d
Merge branch 'develop' into enhancement/2313-highlight-amp-compatible…
dhaval-parekh Oct 12, 2021
04ac429
Fix unit test cases
dhaval-parekh Oct 12, 2021
097ac8d
Rename the command and file that update AMP extension files
dhaval-parekh Oct 12, 2021
7ecf415
Replace single quote with double quote while converting object to php…
dhaval-parekh Oct 12, 2021
91cf776
Prevent to store plugin description in php file
dhaval-parekh Oct 12, 2021
68bbb9c
Use innerText instead of innerHTML
dhaval-parekh Oct 12, 2021
d8ac7dc
Add unit test case for get_plugins() and get_themes()
dhaval-parekh Oct 13, 2021
55faed3
Update the logic to covernt JS object into PHP array
dhaval-parekh Oct 13, 2021
de077b4
Update Gruntfile.js to add auto-generated files
dhaval-parekh Oct 13, 2021
fe7d4bb
Add multiple attempt to fetch data from wp.org API
dhaval-parekh Oct 13, 2021
89839bf
Fix unit test cases
dhaval-parekh Oct 13, 2021
6558ab5
Add a check for if an auto-generated file is exists
dhaval-parekh Oct 13, 2021
de2bd9e
Merge branch 'develop' into enhancement/2313-highlight-amp-compatible…
dhaval-parekh Oct 14, 2021
d99b7a3
Remove unwanted eslint ignore comments
dhaval-parekh Oct 14, 2021
85247dd
Add logging to indicate what is going on
westonruter Oct 19, 2021
d032f72
Simplify conditional
westonruter Oct 19, 2021
088b805
Abort update-extension-files when files exist
westonruter Oct 19, 2021
599d1f3
Opt to commit amp-plugins and amp-themes data to repo
westonruter Oct 19, 2021
ce93a3f
Exclude phpcs rules for exported data
westonruter Oct 19, 2021
231749e
Fix lintstaged pattern to match 'amp-' prefixed files in includes dir…
westonruter Oct 19, 2021
8ef0ec3
Move theme/plugin files into includes/ecosystem-data directory
westonruter Oct 19, 2021
1a10ded
Remove update-extension-files from running as part of build
westonruter Oct 19, 2021
b82cf95
Add notice for how files were generated
westonruter Oct 19, 2021
888a639
Mark ecosystem data files as being generated files
westonruter Oct 19, 2021
4d02116
Update script to fetch AMP extension data,
dhaval-parekh Oct 20, 2021
08861f9
Remove the usage of tmp file to convert JS object into PHP array
dhaval-parekh Oct 21, 2021
e240f44
Prevent rectangular images from being stretched into a square plugin …
westonruter Oct 21, 2021
cbd8cab
Remove AMP logo from theme/plugin directory tabs
westonruter Oct 21, 2021
2514c1c
Add AMP Compatible tab to end instead of beginning
westonruter Oct 21, 2021
6d923e7
Remove additional info from plugin card in AMP Compatible tab
dhaval-parekh Oct 25, 2021
65bfa8b
Omit extra field being stored for AMP plugins and themes.
dhaval-parekh Oct 25, 2021
112a772
Prevent showing AMP compatibility message in AMP compatible tab
dhaval-parekh Oct 25, 2021
a0514dd
Speed up update-extension-files by requesting ecosystem data with lin…
westonruter Oct 27, 2021
9171748
Regenerate ecosystem data after data entry fixes on amp-wp.org
westonruter Oct 27, 2021
5318ec1
Move AMP compatible message from bottom to top left corner
dhaval-parekh Oct 29, 2021
2fbad0e
Update package-lock.json
dhaval-parekh Oct 29, 2021
c0cf8c5
Merge branch 'develop' into enhancement/2313-highlight-amp-compatible…
dhaval-parekh Oct 29, 2021
7a93019
Merge branch 'develop' of github.com:ampproject/amp-wp into enhanceme…
westonruter Nov 2, 2021
a266f25
Revert "Update package-lock.json"
westonruter Nov 2, 2021
47ebc63
Replace extension-card-px-message with amp-extension-card-message
westonruter Nov 2, 2021
3082968
Replace 'AMP' with 'Amp' for symbol readability
westonruter Nov 2, 2021
b2a3dc4
Replace references to PX with AMP for now
westonruter Nov 2, 2021
7e9331d
Utilize URLSearchParams for parsing query params
westonruter Nov 2, 2021
78fcfd2
Improve tooltip text
westonruter Nov 2, 2021
6630e71
Remove AMP icon from plugin row meta
westonruter Nov 2, 2021
46cf134
Exclude ecosystem-data from codecov
westonruter Nov 2, 2021
afbbcd4
Sort imports
westonruter Nov 2, 2021
f0e5cee
Update package-lock with latest for version 1
westonruter Nov 2, 2021
7d07c70
Improve method name for filtering themes_api
westonruter Nov 2, 2021
ee71030
Add missing link text for AMP Compatible tab on Themes screen
westonruter Nov 2, 2021
3edc227
Add amp_compatible_ecosystem_shown filter to disable integration
westonruter Nov 2, 2021
ec437c5
Add PhpUnusedParameterInspection ignorance
westonruter Nov 2, 2021
03171f8
Account for plugins and themes variables always being arrays
westonruter Nov 2, 2021
08743c6
Sort themes and plugins alphabetically
westonruter Nov 2, 2021
16735e3
Add includes/ecosystem-data to PHP exclusion list
westonruter Nov 2, 2021
6e552c1
Utilize MutationObserver to watch for card updates
westonruter Nov 2, 2021
15e6199
Only run code for plugin search results setup once
westonruter Nov 2, 2021
25b83eb
Improve placement of isAmpCompatibleTab conditionals
westonruter Nov 2, 2021
c64ff0e
Simplify logic considering once events
westonruter Nov 3, 2021
7a8487f
Remove extraneous spaces and improve child manipulation
westonruter Nov 3, 2021
46db0a2
Prevent showing AMP badge icon on AMP Compatible themes tab
westonruter Nov 3, 2021
f47398b
Remove fs and child_process packages since built-in to Node
westonruter Nov 3, 2021
760ae35
Regenerate ecosystem data
westonruter Nov 3, 2021
53a85b7
Prevent adding assets needlessly to plugin list table
westonruter Nov 3, 2021
9cfc78c
Fix AmpPlugin::register test and remove unused is_file_exists vars
westonruter Nov 3, 2021
46fc670
Try fixing AmpThemesTest::test_is_needed
westonruter Nov 3, 2021
0981169
Define 'amp-compatible' in constants
westonruter Nov 3, 2021
326b603
Fix import order
westonruter Nov 3, 2021
496a134
Add noopener and noreferrer to ecosystem links
westonruter Nov 3, 2021
83c6d3c
Show all AMP-compatible plugins since pagination is not working
westonruter Nov 3, 2021
b7f8e6e
Improve method names in AmpPlugins
westonruter Nov 3, 2021
7ee0295
Improve methods in AmpThemes
westonruter Nov 3, 2021
49b37fa
Use more int casting
westonruter Nov 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"react/no-unused-prop-types": "error",
"react/self-closing-comp": "error",
"import/no-unresolved": [ "error", {
"ignore": [ "jquery", "amp-block-editor-data", "amp-settings", "amp-support", "amp-block-validation" ]
"ignore": [ "jquery", "amp-block-editor-data", "amp-settings", "amp-themes", "amp-plugins", "amp-support", "amp-block-validation" ]
} ],
"import/order": [ "error", { "groups": [ "builtin", [ "external", "unknown" ], "internal", "parent", "sibling", "index" ] } ],
"jsdoc/check-indentation": "error",
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ includes/sanitizers/class-amp-allowed-tags-generated.php linguist-generated=true
docs/**/*.md linguist-generated=true
docs/docs.json linguist-generated=true
**/__data__/*.js linguist-generated=true
includes/ecosystem-data/*.php linguist-generated=true
2 changes: 1 addition & 1 deletion .lintstagedrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
"**/*.js": [
"npm run lint:js"
],
"**/!(amp).php": [
"**/!(amp.php).php": [
"npm run lint:php"
],
"amp.php": [
Expand Down
74 changes: 74 additions & 0 deletions assets/css/src/amp-admin.css
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;
}
115 changes: 115 additions & 0 deletions assets/src/admin/amp-plugin-install.js
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();
} );
59 changes: 59 additions & 0 deletions assets/src/admin/amp-theme-install.js
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;
Copy link
Member

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.

},

};

domReady( () => {
ampThemeInstall.init();
} );
Loading