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

Cookie consent integration #1124

Merged
merged 12 commits into from
Aug 1, 2023
4 changes: 4 additions & 0 deletions lang/ui.ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
"defaultMessage": "Alguna cosa ha anat malament. Baixa el teu fitxer hexadecimal per mantenir-lo segur i, a continuació, actualitza la pàgina per tornar-la a carregar.",
"description": "Text displayed when content fails to load"
},
"cookies-action": {
"defaultMessage": "Cookies",
"description": "Action to show dialog to choose website cookie preferences"
},
"copied": {
"defaultMessage": "Copiat",
"description": "Text shown after copy to clipboard"
Expand Down
4 changes: 4 additions & 0 deletions lang/ui.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
"defaultMessage": "Something went wrong. Download your hex file for safe keeping, then refresh the page to reload.",
"description": "Text displayed when content fails to load"
},
"cookies-action": {
"defaultMessage": "Cookies",
"description": "Action to show dialog to choose website cookie preferences"
},
"copied": {
"defaultMessage": "Copied",
"description": "Text shown after copy to clipboard"
Expand Down
4 changes: 4 additions & 0 deletions lang/ui.es-es.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
"defaultMessage": "Algo salió mal. Por seguridad, descarga tu archivo HEX y actualiza la página para recargar.",
"description": "Text displayed when content fails to load"
},
"cookies-action": {
"defaultMessage": "Cookies",
"description": "Action to show dialog to choose website cookie preferences"
},
"copied": {
"defaultMessage": "Copiado",
"description": "Text shown after copy to clipboard"
Expand Down
4 changes: 4 additions & 0 deletions lang/ui.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
"defaultMessage": "Une erreur est survenue. Téléchargez votre fichier hex pour ne pas le perdre, puis actualisez la page.",
"description": "Text displayed when content fails to load"
},
"cookies-action": {
"defaultMessage": "Cookies",
"description": "Action to show dialog to choose website cookie preferences"
},
"copied": {
"defaultMessage": "Copié",
"description": "Text shown after copy to clipboard"
Expand Down
4 changes: 4 additions & 0 deletions lang/ui.ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
"defaultMessage": "問題が発生しました。hex ファイルをダウンロードして、ページをリロードしてください。",
"description": "Text displayed when content fails to load"
},
"cookies-action": {
"defaultMessage": "Cookies",
"description": "Action to show dialog to choose website cookie preferences"
},
"copied": {
"defaultMessage": "コピーしました",
"description": "Text shown after copy to clipboard"
Expand Down
4 changes: 4 additions & 0 deletions lang/ui.ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
"defaultMessage": "오류가 발생했습니다. hex 파일을 다운로드해 작업물을 보호하고 새로 고침으로 페이지를 다시 불러오세요.",
"description": "Text displayed when content fails to load"
},
"cookies-action": {
"defaultMessage": "Cookies",
"description": "Action to show dialog to choose website cookie preferences"
},
"copied": {
"defaultMessage": "복사됨",
"description": "Text shown after copy to clipboard"
Expand Down
4 changes: 4 additions & 0 deletions lang/ui.nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
"defaultMessage": "Er is iets fout gegaan. Download je hexadecimale bestand voor een veilige bewaring, ververs daarna de pagina om te herladen.",
"description": "Text displayed when content fails to load"
},
"cookies-action": {
"defaultMessage": "Cookies",
"description": "Action to show dialog to choose website cookie preferences"
},
"copied": {
"defaultMessage": "Gekopieerd",
"description": "Text shown after copy to clipboard"
Expand Down
4 changes: 4 additions & 0 deletions lang/ui.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
"defaultMessage": "出错了。下载您的 hex 文件以便安全保存,然后刷新页面来重新加载。",
"description": "Text displayed when content fails to load"
},
"cookies-action": {
"defaultMessage": "Cookies",
"description": "Action to show dialog to choose website cookie preferences"
},
"copied": {
"defaultMessage": "已复制",
"description": "Text shown after copy to clipboard"
Expand Down
4 changes: 4 additions & 0 deletions lang/ui.zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
"defaultMessage": "發生錯誤。下載您的 HEX 檔案以便安全儲存,然後重新整理頁面來重新載入。",
"description": "Text displayed when content fails to load"
},
"cookies-action": {
"defaultMessage": "Cookies",
"description": "Action to show dialog to choose website cookie preferences"
},
"copied": {
"defaultMessage": "複製的",
"description": "Text shown after copy to clipboard"
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"mobile-drag-drop": "^2.3.0-rc.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-icons": "^4.2.0",
"react-icons": "^4.8.0",
"react-intl": "^5.20.10",
"vscode-jsonrpc": "^6.0.0",
"vscode-languageserver-protocol": "^3.16.0",
Expand Down
23 changes: 3 additions & 20 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,9 @@
name="twitter:description"
content="A Python Editor for the BBC micro:bit, built by the Micro:bit Educational Foundation and the global Python Community."
/>
<% if (process.env.REACT_APP_GA_MEASUREMENT_ID &&
(process.env.REACT_APP_STAGE === 'PRODUCTION' || process.env.REACT_APP_STAGE
=== "STAGING")) { %>
<script
async
src="https://www.googletagmanager.com/gtag/js?id=%REACT_APP_GA_MEASUREMENT_ID%"
></script>
<script>
window.dataLayer = window.dataLayer || [];
window.gaMeasurementId = "%REACT_APP_GA_MEASUREMENT_ID%";
window.gtag = function () {
window.dataLayer.push(arguments);
};
gtag("js", new Date());
var options = {
anonymize_ip: true,
cookie_prefix: "%REACT_APP_GA_COOKIE_PREFIX%",
};
gtag("config", window.gaMeasurementId, options);
</script>
<% if (process.env.REACT_APP_STAGE === 'PRODUCTION' || process.env.REACT_APP_STAGE === "STAGING") { %>
microbit-matt-hillsdon marked this conversation as resolved.
Show resolved Hide resolved
<script src="https://review-shared-assets.microbit.org/restructure/common/v1/common.js"></script>
<link rel="stylesheet" href="https://review-shared-assets.microbit.org/restructure/common/v1/main.css"></link>
microbit-matt-hillsdon marked this conversation as resolved.
Show resolved Hide resolved
<% } %>
</head>
<body>
Expand Down
13 changes: 8 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const App = () => {
});

const deployment = useDeployment();
const { ConsentProvider } = deployment.compliance;
return (
<>
<VisualViewPortCSSVariables />
Expand All @@ -79,11 +80,13 @@ const App = () => {
<SelectionProvider>
<DialogProvider>
<RouterProvider>
<ProjectDropTarget>
<ActiveEditorProvider>
<Workbench />
</ActiveEditorProvider>
</ProjectDropTarget>
<ConsentProvider>
<ProjectDropTarget>
<ActiveEditorProvider>
<Workbench />
</ActiveEditorProvider>
</ProjectDropTarget>
</ConsentProvider>
</RouterProvider>
</DialogProvider>
</SelectionProvider>
Expand Down
20 changes: 19 additions & 1 deletion src/deployment/default/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,31 @@
*
* SPDX-License-Identifier: MIT
*/
import { DeploymentConfig } from "..";
import { createContext } from "react";
import { CookieConsent, DeploymentConfig } from "..";
import { NullLogging } from "./logging";
import theme from "./theme";

const stubConsentValue: CookieConsent = {
analytics: false,
functional: true,
};
const stubConsentContext = createContext<CookieConsent | undefined>(
stubConsentValue
);

const defaultDeployment: DeploymentConfig = {
chakraTheme: theme,
logging: new NullLogging(),
compliance: {
ConsentProvider: ({ children }) => (
<stubConsentContext.Provider value={stubConsentValue}>
{children}
</stubConsentContext.Provider>
),
consentContext: stubConsentContext,
manageCookies: undefined,
},
};

export default defaultDeployment;
35 changes: 26 additions & 9 deletions src/deployment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,36 @@
*
* SPDX-License-Identifier: MIT
*/
import { ReactNode } from "react";
import { IconType } from "react-icons/lib";
import { ReactNode, useContext } from "react";
import { Logging } from "../logging/logging";

// This is configured via a webpack alias, defaulting to ./default
import { default as d } from "theme-package";
export const deployment: DeploymentConfig = d;

export interface CookieConsent {
analytics: boolean;
functional: boolean;
}

export interface DeploymentConfig {
squareLogo?: ReactNode;
horizontalLogo?: ReactNode;
Compliance?: ({
zIndex,
externalLinkIcon,
}: {
zIndex: number;
externalLinkIcon: IconType;
}) => JSX.Element;
compliance: {
/**
* A provider that will be used to wrap the app UI.
*/
ConsentProvider: (props: { children: ReactNode }) => JSX.Element;
/**
* Context that will be used to read the current consent value.
* The provider is not used directly.
*/
consentContext: React.Context<CookieConsent | undefined>;
/**
* Optional hook for the user to revisit cookie settings.
*/
manageCookies: (() => void) | undefined;
};

chakraTheme: any;

Expand All @@ -35,3 +47,8 @@ export interface DeploymentConfig {
export const useDeployment = (): DeploymentConfig => {
return deployment;
};

export const useCookieConsent = (): CookieConsent | undefined => {
const { compliance } = useDeployment();
return useContext(compliance.consentContext);
};
6 changes: 6 additions & 0 deletions src/messages/ui.ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@
"value": "Alguna cosa ha anat malament. Baixa el teu fitxer hexadecimal per mantenir-lo segur i, a continuació, actualitza la pàgina per tornar-la a carregar."
}
],
"cookies-action": [
{
"type": 0,
"value": "Cookies"
}
],
"copied": [
{
"type": 0,
Expand Down
6 changes: 6 additions & 0 deletions src/messages/ui.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@
"value": "Something went wrong. Download your hex file for safe keeping, then refresh the page to reload."
}
],
"cookies-action": [
{
"type": 0,
"value": "Cookies"
}
],
"copied": [
{
"type": 0,
Expand Down
6 changes: 6 additions & 0 deletions src/messages/ui.es-es.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@
"value": "Algo salió mal. Por seguridad, descarga tu archivo HEX y actualiza la página para recargar."
}
],
"cookies-action": [
{
"type": 0,
"value": "Cookies"
}
],
"copied": [
{
"type": 0,
Expand Down
6 changes: 6 additions & 0 deletions src/messages/ui.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@
"value": "Une erreur est survenue. Téléchargez votre fichier hex pour ne pas le perdre, puis actualisez la page."
}
],
"cookies-action": [
{
"type": 0,
"value": "Cookies"
}
],
"copied": [
{
"type": 0,
Expand Down
6 changes: 6 additions & 0 deletions src/messages/ui.ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,12 @@
"value": "問題が発生しました。hex ファイルをダウンロードして、ページをリロードしてください。"
}
],
"cookies-action": [
{
"type": 0,
"value": "Cookies"
}
],
"copied": [
{
"type": 0,
Expand Down
6 changes: 6 additions & 0 deletions src/messages/ui.ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,12 @@
"value": "오류가 발생했습니다. hex 파일을 다운로드해 작업물을 보호하고 새로 고침으로 페이지를 다시 불러오세요."
}
],
"cookies-action": [
{
"type": 0,
"value": "Cookies"
}
],
"copied": [
{
"type": 0,
Expand Down
6 changes: 6 additions & 0 deletions src/messages/ui.nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@
"value": "Er is iets fout gegaan. Download je hexadecimale bestand voor een veilige bewaring, ververs daarna de pagina om te herladen."
}
],
"cookies-action": [
{
"type": 0,
"value": "Cookies"
}
],
"copied": [
{
"type": 0,
Expand Down
6 changes: 6 additions & 0 deletions src/messages/ui.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@
"value": "出错了。下载您的 hex 文件以便安全保存,然后刷新页面来重新加载。"
}
],
"cookies-action": [
{
"type": 0,
"value": "Cookies"
}
],
"copied": [
{
"type": 0,
Expand Down
Loading