From b6d78bf4f263c428b3c0364682d081692815a19d Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com> Date: Wed, 22 Sep 2021 07:44:18 -0300 Subject: [PATCH] refactor: Changes the list views to use the new Select component (#16393) * chore: Change the list views to use the new Select component * Fix Cypress tests * Enables search for all controls * Adjusts controls width * Removes 'Me' and keeps the logged user on top * Fixes tests * Uses the borderless version for the filters * Fixes the tests * Reverts the Select theme to the default * Rebases and fixes js error * Fixes failing test * Removes unused withTheme --- .../integration/chart_list/filter.test.ts | 88 +++---- .../integration/dashboard_list/filter.test.ts | 68 ++--- .../src/components/DatePicker/index.tsx | 8 +- .../components/ListView/CardSortSelect.tsx | 100 +++---- .../src/components/ListView/Filters/Base.ts | 8 +- .../components/ListView/Filters/DateRange.tsx | 21 +- .../components/ListView/Filters/Search.tsx | 41 ++- .../components/ListView/Filters/Select.tsx | 150 ++++------- .../src/components/ListView/Filters/index.tsx | 29 +- .../src/components/ListView/ListView.test.jsx | 24 +- .../src/components/ListView/ListView.tsx | 21 +- .../src/components/ListView/types.ts | 18 +- .../src/components/ListView/utils.ts | 2 + .../SearchInput/SearchInput.stories.tsx | 62 ----- .../SearchInput/SearchInput.test.jsx | 93 ------- .../src/components/SearchInput/index.tsx | 108 -------- .../src/views/CRUD/alert/AlertList.tsx | 4 +- .../annotationlayers/AnnotationLayersList.tsx | 4 +- .../src/views/CRUD/chart/ChartList.tsx | 249 +++++++++--------- .../CRUD/csstemplates/CssTemplatesList.tsx | 4 +- .../views/CRUD/dashboard/DashboardList.tsx | 150 ++++++----- .../CRUD/data/database/DatabaseList.test.jsx | 4 +- .../CRUD/data/dataset/DatasetList.test.jsx | 10 +- .../views/CRUD/data/dataset/DatasetList.tsx | 4 +- .../src/views/CRUD/data/query/QueryList.tsx | 2 +- .../data/savedquery/SavedQueryList.test.jsx | 2 +- superset-frontend/src/views/CRUD/hooks.ts | 5 +- superset-frontend/src/views/CRUD/utils.tsx | 66 +++-- 28 files changed, 510 insertions(+), 835 deletions(-) delete mode 100644 superset-frontend/src/components/SearchInput/SearchInput.stories.tsx delete mode 100644 superset-frontend/src/components/SearchInput/SearchInput.test.jsx delete mode 100644 superset-frontend/src/components/SearchInput/index.tsx diff --git a/superset-frontend/cypress-base/cypress/integration/chart_list/filter.test.ts b/superset-frontend/cypress-base/cypress/integration/chart_list/filter.test.ts index 6892651e00..4466cc2ad5 100644 --- a/superset-frontend/cypress-base/cypress/integration/chart_list/filter.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/chart_list/filter.test.ts @@ -27,44 +27,34 @@ describe('chart card view filters', () => { it('should filter by owners correctly', () => { // filter by owners - cy.get('.Select__control').first().click(); - cy.get('.Select__menu').contains('alpha user').click(); + cy.get('[data-test="filters-select"]').first().click(); + cy.get('.rc-virtual-list').contains('alpha user').click(); cy.get('[data-test="styled-card"]').should('not.exist'); - cy.get('.Select__control').first().click(); - cy.get('.Select__menu').contains('gamma user').click(); + cy.get('[data-test="filters-select"]').first().click(); + cy.get('.rc-virtual-list').contains('gamma user').click(); cy.get('[data-test="styled-card"]').should('not.exist'); }); - it('should filter by me correctly', () => { - // filter by me - cy.get('.Select__control').first().click(); - cy.get('.Select__menu').contains('me').click(); - cy.get('[data-test="styled-card"]').its('length').should('be.gt', 0); - cy.get('.Select__control').eq(1).click(); - cy.get('.Select__menu').contains('me').click(); - cy.get('[data-test="styled-card"]').its('length').should('be.gt', 0); - }); - it('should filter by created by correctly', () => { // filter by created by - cy.get('.Select__control').eq(1).click(); - cy.get('.Select__menu').contains('alpha user').click(); + cy.get('[data-test="filters-select"]').eq(1).click(); + cy.get('.rc-virtual-list').contains('alpha user').click(); cy.get('.ant-card').should('not.exist'); - cy.get('.Select__control').eq(1).click(); - cy.get('.Select__menu').contains('gamma user').click(); + cy.get('[data-test="filters-select"]').eq(1).click(); + cy.get('.rc-virtual-list').contains('gamma user').click(); cy.get('[data-test="styled-card"]').should('not.exist'); }); xit('should filter by viz type correctly', () => { // filter by viz type - cy.get('.Select__control').eq(2).click(); - cy.get('.Select__menu').contains('area').click({ timeout: 5000 }); + cy.get('[data-test="filters-select"]').eq(2).click(); + cy.get('.rc-virtual-list').contains('area').click({ timeout: 5000 }); cy.get('[data-test="styled-card"]').its('length').should('be.gt', 0); cy.get('[data-test="styled-card"]') .contains("World's Pop Growth") .should('be.visible'); - cy.get('.Select__control').eq(2).click(); - cy.get('.Select__control').eq(2).type('world_map{enter}'); + cy.get('[data-test="filters-select"]').eq(2).click(); + cy.get('[data-test="filters-select"]').eq(2).type('world_map{enter}'); cy.get('[data-test="styled-card"]').should('have.length', 1); cy.get('[data-test="styled-card"]') .contains('% Rural') @@ -73,14 +63,16 @@ describe('chart card view filters', () => { it('should filter by datasource correctly', () => { // filter by datasource - cy.get('.Select__control').eq(3).click(); - cy.get('.Select__menu').contains('unicode_test').click(); + cy.get('[data-test="filters-select"]').eq(3).click(); + cy.get('.rc-virtual-list').contains('unicode_test').click(); cy.get('[data-test="styled-card"]').should('have.length', 1); cy.get('[data-test="styled-card"]') .contains('Unicode Cloud') .should('be.visible'); - cy.get('.Select__control').eq(2).click(); - cy.get('.Select__control').eq(2).type('energy_usage{enter}{enter}'); + cy.get('[data-test="filters-select"]').eq(2).click(); + cy.get('[data-test="filters-select"]') + .eq(2) + .type('energy_usage{enter}{enter}'); cy.get('[data-test="styled-card"]').its('length').should('be.gt', 0); }); }); @@ -94,57 +86,49 @@ describe('chart list view filters', () => { it('should filter by owners correctly', () => { // filter by owners - cy.get('.Select__control').first().click(); - cy.get('.Select__menu').contains('alpha user').click(); + cy.get('[data-test="filters-select"]').first().click(); + cy.get('.rc-virtual-list').contains('alpha user').click(); cy.get('[data-test="table-row"]').should('not.exist'); - cy.get('.Select__control').first().click(); - cy.get('.Select__menu').contains('gamma user').click(); + cy.get('[data-test="filters-select"]').first().click(); + cy.get('.rc-virtual-list').contains('gamma user').click(); cy.get('[data-test="table-row"]').should('not.exist'); }); - it('should filter by me correctly', () => { - // filter by me - cy.get('.Select__control').first().click(); - cy.get('.Select__menu').contains('me').click(); - cy.get('[data-test="table-row"]').its('length').should('be.gt', 0); - cy.get('.Select__control').eq(1).click(); - cy.get('.Select__menu').contains('me').click(); - cy.get('[data-test="table-row"]').its('length').should('be.gt', 0); - }); - it('should filter by created by correctly', () => { // filter by created by - cy.get('.Select__control').eq(1).click(); - cy.get('.Select__menu').contains('alpha user').click(); + cy.get('[data-test="filters-select"]').eq(1).click(); + cy.get('.rc-virtual-list').contains('alpha user').click(); cy.get('[data-test="table-row"]').should('not.exist'); - cy.get('.Select__control').eq(1).click(); - cy.get('.Select__menu').contains('gamma user').click(); + cy.get('[data-test="filters-select"]').eq(1).click(); + cy.get('.rc-virtual-list').contains('gamma user').click(); cy.get('[data-test="table-row"]').should('not.exist'); }); // this is flaky, but seems to fail along with the card view test of the same name xit('should filter by viz type correctly', () => { // filter by viz type - cy.get('.Select__control').eq(2).click(); - cy.get('.Select__menu').contains('area').click({ timeout: 5000 }); + cy.get('[data-test="filters-select"]').eq(2).click(); + cy.get('.rc-virtual-list').contains('area').click({ timeout: 5000 }); cy.get('[data-test="table-row"]').its('length').should('be.gt', 0); cy.get('[data-test="table-row"]') .contains("World's Pop Growth") .should('exist'); - cy.get('.Select__control').eq(2).click(); - cy.get('.Select__control').eq(2).type('world_map{enter}'); + cy.get('[data-test="filters-select"]').eq(2).click(); + cy.get('[data-test="filters-select"]').eq(2).type('world_map{enter}'); cy.get('[data-test="table-row"]').should('have.length', 1); cy.get('[data-test="table-row"]').contains('% Rural').should('exist'); }); it('should filter by datasource correctly', () => { // filter by datasource - cy.get('.Select__control').eq(3).click(); - cy.get('.Select__menu').contains('unicode_test').click(); + cy.get('[data-test="filters-select"]').eq(3).click(); + cy.get('.rc-virtual-list').contains('unicode_test').click(); cy.get('[data-test="table-row"]').should('have.length', 1); cy.get('[data-test="table-row"]').contains('Unicode Cloud').should('exist'); - cy.get('.Select__control').eq(3).click(); - cy.get('.Select__control').eq(3).type('energy_usage{enter}{enter}'); + cy.get('[data-test="filters-select"]').eq(3).click(); + cy.get('[data-test="filters-select"]') + .eq(3) + .type('energy_usage{enter}{enter}'); cy.get('[data-test="table-row"]').its('length').should('be.gt', 0); }); }); diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard_list/filter.test.ts b/superset-frontend/cypress-base/cypress/integration/dashboard_list/filter.test.ts index aede8e7d54..bf852fc625 100644 --- a/superset-frontend/cypress-base/cypress/integration/dashboard_list/filter.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/dashboard_list/filter.test.ts @@ -27,44 +27,34 @@ describe('dashboard filters card view', () => { it('should filter by owners correctly', () => { // filter by owners - cy.get('.Select__control').first().click(); - cy.get('.Select__menu').contains('alpha user').click(); + cy.get('[data-test="filters-select"]').first().click(); + cy.get('.rc-virtual-list').contains('alpha user').click(); cy.get('[data-test="styled-card"]').should('not.exist'); - cy.get('.Select__control').first().click(); - cy.get('.Select__menu').contains('gamma user').click(); + cy.get('[data-test="filters-select"]').first().click(); + cy.get('.rc-virtual-list').contains('gamma user').click(); cy.get('[data-test="styled-card"]').should('not.exist'); }); - it('should filter by me correctly', () => { - // filter by me - cy.get('.Select__control').first().click(); - cy.get('.Select__menu').contains('me').click(); - cy.get('[data-test="styled-card"]').its('length').should('be.gt', 0); - cy.get('.Select__control').eq(1).click(); - cy.get('.Select__menu').contains('me').click(); - cy.get('[data-test="styled-card"]').its('length').should('be.gt', 0); - }); - it('should filter by created by correctly', () => { // filter by created by - cy.get('.Select__control').eq(1).click(); - cy.get('.Select__menu').contains('alpha user').click(); + cy.get('[data-test="filters-select"]').eq(1).click(); + cy.get('.rc-virtual-list').contains('alpha user').click(); cy.get('.ant-card').should('not.exist'); - cy.get('.Select__control').eq(1).click(); - cy.get('.Select__menu').contains('gamma user').click(); + cy.get('[data-test="filters-select"]').eq(1).click(); + cy.get('.rc-virtual-list').contains('gamma user').click(); cy.get('.ant-card').should('not.exist'); }); it('should filter by published correctly', () => { // filter by published - cy.get('.Select__control').eq(2).click(); - cy.get('.Select__menu').contains('Published').click({ timeout: 5000 }); + cy.get('[data-test="filters-select"]').eq(2).click(); + cy.get('.rc-virtual-list').contains('Published').click({ timeout: 5000 }); cy.get('[data-test="styled-card"]').should('have.length', 3); cy.get('[data-test="styled-card"]') .contains('USA Births Names') .should('be.visible'); - cy.get('.Select__control').eq(1).click(); - cy.get('.Select__control').eq(1).type('unpub{enter}'); + cy.get('[data-test="filters-select"]').eq(1).click(); + cy.get('[data-test="filters-select"]').eq(1).type('unpub{enter}'); cy.get('[data-test="styled-card"]').should('have.length', 3); }); }); @@ -78,44 +68,34 @@ describe('dashboard filters list view', () => { it('should filter by owners correctly', () => { // filter by owners - cy.get('.Select__control').first().click(); - cy.get('.Select__menu').contains('alpha user').click(); + cy.get('[data-test="filters-select"]').first().click(); + cy.get('.rc-virtual-list').contains('alpha user').click(); cy.get('[data-test="table-row"]').should('not.exist'); - cy.get('.Select__control').first().click(); - cy.get('.Select__menu').contains('gamma user').click(); + cy.get('[data-test="filters-select"]').first().click(); + cy.get('.rc-virtual-list').contains('gamma user').click(); cy.get('[data-test="table-row"]').should('not.exist'); }); - it('should filter by me correctly', () => { - // filter by me - cy.get('.Select__control').first().click(); - cy.get('.Select__menu').contains('me').click(); - cy.get('[data-test="table-row"]').its('length').should('be.gt', 0); - cy.get('.Select__control').eq(1).click(); - cy.get('.Select__menu').contains('me').click(); - cy.get('[data-test="table-row"]').its('length').should('be.gt', 0); - }); - it('should filter by created by correctly', () => { // filter by created by - cy.get('.Select__control').eq(1).click(); - cy.get('.Select__menu').contains('alpha user').click(); + cy.get('[data-test="filters-select"]').eq(1).click(); + cy.get('.rc-virtual-list').contains('alpha user').click(); cy.get('[data-test="table-row"]').should('not.exist'); - cy.get('.Select__control').eq(1).click(); - cy.get('.Select__menu').contains('gamma user').click(); + cy.get('[data-test="filters-select"]').eq(1).click(); + cy.get('.rc-virtual-list').contains('gamma user').click(); cy.get('[data-test="table-row"]').should('not.exist'); }); it('should filter by published correctly', () => { // filter by published - cy.get('.Select__control').eq(2).click(); - cy.get('.Select__menu').contains('Published').click(); + cy.get('[data-test="filters-select"]').eq(2).click(); + cy.get('.rc-virtual-list').contains('Published').click(); cy.get('[data-test="table-row"]').should('have.length', 3); cy.get('[data-test="table-row"]') .contains('USA Births Names') .should('be.visible'); - cy.get('.Select__control').eq(2).click(); - cy.get('.Select__control').eq(2).type('unpub{enter}'); + cy.get('[data-test="filters-select"]').eq(2).click(); + cy.get('[data-test="filters-select"]').eq(2).type('unpub{enter}'); cy.get('[data-test="table-row"]').should('have.length', 3); }); }); diff --git a/superset-frontend/src/components/DatePicker/index.tsx b/superset-frontend/src/components/DatePicker/index.tsx index d7c254206d..56c0458c4e 100644 --- a/superset-frontend/src/components/DatePicker/index.tsx +++ b/superset-frontend/src/components/DatePicker/index.tsx @@ -17,6 +17,12 @@ * under the License. */ import { DatePicker as AntdDatePicker } from 'antd'; +import { styled } from '@superset-ui/core'; + +const AntdRangePicker = AntdDatePicker.RangePicker; + +export const RangePicker = styled(AntdRangePicker)` + border-radius: ${({ theme }) => theme.gridUnit}px; +`; -export const { RangePicker } = AntdDatePicker; export const DatePicker = AntdDatePicker; diff --git a/superset-frontend/src/components/ListView/CardSortSelect.tsx b/superset-frontend/src/components/ListView/CardSortSelect.tsx index 8b377c75ca..479355881f 100644 --- a/superset-frontend/src/components/ListView/CardSortSelect.tsx +++ b/superset-frontend/src/components/ListView/CardSortSelect.tsx @@ -16,24 +16,21 @@ * specific language governing permissions and limitations * under the License. */ -import React, { useState } from 'react'; -import { styled, withTheme, SupersetThemeProps, t } from '@superset-ui/core'; -import { PartialThemeConfig, Select } from 'src/components/Select'; +import React, { useState, useMemo } from 'react'; +import { styled, t } from '@superset-ui/core'; +import { Select } from 'src/components'; +import { FormLabel } from 'src/components/Form'; +import { SELECT_WIDTH } from './utils'; import { CardSortSelectOption, FetchDataConfig, SortColumn } from './types'; -import { filterSelectStyles } from './utils'; - -const SortTitle = styled.label` - font-weight: bold; - line-height: 27px; - margin: 0 0.4em 0 0; -`; const SortContainer = styled.div` display: inline-flex; font-size: ${({ theme }) => theme.typography.sizes.s}px; - padding-top: ${({ theme }) => theme.gridUnit}px; + align-items: center; text-align: left; + width: ${SELECT_WIDTH}px; `; + interface CardViewSelectSortProps { onChange: (conf: FetchDataConfig) => any; options: Array; @@ -42,43 +39,6 @@ interface CardViewSelectSortProps { pageSize: number; } -interface StyledSelectProps { - onChange: (value: CardSortSelectOption) => void; - options: CardSortSelectOption[]; - selectStyles: any; - theme: SupersetThemeProps['theme']; - value: CardSortSelectOption; -} - -function StyledSelect({ - onChange, - options, - selectStyles, - theme, - value, -}: StyledSelectProps) { - const filterSelectTheme: PartialThemeConfig = { - spacing: { - baseUnit: 1, - fontSize: theme.typography.sizes.s, - minWidth: '5em', - }, - }; - return ( - - )} +