Skip to content

Commit 3a0cf33

Browse files
πŸ› Fix presentation tool links #3749 (#3766)
* 🎨 presentation tool and some preview fixes in web * 🎨 use default web language if present * 🎨 cleanup
1 parent 9cd05f7 commit 3a0cf33

13 files changed

Lines changed: 111 additions & 55 deletions

File tree

β€Žstudio/languages.tsβ€Ž

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import { getLanguages } from '@energyvision/shared/satelliteConfig'
1+
import {
2+
defaultWebLanguage,
3+
getLanguages,
4+
} from '@energyvision/shared/satelliteConfig'
25
import { dataset } from './sanity.client'
36

47
export const languages = getLanguages(dataset)
58

69
export const defaultLanguage = languages[0]
10+
export const defaultWebLang = languages?.find(
11+
lang => lang.id === (defaultWebLanguage[dataset] ?? defaultLanguage.id),
12+
)

β€Žstudio/presentation/locations.tsβ€Ž

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getDraftId } from 'sanity'
33
import type { DocumentLocationResolver } from 'sanity/presentation'
44
import blocksToText from '@/helpers/blocksToText'
55
import { capitalizeFirstLetter } from '@/helpers/formatters'
6+
import { defaultWebLang } from '@/languages'
67
import { getIdFromName, getLocaleFromName } from '../src/lib/localization'
78

89
export const locations: DocumentLocationResolver = (params, context) => {
@@ -16,26 +17,35 @@ export const locations: DocumentLocationResolver = (params, context) => {
1617
'localNews',
1718
]
1819

19-
if (routePages?.includes(params.type)) {
20+
if (params.type === 'homePage') {
2021
query = {
2122
fetch: `*[_id==$id][0]{
22-
"slugs": *[_type match "route*" && references(^._id)].slug.current,
23+
lang,
24+
"isActive": count(
25+
*[_type match "route_homepage" && (
26+
references(
27+
*[_type == "translation.metadata" && references($id)][0]
28+
.translations[_key == $defaultLang][0].value._ref
29+
) || references($id)
30+
)]
31+
) > 0,
2332
"translationSlugs": *[_type == "translation.metadata" && references(^._id)].translations[].value->{
24-
"slug" : *[_type match "route*" && references(^._id)][0].slug.current,
2533
lang,
26-
title,
2734
},
2835
...
2936
}
3037
`,
3138
listen: `*[_id in [$id,$draftId]]`,
3239
}
33-
} else if (params.type === 'homePage') {
40+
} else if (routePages?.includes(params.type)) {
3441
query = {
3542
fetch: `*[_id==$id][0]{
36-
"isActive": count(*[_type match "route_homepage" && references(^._id)]) > 0,
43+
lang,
44+
"slugs": *[_type match "route*" && references(^._id)].slug.current,
3745
"translationSlugs": *[_type == "translation.metadata" && references(^._id)].translations[].value->{
46+
"slug" : *[_type match "route*" && references(^._id)][0].slug.current,
3847
lang,
48+
title,
3949
},
4050
...
4151
}
@@ -46,6 +56,7 @@ export const locations: DocumentLocationResolver = (params, context) => {
4656
//pages with slugs on them
4757
query = {
4858
fetch: `*[_id==$id][0]{
59+
lang,
4960
"slugs": *[_type match "route*" && references(^._id)][0].slug.current,
5061
"translationSlugs": *[_type == "translation.metadata" && references(^._id)].translations[].value->{
5162
"slug": slug.current,
@@ -58,10 +69,16 @@ export const locations: DocumentLocationResolver = (params, context) => {
5869
}
5970

6071
if (query) {
61-
const pageParams = { id: params.id, draftId: getDraftId(params.id) }
72+
const pageParams = {
73+
id: params.id,
74+
draftId: getDraftId(params.id),
75+
publishedId: params.id.replace(/^drafts\./, ''),
76+
defaultLang: defaultWebLang?.name,
77+
}
6278

6379
const doc$ = context.documentStore.listenQuery(
6480
query,
81+
//@ts-ignore
6582
pageParams,
6683
{ perspective: 'drafts' }, // returns a draft article if it exists
6784
)
@@ -71,10 +88,8 @@ export const locations: DocumentLocationResolver = (params, context) => {
7188
map(doc => {
7289
// If the document doesn't exist or have a slug, return null
7390
if (!doc || (doc?._type === 'homePage' && !doc?.isActive)) {
74-
console.log('return no locations')
7591
return null
7692
}
77-
7893
let locs = []
7994
if (routePages?.includes(params.type)) {
8095
if (
@@ -91,7 +106,7 @@ export const locations: DocumentLocationResolver = (params, context) => {
91106
const locale = getLocaleFromName(translation?.lang)
92107
return {
93108
title: `${blocksToText(translation?.title)}`,
94-
href: `${translation?.lang !== 'en_GB' ? `${locale}` : ''}${translation?.slug}`,
109+
href: `${translation?.lang !== defaultWebLang?.name ? `${locale}` : ''}${translation?.slug}`,
95110
}
96111
})
97112
} else if (doc?.slugs?.filter((slug: string) => slug)?.length > 0) {
@@ -101,7 +116,7 @@ export const locations: DocumentLocationResolver = (params, context) => {
101116
const locale = getLocaleFromName(doc?.lang)
102117
return {
103118
title: `${blocksToText(doc?.title)}`,
104-
href: `${doc?.lang !== 'en_GB' ? `${locale}` : ''}${slug}`,
119+
href: `${doc?.lang !== defaultWebLang?.name ? `${locale}` : ''}${slug}`,
105120
}
106121
})
107122
} else {
@@ -113,17 +128,32 @@ export const locations: DocumentLocationResolver = (params, context) => {
113128
]
114129
}
115130
} else if (doc?._type === 'homePage' && doc?.isActive) {
116-
locs = doc?.translationSlugs?.map((item: any) => {
117-
const itemLocale = getLocaleFromName(item?.lang)
118-
const localeId = capitalizeFirstLetter(getIdFromName(item?.lang))
119-
120-
return {
121-
title: `${localeId} homepage`,
122-
href: `${item?.lang !== 'en_GB' ? `/${itemLocale}` : '/'}`,
123-
}
124-
})
131+
if (!doc?.translationSlugs || doc?.translationSlugs?.length === 0) {
132+
const localeId = capitalizeFirstLetter(
133+
getIdFromName(defaultWebLang?.name),
134+
)
135+
locs = [
136+
{
137+
title: `${localeId} homepage`,
138+
href: `/`,
139+
},
140+
]
141+
}
142+
if (doc?.translationSlugs?.length > 0) {
143+
locs = doc?.translationSlugs
144+
?.filter((item: any) => item?.lang === doc?.lang)
145+
?.map((item: any) => {
146+
const itemLocale = getLocaleFromName(item?.lang)
147+
const localeId = capitalizeFirstLetter(
148+
getIdFromName(item?.lang),
149+
)
150+
return {
151+
title: `${localeId} homepage`,
152+
href: `${item?.lang !== defaultWebLang?.name ? `/${itemLocale}` : '/'}`,
153+
}
154+
})
155+
}
125156
} else if (pagesWithSlugOnThem?.includes(params.type)) {
126-
console.log('pagesWithSlugOnThem')
127157
const locale = getLocaleFromName(doc?.lang)
128158
const plainTitle = Array.isArray(doc.title)
129159
? blocksToText(doc.title)
@@ -132,7 +162,7 @@ export const locations: DocumentLocationResolver = (params, context) => {
132162
locs = [
133163
{
134164
title: doc.title ? plainTitle : 'Untitled',
135-
href: `${doc?.lang !== 'en_GB' ? `${locale}/` : ''}${doc?.slug?.current}`,
165+
href: `${doc?.lang !== defaultWebLang?.name ? `${locale}/` : ''}${doc?.slug?.current}`,
136166
},
137167
]
138168
}

β€Žweb/app/[locale]/FriendlyCaptchaWrapper.tsxβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use client'
2-
import { FriendlyCaptchaSDK } from '@friendlycaptcha/sdk'
32
import { type ReactNode, useCallback, useState } from 'react'
43
import { FriendlyCaptchaContextProvider } from '@/contexts/FriendlyCaptchaContext'
54

β€Žweb/app/[locale]/layout.tsxβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Script from 'next/script'
88
import { hasLocale, NextIntlClientProvider } from 'next-intl'
99
import { getTranslations, setRequestLocale } from 'next-intl/server'
1010
import { PageProvider } from '@/contexts/pageContext'
11-
import { dataset } from '@/languageConfig'
1211
import { getLocaleFromIso, getNameFromIso } from '@/sanity/helpers/localization'
1312
import { routeSanityFetch, SanityLive } from '@/sanity/lib/live'
1413
import { footerAndErrorImageQuery } from '@/sanity/queries/footer'
@@ -65,7 +64,7 @@ export default async function LocaleLayout({
6564
const { errorImage, ...footerData } = footerAndErrorImageData || {}
6665

6766
async function loadVisualEditing() {
68-
if (dataset === 'global-development' && (await draftMode()).isEnabled) {
67+
if ((await draftMode()).isEnabled) {
6968
const DraftModeToolbar = dynamic(
7069
() => import('@/sections/DraftMode/DraftModeToolbar'),
7170
)

β€Žweb/core/Carousel/Carousel.tsxβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ export const Carousel = forwardRef<HTMLElement, CarouselProps>(
323323
aspectRatio={'16:9'}
324324
height={iframeData?.height}
325325
hasSectionTitle={!!title}
326+
className='my-20'
326327
/>
327328
)
328329

β€Žweb/core/IFrame/IFrame.tsxβ€Ž

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ const isIframeAllowedByCsp = (url: string) => {
5050
}
5151
}
5252

53+
const isDraftModeEnabled = () =>
54+
typeof document !== 'undefined' &&
55+
document.cookie.includes('__prerender_bypass=')
56+
5357
type IFrameProps = {
5458
frameTitle: string
5559
url: string
@@ -93,7 +97,8 @@ export const IFrame = forwardRef<HTMLDivElement, IFrameProps>(function IFrame(
9397
},
9498
ref,
9599
) {
96-
const isPreview = useIsPresentationTool()
100+
const isPresentationTool = useIsPresentationTool()
101+
const isPreview = isPresentationTool || isDraftModeEnabled()
97102
const [consented, setConsented] = useState(useConsent(cookiePolicy))
98103
const titleId = useId()
99104
const descriptionId = useId()
@@ -191,21 +196,17 @@ export const IFrame = forwardRef<HTMLDivElement, IFrameProps>(function IFrame(
191196
</>
192197
)
193198

194-
if (isPreview) {
195-
return iframeElement
196-
}
197-
198199
return (
199-
<section ref={ref} className={twMerge('my-20 h-min', className)}>
200-
{consented ? (
200+
<div ref={ref} className={twMerge('h-min', className)}>
201+
{consented || isPreview ? (
201202
iframeElement
202203
) : (
203204
<RequestConsentContainer
204205
hasSectionTitle={hasSectionTitle}
205206
cookiePolicy={cookiePolicy}
206207
/>
207208
)}
208-
</section>
209+
</div>
209210
)
210211
})
211212

β€Žweb/portableText/Blocks.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ export default function Blocks({
475475
}
476476
/** Basic iframe block */
477477
if (block._type === 'basicIframe') {
478-
let marginOverride = ''
478+
let marginOverride = 'my-20'
479479
// If the next block is a basicIframe, remove margin bottom
480480
if (blocks[i + 1]?._type === 'basicIframe') {
481481
marginOverride = 'mb-0'

β€Žweb/sections/Hero/FiftyFiftyHero.tsxβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const FiftyFiftyHero = ({
4848
}
4949

5050
return (
51-
<section>
51+
<>
5252
<div
5353
className={twMerge(
5454
`flex flex-col-reverse ${bg}`,
@@ -131,6 +131,6 @@ export const FiftyFiftyHero = ({
131131
)}
132132
/>
133133
</div>
134-
</section>
134+
</>
135135
)
136136
}

β€Žweb/sections/Hero/HeroBlock.tsxβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ export const HeroBlock = ({
210210
}
211211

212212
return type !== HeroTypes?.NO_HERO ? (
213-
<section className='h-full w-full'>
213+
//bg white here because presentation tools shows grey as a fallback, the hero with background color will lay over and override the white
214+
<section className='h-full w-full bg-white-100'>
214215
{getHero()}
215216
{breadcrumbs?.enableBreadcrumbs &&
216217
heroTypesThatHaveBreadcrumbsBelow.includes(type) && (

β€Žweb/sections/IFrameBlock/IFrameBlock.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const IFrameBlock = ({
4343
className={twMerge(`${bg} ${dark ? 'dark' : ''} `, className)}
4444
id={anchor}
4545
>
46-
<div className='mx-auto max-w-content px-layout-lg pb-page-content'>
46+
<div className='mx-auto max-w-content px-layout-lg'>
4747
{title && <Blocks variant='h2' id={headingId} value={title} />}
4848
<div className='flex flex-col'>
4949
{ingress && <Blocks variant='ingress' value={ingress} />}

0 commit comments

Comments
Β (0)