-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add NoResultsComponent to charts (#305)
- Loading branch information
1 parent
517020a
commit 06d7ad5
Showing
5 changed files
with
254 additions
and
38 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
..._superset_ui/superset-ui/packages/superset-ui-chart/src/components/NoResultsComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, { CSSProperties, useMemo } from 'react'; | ||
|
||
const MESSAGE_STYLES: CSSProperties = { maxWidth: 800 }; | ||
const TITLE_STYLES: CSSProperties = { fontSize: 20, fontWeight: 'bold', paddingBottom: 8 }; | ||
const BODY_STYLES: CSSProperties = { fontSize: 16 }; | ||
|
||
const generateContainerStyles: ( | ||
height: number | string, | ||
width: number | string, | ||
) => CSSProperties = (height: number | string, width: number | string) => ({ | ||
alignItems: 'center', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
height, | ||
justifyContent: 'center', | ||
padding: 16, | ||
textAlign: 'center', | ||
width, | ||
}); | ||
|
||
type Props = { | ||
className?: string; | ||
height: number | string; | ||
id?: string; | ||
width: number | string; | ||
}; | ||
|
||
const NoResultsComponent = ({ className, height, id, width }: Props) => { | ||
const containerStyles = useMemo(() => generateContainerStyles(height, width), [height, width]); | ||
|
||
return ( | ||
<div className={className} id={id} style={containerStyles}> | ||
<div style={MESSAGE_STYLES}> | ||
<div style={TITLE_STYLES}>No Results</div> | ||
<div style={BODY_STYLES}> | ||
No results were returned for this query. If you expected results to be returned, ensure | ||
any filters are configured properly and the datasource contains data for the selected time | ||
range. | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NoResultsComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...set_ui/superset-ui/packages/superset-ui-chart/test/components/NoResultsComponent.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import NoResultsComponent from '../../src/components/NoResultsComponent'; | ||
|
||
describe('NoResultsComponent', () => { | ||
it('renders the no results error', () => { | ||
const wrapper = shallow(<NoResultsComponent height="400" width="300" />); | ||
|
||
expect(wrapper.text()).toEqual( | ||
'No ResultsNo results were returned for this query. If you expected results to be returned, ensure any filters are configured properly and the datasource contains data for the selected time range.', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.