Skip to content

Commit 69106fd

Browse files
feat: add third parties plugins nice display names
1 parent f15088f commit 69106fd

File tree

1 file changed

+85
-9
lines changed

1 file changed

+85
-9
lines changed

onboarding/src/Components/FeaturesList.js

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { useState, useEffect } from '@wordpress/element';
22
import { __ } from '@wordpress/i18n';
33

4+
const MAX_FEATURE_LIST_LENGTH = 6;
5+
46
const decodeHtmlEntities = (str) => {
57
const textArea = document.createElement('textarea');
68
textArea.innerHTML = str;
79
return textArea.value;
810
};
911

10-
const featureCollection = [
12+
/**
13+
* Product display.
14+
*/
15+
const featuredPluginCollection = [
1116
{
1217
id: 'pageBuilder',
1318
pluginSlug: 'otter-blocks',
@@ -46,8 +51,62 @@ const featureCollection = [
4651
},
4752
];
4853

54+
/**
55+
* Third-party product display. Appears only if they are a part of the required plugins for template site.
56+
*/
57+
const thirdPartyFeaturedPluginCollection = [
58+
{
59+
id: 'woocommerce',
60+
pluginSlug: 'woocommerce',
61+
label: __('WooCommerce', 'templates-patterns-collection'),
62+
description: __('Build any commerce solution you can imagine.', 'templates-patterns-collection')
63+
},
64+
{
65+
id: 'easy-digital-downloads',
66+
pluginSlug: 'easy-digital-downloads',
67+
label: __('Easy Digital Downloads', 'templates-patterns-collection'),
68+
description: __('Sell digital products with ease and manage your online store efficiently.', 'templates-patterns-collection')
69+
},
70+
{
71+
id: 'edd-blocks',
72+
pluginSlug: 'edd-blocks',
73+
label: __('EDD Blocks', 'templates-patterns-collection'),
74+
description: __('Easily display Easy Digital Downloads products in Gutenberg Editor.', 'templates-patterns-collection')
75+
},
76+
{
77+
id: 'recipe-card-blocks-by-wpzoom',
78+
pluginSlug: 'recipe-card-blocks-by-wpzoom',
79+
label: __('Recipe Card Blocks', 'templates-patterns-collection'),
80+
description: __('Easily create and share mouthwatering recipes.', 'templates-patterns-collection')
81+
},
82+
{
83+
id: 'ameliabooking',
84+
pluginSlug: 'ameliabooking',
85+
label: __('Amelia', 'templates-patterns-collection'),
86+
description: __('Booking system for appointments and event booking.', 'templates-patterns-collection')
87+
},
88+
{
89+
id: 'estatik',
90+
pluginSlug: 'estatik',
91+
label: __('Estatik', 'templates-patterns-collection'),
92+
description: __('Full-featured WordPress real estate plugin.', 'templates-patterns-collection')
93+
},
94+
{
95+
id: 'wp-job-openings',
96+
pluginSlug: 'wp-job-openings',
97+
label: __('WP Job Openings', 'templates-patterns-collection'),
98+
description: __('Plugin for setting up a job listing page for your WordPress website.', 'templates-patterns-collection')
99+
},
100+
{
101+
id: 'pods',
102+
pluginSlug: 'pods',
103+
label: __('Pods', 'templates-patterns-collection'),
104+
description: __('A framework for creating, managing, and deploying customized content types and fields for any project.', 'templates-patterns-collection')
105+
}
106+
];
107+
49108
const FeaturesList = ({ requiredPlugins, onToggle }) => {
50-
const [featureList, setFeatureList] = useState( featureCollection );
109+
const [featureList, setFeatureList] = useState( featuredPluginCollection );
51110

52111
const [selectedFeatures, setSelectedFeatures] = useState({
53112
pageBuilder: false,
@@ -72,7 +131,7 @@ const FeaturesList = ({ requiredPlugins, onToggle }) => {
72131
newStatus || (
73132
// Do not disable the plugin installation if another feature that requires it is active.
74133
false === newStatus &&
75-
featureCollection.filter( i => pluginSlug === i.pluginSlug && feature !== i.id ).map(({ id }) => selectedFeatures[id]).every(i => false === i )
134+
featuredPluginCollection.filter( i => pluginSlug === i.pluginSlug && feature !== i.id ).map(({ id }) => selectedFeatures[id]).every(i => false === i )
76135
)
77136
) {
78137
onToggle(pluginSlug, newStatus);
@@ -85,9 +144,11 @@ const FeaturesList = ({ requiredPlugins, onToggle }) => {
85144

86145
useEffect(() => {
87146
const requiredPluginSlugs = Object.keys(requiredPlugins ?? {});
147+
148+
const allProductDisplay = [...featuredPluginCollection, ...thirdPartyFeaturedPluginCollection];
88149

89150
const missingRequiredPlugins = Object.entries(requiredPlugins ?? {})
90-
.filter(([slug]) => featureCollection.every(({ pluginSlug }) => slug !== pluginSlug))
151+
.filter(([slug]) => allProductDisplay.every(({ pluginSlug }) => slug !== pluginSlug))
91152
.map(([slug, label]) => {
92153
const decodedLabel = decodeHtmlEntities(label);
93154
return {
@@ -98,11 +159,26 @@ const FeaturesList = ({ requiredPlugins, onToggle }) => {
98159
};
99160
});
100161

162+
const requiredProducts = allProductDisplay.filter(({ pluginSlug }) =>
163+
requiredPluginSlugs.includes(pluginSlug)
164+
);
165+
101166
const orderedFeatures = [
102-
...missingRequiredPlugins,
103-
...featureCollection.filter(feature => requiredPluginSlugs.includes(feature.pluginSlug)),
104-
...featureCollection.filter(feature => !requiredPluginSlugs.includes(feature.pluginSlug))
105-
].slice(0, 6);
167+
...requiredProducts,
168+
...missingRequiredPlugins
169+
];
170+
171+
if (orderedFeatures.length < MAX_FEATURE_LIST_LENGTH) {
172+
const additionalFeatures = featuredPluginCollection.filter(
173+
({ pluginSlug }) => !orderedFeatures.some(f => f.pluginSlug === pluginSlug)
174+
);
175+
176+
const remainingSlots = Math.max(0, MAX_FEATURE_LIST_LENGTH - orderedFeatures.length);
177+
if (remainingSlots > 0 && additionalFeatures.length > 0) {
178+
orderedFeatures.push(...additionalFeatures.slice(0, remainingSlots));
179+
}
180+
}
181+
106182
setFeatureList(orderedFeatures);
107183
setLockedPluginSlugs(requiredPluginSlugs);
108184
}, [requiredPlugins]);
@@ -130,7 +206,7 @@ const FeaturesList = ({ requiredPlugins, onToggle }) => {
130206
aria-checked={checked}
131207
disabled={isLocked}
132208
>
133-
<div className="ob-feature-header">
209+
<div className="ob-feature-header" data-plugin={feature.pluginSlug}>
134210
<h4 className="ob-feature-title">{feature.label}</h4>
135211
<input
136212
type="checkbox"

0 commit comments

Comments
 (0)