refactor(Switch): Upgrade Switch to Ant Design 5 (#30731)
This commit is contained in:
parent
9bb69ab311
commit
bc5da631c8
|
|
@ -56,7 +56,8 @@ import Mousetrap from 'mousetrap';
|
||||||
import Button from 'src/components/Button';
|
import Button from 'src/components/Button';
|
||||||
import Timer from 'src/components/Timer';
|
import Timer from 'src/components/Timer';
|
||||||
import ResizableSidebar from 'src/components/ResizableSidebar';
|
import ResizableSidebar from 'src/components/ResizableSidebar';
|
||||||
import { AntdDropdown, AntdSwitch, Skeleton } from 'src/components';
|
import { AntdDropdown, Skeleton } from 'src/components';
|
||||||
|
import { Switch } from 'src/components/Switch';
|
||||||
import { Input } from 'src/components/Input';
|
import { Input } from 'src/components/Input';
|
||||||
import { Menu } from 'src/components/Menu';
|
import { Menu } from 'src/components/Menu';
|
||||||
import Icons from 'src/components/Icons';
|
import Icons from 'src/components/Icons';
|
||||||
|
|
@ -698,7 +699,7 @@ const SqlEditor: FC<Props> = ({
|
||||||
<Menu.Item css={{ display: 'flex', justifyContent: 'space-between' }}>
|
<Menu.Item css={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||||
{' '}
|
{' '}
|
||||||
<span>{t('Render HTML')}</span>{' '}
|
<span>{t('Render HTML')}</span>{' '}
|
||||||
<AntdSwitch
|
<Switch
|
||||||
checked={renderHTMLEnabled}
|
checked={renderHTMLEnabled}
|
||||||
onChange={handleToggleRenderHTMLEnabled}
|
onChange={handleToggleRenderHTMLEnabled}
|
||||||
/>{' '}
|
/>{' '}
|
||||||
|
|
@ -706,7 +707,7 @@ const SqlEditor: FC<Props> = ({
|
||||||
<Menu.Item css={{ display: 'flex', justifyContent: 'space-between' }}>
|
<Menu.Item css={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||||
{' '}
|
{' '}
|
||||||
<span>{t('Autocomplete')}</span>{' '}
|
<span>{t('Autocomplete')}</span>{' '}
|
||||||
<AntdSwitch
|
<Switch
|
||||||
checked={autocompleteEnabled}
|
checked={autocompleteEnabled}
|
||||||
onChange={handleToggleAutocompleteEnabled}
|
onChange={handleToggleAutocompleteEnabled}
|
||||||
/>{' '}
|
/>{' '}
|
||||||
|
|
|
||||||
|
|
@ -33,12 +33,15 @@ export const InteractiveSwitch = ({ checked, ...rest }: SwitchProps) => {
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
const defaultCheckedValue = true;
|
||||||
|
|
||||||
InteractiveSwitch.args = {
|
InteractiveSwitch.args = {
|
||||||
checked: false,
|
checked: defaultCheckedValue,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
title: 'Switch',
|
title: 'Switch',
|
||||||
|
defaultChecked: defaultCheckedValue,
|
||||||
|
autoFocus: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
InteractiveSwitch.argTypes = {
|
InteractiveSwitch.argTypes = {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { render, screen } from 'spec/helpers/testing-library';
|
||||||
|
import { Switch } from '.';
|
||||||
|
|
||||||
|
const mockedProps = {
|
||||||
|
label: 'testLabel',
|
||||||
|
dataTest: 'dataTest',
|
||||||
|
checked: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
test('should render', () => {
|
||||||
|
const { container } = render(<Switch {...mockedProps} />);
|
||||||
|
expect(container).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should have the correct checked prop', () => {
|
||||||
|
render(<Switch {...mockedProps} />);
|
||||||
|
|
||||||
|
const switchElement = screen.getByRole('switch');
|
||||||
|
|
||||||
|
expect(switchElement).toBeInTheDocument();
|
||||||
|
expect(switchElement).not.toBeChecked();
|
||||||
|
});
|
||||||
|
|
@ -16,14 +16,8 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import { styled } from '@superset-ui/core';
|
import { SwitchProps } from 'antd-v5/lib/switch';
|
||||||
import BaseSwitch, { SwitchProps } from 'antd/lib/switch';
|
import { Switch as AntdSwitch } from 'antd-v5';
|
||||||
|
|
||||||
const StyledSwitch = styled(BaseSwitch)`
|
export const Switch = (props: SwitchProps) => <AntdSwitch {...props} />;
|
||||||
.ant-switch-checked {
|
|
||||||
background-color: ${({ theme }) => theme.colors.primary.base};
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const Switch = (props: SwitchProps) => <StyledSwitch {...props} />;
|
|
||||||
export type { SwitchProps };
|
export type { SwitchProps };
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,6 @@ export {
|
||||||
Modal as AntdModal,
|
Modal as AntdModal,
|
||||||
Select as AntdSelect,
|
Select as AntdSelect,
|
||||||
Slider as AntdSlider,
|
Slider as AntdSlider,
|
||||||
Switch as AntdSwitch,
|
|
||||||
Tabs as AntdTabs,
|
Tabs as AntdTabs,
|
||||||
Tooltip as AntdTooltip,
|
Tooltip as AntdTooltip,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import { SupersetTheme, t } from '@superset-ui/core';
|
import { SupersetTheme, t } from '@superset-ui/core';
|
||||||
import { AntdSwitch } from 'src/components';
|
import { Switch } from 'src/components/Switch';
|
||||||
import InfoTooltip from 'src/components/InfoTooltip';
|
import InfoTooltip from 'src/components/InfoTooltip';
|
||||||
import ValidatedInput from 'src/components/Form/LabeledErrorBoundInput';
|
import ValidatedInput from 'src/components/Form/LabeledErrorBoundInput';
|
||||||
import { FieldPropTypes } from '../../types';
|
import { FieldPropTypes } from '../../types';
|
||||||
|
|
@ -296,7 +296,7 @@ export const forceSSLField = ({
|
||||||
sslForced,
|
sslForced,
|
||||||
}: FieldPropTypes) => (
|
}: FieldPropTypes) => (
|
||||||
<div css={(theme: SupersetTheme) => infoTooltip(theme)}>
|
<div css={(theme: SupersetTheme) => infoTooltip(theme)}>
|
||||||
<AntdSwitch
|
<Switch
|
||||||
disabled={sslForced && !isEditMode}
|
disabled={sslForced && !isEditMode}
|
||||||
checked={db?.parameters?.encryption || sslForced}
|
checked={db?.parameters?.encryption || sslForced}
|
||||||
onChange={changed => {
|
onChange={changed => {
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ jest.mock('@superset-ui/core', () => ({
|
||||||
isFeatureEnabled: jest.fn().mockReturnValue(true),
|
isFeatureEnabled: jest.fn().mockReturnValue(true),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('src/components', () => ({
|
jest.mock('src/components/Switch', () => ({
|
||||||
AntdSwitch: ({
|
Switch: ({
|
||||||
checked,
|
checked,
|
||||||
onChange,
|
onChange,
|
||||||
}: {
|
}: {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import {
|
||||||
isFeatureEnabled,
|
isFeatureEnabled,
|
||||||
FeatureFlag,
|
FeatureFlag,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { AntdSwitch } from 'src/components';
|
import { Switch } from 'src/components/Switch';
|
||||||
import InfoTooltip from 'src/components/InfoTooltip';
|
import InfoTooltip from 'src/components/InfoTooltip';
|
||||||
import { isEmpty } from 'lodash';
|
import { isEmpty } from 'lodash';
|
||||||
import { infoTooltip, toggleStyle } from './styles';
|
import { infoTooltip, toggleStyle } from './styles';
|
||||||
|
|
@ -80,7 +80,7 @@ const SSHTunnelSwitch = ({
|
||||||
|
|
||||||
return isSSHTunnelEnabled ? (
|
return isSSHTunnelEnabled ? (
|
||||||
<div css={(theme: SupersetTheme) => infoTooltip(theme)}>
|
<div css={(theme: SupersetTheme) => infoTooltip(theme)}>
|
||||||
<AntdSwitch
|
<Switch
|
||||||
checked={isChecked}
|
checked={isChecked}
|
||||||
onChange={handleOnChange}
|
onChange={handleOnChange}
|
||||||
data-test="ssh-tunnel-switch"
|
data-test="ssh-tunnel-switch"
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ import {
|
||||||
loadingCardCount,
|
loadingCardCount,
|
||||||
mq,
|
mq,
|
||||||
} from 'src/views/CRUD/utils';
|
} from 'src/views/CRUD/utils';
|
||||||
import { AntdSwitch } from 'src/components';
|
import { Switch } from 'src/components/Switch';
|
||||||
import getBootstrapData from 'src/utils/getBootstrapData';
|
import getBootstrapData from 'src/utils/getBootstrapData';
|
||||||
import { TableTab } from 'src/views/CRUD/types';
|
import { TableTab } from 'src/views/CRUD/types';
|
||||||
import SubMenu, { SubMenuProps } from 'src/features/home/SubMenu';
|
import SubMenu, { SubMenuProps } from 'src/features/home/SubMenu';
|
||||||
|
|
@ -340,7 +340,7 @@ function Welcome({ user, addDangerToast }: WelcomeProps) {
|
||||||
name: (
|
name: (
|
||||||
<WelcomeNav>
|
<WelcomeNav>
|
||||||
<div className="switch">
|
<div className="switch">
|
||||||
<AntdSwitch checked={checked} onClick={handleToggle} />
|
<Switch checked={checked} onClick={handleToggle} />
|
||||||
<span>{t('Thumbnails')}</span>
|
<span>{t('Thumbnails')}</span>
|
||||||
</div>
|
</div>
|
||||||
</WelcomeNav>
|
</WelcomeNav>
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,10 @@ const baseConfig: ThemeConfig = {
|
||||||
handleSizeHover: 10,
|
handleSizeHover: 10,
|
||||||
handleLineWidthHover: 2,
|
handleLineWidthHover: 2,
|
||||||
},
|
},
|
||||||
|
Switch: {
|
||||||
|
colorPrimaryHover: supersetTheme.colors.primary.base,
|
||||||
|
colorTextTertiary: supersetTheme.colors.grayscale.light1,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue