|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import { __ } from '@wordpress/i18n'; |
6 | | -import { useState, useEffect } from '@wordpress/element'; |
7 | | -import { ToggleControl } from '@wordpress/components'; |
| 6 | +import { useState, useEffect, useMemo } from '@wordpress/element'; |
| 7 | +import { ToggleControl, Tooltip, Icon } from '@wordpress/components'; |
| 8 | +import { external } from '@wordpress/icons'; |
| 9 | +import { cleanForSlug } from '@wordpress/url'; |
8 | 10 | import WizardSection from '../../../../wizards-section'; |
9 | 11 | import WizardsActionCard from '../../../../wizards-action-card'; |
10 | 12 | import useWizardApiFetchToggle from '../../../../hooks/use-wizard-api-fetch-toggle'; |
@@ -98,9 +100,37 @@ function Collections() { |
98 | 100 | } ); |
99 | 101 | }; |
100 | 102 |
|
| 103 | + const DEFAULT_SLUG = 'collections'; |
| 104 | + const collectionsArchiveUrl = useMemo( () => { |
| 105 | + const slug = cleanForSlug( settings.custom_naming_enabled && settings.custom_slug ? settings.custom_slug : DEFAULT_SLUG ) || DEFAULT_SLUG; |
| 106 | + const base = new URL( window.newspack_urls?.site || window.location.origin ); |
| 107 | + base.pathname = base.pathname + ( ! base.pathname.endsWith( '/' ) ? '/' : '' ); |
| 108 | + return new URL( slug, base ).toString(); |
| 109 | + }, [ settings.custom_naming_enabled, settings.custom_slug ] ); |
| 110 | + |
101 | 111 | return ( |
102 | 112 | <div className="newspack-wizard__sections"> |
103 | | - <h1>{ __( 'Collections Settings', 'newspack-plugin' ) }</h1> |
| 113 | + <h1 style={ { display: 'flex', alignItems: 'center' } }> |
| 114 | + { __( 'Collections Settings', 'newspack-plugin' ) } |
| 115 | + { apiData.module_enabled_collections && ( |
| 116 | + <Tooltip text={ __( 'View Collections', 'newspack-plugin' ) }> |
| 117 | + <a |
| 118 | + href={ collectionsArchiveUrl } |
| 119 | + target="_blank" |
| 120 | + rel="noopener noreferrer" |
| 121 | + style={ { |
| 122 | + display: 'inline-flex', |
| 123 | + marginLeft: '8px', |
| 124 | + color: '#757575', |
| 125 | + textDecoration: 'none', |
| 126 | + } } |
| 127 | + aria-label={ __( 'View Collections', 'newspack-plugin' ) } |
| 128 | + > |
| 129 | + <Icon icon={ external } size={ 20 } /> |
| 130 | + </a> |
| 131 | + </Tooltip> |
| 132 | + ) } |
| 133 | + </h1> |
104 | 134 |
|
105 | 135 | <WizardsActionCard |
106 | 136 | isMedium |
|
0 commit comments