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

refactor: Replace react-bootstrap tabs with Antd tabs #11118

Merged
merged 21 commits into from
Oct 31, 2020
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 @@ -47,8 +47,9 @@ describe('Dashboard edit mode', () => {
});

cy.get('[data-test="dashboard-builder-component-pane-tabs-navigation"]')
.children()
.last()
.within(() => {
cy.get('.ant-tabs-tab').last();
})
.click();

// find box plot is available from list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ describe('AdhocFilters', () => {
cy.get('input[type=text]').focus().type('name{enter}');
});

// antd tabs do lazy loading, so we need to click on tab with ace editor
cy.get('#filter-edit-popover').within(() => {
cy.get('.ant-tabs-tab').contains('Custom SQL').click();
cy.get('.ant-tabs-tab').contains('Simple').click();
});

cy.get('script').then(nodes => {
// should load new script chunks for SQL editor
expect(nodes.length).to.greaterThan(numScripts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ describe('AdhocMetrics', () => {
.should('have.text', 'num')
.click();

cy.get('[data-test=option-label]')
.should('have.text', 'SUM(num)')
.first()
.click();

// add custom SQL
cy.get('#adhoc-metric-edit-tabs-tab-SQL').click();
cy.get('[data-test=metrics-edit-popover]').within(() => {
Expand All @@ -103,9 +98,6 @@ describe('AdhocMetrics', () => {
cy.get('[data-test=metrics]')
.find('[data-test="metric-option"]')
.should('have.length', 2);
cy.get('[data-test=metrics]').within(() => {
cy.contains('[data-test="metric-option"]', 'SUM(sum_girls)').click();
});

cy.get('#metrics-edit-popover').within(() => {
cy.get('#adhoc-metric-edit-tabs-tab-SQL').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ describe('Datasource control', () => {
cy.get('[data-test="datasource-menu-trigger"]').click();
cy.get('[data-test="edit-dataset"]').click();
cy.get('.ant-modal-content').within(() => {
cy.get('a[role="tab"]').contains('Metrics').click();
cy.get('[data-test="collection-tab-Metrics"]')
.contains('Metrics')
.click();
});
cy.get(`input[value="${newMetricName}"]`)
.closest('tr')
Expand Down Expand Up @@ -140,7 +142,7 @@ describe('Time range filter', () => {
});

cy.get('#filter-popover').within(() => {
cy.get('div.tab-pane.active').within(() => {
cy.get('div.ant-tabs-tabpane-active').within(() => {
cy.get('div.PopoverSection :not(.dimmed)').within(() => {
cy.get('input[value="100 years ago"]');
cy.get('input[value="now"]');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
* under the License.
*/
import React from 'react';
import { Tabs } from 'react-bootstrap';
import { shallow } from 'enzyme';
import configureStore from 'redux-mock-store';
import fetchMock from 'fetch-mock';
import thunk from 'redux-thunk';

import Tabs from 'src/common/components/Tabs';
rusackas marked this conversation as resolved.
Show resolved Hide resolved
import DatasourceEditor from 'src/datasource/DatasourceEditor';
import Field from 'src/CRUD/Field';
import mockDatasource from '../../fixtures/mockDatasource';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import React from 'react';
import sinon from 'sinon';
import { shallow } from 'enzyme';
import { Tab, Tabs } from 'react-bootstrap';
import Button from 'src/components/Button';

import Tabs from 'src/common/components/Tabs';
import AdhocFilter, {
EXPRESSION_TYPES,
CLAUSES,
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('AdhocFilterEditPopover', () => {
it('renders simple tab content by default', () => {
const { wrapper } = setup();
expect(wrapper.find(Tabs)).toExist();
expect(wrapper.find(Tab)).toHaveLength(2);
expect(wrapper.find(Tabs.TabPane)).toHaveLength(2);
expect(wrapper.find(Button)).toHaveLength(2);
expect(wrapper.find(AdhocFilterEditPopoverSimpleTabContent)).toHaveLength(
1,
Expand All @@ -92,7 +92,7 @@ describe('AdhocFilterEditPopover', () => {
it('renders sql tab content when the adhoc filter expressionType is sql', () => {
const { wrapper } = setup({ adhocFilter: sqlAdhocFilter });
expect(wrapper.find(Tabs)).toExist();
expect(wrapper.find(Tab)).toHaveLength(2);
expect(wrapper.find(Tabs.TabPane)).toHaveLength(2);
expect(wrapper.find(Button)).toHaveLength(2);
expect(wrapper.find(AdhocFilterEditPopoverSqlTabContent)).toExist();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
*/
/* eslint-disable no-unused-expressions */
import React from 'react';
import { OverlayTrigger, Tab, Tabs, Radio } from 'react-bootstrap';
import { OverlayTrigger, Radio } from 'react-bootstrap';
import sinon from 'sinon';
import { styledMount as mount } from 'spec/helpers/theming';

import Popover from 'src/common/components/Popover';
import Tabs from 'src/common/components/Tabs';
import Label from 'src/components/Label';
import DateFilterControl from 'src/explore/components/controls/DateFilterControl';
import ControlHeader from 'src/explore/components/ControlHeader';
Expand Down Expand Up @@ -85,13 +86,13 @@ describe('DateFilterControl', () => {
const popoverContentWrapper = mount(popoverContent);

expect(popoverContentWrapper.find(Tabs)).toExist();
expect(popoverContentWrapper.find(Tab)).toHaveLength(2);
expect(popoverContentWrapper.find(Tabs.TabPane)).toHaveLength(2);
});

it('renders default time options', () => {
const popoverContent = wrapper.find(Popover).first().props().content;
const popoverContentWrapper = mount(popoverContent);
const defaultTab = popoverContentWrapper.find(Tab).first();
const defaultTab = popoverContentWrapper.find(Tabs.TabPane).first();

expect(defaultTab.find(Radio)).toExist();
expect(defaultTab.find(Radio)).toHaveLength(6);
Expand All @@ -100,7 +101,7 @@ describe('DateFilterControl', () => {
it('renders tooltips over timeframe options', () => {
const popoverContent = wrapper.find(Popover).first().props().content;
const popoverContentWrapper = mount(popoverContent);
const defaultTab = popoverContentWrapper.find(Tab).first();
const defaultTab = popoverContentWrapper.find(Tabs.TabPane).first();
const radioTrigger = defaultTab.find(OverlayTrigger);

expect(radioTrigger).toExist();
Expand All @@ -110,7 +111,7 @@ describe('DateFilterControl', () => {
it('renders the correct time range in tooltip', () => {
const popoverContent = wrapper.find(Popover).first().props().content;
const popoverContentWrapper = mount(popoverContent);
const defaultTab = popoverContentWrapper.find(Tab).first();
const defaultTab = popoverContentWrapper.find(Tabs.TabPane).first();
const triggers = defaultTab.find(OverlayTrigger);

const expectedLabels = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const notForwardedProps = ['fullWidth'];
const StyledTabs = styled(AntdTabs, {
shouldForwardProp: prop => !notForwardedProps.includes(prop),
})<TabsProps>`
.ant-tabs-content-holder {
overflow: auto;
}

.ant-tabs-tab {
flex: 1 1 auto;

Expand Down Expand Up @@ -120,5 +124,15 @@ EditableTabs.TabPane.defaultProps = {
),
};

const StyledCardTabs = styled(EditableTabs)``;

const CardTabs = Object.assign(StyledCardTabs, {
TabPane: StyledTabPane,
});

CardTabs.defaultProps = {
type: 'card',
};

export default Tabs;
export { EditableTabs };
export { CardTabs, EditableTabs };
20 changes: 20 additions & 0 deletions superset-frontend/src/common/components/Tabs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export * from './Tabs';
export { default } from './Tabs';
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/* eslint-env browser */
import PropTypes from 'prop-types';
import React from 'react';
import { Tabs, Tab } from 'react-bootstrap';
import Tabs from 'src/common/components/Tabs';
import { StickyContainer, Sticky } from 'react-sticky';
import { ParentSize } from '@vx/responsive';

Expand Down Expand Up @@ -48,23 +48,24 @@ class BuilderComponentPane extends React.PureComponent {
const { isSticky } = this.props;
return (
<Tabs
className="m-t-10 tabs-components"
id="tabs"
className="tabs-components"
style={{ marginTop: '10px' }}
data-test="dashboard-builder-component-pane-tabs-navigation"
>
<Tab eventKey={1} title={t('Components')}>
<Tabs.TabPane key={1} tab={t('Components')}>
<NewTabs />
<NewRow />
<NewColumn />
<NewHeader />
<NewMarkdown />
<NewDivider />
</Tab>
<Tab eventKey={2} title={t('Charts')} className="tab-charts">
</Tabs.TabPane>
<Tabs.TabPane key={2} tab={t('Charts')} className="tab-charts">
<SliceAdder
height={height + (isSticky ? SUPERSET_HEADER_HEIGHT : 0)}
/>
</Tab>
</Tabs.TabPane>
</Tabs>
);
}
Expand Down
Loading