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

Add ability to limit where popupDialog appears with regex #11416

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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