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

fix(sql Lab tabs): Empty SQL Lab tabs #18817

Merged
merged 7 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('TabbedSqlEditors', () => {
defaultQueryLimit: 1000,
maxRow: 100000,
};

const getWrapper = () =>
shallow(<TabbedSqlEditors store={store} {...mockedProps} />)
.dive()
Expand Down Expand Up @@ -227,4 +228,10 @@ describe('TabbedSqlEditors', () => {
wrapper.setProps({ offline: true });
expect(wrapper.find(EditableTabs).props().hideAdd).toBe(true);
});
it('should have an empty state when query editors is empty', () => {
wrapper = getWrapper();
wrapper.setProps({ queryEditors: [] });
const firstTab = wrapper.find(EditableTabs.TabPane).first();
expect(firstTab.props()['data-key']).toBe(0);
});
});
40 changes: 40 additions & 0 deletions superset-frontend/src/SqlLab/components/TabbedSqlEditors/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { areArraysShallowEqual } from 'src/reduxUtils';
import { Tooltip } from 'src/components/Tooltip';
import { detectOS } from 'src/utils/common';
import * as Actions from 'src/SqlLab/actions/sqlLab';
import { EmptyStateBig } from 'src/components/EmptyState';
import SqlEditor from '../SqlEditor';
import TabStatusIcon from '../TabStatusIcon';

Expand Down Expand Up @@ -64,6 +65,10 @@ const TabTitleWrapper = styled.div`
align-items: center;
`;

const StyledTab = styled.span`
line-height: 24px;
`;

const TabTitle = styled.span`
margin-right: ${({ theme }) => theme.gridUnit * 2}px;
text-transform: none;
Expand Down Expand Up @@ -314,6 +319,7 @@ class TabbedSqlEditors extends React.PureComponent {
}

render() {
const noQueryEditors = this.props.queryEditors?.length === 0;
const editors = this.props.queryEditors.map(qe => {
let latestQuery;
if (qe.latestQueryId) {
Expand Down Expand Up @@ -401,6 +407,37 @@ class TabbedSqlEditors extends React.PureComponent {
);
});

const emptyTab = (
<StyledTab>
<TabTitle>{t('Add a new tab')}</TabTitle>
<Tooltip
id="add-tab"
placement="bottom"
title={
userOS === 'Windows'
? t('New tab (Ctrl + q)')
: t('New tab (Ctrl + t)')
}
>
<i data-test="add-tab-icon" className="fa fa-plus-circle" />
</Tooltip>
</StyledTab>
);

const emptyTabState = (
<EditableTabs.TabPane
key={0}
data-key={0}
tab={emptyTab}
closable={false}
>
<EmptyStateBig
image="empty_sql_chart.svg"
description={t('Add a new tab to create SQL Query')}
/>
</EditableTabs.TabPane>
);

return (
<EditableTabs
activeKey={this.props.tabHistory[this.props.tabHistory.length - 1]}
Expand All @@ -410,7 +447,9 @@ class TabbedSqlEditors extends React.PureComponent {
onChange={this.handleSelect}
fullWidth={false}
hideAdd={this.props.offline}
onTabClick={() => noQueryEditors && this.newQueryEditor()}
onEdit={this.handleEdit}
type={noQueryEditors ? 'card' : 'editable-card'}
addIcon={
<Tooltip
id="add-tab"
Expand All @@ -426,6 +465,7 @@ class TabbedSqlEditors extends React.PureComponent {
}
>
{editors}
{noQueryEditors && emptyTabState}
</EditableTabs>
);
}
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/SqlLab/reducers/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export default function sqlLabReducer(state = {}, action) {
[actions.SET_ACTIVE_QUERY_EDITOR]() {
const qeIds = state.queryEditors.map(qe => qe.id);
if (
qeIds.indexOf(action.queryEditor.id) > -1 &&
qeIds.indexOf(action.queryEditor?.id) > -1 &&
state.tabHistory[state.tabHistory.length - 1] !== action.queryEditor.id
) {
const tabHistory = state.tabHistory.slice();
Expand Down
22 changes: 22 additions & 0 deletions superset-frontend/src/assets/images/empty_sql_chart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.