Skip to content

Commit

Permalink
created type for SqlLab redux
Browse files Browse the repository at this point in the history
  • Loading branch information
MayUWish committed Jan 28, 2022
1 parent bea7e97 commit 7cc7c73
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
17 changes: 7 additions & 10 deletions superset-frontend/src/SqlLab/components/QueryTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ import Button from 'src/components/Button';
import { fDuration } from 'src/modules/dates';
import Icons from 'src/components/Icons';
import { Tooltip } from 'src/components/Tooltip';
import { Query } from 'src/SqlLab/types';
import { Query, RootState } from 'src/SqlLab/types';
import ModalTrigger from 'src/components/ModalTrigger';
import rootReducer from 'src/SqlLab/reducers';
import { UserWithPermissionsAndRoles as User } from 'src/types/bootstrapTypes';
import ResultSet from '../ResultSet';
import HighlightedSql from '../HighlightedSql';
import { StaticPosition, verticalAlign, StyledTooltip } from './styles';

type RootState = ReturnType<typeof rootReducer>;

interface QueryTableQuery extends Omit<Query, 'state' | 'sql' | 'progress'> {
state?: Record<string, any>;
sql?: Record<string, any>;
Expand Down Expand Up @@ -89,7 +87,7 @@ const QueryTable = ({
[columns],
);

const user = useSelector((state: RootState) => state.sqlLab.user);
const user = useSelector<RootState, User>(state => state.sqlLab.user);

const {
queryEditorSetSql,
Expand Down Expand Up @@ -140,7 +138,7 @@ const QueryTable = ({
fetching: {
config: {
icon: <Icons.Queued iconColor={theme.colors.primary.base} />,
label: t('fetching'),
label: t('Fetching'),
},
},
timed_out: {
Expand Down Expand Up @@ -171,10 +169,8 @@ const QueryTable = ({

return queries
.map(query => {
// query's type is original Query; Shallow-copy of query, q's type is QueryTableQuery. So that prop, sql passed to another component will remain string, the type of original Query.
// qTemp is used to bring in the properties that you don't overwrite, which will be assigned to q, so that q.state/q.sql/q.progress will be later object.
const { state, sql, progress, ...qTemp } = query;
const q: QueryTableQuery = { ...qTemp };
const { state, sql, progress, ...rest } = query;
const q = rest as QueryTableQuery;

const status = statusAttributes[state] || statusAttributes.error;

Expand Down Expand Up @@ -248,6 +244,7 @@ const QueryTable = ({
actions={actions}
height={400}
displayLimit={displayLimit}
defaultQueryLimit={1000}
/>
}
responsive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ interface ResultSetProps {
showSql?: boolean;
visualize?: boolean;
user: UserWithPermissionsAndRoles;
defaultQueryLimit?: number;
defaultQueryLimit: number;
}

interface ResultSetState {
Expand Down
28 changes: 28 additions & 0 deletions superset-frontend/src/SqlLab/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
import { SupersetError } from 'src/components/ErrorMessage/types';
import { CtasEnum } from 'src/SqlLab/actions/sqlLab';
import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
import { ToastType } from 'src/components/MessageToasts/types';

export type Column = {
name: string;
Expand Down Expand Up @@ -95,3 +97,29 @@ export interface QueryEditor {
errors: SupersetError[];
};
}

export type toastState = {
id: string;
toastType: ToastType;
text: string;
duration: number;
noDuplicate: boolean;
};

export type RootState = {
sqlLab: {
activeSouthPaneTab: string | number; // default is string; action.newQuery.id is number
alerts: any[];
databases: Record<string, any>;
offline: boolean;
queries: Query[];
queryEditors: QueryEditor[];
tabHistory: string[]; // default is activeTab ? [activeTab.id.toString()] : []
tables: Record<string, any>[];
queriesLastUpdate: number;
user: UserWithPermissionsAndRoles;
};
localStorageUsageInKilobytes: number;
messageToasts: toastState[];
common: {};
};

0 comments on commit 7cc7c73

Please sign in to comment.