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

[SRM-1608] add function to remove new lines #1355

Open
wants to merge 2 commits into
base: release/2.19.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion packages/nuxt-ripple/mapping/site/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getMediaPath,
getLinkFromField,
getSiteKeyValues,
stripNewLines,
TideSiteApi
} from '@dpc-sdp/ripple-tide-api'
import {
Expand Down Expand Up @@ -53,7 +54,9 @@ export default {
? getBodyFromField(src, 'field_additional_comment')
: '<p>If you need a response, please use our <a href="/contact-us" class="rpl-text-link rpl-u-focusable-inline">contact us form</a>.</p>'
},
acknowledgementFooter: 'field_acknowledgement_to_country',
acknowledgementFooter: (src: any) => {
return stripNewLines(src?.field_acknowledgement_to_country)
lambry marked this conversation as resolved.
Show resolved Hide resolved
},
copyrightHtml: (src: any) => {
return getBody(src.field_site_footer_text?.processed)
},
Expand Down
13 changes: 11 additions & 2 deletions packages/ripple-tide-api/src/utils/mapping-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
getField,
getSiteKeyValues,
getSiteSection,
humanizeFilesize
humanizeFilesize,
stripNewLines
} from './mapping-utils.js'

const field = {
Expand Down Expand Up @@ -124,7 +125,9 @@ const field = {
{
drupal_internal__tid: 179
}
]
],
field_acknowledgement_to_country:
'We acknowledge Aboriginal and Torres Strait Islander people as the First People and traditional owners and custodians of the lands, seas and waters of Australia. \r\n\r\nWe pay our respect to Elders past and present.\r\n '
},
processedImg = {
alt: 'Demo: Melbourne tram',
Expand Down Expand Up @@ -220,4 +223,10 @@ describe('ripple-tide-api/mapping utils', () => {
it(`returns null if field_node_site has no data`, () => {
expect(getSiteSection('', { field_node_site: {} })).toEqual(null)
})

it(`returns a single line of text without line breaks`, () => {
expect(stripNewLines(field.field_acknowledgement_to_country)).toEqual(
'We acknowledge Aboriginal and Torres Strait Islander people as the First People and traditional owners and custodians of the lands, seas and waters of Australia. We pay our respect to Elders past and present.'
)
})
})
10 changes: 9 additions & 1 deletion packages/ripple-tide-api/src/utils/mapping-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ export const getSiteSection = (sectionId: string, src: any) => {
})
}

/**
* @description strips line returns i.e. new line from the supplied content, returning a 'single' line
*/
export const stripNewLines = (content: string): string => {
return content?.replace(/(\r\n|\n|\r)/g, '')?.trim()
}

export default {
getImageFromField,
getLinkFromField,
Expand All @@ -255,5 +262,6 @@ export default {
getMediaPath,
getDocumentFromField,
getSiteKeyValues,
getSiteSection
getSiteSection,
stripNewLines
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
getField,
getCardImageFromField,
getImageFromField,
getLinkFromField
getLinkFromField,
stripNewLines
} from '@dpc-sdp/ripple-tide-api'

export interface ITideCardMeta {
Expand Down Expand Up @@ -58,7 +59,7 @@ const getCardSummary = (field: { [key: string]: any }) => {

const summary = linkedSummary ? linkedSummary : ownSummary

return summary?.trim()
return stripNewLines(summary)
}

const getCardImage = (field: {}): TideImageField => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const testData = {
},
field_landing_page_bg_colour: 'white',
field_landing_page_hero_theme: 'light',
field_landing_page_intro_text: "Here's the introduction text",
field_landing_page_intro_text: "Here's the introduction\r\n text",
field_landing_page_nav_title: 'Site-section Navigation',
field_landing_page_show_contact: true,
field_landing_page_summary: 'Ripple 2 landing page summary',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import {
getField,
getLinkFromField,
getImageFromField
getImageFromField,
stripNewLines
} from '@dpc-sdp/ripple-tide-api'
import type { TideUrlField } from '@dpc-sdp/ripple-tide-api/types'
import { TideHeroHeader } from '@dpc-sdp/nuxt-ripple/types'

// Intro text goes by many names depending on the content type
const getIntroText = (src) => {
return (
const introText =
src.field_news_intro_text ||
src.field_landing_page_intro_text ||
src.field_page_intro_text ||
''
)

return stripNewLines(introText)
}

const getHeaderTheme = (src) => {
Expand Down