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: migrate QueryAndSaveBtns to TypeScript and add stories #18121

Merged
merged 2 commits into from
Feb 15, 2022
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
22 changes: 12 additions & 10 deletions superset-frontend/src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ import { Tooltip } from 'src/components/Tooltip';

export type OnClickHandler = React.MouseEventHandler<HTMLElement>;

export type ButtonStyle =
| 'primary'
| 'secondary'
| 'tertiary'
| 'success'
| 'warning'
| 'danger'
| 'default'
| 'link'
| 'dashed';

export interface ButtonProps {
id?: string;
className?: string;
Expand All @@ -46,16 +57,7 @@ export interface ButtonProps {
| 'rightBottom';
onClick?: OnClickHandler;
disabled?: boolean;
buttonStyle?:
| 'primary'
| 'secondary'
| 'tertiary'
| 'success'
| 'warning'
| 'danger'
| 'default'
| 'link'
| 'dashed';
buttonStyle?: ButtonStyle;
buttonSize?: 'default' | 'small' | 'xsmall';
style?: CSSProperties;
children?: React.ReactNode;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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 React from 'react';
import QueryAndSaveBtns, { QueryAndSaveBtnsProps } from './QueryAndSaveBtns';

export default {
title: 'QueryAndSaveBtns',
component: QueryAndSaveBtns,
};

export const InteractiveQueryAndSaveBtnsProps = (
args: QueryAndSaveBtnsProps,
) => <QueryAndSaveBtns {...args} />;

InteractiveQueryAndSaveBtnsProps.args = {
canAdd: true,
loading: false,
};

InteractiveQueryAndSaveBtnsProps.argTypes = {
onQuery: { action: 'onQuery' },
onSave: { action: 'onSave' },
onStop: { action: 'onStop' },
};

InteractiveQueryAndSaveBtnsProps.story = {
parameters: {
knobs: {
disable: true,
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,33 @@
* under the License.
*/
import React from 'react';
import PropTypes from 'prop-types';
import ButtonGroup from 'src/components/ButtonGroup';
import { t, useTheme } from '@superset-ui/core';

import { Tooltip } from 'src/components/Tooltip';
import Button from 'src/components/Button';
import Button, { ButtonStyle, OnClickHandler } from 'src/components/Button';

const propTypes = {
canAdd: PropTypes.bool.isRequired,
onQuery: PropTypes.func.isRequired,
onSave: PropTypes.func,
onStop: PropTypes.func,
loading: PropTypes.bool,
chartIsStale: PropTypes.bool,
errorMessage: PropTypes.node,
export type QueryAndSaveBtnsProps = {
canAdd: boolean;
onQuery: OnClickHandler;
onSave: OnClickHandler;
onStop: OnClickHandler;
loading?: boolean;
chartIsStale?: boolean;
errorMessage: React.ReactElement | undefined;
};

const defaultProps = {
onStop: () => {},
onSave: () => {},
};

export default function QueryAndSaveBtns({
canAdd,
onQuery,
onSave,
onStop,
loading,
chartIsStale,
errorMessage,
}) {
let qryButtonStyle = 'tertiary';
export default function QueryAndSaveBtns(props: QueryAndSaveBtnsProps) {
const {
canAdd,
onQuery = () => {},
onSave = () => {},
onStop = () => {},
loading,
chartIsStale,
errorMessage,
} = props;
let qryButtonStyle: ButtonStyle = 'tertiary';
if (errorMessage) {
qryButtonStyle = 'danger';
} else if (chartIsStale) {
Expand Down Expand Up @@ -127,6 +122,3 @@ export default function QueryAndSaveBtns({
</div>
);
}

QueryAndSaveBtns.propTypes = propTypes;
QueryAndSaveBtns.defaultProps = defaultProps;