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

chore: type some SQL Lab components #14178

Merged
merged 2 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,37 @@
* under the License.
*/
import React from 'react';
import PropTypes from 'prop-types';
import Alert from 'src/components/Alert';
import { t } from '@superset-ui/core';

import QueryTable from './QueryTable';
import { Query } from '../types';

const propTypes = {
queries: PropTypes.array.isRequired,
actions: PropTypes.object.isRequired,
displayLimit: PropTypes.number.isRequired,
};
interface QueryHistoryProps {
queries: Query[];
actions: Record<string, unknown>;
displayLimit: number;
}

const QueryHistory = props => {
if (props.queries.length > 0) {
return (
<QueryTable
columns={[
'state',
'started',
'duration',
'progress',
'rows',
'sql',
'output',
'actions',
]}
queries={props.queries}
actions={props.actions}
displayLimit={props.displayLimit}
/>
);
}
return <Alert type="info" message={t('No query history yet...')} />;
};
QueryHistory.propTypes = propTypes;
const QueryHistory = (props: QueryHistoryProps) =>
props.queries.length > 0 ? (
<QueryTable
columns={[
'state',
'started',
'duration',
'progress',
'rows',
'sql',
'output',
'actions',
]}
queries={props.queries}
actions={props.actions}
displayLimit={props.displayLimit}
/>
) : (
<Alert type="info" message={t('No query history yet...')} />
);

export default QueryHistory;
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@
* under the License.
*/
import React from 'react';
import PropTypes from 'prop-types';
import Label from 'src/components/Label';

import { STATE_TYPE_MAP } from '../constants';
import { Query } from '../types';

const propTypes = {
query: PropTypes.object.isRequired,
};
interface QueryStateLabelProps {
query: Query;
}

export default function QueryStateLabel({ query }) {
const type = STATE_TYPE_MAP[query.state];
export default function QueryStateLabel({ query }: QueryStateLabelProps) {
return (
<Label className="m-r-3" type={type}>
<Label className="m-r-3" type={STATE_TYPE_MAP[query.state]}>
{query.state}
</Label>
);
}
QueryStateLabel.propTypes = propTypes;
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
* under the License.
*/
import React from 'react';
import PropTypes from 'prop-types';

export default function TabStatusIcon(props) {
return <div className={`circle ${props.tabState}`} />;
import { QueryState } from '../types';

interface TabStatusIconProps {
tabState: QueryState;
}

TabStatusIcon.propTypes = {
tabState: PropTypes.string.isRequired,
};
export default function TabStatusIcon({ tabState }: TabStatusIconProps) {
return <div className={`circle ${tabState}`} />;
}
18 changes: 10 additions & 8 deletions superset-frontend/src/SqlLab/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ export type Column = {
name: string;
};

export type QueryState =
| 'stopped'
| 'failed'
| 'pending'
| 'running'
| 'scheduled'
| 'success'
| 'timed_out';

export type Query = {
cached: boolean;
ctas: boolean;
Expand All @@ -48,14 +57,7 @@ export type Query = {
schema: string;
sql: string;
sqlEditorId: string;
state:
| 'stopped'
| 'failed'
| 'pending'
| 'running'
| 'scheduled'
| 'success'
| 'timed_out';
state: QueryState;
tab: string | null;
tempSchema: string | null;
tempTable: string;
Expand Down