From 08d9e931d370bd965e902669b99e96c80b43839a Mon Sep 17 00:00:00 2001 From: Borghild Selle <104756130+BorghildSelle@users.noreply.github.com> Date: Fri, 8 Nov 2024 10:51:45 +0100 Subject: [PATCH 1/5] :art: filter out crude oil (#2668) --- web/templates/newsroom/sanity/NewsroomSanity.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/web/templates/newsroom/sanity/NewsroomSanity.tsx b/web/templates/newsroom/sanity/NewsroomSanity.tsx index ea2a7cd16..fd3f115f3 100644 --- a/web/templates/newsroom/sanity/NewsroomSanity.tsx +++ b/web/templates/newsroom/sanity/NewsroomSanity.tsx @@ -1,6 +1,6 @@ import { forwardRef, useRef, useState } from 'react' import Blocks from '../../../pageComponents/shared/portableText/Blocks' -import type { NewsRoomPageType } from '../../../types' +import type { NewsRoomNewsItem, NewsRoomPageType } from '../../../types' import { Heading, Typography } from '@core/Typography' import { ResourceLink } from '@core/Link' import Seo from '../../../pageComponents/shared/Seo' @@ -51,11 +51,13 @@ const NewsRoomTemplateSanity = forwardRef(fu newsArticles?.[newsArticles?.length - 1]?.publishDateTime ?? null, ) - - const [newsList, setNewsList] = useState(newsArticles ?? []) + const filterCrudeAssays = (list: NewsRoomNewsItem[]) => { + return list?.filter((item: NewsRoomNewsItem) => item?.tags?.some((tag: any) => tag.key !== 'crude-oil-assays')) + } + const [newsList, setNewsList] = useState(filterCrudeAssays(newsArticles) ?? []) const setSearchStates = (filteredNews: any) => { - setNewsList(filteredNews) + setNewsList(filterCrudeAssays(filteredNews)) setFirstId(filteredNews?.length > 0 ? filteredNews[0].id : null) setLastId(filteredNews?.length > 0 ? filteredNews[filteredNews.length - 1].id : null) setFirstPublished( From d677f1e55d5f3cf79dc7f2f0d501001565b0a8dd Mon Sep 17 00:00:00 2001 From: Borghild Selle <104756130+BorghildSelle@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:01:38 +0100 Subject: [PATCH 2/5] :art: add warning for http and not valid slug #2496 (#2503) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :art: add warning for http and not valid slug * 🐛 Refactor after comments #2496 * 🚨 Lint #2496 * 💚 🐛 Fix import bug #2496 * 🐛 Fix error with validation #2496 * 🐛 Check lowercase excluding queryparam #2496 * 🐛 Allow http to avoid error msg that confuses #2496 --------- Co-authored-by: Padmaja <52911293+padms@users.noreply.github.com> --- sanityv3/schemas/editors/blockContentType.tsx | 8 +++++- sanityv3/schemas/objects/linkSelector.tsx | 9 ++++++- .../schemas/validations/checkEquinorUrls.ts | 5 ++++ sanityv3/schemas/validations/validateSlug.ts | 26 +++++++++++++++++++ satellitesConfig.js | 4 +++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 sanityv3/schemas/validations/checkEquinorUrls.ts diff --git a/sanityv3/schemas/editors/blockContentType.tsx b/sanityv3/schemas/editors/blockContentType.tsx index 14d944d4f..59ac24dc6 100644 --- a/sanityv3/schemas/editors/blockContentType.tsx +++ b/sanityv3/schemas/editors/blockContentType.tsx @@ -6,6 +6,7 @@ import { Flags } from '../../src/lib/datasetHelpers' import { ExternalLinkRenderer, SubScriptRenderer, SuperScriptRenderer } from '../components' import routes from '../routes' import { defaultColors } from '../defaultColors' +import { strictExternal, warnHttpExternal, warnHttpOrNotValidSlugExternal } from '../validations/validateSlug' export type BlockContentProps = { h2?: boolean @@ -181,7 +182,12 @@ export const configureBlockContent = (options: BlockContentProps = {}): BlockDef { name: 'href', type: 'url', - validation: (Rule: any) => Rule.uri({ scheme: ['http', 'https', 'tel', 'mailto'] }), + validation: (Rule: any) => + Rule.uri({ scheme: ['http', 'https', 'tel', 'mailto'] }) + .custom((value: any, context: ValidationContext) => { + return warnHttpOrNotValidSlugExternal(value, context) + }) + .error(), }, ], } diff --git a/sanityv3/schemas/objects/linkSelector.tsx b/sanityv3/schemas/objects/linkSelector.tsx index 2300559da..908729d99 100644 --- a/sanityv3/schemas/objects/linkSelector.tsx +++ b/sanityv3/schemas/objects/linkSelector.tsx @@ -9,6 +9,7 @@ import { AnchorLinkDescription } from './anchorReferenceField' // eslint-disable-next-line import/no-unresolved import { defaultLanguage } from '../../languages' import { apiVersion } from '../../sanity.client' +import { warnHttpOrNotValidSlugExternal } from '../validations/validateSlug' export type ReferenceTarget = { type: string @@ -118,7 +119,13 @@ export const getLinkSelectorFields = (labelFieldset?: string, flag?: string) => const { parent } = context as { parent: LinkSelector } if (isHidden(parent)) return true const connectedField = parent?.linkToOtherLanguage ? parent?.referenceToOtherLanguage : parent?.reference - return validateInternalOrExternalUrl(value, connectedField) + const internalValidation = validateInternalOrExternalUrl(value, connectedField) + //If message from internalValidation return that if not continue to check external url + if (internalValidation) { + return warnHttpOrNotValidSlugExternal(value, context) + } else { + return internalValidation + } }), hidden: ({ parent }: { parent: LinkSelector }) => isHidden(parent), }, diff --git a/sanityv3/schemas/validations/checkEquinorUrls.ts b/sanityv3/schemas/validations/checkEquinorUrls.ts new file mode 100644 index 000000000..5f39c3250 --- /dev/null +++ b/sanityv3/schemas/validations/checkEquinorUrls.ts @@ -0,0 +1,5 @@ +import { getAllDomainUrls } from '../../../satellitesConfig' + +export const isEquinorUrl = (slug: string) => { + return getAllDomainUrls().some((allowedUrl) => slug.toLowerCase().startsWith(allowedUrl)) +} diff --git a/sanityv3/schemas/validations/validateSlug.ts b/sanityv3/schemas/validations/validateSlug.ts index 01ab31878..aa355fbbd 100644 --- a/sanityv3/schemas/validations/validateSlug.ts +++ b/sanityv3/schemas/validations/validateSlug.ts @@ -1,6 +1,7 @@ import { ValidationContext } from 'sanity' import { apiVersion } from '../../sanity.client' import { Flags } from '../../src/lib/datasetHelpers' +import { isEquinorUrl } from './checkEquinorUrls' const validateIsUniqueWithinLocale = async (slug: string, context: ValidationContext) => { const { document, getClient } = context @@ -41,3 +42,28 @@ export const withSlugValidation = (options: any) => { } : options } + +const stringIsSlug = + /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/ +const httpRegex = /^http:\/\/[^\s]+$/ +export const warnHttpOrNotValidSlugExternal = (slug: string) => { + if (!slug) return true + if (!slug.startsWith('http')) return true // ignore mailto , tel + const isHttp = httpRegex.test(slug) + const validSlug = stringIsSlug.test(slug) + const slugWithOutQueryParam = slug.split('?')[0] + const isInvalidEquinorUrl = slugWithOutQueryParam !== slugWithOutQueryParam.toLowerCase() && isEquinorUrl(slug) + + let message = '' + if (isHttp) { + message = 'Use https in url. ' + } + if (!validSlug) { + message = message.concat(`Not a valid url.`) + } + + if (isInvalidEquinorUrl) { + message = message.concat('Equinor urls should contain lowercase letters only.') + } + return isHttp || !validSlug || isInvalidEquinorUrl ? message : true +} diff --git a/satellitesConfig.js b/satellitesConfig.js index b6dc08600..32f4b9738 100644 --- a/satellitesConfig.js +++ b/satellitesConfig.js @@ -185,3 +185,7 @@ export const getDomain = (dataset) => websiteDomains[dataset]?.url || 'Domain no export const getMetaTitleSuffix = (dataset) => { return websiteDomains[dataset]?.meta || 'Equinor' } + +export const getAllDomainUrls = () => { + return Object.keys(datasets).map((dataset) => websiteDomains[dataset]?.url) +} From 7f1140c04d887855052a22e4c3ca96d16df9932b Mon Sep 17 00:00:00 2001 From: VarunVAshrit <159520405+VarunVAshrit@users.noreply.github.com> Date: Fri, 8 Nov 2024 15:32:09 +0530 Subject: [PATCH 3/5] :hammer: Migration script to find http links (#2519) --- sanityv3/migrations/issue-2496/index.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 sanityv3/migrations/issue-2496/index.ts diff --git a/sanityv3/migrations/issue-2496/index.ts b/sanityv3/migrations/issue-2496/index.ts new file mode 100644 index 000000000..9cd6ce41a --- /dev/null +++ b/sanityv3/migrations/issue-2496/index.ts @@ -0,0 +1,15 @@ +import {defineMigration, set} from 'sanity/migrate' + +export default defineMigration({ + title: 'Issue 2496', + documentTypes: ["page", "news", "magazine", "event"], + + migrate: { + string(node, path, context) { + if(node.startsWith("http:")){ + return set(node.replace("http:", "https:")); + } + }, + + }, +}) From fe551edc4fe3b7d7fc2069d78e96e931db231d13 Mon Sep 17 00:00:00 2001 From: "Malin J." Date: Tue, 12 Nov 2024 13:15:23 +0100 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=90=9B=20Image=20carousel=202=20items?= =?UTF-8?q?=20are=20now=20scrollable=20#2589?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/core/Carousel/Carousel.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/core/Carousel/Carousel.tsx b/web/core/Carousel/Carousel.tsx index 78818bff8..12cc66f6c 100644 --- a/web/core/Carousel/Carousel.tsx +++ b/web/core/Carousel/Carousel.tsx @@ -356,7 +356,7 @@ export const Carousel = forwardRef(function Carousel variant === 'image' && displayMode === 'single' ? 'w-[var(--image-carousel-card-w-sm)] md:w-[var(--image-carousel-card-w-md)] lg:w-[var(--image-carousel-card-w-lg)] mx-auto col-start-1 col-end-1 row-start-2 row-end-2' : '' - } pt-6 pb-2 ${items.length === 2 ? 'lg:hidden' : ''} flex ${ + } pt-6 pb-2 ${items.length === 3 ? 'lg:hidden' : ''} flex ${ internalAutoRotation ? 'justify-between' : 'justify-end' }`} > From 423d80e6e3d6952fbbdfecc1e76f629a2db5fd58 Mon Sep 17 00:00:00 2001 From: "Malin J." Date: Tue, 12 Nov 2024 13:17:45 +0100 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=90=9B=20Add=20key=20on=20carousel=20?= =?UTF-8?q?item=20#2598?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/core/Carousel/Carousel.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/core/Carousel/Carousel.tsx b/web/core/Carousel/Carousel.tsx index 12cc66f6c..8cedeb95b 100644 --- a/web/core/Carousel/Carousel.tsx +++ b/web/core/Carousel/Carousel.tsx @@ -300,7 +300,7 @@ export const Carousel = forwardRef(function Carousel return (