From 2adfb8559736bff97b47c6fee2725b4344c4ebf3 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com> Date: Tue, 2 Feb 2021 03:15:07 -0300 Subject: [PATCH] Migrates Label component from Bootstrap to AntD. (#12774) --- .../integration/explore/control.test.ts | 2 +- .../explore/visualizations/table.test.ts | 2 +- .../javascripts/components/Timer_spec.tsx | 5 +- .../explore/components/RowCountLabel_spec.jsx | 2 +- .../javascripts/profile/Security_spec.tsx | 12 +- .../src/SqlLab/components/QueryStateLabel.jsx | 6 +- .../src/SqlLab/components/QueryTable.jsx | 2 +- .../src/SqlLab/components/SouthPane.jsx | 7 +- .../src/SqlLab/components/SqlEditor.jsx | 6 +- superset-frontend/src/SqlLab/constants.ts | 2 +- .../src/addSlice/AddSliceContainer.tsx | 2 +- .../src/common/components/index.tsx | 1 + .../src/components/CachedLabel.jsx | 4 +- .../src/components/DatabaseSelector.tsx | 11 +- .../src/components/Label/Label.stories.tsx | 63 +++-- .../src/components/Label/Label.test.tsx | 18 +- .../src/components/Label/index.tsx | 215 +++++++----------- superset-frontend/src/components/Timer.tsx | 9 +- .../src/explore/components/RowCountLabel.jsx | 4 +- .../components/controls/VizTypeControl.jsx | 12 +- .../src/views/CRUD/chart/ChartCard.tsx | 2 +- 21 files changed, 162 insertions(+), 225 deletions(-) diff --git a/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts b/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts index 70b01351e..c65b5dfb5 100644 --- a/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts @@ -104,7 +104,7 @@ describe('VizType control', () => { numScripts = nodes.length; }); - cy.get('.Control .label').contains('Table').click(); + cy.get('[data-test="visualization-type"]').contains('Table').click(); cy.get('[role="button"]').contains('Line Chart').click(); diff --git a/superset-frontend/cypress-base/cypress/integration/explore/visualizations/table.test.ts b/superset-frontend/cypress-base/cypress/integration/explore/visualizations/table.test.ts index 868d2fe27..0af7dce36 100644 --- a/superset-frontend/cypress-base/cypress/integration/explore/visualizations/table.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/explore/visualizations/table.test.ts @@ -161,7 +161,7 @@ describe('Visualization > Table', () => { cy.verifySliceContainer('table'); expect(response?.body.result[0].data.length).to.eq(limit); }); - cy.get('span.label-danger').contains('10 rows'); + cy.get('[data-test="row-count-label"]').contains('10 rows'); }); it('Test table with columns and row limit', () => { diff --git a/superset-frontend/spec/javascripts/components/Timer_spec.tsx b/superset-frontend/spec/javascripts/components/Timer_spec.tsx index 4af7ae708..f37004af8 100644 --- a/superset-frontend/spec/javascripts/components/Timer_spec.tsx +++ b/superset-frontend/spec/javascripts/components/Timer_spec.tsx @@ -21,7 +21,7 @@ */ import React from 'react'; import { render, sleep, waitFor } from 'spec/helpers/testing-library'; -import Timer from 'src/components/Timer'; +import Timer, { TimerProps } from 'src/components/Timer'; import { now } from 'src/modules/dates'; function parseTime(text?: string | null) { @@ -29,7 +29,7 @@ function parseTime(text?: string | null) { } describe('Timer', () => { - const mockProps = { + const mockProps: TimerProps = { startTime: now(), endTime: undefined, isRunning: true, @@ -41,7 +41,6 @@ describe('Timer', () => { const node = screen.getByRole('timer'); let text = node.textContent || ''; expect(node).toBeInTheDocument(); - expect(node).toHaveClass('label-warning'); expect(node).toHaveTextContent('00:00:00.00'); // should start running await waitFor(() => { diff --git a/superset-frontend/spec/javascripts/explore/components/RowCountLabel_spec.jsx b/superset-frontend/spec/javascripts/explore/components/RowCountLabel_spec.jsx index 7776788cb..13de226e7 100644 --- a/superset-frontend/spec/javascripts/explore/components/RowCountLabel_spec.jsx +++ b/superset-frontend/spec/javascripts/explore/components/RowCountLabel_spec.jsx @@ -45,6 +45,6 @@ describe('RowCountLabel', () => { limit: 100, }; const wrapper = shallow(); - expect(wrapper.find(Label).first().props().bsStyle).toBe('danger'); + expect(wrapper.find(Label).first().props().type).toBe('danger'); }); }); diff --git a/superset-frontend/spec/javascripts/profile/Security_spec.tsx b/superset-frontend/spec/javascripts/profile/Security_spec.tsx index 6732e7b2a..31eda0aae 100644 --- a/superset-frontend/spec/javascripts/profile/Security_spec.tsx +++ b/superset-frontend/spec/javascripts/profile/Security_spec.tsx @@ -19,7 +19,7 @@ import React from 'react'; import { styledMount as mount } from 'spec/helpers/theming'; import Security from 'src/profile/components/Security'; - +import Label from 'src/components/Label'; import { user, userNoPerms } from './fixtures'; describe('Security', () => { @@ -31,19 +31,19 @@ describe('Security', () => { }); it('renders 2 role labels', () => { const wrapper = mount(); - expect(wrapper.find('.roles').find('.label')).toHaveLength(2); + expect(wrapper.find('.roles').find(Label)).toHaveLength(2); }); it('renders 2 datasource labels', () => { const wrapper = mount(); - expect(wrapper.find('.datasources').find('.label')).toHaveLength(2); + expect(wrapper.find('.datasources').find(Label)).toHaveLength(2); }); it('renders 3 database labels', () => { const wrapper = mount(); - expect(wrapper.find('.databases').find('.label')).toHaveLength(3); + expect(wrapper.find('.databases').find(Label)).toHaveLength(3); }); it('renders no permission label when empty', () => { const wrapper = mount(); - expect(wrapper.find('.datasources').find('.label')).not.toExist(); - expect(wrapper.find('.databases').find('.label')).not.toExist(); + expect(wrapper.find('.datasources').find(Label)).not.toExist(); + expect(wrapper.find('.databases').find(Label)).not.toExist(); }); }); diff --git a/superset-frontend/src/SqlLab/components/QueryStateLabel.jsx b/superset-frontend/src/SqlLab/components/QueryStateLabel.jsx index 74b0d3f7a..5afb30bd3 100644 --- a/superset-frontend/src/SqlLab/components/QueryStateLabel.jsx +++ b/superset-frontend/src/SqlLab/components/QueryStateLabel.jsx @@ -20,16 +20,16 @@ import React from 'react'; import PropTypes from 'prop-types'; import Label from 'src/components/Label'; -import { STATE_BSSTYLE_MAP } from '../constants'; +import { STATE_TYPE_MAP } from '../constants'; const propTypes = { query: PropTypes.object.isRequired, }; export default function QueryStateLabel({ query }) { - const bsStyle = STATE_BSSTYLE_MAP[query.state]; + const type = STATE_TYPE_MAP[query.state]; return ( -