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

ELES-1362 share highlight preview when copying a link #787

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 9 additions & 6 deletions components/x-gift-article/__tests__/x-gift-article.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const baseArgs = {
'Lorem ipsum dolor sit amet consectetur, adipisicing elit. Dolorum quos, quis quas ad, minima fuga at nemo deleniti hic repellendus totam. Impedit mollitia quam repellat harum. Nostrum sapiente minima soluta , Lorem ipsum dolor sit amet consectetur, adipisicing elit. Dolorum quos, quis quas ad, minima fuga at nemo deleniti hic repellendus totam. Impedit mollitia quam repellat harum. Nostrum sapiente minima soluta.'
}

const trimmedHighlight = baseArgs.highlight.split(' ').slice(0, 30).join(' ')
const expectedHighlightText = `${baseArgs.article.title} - "${trimmedHighlight} ..."`

describe('x-gift-article', () => {
let actions = {}

Expand Down Expand Up @@ -85,8 +88,8 @@ describe('x-gift-article', () => {

subject.update()

const input = subject.find('input#share-link')
expect(input.prop('value')).toEqual('https://shortened-non-gift-url')
const input = subject.find('#share-link')
expect(input.prop('value')).toEqual(expectedHighlightText + '\n\n' + 'https://shortened-non-gift-url')
})

it('should call createGiftUrl and display correct url', async () => {
Expand All @@ -96,9 +99,9 @@ describe('x-gift-article', () => {

subject.update()

const input = subject.find('input#share-link')
const input = subject.find('#share-link')

expect(input.prop('value')).toEqual('https://shortened-gift-url')
expect(input.prop('value')).toEqual(expectedHighlightText + '\n\n' + 'https://shortened-gift-url')
})

it('should call createEnterpriseUrl and display correct url', async () => {
Expand All @@ -108,8 +111,8 @@ describe('x-gift-article', () => {

subject.update()

const input = subject.find('input#share-link')
expect(input.prop('value')).toEqual('https://gift-url-redeemed')
const input = subject.find('#share-link')
expect(input.prop('value')).toEqual(expectedHighlightText + '\n\n' + 'https://gift-url-redeemed')
})

it('when credits are available, an alert is not shown', async () => {
Expand Down
4 changes: 4 additions & 0 deletions components/x-gift-article/src/ShareArticleDialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@
margin: 0;
}

#share-link {
margin-bottom: oSpacingByName('s4');
}

padding: oSpacingByName('s4');

.share-article-dialog__header {
Expand Down
28 changes: 25 additions & 3 deletions components/x-gift-article/src/UrlSection.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { h } from '@financial-times/x-engine'
import { trimHighlights } from './lib/highlightsHelpers'
import CopyConfirmation from './CopyConfirmation'
import { ShareType } from './lib/constants'
import { SocialShareButtons } from './SocialShareButtons'

export const UrlSection = (props) => {
const { urlType, url, actions, shareType, showCopyConfirmation, enterpriseEnabled } = props
const {
urlType,
url,
actions,
shareType,
showCopyConfirmation,
enterpriseEnabled,
includeHighlights,
article,
highlight
} = props

const copyLinkHandler = (event) => {
switch (shareType) {
Expand All @@ -28,15 +39,26 @@ export const UrlSection = (props) => {
data-section-id={shareType + 'Link'}
data-trackable="copy-link"
>
<input id="share-link" type="text" name={urlType} value={url} readOnly />
{includeHighlights ? (
<textarea
rows={12}
cols={40}
id="share-link"
name={urlType}
value={`${article.title} - "${trimHighlights(highlight)}"\n\n${url}`}
readOnly
/>
) : (
<input id="share-link" type="text" name={urlType} value={url} readOnly />
)}
<button
className={`o-buttons o-buttons--big o-buttons--primary ${
enterpriseEnabled ? 'o-buttons--professional' : ''
}`}
aria-label="Copy link of the gift article to your clipboard"
onClick={copyLinkHandler}
>
Copy link
{includeHighlights ? 'Copy' : 'Copy link'}
</button>
{showCopyConfirmation && <CopyConfirmation hideCopyConfirmation={actions.hideCopyConfirmation} />}
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/x-gift-article/src/lib/share-link-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function createMailtoUrl({ article, includeHighlights, highlight }, shareUrl) {

function copyToClipboard(event) {
const urlSection = event.target.closest('.js-gift-article__url-section')
const inputEl = urlSection.querySelector('input')
const inputEl = urlSection.querySelector('#share-link')
const oldContentEditable = inputEl.contentEditable
const oldReadOnly = inputEl.readOnly
const range = document.createRange()
Expand Down