From 176662e3b80c4fd451b6f244ef7f1570d445785e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa?= Date: Thu, 31 Oct 2024 12:11:46 +0100 Subject: [PATCH] regex --- .../containers/countries/countries-table.tsx | 74 ++++++++++--------- client/src/containers/countries/utils.ts | 2 +- .../content-types/resource/schema.json | 6 +- cms/types/generated/contentTypes.d.ts | 1 + 4 files changed, 46 insertions(+), 37 deletions(-) diff --git a/client/src/containers/countries/countries-table.tsx b/client/src/containers/countries/countries-table.tsx index 2ef86902..89ecc2a6 100644 --- a/client/src/containers/countries/countries-table.tsx +++ b/client/src/containers/countries/countries-table.tsx @@ -104,42 +104,48 @@ const CountriesTable = () => { {v.isResource ? ( v.resources?.length ? ( - v.resources?.map((r) => ( - - - {r.link_title} - - - - + v.resources?.map((r) => { + if (!/^https?:\/\/|^www\./i.test(r.link_url)) { + r.link_url = `https://${r.link_url}`; + } -
-

- {t.name} -

- - - -
-

- {r.link_title} -

-

{r.description}

- + + {r.link_title} + + + - Learn more - -
-
-
- )) + + +
+

+ {t.name} +

+ + + +
+

+ {r.link_title} +

+

{r.description}

+ + Learn more + + + + + ); + }) ) : ( "-" ) diff --git a/client/src/containers/countries/utils.ts b/client/src/containers/countries/utils.ts index 1f694e9c..0ca0c852 100644 --- a/client/src/containers/countries/utils.ts +++ b/client/src/containers/countries/utils.ts @@ -125,7 +125,7 @@ const useTableData = () => { isDatasetValueProperty(value_type) && datasetValue?.attributes?.[value_type]; const country = countriesData?.data?.find((c1) => c1.attributes?.iso3 === c); - console.log({ country, c, datasetValue, value }); + return { iso3: c, countryLink: country?.attributes?.link, diff --git a/cms/src/api/resource/content-types/resource/schema.json b/cms/src/api/resource/content-types/resource/schema.json index 5f1b6102..2ea6b541 100644 --- a/cms/src/api/resource/content-types/resource/schema.json +++ b/cms/src/api/resource/content-types/resource/schema.json @@ -4,7 +4,8 @@ "info": { "singularName": "resource", "pluralName": "resources", - "displayName": "Resource" + "displayName": "Resource", + "description": "" }, "options": { "draftAndPublish": true @@ -17,7 +18,8 @@ }, "link_url": { "type": "text", - "required": true + "required": true, + "regex": "/^(https?:\\/\\/|www\\.)[a-zA-Z0-9-]+\\.[a-zA-Z]{2,}(\\/[^\\s]*)?$/" }, "description": { "type": "text" diff --git a/cms/types/generated/contentTypes.d.ts b/cms/types/generated/contentTypes.d.ts index 902863a0..87c6d90f 100644 --- a/cms/types/generated/contentTypes.d.ts +++ b/cms/types/generated/contentTypes.d.ts @@ -1489,6 +1489,7 @@ export interface ApiResourceResource extends Schema.CollectionType { singularName: 'resource'; pluralName: 'resources'; displayName: 'Resource'; + description: ''; }; options: { draftAndPublish: true;