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

PRESS2 347 Build Site Features MVP Step #107

Merged
merged 53 commits into from
Dec 6, 2022
Merged
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
efc08ca
Basic Components for Site Features
officiallygod Nov 21, 2022
8286dac
Added Some Styling
officiallygod Nov 21, 2022
fec61c9
Merge branch 'release/v1.0.0' into PRESS2-347-Build-Site-Features-MVP…
officiallygod Nov 22, 2022
bdf4d9c
Added some Styling
officiallygod Nov 22, 2022
d7413f3
Merge branch 'release/v1.0.0' into PRESS2-347-Build-Site-Features-MVP…
officiallygod Nov 24, 2022
8a7d2e5
Added Styling
officiallygod Nov 24, 2022
69ea17c
Fixed Checkbox Behaviour
officiallygod Nov 24, 2022
aa0d00e
Added an API to fetch the Plugins
officiallygod Nov 24, 2022
4a475f4
Added some styling
officiallygod Nov 24, 2022
1477c93
Added support to be checked and unchecked
officiallygod Nov 25, 2022
45dbbd5
Added saving to Store
officiallygod Nov 25, 2022
4e238a9
Refactored Code
officiallygod Nov 25, 2022
34ac04e
Added some Boiler Plate Code
officiallygod Nov 28, 2022
e2150b9
Changed Option name
officiallygod Nov 28, 2022
5ef49e0
Minor Refactoring
officiallygod Nov 29, 2022
6a809dd
Pre-checked Installed Plugins
officiallygod Nov 29, 2022
13ed47d
Added uninstall code
officiallygod Nov 29, 2022
4b1d5df
Added a cron for uninstalling
officiallygod Nov 29, 2022
0221d59
Added some CSS
officiallygod Nov 29, 2022
aea1d85
Added Icon Support
officiallygod Nov 29, 2022
3523224
Update PluginsController.php
officiallygod Nov 30, 2022
d974c88
Update index.js
officiallygod Nov 30, 2022
b1e512a
Fixed Plugin Slugs
officiallygod Nov 30, 2022
6853aa6
Update PluginUninstaller.php
officiallygod Nov 30, 2022
efca3a2
Update PluginUninstaller.php
officiallygod Nov 30, 2022
066cf9e
Refactored Code
officiallygod Dec 1, 2022
b998d00
Merge remote-tracking branch 'origin/release/v1.0.0' into PRESS2-347-…
officiallygod Dec 1, 2022
c256dfa
Fixed Code Comments
officiallygod Dec 1, 2022
9a08184
Update PluginsController.php
officiallygod Dec 1, 2022
31c5d2c
Linting the JS
officiallygod Dec 1, 2022
7e3fbfe
Update index.js
officiallygod Dec 1, 2022
f59437e
Removed SiteFeaturesController
officiallygod Dec 1, 2022
440b08b
Added a Fix for Dirty Read
officiallygod Dec 1, 2022
987bc95
Update PluginInstallTaskManager.php
officiallygod Dec 1, 2022
e201bfe
Update PluginUninstallTaskManager.php
officiallygod Dec 2, 2022
2348433
CSS Tweaks
officiallygod Dec 5, 2022
affd33f
CSS Styles to Fix Overlap
officiallygod Dec 5, 2022
8d60645
Some Review Comments
officiallygod Dec 5, 2022
07a540e
Code Reviewz
officiallygod Dec 5, 2022
d7f598b
Added Classname option
officiallygod Dec 5, 2022
6075671
Update PluginsController.php
officiallygod Dec 5, 2022
a67fc86
Check Approved
officiallygod Dec 5, 2022
dc1c3ce
Added a wp_error case for delete_plugin
officiallygod Dec 5, 2022
353aa8b
Update Plugins.php
officiallygod Dec 5, 2022
008840d
Changed Cron to 10 Seconds
officiallygod Dec 5, 2022
1fbb23f
Refactored Code
officiallygod Dec 5, 2022
3482139
Update SiteFeatures.php
officiallygod Dec 6, 2022
19a83c3
Update PluginsController.php
officiallygod Dec 6, 2022
a675648
Changed from key to name
officiallygod Dec 6, 2022
b543f28
Update stylesheet.scss
officiallygod Dec 6, 2022
80cd577
Update stylesheet.scss
officiallygod Dec 6, 2022
e8ebd45
Merge remote-tracking branch 'origin/release/v1.0.0' into PRESS2-347-…
officiallygod Dec 6, 2022
633b1a6
Update index.js
officiallygod Dec 6, 2022
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
62 changes: 21 additions & 41 deletions includes/Data/SiteFeatures.php
Original file line number Diff line number Diff line change
@@ -6,130 +6,110 @@

final class SiteFeatures {

protected static $default_plugins = array(
'default' => array(),
protected static $site_features = array(
'default' => array(),
'ecommerce' => array(
array(
'jetpack' => array(
'slug' => 'jetpack',
'icon' => '--site-features-security',
'title' => 'Security, Speed & Growth',
'subtitle' => 'Powered by Jetpack',
'desc' => 'Jetpack',
'selected' => false,
),
array(
'wpforms-lite' => array(
'slug' => 'wpforms-lite',
'icon' => '--site-features-form',
'title' => 'Forms',
'subtitle' => 'Powered by WP Forms',
'desc' => 'WP Forms',
'selected' => false,
),
array(
'google-analytics-for-wordpress' => array(
'slug' => 'google-analytics-for-wordpress',
'icon' => '--site-features-analytics',
'title' => 'Site Traffic',
'subtitle' => 'Powered by MonsterInsights',
'desc' => 'MonsterInsights',
'selected' => false,
),
array(
'wordpress-seo' => array(
'slug' => 'wordpress-seo',
'icon' => '--site-features-share',
'title' => 'Search Engine Optimization',
'subtitle' => 'Powered by Yoast',
'desc' => 'Yoast',
'selected' => false,
),
array(
'creative-mail-by-constant-contact' => array(
'slug' => 'creative-mail-by-constant-contact',
'icon' => '--site-features-email',
'title' => 'Email Newsletters',
'subtitle' => 'Powered by Creative Email',
'desc' => 'Creative Email',
'selected' => false,
),
array(
'yith-woocommerce-ajax-search' => array(
'slug' => 'yith-woocommerce-ajax-search',
'icon' => '--site-features-search',
'title' => 'Enhanced Product Search',
'subtitle' => 'Powered by YITH',
'desc' => 'YITH',
'selected' => false,
),
array(
'nfd_slug_yith_woocommerce_ajax_product_filter' => array(
'slug' => 'nfd_slug_yith_woocommerce_ajax_product_filter',
'icon' => '--site-features-filter',
'title' => 'Enhanced Product Filters',
'subtitle' => 'Powered by YITH',
'desc' => 'YITH',
'selected' => false,
),
array(
'nfd_slug_yith_woocommerce_booking' => array(
'slug' => 'nfd_slug_yith_woocommerce_booking',
'icon' => '--site-features-bookingcalendar',
'title' => 'Bookings & Appointments',
'subtitle' => 'Powered by YITH',
'desc' => 'YITH',
'selected' => false,
),
array(
'nfd_slug_yith_woocommerce_wishlist' => array(
'slug' => 'nfd_slug_yith_woocommerce_wishlist',
'icon' => '--site-features-wishlist',
'title' => 'Product Wishlists',
'subtitle' => 'Powered by YITH',
'desc' => 'YITH',
'selected' => false,
),
array(
'optinmonster' => array(
'slug' => 'optinmonster',
'icon' => '--site-features-lead',
'title' => 'Lead Generation',
'subtitle' => 'Powered by Optin Monster',
'desc' => 'Optin Monster',
'selected' => false,
),
)
),
);

public static function convert_to_hash() {
$idx = 0;
$flow = Data::current_flow();
$default_plugins_hash = array();

foreach ( self::$default_plugins[$flow] as $default_plugin ) {
$default_plugins_hash[ $default_plugin['slug'] ] = $idx;
$idx += 1;
}

return $default_plugins_hash;
}

public static function mark_initial_plugins() {
$flow = Data::current_flow();
$flow = Data::current_flow();
$installed_plugins = Plugins::get_init();

// Make an Hash Map for faster updation
$default_plugins_hash = self::convert_to_hash();
// Get a Copy of the list for alteration
$site_features_marked = self::$site_features[ $flow ];

foreach ( $installed_plugins as $installed_plugin ) {
if ( isset( $default_plugins_hash[ $installed_plugin['slug'] ] ) ) {
self::$default_plugins[$flow][ $default_plugins_hash[ $installed_plugin['slug'] ] ]['selected'] = true;
if ( isset( $site_features_marked[ $installed_plugin['slug'] ] ) ) {
$site_features_marked[ $installed_plugin['slug'] ]['selected'] = true;
}
}

return $site_features_marked;
}


public static function get_default_plugins_list() {
$flow = Data::current_flow();
self::mark_initial_plugins();
return self::$default_plugins[$flow];
}

public static function get_custom_plugins_list() {

return self::get_default_plugins_list();
public static function get() {
return self::mark_initial_plugins();
}

}
9 changes: 4 additions & 5 deletions includes/RestApi/PluginsController.php
Original file line number Diff line number Diff line change
@@ -83,11 +83,11 @@ public function register_routes() {

\register_rest_route(
$this->namespace,
$this->rest_base . '/features',
$this->rest_base . '/site-features',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( $this, 'get_custom_plugins' ),
'callback' => array( $this, 'get_site_features' ),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
),
)
@@ -284,9 +284,8 @@ public function get_status( \WP_REST_Request $request ) {
*
* @return array|\WP_Error
*/
public function get_custom_plugins() {
$custom_plugins = SiteFeatures::get_custom_plugins_list();
return $custom_plugins;
public function get_site_features() {
return SiteFeatures::get();
}

/**
6 changes: 3 additions & 3 deletions includes/Services/PluginUninstaller.php
Original file line number Diff line number Diff line change
@@ -19,11 +19,11 @@ public static function uninstall( $plugin ) {
if ( isset( $plugin_path ) && self::is_plugin_installed( $plugin_path ) ) {

self::deactivate_plugin_if_active( $plugin_path );
$res = self::delete_plugin( $plugin_path );
$deleted = self::delete_plugin( $plugin_path );

// If Deletion is not successful throw an error for a retry.
if ( is_wp_error( $res ) ) {
return $res;
if ( is_wp_error( $deleted ) ) {
return $deleted;
}
}

Original file line number Diff line number Diff line change
@@ -16,11 +16,12 @@ import { CheckboxControl } from '@wordpress/components';
*/

const CheckboxItem = ( {
officiallygod marked this conversation as resolved.
Show resolved Hide resolved
slug,
key,
icon,
title,
subtitle,
desc,
subtitle,
className,
isSelectedDefault,
callback,
} ) => {
@@ -29,7 +30,7 @@ const CheckboxItem = ( {

const handleCheck = () => {
setIsSelected( ! isSelected );
callback( slug, ! isSelected );
callback( key, ! isSelected );
};

const handleShowDesc = () => {
@@ -39,7 +40,7 @@ const CheckboxItem = ( {
return (
<div>
<div
className={`checkbox-item ${isSelected && 'checkbox-item--selected'
className={`${ className } checkbox-item ${isSelected && 'checkbox-item--selected'
} ${showDescription && 'checkbox-item--shown'}`}
>
<div className="checkbox-item-container">
46 changes: 27 additions & 19 deletions src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js
Original file line number Diff line number Diff line change
@@ -4,43 +4,51 @@ import { CheckboxItem } from '../index';
* Checkbox List Component
* This returns a List of Checkbox Items to be placed dynamically on screen
*
* @param customPluginsList.callback
* @param {Object} customPluginsList - The List to be shown with a Title, Subtitle and a Description
* @param customItemsList.callback
* @param {Object} customItemsList - The List to be shown with a Title, Subtitle and a Description
*
* @param customPluginsList.selectedPlugins
* @param customPluginsList.customPluginsList
* @param customItemsList.selectedItems
* @param customItemsList.customItemsList
* @return CheckboxList
*/
const CheckboxList = ( { callback, selectedPlugins, customPluginsList } ) => {
const CheckboxList = ( { callback, selectedItems, customItemsList } ) => {

const length = Object.keys(customItemsList).length;

const buildCheckboxItems = () => {
return customPluginsList.map( ( item, idx ) => {
const isSelectedDefault = selectedPlugins[ item.slug ];
return (
var customItems = [];

for (const key in customItemsList) {
var item = customItemsList[key];
const isSelectedDefault = selectedItems[item.slug];
customItems.push(
<CheckboxItem
slug={ item.slug }
icon={ item.icon }
title={ item.title }
subtitle={ item.subtitle }
desc={ item.desc }
callback={ callback }
isSelectedDefault={ isSelectedDefault ?? false }
slug={item.slug}
icon={item.icon}
title={item.title}
subtitle={item.subtitle}
desc={item.desc}
callback={callback}
isSelectedDefault={isSelectedDefault ?? false}
/>
);
} );
}

return customItems;
};

return (
<div className="checkbox-list">
<div className="checkbox-list-col">
{ buildCheckboxItems().slice(
0,
Math.floor( customPluginsList.length / 2 )
Math.floor( length / 2 )
) }
</div>
<div className="checkbox-list-col">
{ buildCheckboxItems().slice(
Math.floor( customPluginsList.length / 2 ),
customPluginsList.length
Math.floor( length / 2 ),
length
) }
</div>
</div>
15 changes: 8 additions & 7 deletions src/OnboardingSPA/pages/Steps/SiteFeatures/index.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import { store as nfdOnboardingStore } from '../../../store';

import { VIEW_NAV_PRIMARY } from '../../../../constants';
import CommonLayout from '../../../components/Layouts/Common';
import { getCustomPluginsList } from '../../../utils/api/plugins';
import { getSiteFeatures } from '../../../utils/api/plugins';
import HeadingWithSubHeading from '../../../components/HeadingWithSubHeading';
import CheckboxList from '../../../components/CheckboxTemplate/CheckboxList';

@@ -48,9 +48,10 @@ const StepSiteFeatures = () => {
) {
const selectedPlugins = {};

customPluginsList.forEach( ( plugin ) => {
selectedPlugins[ plugin.slug ] = plugin.selected;
} );
for (const key in customPluginsList) {
var plugin = customPluginsList[key];
selectedPlugins[plugin.slug] = plugin.selected;
}
setSelectedPlugins( selectedPlugins );

if ( saveToStore ) {
@@ -60,7 +61,7 @@ const StepSiteFeatures = () => {
}

async function getCustomPlugins() {
const customPluginsList = await getCustomPluginsList();
const customPluginsList = await getSiteFeatures();
if ( isEmpty( currentData?.data?.siteFeatures ) )
changeToStoreSchema( customPluginsList.body, true );
else setSelectedPlugins( { ...currentData?.data?.siteFeatures } );
@@ -93,8 +94,8 @@ const StepSiteFeatures = () => {
{ customPluginsList && (
<CheckboxList
callback={ selectPlugin }
selectedPlugins={ selectedPlugins }
customPluginsList={ customPluginsList }
selectedItems={ selectedPlugins }
customItemsList={ customPluginsList }
/>
) }
</CommonLayout>
4 changes: 2 additions & 2 deletions src/OnboardingSPA/utils/api/plugins.js
Original file line number Diff line number Diff line change
@@ -31,10 +31,10 @@ export const getPluginStatus = async ( plugin ) => {
);
};

export const getCustomPluginsList = async () => {
export const getSiteFeatures = async () => {
return await resolve(
apiFetch( {
url: onboardingRestURL( 'plugins/features' ),
url: onboardingRestURL( 'plugins/site-features' ),
} )
);
};