Skip to content

Commit

Permalink
Merge pull request #11416 from wellcomecollection/popup-dialog-regex
Browse files Browse the repository at this point in the history
Add ability to limit where popupDialog appears with regex
  • Loading branch information
davidpmccormick authored Nov 20, 2024
2 parents 79a744e + 0d75f56 commit 558c1e7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const meta: Meta<typeof PopupDialog> = {
},
],
isShown: true,
routeRegex: null,
},
},
},
Expand Down
11 changes: 9 additions & 2 deletions common/customtypes/popup-dialog/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"label": "Popup dialog",
"repeatable": false,
"status": true,
"format": "custom",
"json": {
"Popup dialog": {
"openButtonText": {
Expand Down Expand Up @@ -44,8 +45,14 @@
"default_value": false,
"label": "Is shown?"
}
},
"routeRegex": {
"type": "Text",
"config": {
"label": "Route regex",
"placeholder": "Pipe-separated (|) list of page paths here if you only want this on certain pages"
}
}
}
},
"format": "custom"
}
}
11 changes: 11 additions & 0 deletions common/prismicio-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4221,6 +4221,17 @@ interface PopupDialogDocumentData {
* - **Documentation**: https://prismic.io/docs/field#boolean
*/
isShown: prismic.BooleanField;

/**
* Route regex field in *Popup dialog*
*
* - **Field Type**: Text
* - **Placeholder**: Pipe-separated (|) list of page paths here if you only want this on certain pages
* - **API ID Path**: popup-dialog.routeRegex
* - **Tab**: Popup dialog
* - **Documentation**: https://prismic.io/docs/field#key-text
*/
routeRegex: prismic.KeyTextField;
}

/**
Expand Down
1 change: 1 addition & 0 deletions common/server-data/prismic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const defaultValue = {
openButtonText: null,
text: [] as prismic.RichTextField,
title: null,
routeRegex: null,
},
},
collectionVenues: {
Expand Down
1 change: 1 addition & 0 deletions common/services/prismic/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,6 @@ export function emptyPopupDialog(): RawPopupDialogDocument {
openButtonText: null,
text: [],
title: null,
routeRegex: null,
}) as RawPopupDialogDocument;
}
1 change: 1 addition & 0 deletions common/test/fixtures/prismicData/prismic-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const prismicData: SimplifiedPrismicData = {
url: 'https://interviewer.djsresearch.com/scripts/Dubinterviewer.dll/Frames?Quest=7577',
},
isShown: false,
routeRegex: null,
},
},
collectionVenues: {
Expand Down
6 changes: 5 additions & 1 deletion common/views/components/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,11 @@ const PageLayoutComponent: FunctionComponent<Props> = ({
}}
/>
)}
{popupDialog.data.isShown && <PopupDialog document={popupDialog} />}
{popupDialog.data.isShown &&
(!popupDialog.data.routeRegex ||
urlString.match(new RegExp(popupDialog.data.routeRegex))) && (
<PopupDialog document={popupDialog} />
)}
<div
id="main"
className="main"
Expand Down

0 comments on commit 558c1e7

Please sign in to comment.