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

1889 As editors we see a need to have text promotion cards to link to other pages #1943

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bf67944
✨ WIP: text promo component #1889
millianapia Oct 20, 2023
b3d0ca5
✨ WIP: cleanup text promo component #1889
millianapia Nov 2, 2023
7d82fd7
✨ WIP: cleanup text promo component #1889
millianapia Nov 7, 2023
d5700ed
Revert "✨ WIP: cleanup text promo component #1889"
millianapia Nov 7, 2023
67ea374
✨ WIP: cleanup text promo component #1889
millianapia Nov 7, 2023
2f09be2
♻️ Extract action from contentfields #1889
millianapia Nov 7, 2023
32b83ca
♻️ Remove title, add link toggle #1889
millianapia Nov 8, 2023
1cd82c8
♻️ Removed one too many lines #1889
millianapia Nov 8, 2023
22acdf7
♻️ Add padding and bigger fontsize #1889
millianapia Nov 8, 2023
826c1dd
♻️ Change from text to ingress #1889
millianapia Nov 8, 2023
620e799
♻️ Add a better toggling of spacing and aligning #1889
millianapia Nov 13, 2023
b2f928f
🐛 Working links #1889
millianapia Nov 14, 2023
36a4c4e
🚚 Rename for tile #1889
millianapia Nov 14, 2023
173f3b3
♻️ Refactor promotilebuttonlogic #1889
millianapia Nov 14, 2023
5f46bac
♻️ Small refactor for double linkreferences #1889
millianapia Nov 15, 2023
1dadce0
♻️ Restructure code #1889
fernandolucchesi Nov 15, 2023
0486a21
♻️ Restructure code #1889
millianapia Nov 15, 2023
142d4c3
♻️ Refactor type and preview #1889
millianapia Nov 20, 2023
af315fc
🔥 Remove redundant css #1889
millianapia Nov 20, 2023
70ec668
🔥 Remove redundant css #1889
millianapia Nov 21, 2023
b69f9f7
🐛 Limit gridtemplate columns #1889
millianapia Dec 1, 2023
f663032
🔥 size adjustment, breakline added and remove char limit #1889
millianapia Dec 8, 2023
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
1 change: 1 addition & 0 deletions sanityv3/schemas/documents/magazine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export default {
{ type: 'pullQuote', initialValue: { background: defaultColors[0] } },
{ type: 'accordion' },
{ type: 'promoTileArray' },
{ type: 'promoTextTileArray' },
{ type: 'promotion' },
{ type: 'iframe' },
{ type: 'imageCarousel' },
Expand Down
1 change: 1 addition & 0 deletions sanityv3/schemas/documents/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default {
{ type: 'pullQuote', initialValue: { background: defaultColors[0] } },
{ type: 'accordion' },
{ type: 'promoTileArray' },
{ type: 'promoTextTileArray' },
{ type: 'promotion' },
{ type: 'table' },
{ type: 'stockValuesApi' },
Expand Down
4 changes: 4 additions & 0 deletions sanityv3/schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ import menuLink from './objects/menuLink'
import newsList from './objects/newsList'
import positionedInlineImage from './objects/positionedInlineImage'
import promoTile from './objects/promoTile'
import promoTextTile from './objects/promoTextTile'
import promoTileArray from './objects/promoTileArray'
import promoTextTileArray from './objects/promoTextTileArray'
import promoteEvents from './objects/promotion/promoteEvents'
import promoteMagazine from './objects/promotion/promoteMagazine'
import promoteNews from './objects/promotion/promoteNews'
Expand Down Expand Up @@ -131,7 +133,9 @@ const RemainingSchemas = [
textWithIconArray,
linkSelector,
promoTile,
promoTextTile,
promoTileArray,
promoTextTileArray,
stockValuesApi,
iframe,
basicIframe,
Expand Down
104 changes: 104 additions & 0 deletions sanityv3/schemas/objects/promoTextTile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { label } from '@equinor/eds-icons'
import type { PortableTextBlock, Rule, ValidationContext } from 'sanity'
import type { ColorSelectorValue } from '../components/ColorSelector'
import { EdsIcon } from '../../icons'
import { validateCharCounterEditor } from '../validations/validateCharCounterEditor'
import type { LinkSelector } from './linkSelector'
import { configureBlockContent } from '../editors'
import { getLinkSelectorFields } from './linkSelector'

const ingressBlockContentType = configureBlockContent({
h1: false,
h2: false,
h3: false,
h4: false,
internalLink: false,
externalLink: false,
attachment: false,
lists: false,
})

export type PromoTextTile = {
_type: 'promoTextTile'
linkLabelAsTitle?: boolean
millianapia marked this conversation as resolved.
Show resolved Hide resolved
link?: LinkSelector
isLink?: boolean
background?: ColorSelectorValue
}

const linkFields = getLinkSelectorFields('label', 'isLink')

export default {
title: 'Promo text tile',
name: 'promoTextTile',
type: 'object',
fieldsets: [
{
title: 'Design options',
name: 'design',
description: 'Some options for design',
options: {
collapsible: true,
collapsed: false,
},
},
{
name: 'link',
title: 'Link',
description: 'Select either an internal link or external URL.',
},
{
name: 'label',
title: 'Label',
description: 'The label that the link/button should have.',
},
],
fields: [
{
name: 'ingress',
title: 'Promo Text',
description: 'Max 100 characters',
type: 'array',
of: [ingressBlockContentType],
validation: (Rule: Rule) => Rule.custom((value: any) => validateCharCounterEditor(value, 100)),
millianapia marked this conversation as resolved.
Show resolved Hide resolved
},
{
name: 'isLink',
type: 'boolean',
title: 'Use a link',
description: 'Link to another piece of content',
initialValue: false,
},
...getLinkSelectorFields('label', 'isLink'),
{
name: 'showLinkLabel',
title: 'Show link label',
description: 'This will add the text to the button',
type: 'boolean',
initialValue: false,
hidden: ({ parent }: { parent: PromoTextTile }) => !parent.isLink,
fieldset: 'label',
},
{
title: 'Background',
description: 'Pick a colour for the background. Default is white.',
name: 'background',
type: 'colorlist',
fieldset: 'design',
},
],
preview: {
select: {
title: 'title',
linkLabelAsTitle: 'linkLabelAsTitle',
millianapia marked this conversation as resolved.
Show resolved Hide resolved
link: 'label',
},
prepare({ linkLabelAsTitle, link }: { title: PortableTextBlock[]; linkLabelAsTitle: boolean; link: string }) {
return {
title: linkLabelAsTitle || link || 'Promo Text Tile',
millianapia marked this conversation as resolved.
Show resolved Hide resolved
subtitle: `Promo text tile component`,
media: EdsIcon(label),
}
},
},
}
43 changes: 43 additions & 0 deletions sanityv3/schemas/objects/promoTextTileArray.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { collection_2 } from '@equinor/eds-icons'
import { EdsIcon } from '../../icons'
import type { Rule } from 'sanity'
import type { PromoTextTile } from './promoTextTile'

export type PromoTextTileArray = {
_type: 'promoTextTileArray'
group: PromoTextTile[]
}

export default {
type: 'object',
name: 'promoTextTileArray',
title: 'Promo text tiles',
fields: [
{
name: 'spacing',
type: 'boolean',
title: 'Space between other components',
initialValue: false,
},
{
type: 'array',
name: 'group',
description: 'Add promo tiles as one or a pair',
title: 'Promo text tiles',
of: [{ type: 'promoTextTile' }],
validation: (Rule: Rule) => Rule.required().min(1).max(2),
},
].filter((e) => e),
millianapia marked this conversation as resolved.
Show resolved Hide resolved
preview: {
select: {
group: 'group',
},
prepare() {
return {
title: 'Promo text tiles',
subtitle: `Promo text tile component`,
media: <div>{EdsIcon(collection_2)}</div>,
millianapia marked this conversation as resolved.
Show resolved Hide resolved
}
},
},
}
11 changes: 6 additions & 5 deletions sanityv3/schemas/objects/promoTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { EdsIcon } from '../../icons'
import CompactBlockEditor from '../components/CompactBlockEditor'
import type { ImageWithAlt } from './imageWithAlt'
import type { LinkSelector } from './linkSelector'
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { configureTitleBlockContent } from '../editors'

const titleContentType = configureTitleBlockContent()

export type PromoTile = {
_type: 'promoTile'
title: any[]
title: PortableTextBlock[]
linkLabelAsTitle?: boolean
image?: ImageWithAlt
link?: LinkSelector
Expand Down Expand Up @@ -50,7 +49,9 @@ export default {
{
name: 'title',
type: 'array',
inputComponent: CompactBlockEditor,
components: {
input: CompactBlockEditor,
},
of: [titleContentType],
title: 'Title',
hidden: ({ parent }: { parent: PromoTile }) => parent?.linkLabelAsTitle,
Expand Down Expand Up @@ -92,13 +93,13 @@ export default {
linkLabelAsTitle,
link,
}: {
title: any[]
title: PortableTextBlock[]
imageUrl: string
linkLabelAsTitle: boolean
link: string
}) {
return {
title: linkLabelAsTitle ? link : blocksToText(title as any[]),
title: linkLabelAsTitle ? link : blocksToText(title),
subtitle: `Promo tile component`,
media: imageUrl ? <img src={imageUrl} alt="" style={{ height: '100%' }} /> : EdsIcon(label),
}
Expand Down
38 changes: 21 additions & 17 deletions web/lib/queries/common/actions/linkSelectorFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,26 @@ export const linkReferenceFields = /* groq */ `
}
`

const linkSelectorFields = /* groq */ `
_type == "linkSelector" => {
"id": _key,
"type": select(
defined(url) => "externalUrl", "internalUrl"
),
label,
ariaLabel,
"link": select(
linkToOtherLanguage == true =>
referenceToOtherLanguage->${linkReferenceFields},
reference->${linkReferenceFields},
),
"href": url,
anchorReference,
}
export const linkSelectorFields = /* groq */ `
{
"id": _key,
"type": select(
defined(url) => "externalUrl", "internalUrl"
),
label,
ariaLabel,
"link": select(
linkToOtherLanguage == true =>
referenceToOtherLanguage->${linkReferenceFields},
reference->${linkReferenceFields},
),
"href": url,
anchorReference,
}
`

const linkSelector = /* groq */ `
_type == "linkSelector" => ${linkSelectorFields}
`

export default linkSelectorFields
export default linkSelector
4 changes: 2 additions & 2 deletions web/lib/queries/common/eventContentFields.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import markDefs from './blockEditorMarks'
import linkSelectorFields from './actions/linkSelectorFields'
import linkSelector from './actions/linkSelectorFields'
import downloadableFileFields from './actions/downloadableFileFields'
import downloadableImageFields from './actions/downloadableImageFields'

Expand Down Expand Up @@ -76,7 +76,7 @@ export const eventContentFields = /* groq */ `
title,
heroImage,
"links": links[]{
${linkSelectorFields},
${linkSelector},
${downloadableFileFields},
${downloadableImageFields},
},
Expand Down
4 changes: 2 additions & 2 deletions web/lib/queries/common/heroFields.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import linkSelectorFields from './actions/linkSelectorFields'
import linkSelector from './actions/linkSelectorFields'

export const heroFields = /* groq */ `{
"type": coalesce(heroType, 'default'),
Expand All @@ -16,6 +16,6 @@ export const heroFields = /* groq */ `{
"ratio": heroLoopingVideoRatio,
},
"link": heroLink[0]{
${linkSelectorFields}
${linkSelector}
}
}`
4 changes: 2 additions & 2 deletions web/lib/queries/common/newsSubqueries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import downloadableFileFields from './actions/downloadableFileFields'
import downloadableImageFields from './actions/downloadableImageFields'
import linkSelectorFields from './actions/linkSelectorFields'
import linkSelector from './actions/linkSelectorFields'
import markDefs from './blockEditorMarks'

export const iframeForNewsQuery = /* groq */ `iframe {
Expand Down Expand Up @@ -43,7 +43,7 @@ export const relatedLinksForNewsQuery = /* groq */ `relatedLinks {
title,
heroImage,
"links": links[]{
${linkSelectorFields},
${linkSelector},
${downloadableFileFields},
${downloadableImageFields},
}
Expand Down
12 changes: 8 additions & 4 deletions web/lib/queries/common/pageContentFields.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { iframeCarouselFields } from '../iframeCarouselFields'
import { videoPlayerCarouselFields } from '../videoPlayerCarouselFields'
import { videoPlayerFields } from '../videoPlayerFields'
import { promoTextTileArrayFields } from '../promoTextTileArrayFields'
import downloadableFileFields from './actions/downloadableFileFields'
import downloadableImageFields from './actions/downloadableImageFields'
import linkSelectorFields, { linkReferenceFields } from './actions/linkSelectorFields'
import linkSelector, { linkReferenceFields } from './actions/linkSelectorFields'
import markDefs from './blockEditorMarks'
import { eventPromotionFields, futureEventsQuery, pastEventsQuery } from './eventPromotion'
import { imageCarouselFields } from './imageCarouselFields'
Expand Down Expand Up @@ -33,7 +34,7 @@ const pageContentFields = /* groq */ `
"extension": asset-> extension
},
"action": action[0]{
${linkSelectorFields},
${linkSelector},
${downloadableFileFields},
${downloadableImageFields},
},
Expand All @@ -52,7 +53,7 @@ const pageContentFields = /* groq */ `
ingress[]{..., ${markDefs}},
text[]{..., ${markDefs}},
"callToActions": action[]{
${linkSelectorFields},
${linkSelector},
${downloadableFileFields},
${downloadableImageFields},
},
Expand Down Expand Up @@ -194,7 +195,7 @@ const pageContentFields = /* groq */ `
},
frameTitle,
"action": action[0]{
${linkSelectorFields},
${linkSelector},
},
url,
"cookiePolicy": coalesce(cookiePolicy, 'none'),
Expand Down Expand Up @@ -515,6 +516,9 @@ const pageContentFields = /* groq */ `
_type == "videoPlayerCarousel" => {
${videoPlayerCarouselFields}
},
_type == "promoTextTileArray" => {
${promoTextTileArrayFields}
},
`

export default pageContentFields
4 changes: 2 additions & 2 deletions web/lib/queries/iframeCarouselFields.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import linkSelectorFields from './common/actions/linkSelectorFields'
import linkSelector from './common/actions/linkSelectorFields'

export const iframeCarouselFields = /* groq */ `
"id": _key,
"type": _type,
title,
items[]{..., "action": action[0]{
${linkSelectorFields},
${linkSelector},
},},
"designOptions": {
"background": coalesce(background.title, 'none'),
Expand Down
4 changes: 2 additions & 2 deletions web/lib/queries/magazine.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { heroFields } from './common/heroFields'
import pageContentFields from './common/pageContentFields'
import slugsForNewsAndMagazine from './slugsForNewsAndMagazine'
import linkSelectorFields from './common/actions/linkSelectorFields'
import linkSelector from './common/actions/linkSelectorFields'
import downloadableFileFields from './common/actions/downloadableFileFields'
import downloadableImageFields from './common/actions/downloadableImageFields'
import markDefs from './common/blockEditorMarks'
Expand All @@ -23,7 +23,7 @@ const footerComponentFields = /* groq */ `
"extension": asset-> extension
},
"action": action[0]{
${linkSelectorFields},
${linkSelector},
${downloadableFileFields},
${downloadableImageFields},
},
Expand Down
Loading