Skip to content
Snippets Groups Projects
Unverified Commit e96cf05b authored by Dalton's avatar Dalton Committed by GitHub
Browse files

don't show error card in prod & make it fullscreen when running cypress (#16908)

* don't show error card in prod & make it fullscreen when running cypress

* fix height styling
parent 19936cc3
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ import Navbar from "metabase/nav/containers/Navbar"; ...@@ -7,7 +7,7 @@ import Navbar from "metabase/nav/containers/Navbar";
import { IFRAMED, initializeIframeResizer } from "metabase/lib/dom"; import { IFRAMED, initializeIframeResizer } from "metabase/lib/dom";
import UndoListing from "metabase/containers/UndoListing"; import UndoListing from "metabase/containers/UndoListing";
import ErrorCard from "metabase/components/ErrorCard"; import AppErrorCard from "metabase/components/AppErrorCard/AppErrorCard";
import { import {
Archived, Archived,
...@@ -55,6 +55,7 @@ export default class App extends Component { ...@@ -55,6 +55,7 @@ export default class App extends Component {
} }
componentDidCatch(error, errorInfo) { componentDidCatch(error, errorInfo) {
console.log("COMPONENT DID CATCH LOLE");
this.setState({ errorInfo }); this.setState({ errorInfo });
} }
...@@ -69,7 +70,7 @@ export default class App extends Component { ...@@ -69,7 +70,7 @@ export default class App extends Component {
{errorPage ? getErrorComponent(errorPage) : children} {errorPage ? getErrorComponent(errorPage) : children}
<UndoListing /> <UndoListing />
</div> </div>
<ErrorCard errorInfo={errorInfo} /> <AppErrorCard errorInfo={errorInfo} />
</ScrollToTop> </ScrollToTop>
); );
} }
......
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { t } from "ttag";
import { isCypressActive, isProduction } from "metabase/env";
import BodyComponent from "metabase/components/BodyComponent"; import BodyComponent from "metabase/components/BodyComponent";
import Card from "metabase/components/Card";
import Icon from "metabase/components/Icon"; import Icon from "metabase/components/Icon";
import { t } from "ttag"; import Button from "metabase/components/Button";
import { FullscreenCard, FixedCard } from "./AppErrorCard.styled";
const CardComponent = isCypressActive ? FullscreenCard : FixedCard;
const isInEnvWhereErrorShouldBeShown = !isProduction || isCypressActive;
export default BodyComponent(AppErrorCard);
function ErrorCard({ errorInfo }) { AppErrorCard.propTypes = {
const [showError, setShowError] = useState(false); errorInfo: PropTypes.shape({
componentStack: PropTypes.string,
}),
};
function AppErrorCard({ errorInfo }) {
const [hasNewError, setHasNewError] = useState(false);
useEffect(() => { useEffect(() => {
if (errorInfo) { if (errorInfo) {
setShowError(true); setHasNewError(true);
} }
}, [errorInfo]); }, [errorInfo]);
const showError = hasNewError && isInEnvWhereErrorShouldBeShown;
return showError ? ( return showError ? (
<Card className="fixed right bottom zF" p={2} m={2} width={350}> <CardComponent>
<div className="flex justify-between align-center mb1"> <div className="flex justify-between align-center mb1">
<div className="text-error flex align-center"> <div className="text-error flex align-center">
<Icon name="info_outline" mr={1} size="20" /> <Icon name="info_outline" mr={1} size="20" />
<h2>{t`Something went wrong`}</h2> <h2>{t`Something went wrong`}</h2>
</div> </div>
<Icon <Button
name="close" onlyIcon
className="pl1 cursor-pointer text-dark" icon="close"
onClick={() => setShowError(false)} className="pl1"
onClick={() => setHasNewError(false)}
/> />
</div> </div>
<pre style={{ height: "20vh" }} className="overflow-auto"> <pre>{errorInfo.componentStack}</pre>
{errorInfo.componentStack} </CardComponent>
</pre> ) : null;
</Card>
) : (
showError
);
} }
ErrorCard.propTypes = {
errorInfo: PropTypes.object,
};
export default BodyComponent(ErrorCard);
import styled from "styled-components";
import Card from "metabase/components/Card";
export const FullscreenCard = styled(Card)`
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
height: 100vh;
padding: 1rem;
z-index: 5;
overflow: auto;
`;
export const FixedCard = styled(Card)`
position: fixed;
right: 0;
bottom: 0;
width: 350px;
height: 500px;
margin: 1rem;
padding: 1rem;
z-index: 5;
overflow: auto;
`;
...@@ -6,10 +6,11 @@ import ResizeObserver from "resize-observer-polyfill"; ...@@ -6,10 +6,11 @@ import ResizeObserver from "resize-observer-polyfill";
import cx from "classnames"; import cx from "classnames";
import _ from "underscore"; import _ from "underscore";
import { isCypressActive } from "metabase/env";
// After adding throttling for resize re-renders, our Cypress tests became flaky // After adding throttling for resize re-renders, our Cypress tests became flaky
// due to queried DOM elements are getting detached after re-renders // due to queried DOM elements are getting detached after re-renders
const throttleDuration = window.Cypress ? 0 : 500; const throttleDuration = isCypressActive ? 0 : 500;
export default ({ selector, wrapped } = {}) => ComposedComponent => export default ({ selector, wrapped } = {}) => ComposedComponent =>
class extends Component { class extends Component {
......
export const isCypressActive = !!window.Cypress;
// eslint-disable-next-line no-undef
export const isProduction = process.env.NODE_ENV === "production";
import _ from "underscore"; import _ from "underscore";
import { isCypressActive } from "metabase/env";
// IE doesn't support scrollX/scrollY: // IE doesn't support scrollX/scrollY:
export const getScrollX = () => export const getScrollX = () =>
typeof window.scrollX === "undefined" ? window.pageXOffset : window.scrollX; typeof window.scrollX === "undefined" ? window.pageXOffset : window.scrollX;
...@@ -9,7 +11,7 @@ export const getScrollY = () => ...@@ -9,7 +11,7 @@ export const getScrollY = () =>
// Cypress renders the whole app within an iframe, but we want to exlude it from this check to avoid certain components (like Nav bar) not rendering // Cypress renders the whole app within an iframe, but we want to exlude it from this check to avoid certain components (like Nav bar) not rendering
export const IFRAMED = (function() { export const IFRAMED = (function() {
try { try {
return !window.Cypress && window.self !== window.top; return !isCypressActive && window.self !== window.top;
} catch (e) { } catch (e) {
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment