From 2e23ba81f158eed97f72da4150edf1f4a1b5b087 Mon Sep 17 00:00:00 2001 From: David Featherston Date: Mon, 23 Sep 2024 14:34:20 +1000 Subject: [PATCH] fix(@dpc-sdp/ripple-tide-api): update getLinkFromField to account for internal: links --- .../ripple-tide-api/src/utils/mapping-utils.test.ts | 10 ++++++++++ packages/ripple-tide-api/src/utils/mapping-utils.ts | 10 +++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/ripple-tide-api/src/utils/mapping-utils.test.ts b/packages/ripple-tide-api/src/utils/mapping-utils.test.ts index cc2bb58569..6453cdd4db 100644 --- a/packages/ripple-tide-api/src/utils/mapping-utils.test.ts +++ b/packages/ripple-tide-api/src/utils/mapping-utils.test.ts @@ -79,6 +79,11 @@ const field = { url: '/landing-page-cc-2', origin_url: '/landing-page-cc-2' }, + field_related_link: { + uri: 'internal:/contact-us', + title: 'Get in touch', + options: [] + }, field_paragraph_location: { langcode: null, country_code: 'AU', @@ -160,6 +165,11 @@ describe('ripple-tide-api/mapping utils', () => { text: '', url: '/landing-page-cc-2' }) + + expect(getLinkFromField(field, 'field_related_link')).toEqual({ + text: 'Get in touch', + url: '/contact-us' + }) }) it(`returns null on invalid api key`, () => { diff --git a/packages/ripple-tide-api/src/utils/mapping-utils.ts b/packages/ripple-tide-api/src/utils/mapping-utils.ts index 66007a0893..4f8ac3eeeb 100644 --- a/packages/ripple-tide-api/src/utils/mapping-utils.ts +++ b/packages/ripple-tide-api/src/utils/mapping-utils.ts @@ -145,10 +145,14 @@ export const getLinkFromField = ( return null } - return { - text: linkField.title || linkField.text || '', - url: linkField.url || linkField.origin_url || linkField.uri || '' + let text = linkField.title || linkField.text || '' + let url = linkField.url || linkField.origin_url || linkField.uri || '' + + if (url.startsWith('internal:')) { + url = url.replace(/^internal:/, '') } + + return { text, url } } export const getAddress = (field: drupalField) => {