betodealmeida commented on a change in pull request #17944: URL: https://github.com/apache/superset/pull/17944#discussion_r780543948
########## File path: superset-frontend/src/SqlLab/components/QueryTable/index.tsx ########## @@ -29,133 +28,158 @@ 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 ResultSet from '../ResultSet'; import ModalTrigger from '../../../components/ModalTrigger'; import HighlightedSql from '../HighlightedSql'; import { StaticPosition, verticalAlign, StyledTooltip } from './styles'; +import rootReducer from '../../reducers/index'; -const propTypes = { - columns: PropTypes.array, - actions: PropTypes.object, - queries: PropTypes.array, - onUserClicked: PropTypes.func, - onDbClicked: PropTypes.func, - displayLimit: PropTypes.number.isRequired, -}; -const defaultProps = { - columns: ['started', 'duration', 'rows'], - queries: [], - onUserClicked: () => {}, - onDbClicked: () => {}, -}; +// Acquire redux rootstate type, to be used in useSelector +type RootState = ReturnType<typeof rootReducer>; + +// 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 +interface QueryTableQueryTemp1 extends Omit<Query, 'sql'> { + sql: string | Record<string, any>; +} + +interface QueryTableQueryTemp2 extends Omit<QueryTableQueryTemp1, 'progress'> { + progress: number | Record<string, any>; +} Review comment: ```suggestion ``` ########## File path: superset-frontend/src/SqlLab/components/QueryTable/index.tsx ########## @@ -29,133 +28,158 @@ 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 ResultSet from '../ResultSet'; import ModalTrigger from '../../../components/ModalTrigger'; import HighlightedSql from '../HighlightedSql'; import { StaticPosition, verticalAlign, StyledTooltip } from './styles'; +import rootReducer from '../../reducers/index'; -const propTypes = { - columns: PropTypes.array, - actions: PropTypes.object, - queries: PropTypes.array, - onUserClicked: PropTypes.func, - onDbClicked: PropTypes.func, - displayLimit: PropTypes.number.isRequired, -}; -const defaultProps = { - columns: ['started', 'duration', 'rows'], - queries: [], - onUserClicked: () => {}, - onDbClicked: () => {}, -}; +// Acquire redux rootstate type, to be used in useSelector +type RootState = ReturnType<typeof rootReducer>; + +// 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 +interface QueryTableQueryTemp1 extends Omit<Query, 'sql'> { + sql: string | Record<string, any>; +} + +interface QueryTableQueryTemp2 extends Omit<QueryTableQueryTemp1, 'progress'> { + progress: number | Record<string, any>; +} -const openQuery = id => { +interface QueryTableQuery extends Omit<QueryTableQueryTemp2, 'state'> { + state: string | Record<string, any>; +} Review comment: You can `Omit` [several keys](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys): ```suggestion interface QueryTableQuery extends Omit<Query, 'state' | 'sql' | 'progress'> { state: string | Record<string, any>; sql: string | Record<string, any>; progress: number | Record<string, any>; } ``` But in general it's not a good idea to have attributes with multiple types like this. We've had a lot of errors in the past caused by storing attributes with different types, and it leads to complicated logic that needs to check types (like you did below where you check if `state` is a string). Why do you need to store these attributes as records? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org