kgabryje commented on code in PR #21186:
URL: https://github.com/apache/superset/pull/21186#discussion_r955036700
##########
superset-frontend/src/SqlLab/components/ResultSet/index.tsx:
##########
@@ -121,115 +120,84 @@ const LimitMessage = styled.span`
margin-left: ${({ theme }) => theme.gridUnit * 2}px;
`;
-export default class ResultSet extends React.PureComponent<
- ResultSetProps,
- ResultSetState
-> {
- static defaultProps = {
- cache: false,
- csv: true,
- database: {},
- search: true,
- showSql: false,
- visualize: true,
- };
-
- constructor(props: ResultSetProps) {
- super(props);
- this.state = {
- searchText: '',
- showExploreResultsButton: false,
- data: [],
- showSaveDatasetModal: false,
- alertIsOpen: false,
- };
- this.changeSearch = this.changeSearch.bind(this);
- this.fetchResults = this.fetchResults.bind(this);
- this.popSelectStar = this.popSelectStar.bind(this);
- this.reFetchQueryResults = this.reFetchQueryResults.bind(this);
- this.toggleExploreResultsButton =
- this.toggleExploreResultsButton.bind(this);
- }
-
- async componentDidMount() {
+const ResultSet = ({
+ cache = false,
+ csv = true,
+ database = {},
+ displayLimit,
+ height,
+ query,
+ search = true,
+ showSql = false,
+ visualize = true,
+ user,
+ defaultQueryLimit,
+}: ResultSetProps) => {
+ const [searchText, setSearchText] = useState('');
+ const [cachedData, setCachedData] = useState<Record<string, unknown>[]>([]);
+ const [showSaveDatasetModal, setShowSaveDatasetModal] = useState(false);
+ const [alertIsOpen, setAlertIsOpen] = useState(false);
+
+ const dispatch = useDispatch();
+
+ useEffect(() => {
// only do this the first time the component is rendered/mounted
- this.reRunQueryIfSessionTimeoutErrorOnMount();
- }
-
- UNSAFE_componentWillReceiveProps(nextProps: ResultSetProps) {
- // when new results comes in, save them locally and clear in store
- if (
- this.props.cache &&
- !nextProps.query.cached &&
- nextProps.query.results &&
- nextProps.query.results.data &&
- nextProps.query.results.data.length > 0
- ) {
- this.setState({ data: nextProps.query.results.data }, () =>
- this.clearQueryResults(nextProps.query),
- );
+ reRunQueryIfSessionTimeoutErrorOnMount();
Review Comment:
This function is used before it's defined (which is fine in class components
but cause warnings in functional components. Can you move the function
definition above this `useEffect`? Also, if you wrap it in `useCallback` and
put `reRunQueryIfSessionTimeoutErrorOnMount` in this `useEffect`'s dependency
array, you'll get rid of 1 more error.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]