Skip to content

Commit 770946b

Browse files
Add compliance component. (#975)
Allows the deployment to optionally display a compliance notice. Disabled when embedded via iframe on the basis that the embedding application is responsible (e.g. micro:bit classroom, the current Python Editor versioning component).
1 parent cff776d commit 770946b

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ _steps:
3434
install_dependencies: &install_dependencies
3535
run: npm ci --cache .npm-cache && sudo npm config set @microbit-foundation:registry https://npm.pkg.github.com/microbit-foundation && sudo npm i -g @microbit-foundation/[email protected] @microbit-foundation/[email protected] @microbit-foundation/circleci-npm-package-versioner@1
3636
install_theme: &install_theme
37-
run: npm config set @microbit-foundation:registry https://npm.pkg.github.com/microbit-foundation && npm install --no-save @microbit-foundation/[email protected].183
37+
run: npm config set @microbit-foundation:registry https://npm.pkg.github.com/microbit-foundation && npm install --no-save @microbit-foundation/[email protected].192
3838
update_version: &update_version
3939
run: npm run ci:update-version
4040
build: &build

src/App.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
html,
3232
body,
3333
#root,
34+
.WorkbenchContainer,
3435
.Workbench {
3536
width: 100%;
3637
/* --ios-vvh set by VisualViewPortCSSVariables on iOS only. */

src/common/zIndex.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export const splitViewHideButton = 4;
1313
// z-index above the xterm.js's layers (currently 10 but given some margin for increases as it can vary with config)
1414
export const zIndexAboveTerminal = 20;
1515
export const zIndexOverlay = 30;
16+
export const zIndexAboveDialogs = 1500;

src/deployment/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: MIT
55
*/
66
import { ReactNode } from "react";
7+
import { IconType } from "react-icons/lib";
78
import { Logging } from "../logging/logging";
89

910
// This is configured via a webpack alias, defaulting to ./default
@@ -13,6 +14,13 @@ export const deployment: DeploymentConfig = d;
1314
export interface DeploymentConfig {
1415
squareLogo?: ReactNode;
1516
horizontalLogo?: ReactNode;
17+
Compliance?: ({
18+
zIndex,
19+
externalLinkIcon,
20+
}: {
21+
zIndex: number;
22+
externalLinkIcon: IconType;
23+
}) => JSX.Element;
1624

1725
chakraTheme: any;
1826

src/workbench/Workbench.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { Box, Flex } from "@chakra-ui/layout";
77
import { useMediaQuery } from "@chakra-ui/react";
88
import { ReactNode, useCallback, useEffect, useRef, useState } from "react";
9+
import { RiExternalLinkLine } from "react-icons/ri";
910
import { useIntl } from "react-intl";
1011
import {
1112
hideSidebarMediaQuery,
@@ -20,6 +21,8 @@ import {
2021
SplitViewSized,
2122
} from "../common/SplitView";
2223
import { SizedMode } from "../common/SplitView/SplitView";
24+
import { zIndexAboveDialogs } from "../common/zIndex";
25+
import { useDeployment } from "../deployment";
2326
import { ConnectionStatus } from "../device/device";
2427
import { useConnectionStatus } from "../device/device-hooks";
2528
import EditorArea from "../editor/EditorArea";
@@ -116,9 +119,23 @@ const Workbench = () => {
116119
)}
117120
</Box>
118121
);
119-
122+
const inIframe = () => {
123+
try {
124+
return window.self !== window.top;
125+
} catch (e) {
126+
return true;
127+
}
128+
};
129+
const deployment = useDeployment();
130+
const Compliance = deployment.Compliance ?? (() => null);
120131
return (
121-
<>
132+
<Flex className="WorkbenchContainer" flexDir="column">
133+
{!inIframe() && (
134+
<Compliance
135+
zIndex={zIndexAboveDialogs}
136+
externalLinkIcon={RiExternalLinkLine}
137+
/>
138+
)}
122139
<Flex className="Workbench">
123140
<SplitView
124141
direction="row"
@@ -161,7 +178,7 @@ const Workbench = () => {
161178
</SplitView>
162179
</Flex>
163180
<Overlay />
164-
</>
181+
</Flex>
165182
);
166183
};
167184

0 commit comments

Comments
 (0)