Skip to content

Commit

Permalink
DataPanel: add flag to display a LoadingOverlay
Browse files Browse the repository at this point in the history
- update CSS to contain LoadingOverlay
- add isLoading prop
  • Loading branch information
cee-chen committed Mar 10, 2021
1 parent 5d9ddfa commit 7d61dd5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.dataPanel {
position: relative;
overflow: hidden;

// TODO: This CSS can be removed once EUI supports tables in `subdued` panels
&--filled {
.euiTable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { shallow } from 'enzyme';

import { EuiIcon, EuiButton } from '@elastic/eui';

import { LoadingOverlay } from '../../../shared/loading';

import { DataPanel } from './data_panel';

describe('DataPanel', () => {
Expand Down Expand Up @@ -80,6 +82,18 @@ describe('DataPanel', () => {
expect(wrapper.prop('className')).toEqual('dataPanel dataPanel--filled');
});

it('renders a loading overlay based on isLoading flag', () => {
const wrapper = shallow(<DataPanel title={<h1>Test</h1>} />);

expect(wrapper.prop('aria-busy')).toBeFalsy();
expect(wrapper.find(LoadingOverlay)).toHaveLength(0);

wrapper.setProps({ isLoading: true });

expect(wrapper.prop('aria-busy')).toBeTruthy();
expect(wrapper.find(LoadingOverlay)).toHaveLength(1);
});

it('passes class names', () => {
const wrapper = shallow(<DataPanel title={<h1>Test</h1>} className="testing" />);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
EuiTitle,
} from '@elastic/eui';

import { LoadingOverlay } from '../../../shared/loading';

import './data_panel.scss';

interface Props {
Expand All @@ -27,6 +29,7 @@ interface Props {
iconType?: string;
action?: React.ReactNode;
filled?: boolean;
isLoading?: boolean;
className?: string;
}

Expand All @@ -36,6 +39,7 @@ export const DataPanel: React.FC<Props> = ({
iconType,
action,
filled,
isLoading,
className,
children,
...props // e.g., data-test-subj
Expand All @@ -45,7 +49,13 @@ export const DataPanel: React.FC<Props> = ({
});

return (
<EuiPanel {...props} color={filled ? 'subdued' : 'plain'} className={classes} hasShadow={false}>
<EuiPanel
{...props}
color={filled ? 'subdued' : 'plain'}
className={classes}
hasShadow={false}
aria-busy={isLoading}
>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center" responsive={false}>
<EuiFlexItem>
<EuiFlexGroup gutterSize="s" alignItems="center" responsive={false}>
Expand All @@ -68,6 +78,7 @@ export const DataPanel: React.FC<Props> = ({
</EuiFlexGroup>
<EuiSpacer />
{children}
{isLoading && <LoadingOverlay />}
</EuiPanel>
);
};

0 comments on commit 7d61dd5

Please sign in to comment.