Skip to content

ERA-11250 Swap in new cookie manager by Osana #1241

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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
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
16 changes: 7 additions & 9 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@
-->
<script data-jsd-embedded data-key="e1d5f5e4-1bf6-43ce-ae10-972895d6c040"
data-base-url="https://jsd-widget.atlassian.com" src="https://jsd-widget.atlassian.com/assets/embed.js"></script>
<% if (process.env.NODE_ENV==='production' ) { %>
<!-- OneTrust Cookies Consent Notice start for pamdas.org -->

<script src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js" data-document-language="true"
type="text/javascript" charset="UTF-8" data-domain-script="3593d516-42e1-432a-89b5-ecb82c267279"></script>
<!-- OneTrust Cookies Consent Notice end for pamdas.org -->
<script type="text/javascript">
function OptanonWrapper() { }
</script>
<% if (process.env.NODE_ENV==='production' ) { %>
<!-- Osano Cookies Consent Notice start for pamdas.org -->
<script src="https://cmp.osano.com/AzqB4OUPPVD5j8EeT/bc796e8a-d3d4-4a74-b9c7-f737cbc3379b/osano.js"></script>
<style>
.osano-cm-widget{display: none;}
</style>
<!-- Osano Cookies Consent Notice end for pamdas.org -->
<% } %>
</body>

Expand Down
6 changes: 5 additions & 1 deletion src/UserMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ const UserMenu = ({ onLogOutClick, onProfileClick, selectedUserProfile, user, us
<Dropdown.Divider />
</>}

<Dropdown.Item onClick={() => cookieSettingsRef.current.click()}>{t('cookieSettingsItem')}</Dropdown.Item>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we can do a bit more cleanup in this file. The following lines can go away:

// Line 1 (just the useRef import)
import React, { useRef } from 'react';
...
// Line 17
const cookieSettingsRef = useRef();
...
// Line 28
<button className="ot-sdk-show-settings" hidden id="ot-sdk-btn" ref={cookieSettingsRef} />

{window.Osano?.cm && (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add some optional chaining to the window object (like window?.Osano?.cm) so we're not set up for future failures in headless test environments.

<Dropdown.Item onClick={() => window.Osano.cm.showDrawer('osano-cm-dom-info-dialog-open')}>
{t('cookieSettingsItem')}
</Dropdown.Item>
)}

<Dropdown.Item onClick={onLogOutItemClick}>{t('logoutItem')}</Dropdown.Item>
</Dropdown.Menu>
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ const RootApp = () => {
const { i18n } = useTranslation();

useEffect(() => {
if (window?.OneTrust) {
if (typeof window !== 'undefined' && window.Osano) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually go for optional chaining, so we can keep the code as it was, just changing the property:

if (window?.Osano) {

It's logically the same.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^that. window?.Osano?.cm is a step safer as well, since it checks for the target object receiving a property in this code.

document.documentElement.lang = i18n.language;
window.OneTrust.changeLanguage(i18n.language);
window.Osano.cm.locale = i18n.language;
if (window.Osano.cm.locale !== i18n.language) {
window.Osano.cm.locale = 'en';
}
}
}, [i18n.language]);

Expand Down