Merge pull request #14780 from backstage/freben/globals

avoid globals
This commit is contained in:
Fredrik Adelöw
2022-11-22 20:18:27 +01:00
committed by GitHub
19 changed files with 212 additions and 21 deletions
@@ -241,7 +241,7 @@ export class GoogleAnalytics implements AnalyticsApi {
* Simple hash function; relies on web cryptography + the sha-256 algorithm.
*/
private async hash(value: string): Promise<string> {
const digest = await crypto.subtle.digest(
const digest = await window.crypto.subtle.digest(
'sha-256',
new TextEncoder().encode(value),
);
@@ -89,7 +89,7 @@ export function EntityContextMenu(props: EntityContextMenuProps) {
const alertApi = useApi(alertApiRef);
const copyToClipboard = useCallback(() => {
navigator.clipboard
window.navigator.clipboard
.writeText(window.location.toString())
.then(() => alertApi.post({ message: 'Copied!', severity: 'info' }));
}, [alertApi]);
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Entity } from '@backstage/catalog-model';
import {
Box,
@@ -61,7 +61,9 @@ const DetailsPage = () => {
const classes = useStyles();
const [{ status, result: details, error }, { execute }] = useAsync(async () =>
api.getProject(decodeURIComponent(location.search.split('projectId=')[1])),
api.getProject(
decodeURIComponent(window.location.search.split('projectId=')[1]),
),
);
useMountEffect(execute);
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Entity } from '@backstage/catalog-model';
import { readGithubIntegrationConfigs } from '@backstage/integration';
import {
@@ -43,7 +44,6 @@ import { WorkflowRunStatus } from '../WorkflowRunStatus';
import { useWorkflowRunJobs } from './useWorkflowRunJobs';
import { useWorkflowRunsDetails } from './useWorkflowRunsDetails';
import { WorkflowRunLogs } from '../WorkflowRunLogs';
import { configApiRef, useApi } from '@backstage/core-plugin-api';
import { Breadcrumbs, Link } from '@backstage/core-components';
@@ -116,8 +116,6 @@ const JobListItem = ({
<Accordion TransitionProps={{ unmountOnExit: true }} className={className}>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls={`panel-${name}-content`}
id={`panel-${name}-header`}
IconButtonProps={{
className: classes.button,
}}
@@ -105,8 +105,6 @@ export const WorkflowRunLogs = ({
<Accordion TransitionProps={{ unmountOnExit: true }} disabled={inProgress}>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls={`panel-${name}-content`}
id={`panel-${name}-header`}
IconButtonProps={{
className: classes.button,
}}
@@ -47,7 +47,7 @@ export class StorageBucket implements Storage {
private readonly bucket: string,
) {}
[name: string]: any;
[itemName: string]: any;
get length(): number {
throw new Error('Method not implemented.');
@@ -59,7 +59,7 @@ describe('TextSize', () => {
expect(slider).toHaveTextContent('115%');
let style = getComputedStyle(getByText('TEST_CONTENT'));
let style = window.getComputedStyle(getByText('TEST_CONTENT'));
expect(style.getPropertyValue('--md-typeset-font-size')).toBe('18.4px');
@@ -73,7 +73,7 @@ describe('TextSize', () => {
expect(slider).toHaveTextContent('100%');
style = getComputedStyle(getByText('TEST_CONTENT'));
style = window.getComputedStyle(getByText('TEST_CONTENT'));
expect(style.getPropertyValue('--md-typeset-font-size')).toBe('16px');
});
@@ -105,7 +105,7 @@ describe('TextSize', () => {
expect(slider).toHaveTextContent('115%');
let style = getComputedStyle(getByText('TEST_CONTENT'));
let style = window.getComputedStyle(getByText('TEST_CONTENT'));
expect(style.getPropertyValue('--md-typeset-font-size')).toBe('18.4px');
@@ -117,7 +117,7 @@ describe('TextSize', () => {
expect(slider).toHaveTextContent('100%');
style = getComputedStyle(getByText('TEST_CONTENT'));
style = window.getComputedStyle(getByText('TEST_CONTENT'));
expect(style.getPropertyValue('--md-typeset-font-size')).toBe('16px');
});
@@ -20,7 +20,7 @@ import { lightTheme } from '@backstage/theme';
import { waitFor } from '@testing-library/react';
const clipboardSpy = jest.fn();
Object.defineProperty(navigator, 'clipboard', {
Object.defineProperty(window.navigator, 'clipboard', {
value: {
writeText: clipboardSpy,
},
@@ -49,7 +49,7 @@ const CopyToClipboardButton = ({ text }: CopyToClipboardButtonProps) => {
const [open, setOpen] = useState(false);
const handleClick = useCallback(() => {
navigator.clipboard.writeText(text);
window.navigator.clipboard.writeText(text);
setOpen(true);
}, [text]);