chore: Improves the layout of the VizTypeGallery component (#15907)

* chore: Improves the layout of the VizTypeGallery component

* copy edit

* Enables search

Co-authored-by: Evan Rusackas <evan@preset.io>
This commit is contained in:
Michael S. Molina
2021-07-27 15:17:36 -03:00
committed by GitHub
parent 3f5237a3c1
commit 663dd3f853
3 changed files with 79 additions and 52 deletions

View File

@@ -18,7 +18,7 @@
*/
import React from 'react';
import Button from 'src/components/Button';
import Select from 'src/components/Select';
import { Select } from 'src/components';
import { css, styled, t } from '@superset-ui/core';
import VizTypeGallery, {
@@ -42,21 +42,45 @@ export type AddSliceContainerState = {
};
const ESTIMATED_NAV_HEIGHT = '56px';
const styleSelectContainer = { width: 600, marginBottom: '10px' };
const StyledContainer = styled.div`
flex: 1 1 auto;
display: flex;
flex-direction: column;
justify-content: space-between;
width: 100%;
max-width: ${MAX_ADVISABLE_VIZ_GALLERY_WIDTH}px;
max-height: calc(100vh - ${ESTIMATED_NAV_HEIGHT});
border-radius: ${({ theme }) => theme.gridUnit}px;
background-color: ${({ theme }) => theme.colors.grayscale.light5};
padding-bottom: ${({ theme }) => theme.gridUnit * 3}px;
h3 {
padding-bottom: ${({ theme }) => theme.gridUnit * 3}px;
}
${({ theme }) => `
flex: 1 1 auto;
display: flex;
flex-direction: column;
justify-content: space-between;
width: 100%;
max-width: ${MAX_ADVISABLE_VIZ_GALLERY_WIDTH}px;
max-height: calc(100vh - ${ESTIMATED_NAV_HEIGHT});
border-radius: ${theme.gridUnit}px;
background-color: ${theme.colors.grayscale.light5};
margin-left: auto;
margin-right: auto;
padding-left: ${theme.gridUnit * 4}px;
padding-right: ${theme.gridUnit * 4}px;
padding-bottom: ${theme.gridUnit * 4}px;
h3 {
padding-bottom: ${theme.gridUnit * 3}px;
}
& .dataset {
display: flex;
flex-direction: row;
align-items: center;
& > div {
min-width: 200px;
width: 300px;
}
& > span {
color: ${theme.colors.grayscale.light1};
margin-left: ${theme.gridUnit * 4}px;
margin-top: ${theme.gridUnit * 5}px;
}
}
`}
`;
const cssStatic = css`
@@ -64,9 +88,12 @@ const cssStatic = css`
`;
const StyledVizTypeGallery = styled(VizTypeGallery)`
border: 1px solid ${({ theme }) => theme.colors.grayscale.light2};
margin: ${({ theme }) => theme.gridUnit * 3}px 0px;
flex: 1 1 auto;
${({ theme }) => `
border: 1px solid ${theme.colors.grayscale.light2};
border-radius: ${theme.gridUnit}px;
margin: ${theme.gridUnit * 3}px 0px;
flex: 1 1 auto;
`}
`;
export default class AddSliceContainer extends React.PureComponent<
@@ -98,10 +125,10 @@ export default class AddSliceContainer extends React.PureComponent<
window.location.href = this.exploreUrl();
}
changeDatasource(option: { value: string }) {
changeDatasource(value: string) {
this.setState({
datasourceValue: option.value,
datasourceId: option.value.split('__')[0],
datasourceValue: value,
datasourceId: value.split('__')[0],
});
}
@@ -115,31 +142,22 @@ export default class AddSliceContainer extends React.PureComponent<
render() {
return (
<StyledContainer className="container">
<StyledContainer>
<h3 css={cssStatic}>{t('Create a new chart')}</h3>
<div css={cssStatic}>
<p>{t('Choose a dataset')}</p>
<div style={styleSelectContainer}>
<Select
clearable={false}
ignoreAccents={false}
name="select-datasource"
onChange={this.changeDatasource}
options={this.props.datasources}
placeholder={t('Choose a dataset')}
value={
this.state.datasourceValue
? {
value: this.state.datasourceValue,
}
: undefined
}
width={600}
/>
</div>
<span className="text-muted">
<div className="dataset">
<Select
ariaLabel={t('Dataset')}
name="select-datasource"
header={t('Choose a dataset')}
onChange={this.changeDatasource}
options={this.props.datasources}
placeholder={t('Choose a dataset')}
showSearch
value={this.state.datasourceValue}
/>
<span>
{t(
'If the dataset you are looking for is not available in the list, follow the instructions on how to add it in the Superset tutorial.',
"If you can't find a dataset, follow the instructions on how to add it in the Superset tutorial.",
)}{' '}
<a
href="https://superset.apache.org/docs/creating-charts-dashboards/first-dashboard#adding-a-new-table"