Skip to content

Commit 42694ec

Browse files
committed
feat(collections): add archive link in settings page (#4203)
1 parent f10193e commit 42694ec

File tree

1 file changed

+33
-3
lines changed
  • src/wizards/newspack/views/settings/collections

1 file changed

+33
-3
lines changed

src/wizards/newspack/views/settings/collections/index.tsx

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
*/
44

55
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';
810
import WizardSection from '../../../../wizards-section';
911
import WizardsActionCard from '../../../../wizards-action-card';
1012
import useWizardApiFetchToggle from '../../../../hooks/use-wizard-api-fetch-toggle';
@@ -98,9 +100,37 @@ function Collections() {
98100
} );
99101
};
100102

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+
101111
return (
102112
<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>
104134

105135
<WizardsActionCard
106136
isMedium

0 commit comments

Comments
 (0)