- Add a header, a shared accordion, a docked status region, and token-based styles - Use the blue primary style for every action button and collapse all sections by default - Improve labels, selection hints, destructive confirmations, grid semantics, and narrow-pane layout - Add docs/UI_GUIDELINES.md and update the README, user guide, and developer guide
71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
/**
|
|
* @file ErrorBoundary.tsx
|
|
* @description Catches render errors so the task pane never shows a blank page.
|
|
*/
|
|
|
|
import * as React from "react";
|
|
import { Button, makeStyles, Text, tokens } from "@fluentui/react-components";
|
|
import { getErrorMessage } from "../types/office-types";
|
|
|
|
interface ErrorBoundaryProps {
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
interface ErrorBoundaryState {
|
|
hasError: boolean;
|
|
message: string;
|
|
}
|
|
|
|
const useStyles = makeStyles({
|
|
root: {
|
|
display: "flex",
|
|
flexDirection: "column",
|
|
alignItems: "flex-start",
|
|
gap: tokens.spacingVerticalM,
|
|
padding: tokens.spacingVerticalL,
|
|
backgroundColor: tokens.colorNeutralBackground1
|
|
},
|
|
message: {
|
|
color: tokens.colorNeutralForeground2,
|
|
whiteSpace: "pre-wrap"
|
|
}
|
|
});
|
|
|
|
const ErrorFallback: React.FC<{ message: string }> = ({ message }) => {
|
|
const styles = useStyles();
|
|
|
|
return (
|
|
<div role="alert" className={styles.root}>
|
|
<Text size={400} weight="semibold">Edison could not load</Text>
|
|
<Text size={300} className={styles.message}>
|
|
{message || "An unexpected error occurred."}
|
|
</Text>
|
|
<Button appearance="primary" onClick={() => window.location.reload()}>
|
|
Reload task pane
|
|
</Button>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
state: ErrorBoundaryState = { hasError: false, message: "" };
|
|
|
|
static getDerivedStateFromError(error: unknown): ErrorBoundaryState {
|
|
return { hasError: true, message: getErrorMessage(error) };
|
|
}
|
|
|
|
componentDidCatch(error: unknown, info: React.ErrorInfo): void {
|
|
console.error("Task pane render error:", error, info.componentStack);
|
|
}
|
|
|
|
render(): React.ReactNode {
|
|
if (this.state.hasError) {
|
|
return <ErrorFallback message={this.state.message} />;
|
|
}
|
|
|
|
return this.props.children;
|
|
}
|
|
}
|
|
|
|
export default ErrorBoundary;
|