-
Notifications
You must be signed in to change notification settings - Fork 88
Feat/performance recommended plugins #4577
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
harshitarora-in
wants to merge
6
commits into
development
Choose a base branch
from
feat/performance-recommended-plugins
base: development
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.
+165
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d04caf2
feat(dashboard): add recommended plugins in performance tab
harshitarora-in 5d0663d
fix: hide promoted plugin cards after successful activation
Copilot e5ac5bc
refactor(dashboard): render performance plugins inside the tab content
harshitarora-in 809a825
Merge branch 'development' into feat/performance-recommended-plugins
harshitarora-in 01a2a33
refactor(dashboard): use ControlWrap for the recommended plugins section
harshitarora-in 12efc00
fix(dashboard): guard plugin lookup and set explicit button type
harshitarora-in 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
162 changes: 162 additions & 0 deletions
162
assets/apps/dashboard/src/Components/Content/Settings/PerformancePlugins.js
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,162 @@ | ||
| /* global neveDash */ | ||
| import { useEffect, useState } from '@wordpress/element'; | ||
| import { __ } from '@wordpress/i18n'; | ||
| import cn from 'classnames'; | ||
| import { LoaderCircle, LucidePuzzle, LucideRocket } from 'lucide-react'; | ||
|
|
||
| import Pill from '../../Common/Pill'; | ||
| import Toast from '../../Common/Toast'; | ||
| import TransitionInOut from '../../Common/TransitionInOut'; | ||
| import ControlWrap from '../../Controls/ControlWrap'; | ||
| import usePluginActions from '../../../Hooks/usePluginActions'; | ||
| import { | ||
| NEVE_HIDE_PLUGINS, | ||
| NEVE_PLUGIN_ICON_MAP, | ||
| } from '../../../utils/constants'; | ||
|
|
||
| const PROMOTED_SLUGS = ['optimole-wp', 'wp-cloudflare-page-cache']; | ||
|
|
||
| // How long the "Active" pill stays up before the card removes itself. | ||
| const ACTIVE_PILL_TIMEOUT = 1500; | ||
|
|
||
| const PluginCard = ({ slug, data, onDismiss }) => { | ||
| const ICON = NEVE_PLUGIN_ICON_MAP[slug] || LucidePuzzle; | ||
| // Titles and descriptions are already localized in inc/admin/dashboard/main.php. | ||
| const { title, description } = data; | ||
|
|
||
| const [error, setError] = useState(null); | ||
| const [success, setSuccess] = useState(false); | ||
|
|
||
| const { doPluginAction, loading, buttonText } = usePluginActions( | ||
| slug, | ||
| true | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| if (!success) { | ||
| return; | ||
| } | ||
|
|
||
| // Only `success` belongs in the deps: onDismiss is recreated on every | ||
| // parent render and would restart a countdown already in progress. | ||
| const timeoutId = window.setTimeout(() => { | ||
| onDismiss(slug); | ||
| }, ACTIVE_PILL_TIMEOUT); | ||
|
|
||
| return () => window.clearTimeout(timeoutId); | ||
| }, [success]); | ||
|
|
||
| const handleClick = async () => { | ||
| setError(null); | ||
|
|
||
| window.tiTrk?.with('neve').set(slug, { | ||
|
harshitarora-in marked this conversation as resolved.
|
||
| feature: 'performance-plugin-promo', | ||
| featureComponent: slug, | ||
| }); | ||
|
|
||
| const result = await doPluginAction(); | ||
|
|
||
| if (result.success) { | ||
| setSuccess(true); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| setError(result.error); | ||
| }; | ||
|
|
||
| return ( | ||
| <div | ||
| className="flex flex-col h-full p-4 bg-white rounded-lg border border-gray-100" | ||
| data-plugin={slug} | ||
| > | ||
| <div className="flex gap-3 items-center"> | ||
| <ICON className="size-6 text-blue-500 shrink-0" /> | ||
| <h4 className="text-sm font-medium text-gray-900">{title}</h4> | ||
|
|
||
| {success && ( | ||
| <div className="ml-auto"> | ||
| <TransitionInOut show> | ||
| <Pill type="success">{__('Active', 'neve')}</Pill> | ||
| </TransitionInOut> | ||
| </div> | ||
| )} | ||
| </div> | ||
|
|
||
| {/* grow keeps the CTAs aligned when descriptions wrap to different heights */} | ||
| <p className="grow text-sm leading-relaxed text-gray-600 mt-2"> | ||
| {description} | ||
| </p> | ||
|
|
||
| {!success && ( | ||
| <button | ||
| type="button" | ||
| onClick={handleClick} | ||
| disabled={loading} | ||
| className={cn( | ||
| 'mt-3 self-start text-blue-600 hover:text-blue-700 text-sm font-medium flex items-center', | ||
| { 'opacity-75 cursor-not-allowed': loading } | ||
| )} | ||
| > | ||
|
harshitarora-in marked this conversation as resolved.
|
||
| {loading && ( | ||
| <LoaderCircle size={14} className="animate-spin mr-2" /> | ||
| )} | ||
| <span>{buttonText}</span> | ||
| </button> | ||
| )} | ||
|
|
||
| {error && ( | ||
| <div className="mt-2"> | ||
| <Toast type="error" dismiss={setError} message={error} /> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const PerformancePlugins = () => { | ||
| // Snapshot: a card leaves this list when it asks to, not when the store | ||
| // changes, so the "Active" pill outlives the activation request. | ||
| const [visibleSlugs, setVisibleSlugs] = useState(() => | ||
| PROMOTED_SLUGS.filter((slug) => { | ||
| // Super Page Cache is dropped server side when SPC Pro is | ||
| // installed, so a promoted slug can be missing entirely. | ||
| const plugin = neveDash.plugins?.[slug]; | ||
|
|
||
| return plugin && plugin.cta !== 'deactivate'; | ||
| }) | ||
| ); | ||
|
harshitarora-in marked this conversation as resolved.
|
||
|
|
||
| if (NEVE_HIDE_PLUGINS || visibleSlugs.length < 1) { | ||
| return null; | ||
| } | ||
|
|
||
| const handleDismiss = (dismissed) => | ||
| setVisibleSlugs((current) => | ||
| current.filter((slug) => slug !== dismissed) | ||
| ); | ||
|
|
||
| return ( | ||
| <ControlWrap | ||
| label={__('Recommended Plugins', 'neve')} | ||
| icon={LucideRocket} | ||
| > | ||
| <div | ||
| className={cn('grid gap-4', { | ||
| 'md:grid-cols-2': visibleSlugs.length > 1, | ||
| })} | ||
| > | ||
| {visibleSlugs.map((slug) => ( | ||
| <PluginCard | ||
| key={slug} | ||
| slug={slug} | ||
| data={neveDash.plugins[slug]} | ||
| onDismiss={handleDismiss} | ||
| /> | ||
| ))} | ||
|
harshitarora-in marked this conversation as resolved.
|
||
| </div> | ||
| </ControlWrap> | ||
| ); | ||
| }; | ||
|
|
||
| export default PerformancePlugins; | ||
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.
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.
Hi @abaicus, I am not really sure about this one. I have fixed the rest.
Thanks!