Skip to content

Commit 7aa07c1

Browse files
authored
feat: DH-22048: Add optional button to dismiss the ErrorView component (#2638)
- add dismiss button to ErrorView - button is only shown if an optional callback is provided - parent component must implement logic of callback to dismiss - show in styleguide
1 parent 0df7f10 commit 7aa07c1

5 files changed

Lines changed: 80 additions & 4 deletions

File tree

packages/code-studio/src/styleguide/ErrorViews.tsx

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
/* eslint no-alert: "off" */
2-
import React, { type CSSProperties } from 'react';
3-
import { ErrorView } from '@deephaven/components';
1+
import React, { useState, type CSSProperties } from 'react';
2+
import { Button, ErrorView } from '@deephaven/components';
43
import SampleSection from './SampleSection';
54

65
function ErrorViews(): React.ReactElement {
6+
const [isShortDismissed, setIsShortDismissed] = useState(false);
7+
const [isMidDismissed, setIsMidDismissed] = useState(false);
8+
const [isLongDismissed, setIsLongDismissed] = useState(false);
9+
710
const columnStyle: CSSProperties = {
811
maxHeight: 500,
912
display: 'flex',
@@ -18,6 +21,14 @@ function ErrorViews(): React.ReactElement {
1821
const midErrorType = 'MidError';
1922
const longErrorType = 'SuperLongErrorMessageType';
2023

24+
const hasAnyDismissed = isShortDismissed || isMidDismissed || isLongDismissed;
25+
26+
const handleReset = () => {
27+
setIsShortDismissed(false);
28+
setIsMidDismissed(false);
29+
setIsLongDismissed(false);
30+
};
31+
2132
return (
2233
<SampleSection name="error-views">
2334
<h2 className="ui-title" title="Display error messages easily">
@@ -51,6 +62,52 @@ function ErrorViews(): React.ReactElement {
5162
/>
5263
</div>
5364
</div>
65+
<h3>
66+
Dismissable
67+
{hasAnyDismissed && (
68+
<Button
69+
kind="primary"
70+
onClick={handleReset}
71+
style={{ marginLeft: '1rem' }}
72+
>
73+
Reset
74+
</Button>
75+
)}
76+
</h3>
77+
<div className="row" style={{ maxHeight: 500 }}>
78+
<div className="col" style={columnStyle}>
79+
{!isShortDismissed && (
80+
<ErrorView
81+
message={shortErrorMessage}
82+
onDismiss={() => {
83+
setIsShortDismissed(true);
84+
}}
85+
/>
86+
)}
87+
</div>
88+
<div className="col" style={columnStyle}>
89+
{!isMidDismissed && (
90+
<ErrorView
91+
message={midErrorMessage}
92+
type={midErrorType}
93+
onDismiss={() => {
94+
setIsMidDismissed(true);
95+
}}
96+
/>
97+
)}
98+
</div>
99+
<div className="col" style={columnStyle}>
100+
{!isLongDismissed && (
101+
<ErrorView
102+
message={longErrorMessage}
103+
type={longErrorType}
104+
onDismiss={() => {
105+
setIsLongDismissed(true);
106+
}}
107+
/>
108+
)}
109+
</div>
110+
</div>
54111
</SampleSection>
55112
);
56113
}

packages/components/src/ErrorView.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';
22
import classNames from 'classnames';
33
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
4-
import { vsDiffAdded, vsDiffRemoved, vsWarning } from '@deephaven/icons';
4+
import {
5+
vsClose,
6+
vsDiffAdded,
7+
vsDiffRemoved,
8+
vsWarning,
9+
} from '@deephaven/icons';
510
import {
611
useDebouncedCallback,
712
useResizeObserver,
@@ -19,6 +24,9 @@ export type ErrorViewerProps = {
1924

2025
/** The type of error message to display in the header. Defaults to Error. */
2126
type?: string;
27+
28+
/** Optional callback to dismiss the error. If provided, a Dismiss button will be displayed. It is up to the parent to implement the logic to dismiss the error. */
29+
onDismiss?: () => void;
2230
};
2331

2432
/**
@@ -28,6 +36,7 @@ function ErrorView({
2836
message,
2937
isExpanded: isExpandedProp = false,
3038
type = 'Error',
39+
onDismiss,
3140
}: ErrorViewerProps): JSX.Element {
3241
const [isExpandable, setIsExpandable] = useState(false);
3342
const [isExpanded, setIsExpanded] = useState(false);
@@ -79,6 +88,16 @@ function ErrorView({
7988
{isExpanded ? 'Show Less' : 'Show More'}
8089
</Button>
8190
)}
91+
{onDismiss != null && (
92+
<Button
93+
kind="danger"
94+
className="error-view-dismiss-button"
95+
onClick={onDismiss}
96+
icon={vsClose}
97+
>
98+
Dismiss
99+
</Button>
100+
)}
82101
</div>
83102
</div>
84103
<pre className="error-view-text" ref={textRef}>
21.8 KB
Loading
41.8 KB
Loading
9.39 KB
Loading

0 commit comments

Comments
 (0)