Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add empty states to sqlab editor and select #19598

Merged
merged 31 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7dadc58
feat: add empty states to sqlab editor and select
pkdotson Apr 7, 2022
d9984ea
add suggestions and test
pkdotson Apr 11, 2022
aa5e8bc
update type
pkdotson Apr 11, 2022
5d04b36
Merge branch 'master' of https://github.com/preset-io/superset into f…
pkdotson Apr 11, 2022
cd4abf9
lint fix and add suggestions
pkdotson Apr 11, 2022
e417d79
fix typo
pkdotson Apr 11, 2022
d088f14
run lint
pkdotson Apr 11, 2022
68d5827
remove unused code
pkdotson Apr 11, 2022
bae0137
fix test
pkdotson Apr 12, 2022
bdcda07
remove redux for propagation and other suggestions
pkdotson Apr 13, 2022
efcdf4b
add t
pkdotson Apr 13, 2022
7f15b18
Merge branch 'master' of https://github.com/preset-io/superset into f…
pkdotson Apr 13, 2022
61ee6c6
lint
pkdotson Apr 13, 2022
7255d35
fix text and remove code
pkdotson Apr 13, 2022
19283db
ts and fix t in p
pkdotson Apr 13, 2022
dbed5fe
fix spelling
pkdotson Apr 13, 2022
f1eba19
remove unused prop
pkdotson Apr 13, 2022
7bca734
add fn to prop change state
pkdotson Apr 14, 2022
a586d38
remove unused code
pkdotson Apr 14, 2022
a5c5bf2
remove unused types
pkdotson Apr 14, 2022
c705ce6
update code and test
pkdotson Apr 15, 2022
94d3485
fix lint
pkdotson Apr 15, 2022
d222fea
fix ts
pkdotson Apr 15, 2022
66e9c46
update ts
pkdotson Apr 15, 2022
8bd7cf6
add type export and fix test
pkdotson Apr 15, 2022
9adc5ea
Update superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index…
pkdotson Apr 15, 2022
2a4995c
Update superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index…
pkdotson Apr 15, 2022
8217c2c
Update superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index…
pkdotson Apr 15, 2022
925e107
Update superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index…
pkdotson Apr 15, 2022
bf36826
remove handlerror and unused code
pkdotson Apr 15, 2022
b628c7c
Merge branch 'feat-blackstate-sql1' of https://github.com/preset-io/s…
pkdotson Apr 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const SET_USER_OFFLINE = 'SET_USER_OFFLINE';
export const RUN_QUERY = 'RUN_QUERY';
export const START_QUERY = 'START_QUERY';
export const STOP_QUERY = 'STOP_QUERY';
export const NO_DB_CONNECTED = 'NO_DB_CONNECTED';
export const REQUEST_QUERY_RESULTS = 'REQUEST_QUERY_RESULTS';
export const QUERY_SUCCESS = 'QUERY_SUCCESS';
export const QUERY_FAILED = 'QUERY_FAILED';
Expand Down Expand Up @@ -127,6 +128,10 @@ export function resetState() {
return { type: RESET_STATE };
}

export function setNoDatabaseConnected(bool) {
return {type: NO_DB_CONNECTED, isConnected: bool }
}

export function startQueryValidation(query) {
Object.assign(query, {
id: query.id ? query.id : shortid.generate(),
Expand Down
14 changes: 13 additions & 1 deletion superset-frontend/src/SqlLab/components/SqlEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { bindActionCreators } from 'redux';
import PropTypes from 'prop-types';
import Split from 'react-split';
import { t, styled, withTheme } from '@superset-ui/core';
import { isEmpty } from 'lodash';
import debounce from 'lodash/debounce';
import throttle from 'lodash/throttle';
import StyledModal from 'src/components/Modal';
Expand Down Expand Up @@ -75,6 +76,7 @@ import ShareSqlLabQuery from '../ShareSqlLabQuery';
import SqlEditorLeftBar from '../SqlEditorLeftBar';
import AceEditorWrapper from '../AceEditorWrapper';
import RunQueryActionButton from '../RunQueryActionButton';
import { EmptyStateBig } from 'src/components/EmptyState';

const LIMIT_DROPDOWN = [10, 100, 1000, 10000, 100000];
const SQL_EDITOR_PADDING = 10;
Expand Down Expand Up @@ -740,6 +742,7 @@ class SqlEditor extends React.PureComponent {
const leftBarStateClass = this.props.hideLeftBar
? 'schemaPane-exit-done'
: 'schemaPane-enter-done';
console.log('this.props', this.props.sqlLab.dbConnect)
return (
<div ref={this.sqlEditorRef} className="SqlEditor">
<CSSTransition
Expand All @@ -756,7 +759,16 @@ class SqlEditor extends React.PureComponent {
/>
</div>
</CSSTransition>
{this.queryPane()}
{this.props.sqlLab.dbConnect
?
this.queryPane()
:
<EmptyStateBig
image="vector.svg"
title="Select a database to write a query"
description="Choose one of the avaialable database on the left"
pkdotson marked this conversation as resolved.
Show resolved Hide resolved
/>
}
<StyledModal
visible={this.state.showCreateAsModal}
title={t(createViewModalTitle)}
Expand Down
3 changes: 3 additions & 0 deletions superset-frontend/src/SqlLab/reducers/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import {

export default function sqlLabReducer(state = {}, action) {
const actionHandlers = {
[actions.NO_DB_CONNECTED]() {
return {...state, dbConnect: action.isConnected}
},
[actions.ADD_QUERY_EDITOR]() {
const tabHistory = state.tabHistory.slice();
tabHistory.push(action.queryEditor.id);
Expand Down
21 changes: 21 additions & 0 deletions superset-frontend/src/assets/images/vector.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 20 additions & 2 deletions superset-frontend/src/components/DatabaseSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import Label from 'src/components/Label';
import { FormLabel } from 'src/components/Form';
import RefreshLabel from 'src/components/RefreshLabel';
import { useToasts } from 'src/components/MessageToasts/withToasts';
import { useDispatch, useSelector } from 'react-redux';
import { EmptyStateSmall } from '../EmptyState';
import { setNoDatabaseConnected } from 'src/SqlLab/actions/sqlLab';

const DatabaseSelectorWrapper = styled.div`
${({ theme }) => `
Expand Down Expand Up @@ -141,6 +144,8 @@ export default function DatabaseSelector({
}
: undefined,
);
const dispatch = useDispatch();
const dbConnect = useSelector<any, any>(state => state.sqlLab.dbConnect);
const [currentSchema, setCurrentSchema] = useState<SchemaValue | undefined>(
schema ? { label: schema, value: schema } : undefined,
);
Expand Down Expand Up @@ -240,6 +245,7 @@ export default function DatabaseSelector({
) {
setCurrentDb(database);
setCurrentSchema(undefined);
dispatch(setNoDatabaseConnected(true));
if (onDbChange) {
onDbChange(database);
}
Expand All @@ -263,11 +269,23 @@ export default function DatabaseSelector({
</div>
);
}
const p = new Promise(() => null);

function renderDatabaseSelect() {
return renderSelectRow(
<Select
ariaLabel={t('Select database or type database name')}
emptyState={
<EmptyStateSmall
image="empty.svg"
title="There are no database available"
description={
<p>
Manage your databse <a href="/databaseview/list">here</a>
</p>
}
/>
}
optionFilterProps={['database_name', 'value']}
data-test="select-database"
header={<FormLabel>{t('Database')}</FormLabel>}
Expand All @@ -283,17 +301,17 @@ export default function DatabaseSelector({
}

function renderSchemaSelect() {
const disabled = dbConnect;
const refreshIcon = !formMode && !readOnly && (
<RefreshLabel
onClick={() => setRefresh(refresh + 1)}
tooltipContent={t('Force refresh schema list')}
/>
);

return renderSelectRow(
<Select
ariaLabel={t('Select schema or type schema name')}
disabled={readOnly}
disabled={!disabled || readOnly}
header={<FormLabel>{t('Schema')}</FormLabel>}
labelInValue
lazyLoading={false}
Expand Down
9 changes: 8 additions & 1 deletion superset-frontend/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import AntdSelect, {
LabeledValue as AntdLabeledValue,
} from 'antd/lib/select';
import { DownOutlined, SearchOutlined } from '@ant-design/icons';
import { Spin } from 'antd';
import debounce from 'lodash/debounce';
import { isEqual } from 'lodash';
import { Spin } from 'antd';
import Icons from 'src/components/Icons';
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
import { SLOW_DEBOUNCE } from 'src/constants';
Expand Down Expand Up @@ -94,6 +94,10 @@ export interface SelectProps extends PickedSelectProps {
* Must be plain English and localized.
*/
ariaLabel: string;
/**
* Override for empty state.
*/
emptyState?: ReactElement;
/**
* It adds a header on top of the Select.
* Can be any ReactNode.
Expand Down Expand Up @@ -614,6 +618,9 @@ const Select = (
if (isLoading && fullSelectOptions.length === 0) {
return <StyledLoadingText>{t('Loading...')}</StyledLoadingText>;
}
if (!isLoading && fullSelectOptions.length === 0) {
return props.emptyState;
}
return error ? <Error error={error} /> : originNode;
};

Expand Down