PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 1.0.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v1.0.0
2.7.0 2.6.0 2.5.0 2.4.0 2.3.0 2.2.0 2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.32.0 1.31.0 1.30.0 1.29.0 1.28.0 1.27.0 1.26.0 1.25.0 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.10.0 All 48 releases
thinkrank / src / admin / components / common / BreadcrumbPreview.js

BreadcrumbPreview.js in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO 1.0.0, at src/admin/components/common/BreadcrumbPreview.js

223 lines 8.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Breadcrumb Preview Component
3 *
4 * Live preview of breadcrumb navigation with different settings
5 *
6 * @package ThinkRank
7 * @since 1.0.0
8 */
9
10 import { useState, useEffect } from '@wordpress/element';
11 import { __ } from '@wordpress/i18n';
12 import {
13 Card,
14 CardBody,
15 CardHeader,
16 __experimentalSpacer as Spacer
17 } from '@wordpress/components';
18
19 /**
20 * Breadcrumb Preview Component
21 */
22 const BreadcrumbPreview = ({
23 breadcrumbSettings,
24 disabled = false
25 }) => {
26 const [previews, setPreviews] = useState({});
27
28 /**
29 * Generate sample breadcrumb data for different page types
30 */
31 const getSampleBreadcrumbs = () => {
32 const homeText = breadcrumbSettings.breadcrumb_home_text || __('Home', 'thinkrank');
33
34 return {
35 'blog_post': [
36 { text: homeText, url: '/', current: false },
37 { text: 'Blog', url: '/blog/', current: false },
38 { text: 'Technology', url: '/category/technology/', current: false },
39 { text: 'Sample Blog Post Title', url: '', current: true }
40 ],
41 'page': [
42 { text: homeText, url: '/', current: false },
43 { text: 'About', url: '/about/', current: false },
44 { text: 'Our Team', url: '', current: true }
45 ],
46 'category': [
47 { text: homeText, url: '/', current: false },
48 { text: 'Blog', url: '/blog/', current: false },
49 { text: 'Technology', url: '', current: true }
50 ],
51 'product': [
52 { text: homeText, url: '/', current: false },
53 { text: 'Shop', url: '/shop/', current: false },
54 { text: 'Electronics', url: '/category/electronics/', current: false },
55 { text: 'Smartphones', url: '/category/smartphones/', current: false },
56 { text: 'iPhone 15 Pro', url: '', current: true }
57 ]
58 };
59 };
60
61 /**
62 * Render breadcrumb trail
63 */
64 const renderBreadcrumb = (breadcrumbs, pageType) => {
65 const separator = breadcrumbSettings.breadcrumb_separator || '';
66 const prefix = breadcrumbSettings.breadcrumb_prefix || '';
67 const showCurrent = breadcrumbSettings.show_current_page !== false;
68
69 // Filter out current page if setting is disabled
70 const filteredBreadcrumbs = showCurrent
71 ? breadcrumbs
72 : breadcrumbs.filter(crumb => !crumb.current);
73
74 return (
75 <div className="breadcrumb-preview" style={{
76 padding: '12px 16px',
77 backgroundColor: '#f8f9fa',
78 border: '1px solid #dee2e6',
79 borderRadius: '4px',
80 fontFamily: 'Arial, sans-serif',
81 fontSize: '14px',
82 lineHeight: '1.4'
83 }}>
84 {prefix && (
85 <span style={{ marginRight: '8px', color: '#6c757d' }}>
86 {prefix}
87 </span>
88 )}
89
90 {filteredBreadcrumbs.map((crumb, index) => (
91 <span key={index}>
92 {crumb.current ? (
93 <span style={{ color: '#6c757d' }}>
94 {crumb.text}
95 </span>
96 ) : (
97 <a
98 href={crumb.url}
99 style={{
100 color: '#007cba',
101 textDecoration: 'none',
102 cursor: 'pointer'
103 }}
104 onClick={(e) => e.preventDefault()}
105 >
106 {crumb.text}
107 </a>
108 )}
109
110 {index < filteredBreadcrumbs.length - 1 && (
111 <span style={{
112 margin: '0 8px',
113 color: '#6c757d',
114 userSelect: 'none'
115 }}>
116 {separator}
117 </span>
118 )}
119 </span>
120 ))}
121 </div>
122 );
123 };
124
125 /**
126 * Get page type display name
127 */
128 const getPageTypeLabel = (pageType) => {
129 const labels = {
130 'blog_post': __('Blog Post', 'thinkrank'),
131 'page': __('Page', 'thinkrank'),
132 'category': __('Category', 'thinkrank'),
133 'product': __('Product', 'thinkrank')
134 };
135 return labels[pageType] || pageType;
136 };
137
138 /**
139 * Update previews when settings change
140 */
141 useEffect(() => {
142 if (!breadcrumbSettings.breadcrumbs_enabled) {
143 setPreviews({});
144 return;
145 }
146
147 const sampleData = getSampleBreadcrumbs();
148 const newPreviews = {};
149
150 Object.keys(sampleData).forEach(pageType => {
151 newPreviews[pageType] = sampleData[pageType];
152 });
153
154 setPreviews(newPreviews);
155 }, [breadcrumbSettings]);
156
157 if (disabled || !breadcrumbSettings.breadcrumbs_enabled) {
158 return (
159 <Card size="small">
160 <CardBody>
161 <p style={{ color: '#757575', fontStyle: 'italic' }}>
162 {disabled
163 ? __('Breadcrumb preview is disabled. Enable site identity to see live previews.', 'thinkrank')
164 : __('Breadcrumbs are disabled. Enable breadcrumbs to see preview.', 'thinkrank')
165 }
166 </p>
167 </CardBody>
168 </Card>
169 );
170 }
171
172 return (
173 <Card size="small">
174 <CardHeader>
175 <h4>{__('Live Breadcrumb Preview', 'thinkrank')}</h4>
176 <p style={{ fontSize: '14px', color: '#757575', margin: '4px 0 0 0' }}>
177 {__('See how breadcrumbs will appear with current settings', 'thinkrank')}
178 </p>
179 </CardHeader>
180 <CardBody>
181 <div className="breadcrumb-preview-list">
182 {Object.keys(previews).map(pageType => {
183 const breadcrumbs = previews[pageType];
184
185 return (
186 <div key={pageType} className="breadcrumb-preview-item" style={{ marginBottom: '20px' }}>
187 <div style={{ marginBottom: '8px' }}>
188 <strong>{getPageTypeLabel(pageType)}</strong>
189 </div>
190
191 {renderBreadcrumb(breadcrumbs, pageType)}
192 </div>
193 );
194 })}
195 </div>
196
197 <Spacer marginY={3} />
198
199 <div style={{
200 padding: '12px',
201 backgroundColor: '#e7f3ff',
202 border: '1px solid #72aee6',
203 borderRadius: '4px',
204 fontSize: '13px'
205 }}>
206 <strong>{__('Breadcrumb Settings:', 'thinkrank')}</strong>
207 <ul style={{ margin: '8px 0 0 0', paddingLeft: '20px' }}>
208 <li><strong>{__('Type:', 'thinkrank')}</strong> {breadcrumbSettings.breadcrumb_type || 'hierarchical'}</li>
209 <li><strong>{__('Separator:', 'thinkrank')}</strong> "{breadcrumbSettings.breadcrumb_separator || ''}"</li>
210 <li><strong>{__('Home Text:', 'thinkrank')}</strong> "{breadcrumbSettings.breadcrumb_home_text || __('Home', 'thinkrank')}"</li>
211 {breadcrumbSettings.breadcrumb_prefix && (
212 <li><strong>{__('Prefix:', 'thinkrank')}</strong> "{breadcrumbSettings.breadcrumb_prefix}"</li>
213 )}
214 <li><strong>{__('Show Current Page:', 'thinkrank')}</strong> {breadcrumbSettings.show_current_page !== false ? __('Yes', 'thinkrank') : __('No', 'thinkrank')}</li>
215 </ul>
216 </div>
217 </CardBody>
218 </Card>
219 );
220 };
221
222 export default BreadcrumbPreview;
223