From 79ff96269b6d29d2bba92768be588d2f19ffe1a0 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com> Date: Sat, 8 May 2021 16:34:52 -0300 Subject: [PATCH] refactor: Bootstrap to AntD - Form - iteration 3 (#14502) --- .../AdhocMetricEditPopover_spec.jsx | 4 +- .../explore/components/BoundsControl_spec.jsx | 12 ++-- .../javascripts/sqllab/SaveQuery_spec.jsx | 6 +- .../src/SqlLab/components/SaveQuery.tsx | 41 ++++++------ .../SqlLab/components/ScheduleQueryButton.tsx | 61 ++++++++++-------- .../src/common/components/index.tsx | 12 ++-- .../src/components/Form/FormItem.tsx | 33 ++++++---- .../components/PropertiesModal/index.jsx | 4 +- .../components/DataTableControl/index.tsx | 6 +- .../components/controls/BoundsControl.jsx | 45 ++++++------- .../AdhocMetricEditPopover.test.tsx | 4 +- .../AdhocMetricEditPopover/index.jsx | 64 ++++++++----------- .../TimeSeriesColumnControl/index.jsx | 63 +++++++++--------- 13 files changed, 176 insertions(+), 179 deletions(-) diff --git a/superset-frontend/spec/javascripts/explore/components/AdhocMetricEditPopover_spec.jsx b/superset-frontend/spec/javascripts/explore/components/AdhocMetricEditPopover_spec.jsx index 2c7e276425..3e436dbe2d 100644 --- a/superset-frontend/spec/javascripts/explore/components/AdhocMetricEditPopover_spec.jsx +++ b/superset-frontend/spec/javascripts/explore/components/AdhocMetricEditPopover_spec.jsx @@ -20,7 +20,7 @@ import React from 'react'; import sinon from 'sinon'; import { shallow } from 'enzyme'; -import { FormGroup } from 'react-bootstrap'; +import { FormItem } from 'src/components/Form'; import Button from 'src/components/Button'; import { AGGREGATES } from 'src/explore/constants'; @@ -67,7 +67,7 @@ function setup(overrides) { describe('AdhocMetricEditPopover', () => { it('renders a popover with edit metric form contents', () => { const { wrapper } = setup(); - expect(wrapper.find(FormGroup)).toHaveLength(4); + expect(wrapper.find(FormItem)).toHaveLength(3); expect(wrapper.find(Button)).toHaveLength(2); }); diff --git a/superset-frontend/spec/javascripts/explore/components/BoundsControl_spec.jsx b/superset-frontend/spec/javascripts/explore/components/BoundsControl_spec.jsx index 37fac69b0a..279ec404a8 100644 --- a/superset-frontend/spec/javascripts/explore/components/BoundsControl_spec.jsx +++ b/superset-frontend/spec/javascripts/explore/components/BoundsControl_spec.jsx @@ -17,10 +17,10 @@ * under the License. */ import React from 'react'; -import { FormControl } from 'react-bootstrap'; import sinon from 'sinon'; import { styledMount as mount } from 'spec/helpers/theming'; import BoundsControl from 'src/explore/components/controls/BoundsControl'; +import { Input } from 'src/common/components'; const defaultProps = { name: 'y_axis_bounds', @@ -35,13 +35,13 @@ describe('BoundsControl', () => { wrapper = mount(); }); - it('renders two FormControls', () => { - expect(wrapper.find(FormControl)).toHaveLength(2); + it('renders two Input', () => { + expect(wrapper.find(Input)).toHaveLength(2); }); it('errors on non-numeric', () => { wrapper - .find(FormControl) + .find(Input) .first() .simulate('change', { target: { value: 's' } }); expect(defaultProps.onChange.calledWith([null, null])).toBe(true); @@ -51,11 +51,11 @@ describe('BoundsControl', () => { }); it('casts to numeric', () => { wrapper - .find(FormControl) + .find(Input) .first() .simulate('change', { target: { value: '1' } }); wrapper - .find(FormControl) + .find(Input) .last() .simulate('change', { target: { value: '5' } }); expect(defaultProps.onChange.calledWith([1, 5])).toBe(true); diff --git a/superset-frontend/spec/javascripts/sqllab/SaveQuery_spec.jsx b/superset-frontend/spec/javascripts/sqllab/SaveQuery_spec.jsx index 3a5673df3c..76f6ca8260 100644 --- a/superset-frontend/spec/javascripts/sqllab/SaveQuery_spec.jsx +++ b/superset-frontend/spec/javascripts/sqllab/SaveQuery_spec.jsx @@ -17,12 +17,12 @@ * under the License. */ import React from 'react'; -import { FormControl } from 'react-bootstrap'; import { shallow } from 'enzyme'; import * as sinon from 'sinon'; import SaveQuery from 'src/SqlLab/components/SaveQuery'; import Modal from 'src/components/Modal'; import Button from 'src/components/Button'; +import { FormItem } from 'src/components/Form'; describe('SavedQuery', () => { const mockedProps = { @@ -52,11 +52,11 @@ describe('SavedQuery', () => { expect(modal.find('[data-test="cancel-query"]')).toHaveLength(1); }); - it('has 2 FormControls', () => { + it('has 2 FormItem', () => { const wrapper = shallow(); const modal = wrapper.find(Modal); - expect(modal.find(FormControl)).toHaveLength(2); + expect(modal.find(FormItem)).toHaveLength(2); }); // eslint-disable-next-line jest/no-disabled-tests it.skip('has a save button if this is a new query', () => { diff --git a/superset-frontend/src/SqlLab/components/SaveQuery.tsx b/superset-frontend/src/SqlLab/components/SaveQuery.tsx index e4e52cf041..6b589b7586 100644 --- a/superset-frontend/src/SqlLab/components/SaveQuery.tsx +++ b/superset-frontend/src/SqlLab/components/SaveQuery.tsx @@ -17,12 +17,10 @@ * under the License. */ import React, { useState } from 'react'; -import { Row, Col } from 'src/common/components'; -import { FormControl, FormGroup } from 'react-bootstrap'; +import { Row, Col, Input, TextArea } from 'src/common/components'; import { t, supersetTheme, styled } from '@superset-ui/core'; - import Button from 'src/components/Button'; -import { FormLabel } from 'src/components/Form'; +import { Form, FormItem } from 'src/components/Form'; import Modal from 'src/components/Modal'; import Icon from 'src/components/Icon'; @@ -100,12 +98,12 @@ export default function SaveQuery({ close(); }; - const onLabelChange = (e: React.FormEvent) => { - setLabel((e.target as HTMLInputElement).value); + const onLabelChange = (e: React.ChangeEvent) => { + setLabel(e.target.value); }; - const onDescriptionChange = (e: React.FormEvent) => { - setDescription((e.target as HTMLInputElement).value); + const onDescriptionChange = (e: React.ChangeEvent) => { + setDescription(e.target.value); }; const toggleSave = () => { @@ -113,27 +111,24 @@ export default function SaveQuery({ }; const renderModalBody = () => ( - +
- - {t('Name')} - - + + +
- - {t('Description')} - - + +