eschutho commented on a change in pull request #13761:
URL: https://github.com/apache/superset/pull/13761#discussion_r600117438
##########
File path: superset-frontend/src/SqlLab/components/ResultSet.tsx
##########
@@ -117,205 +105,59 @@ const ResultSetErrorMessage = styled.div`
padding-top: ${({ theme }) => 4 * theme.gridUnit}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,
- newSaveDatasetName: this.getDefaultDatasetName(),
- saveDatasetRadioBtnState: DatasetRadioState.SAVE_NEW,
- shouldOverwriteDataSet: false,
- datasetToOverwrite: {},
- saveModalAutocompleteValue: '',
- userDatasetOptions: [],
- };
-
- 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,
- );
- this.handleSaveInDataset = this.handleSaveInDataset.bind(this);
- this.handleHideSaveModal = this.handleHideSaveModal.bind(this);
- this.handleDatasetNameChange = this.handleDatasetNameChange.bind(this);
- this.handleSaveDatasetRadioBtnState =
this.handleSaveDatasetRadioBtnState.bind(
- this,
- );
- this.handleOverwriteCancel = this.handleOverwriteCancel.bind(this);
- this.handleOverwriteDataset = this.handleOverwriteDataset.bind(this);
- this.handleOverwriteDatasetOption = this.handleOverwriteDatasetOption.bind(
- this,
- );
- this.handleSaveDatasetModalSearch = debounce(
- this.handleSaveDatasetModalSearch.bind(this),
- 1000,
- );
- this.handleFilterAutocompleteOption =
this.handleFilterAutocompleteOption.bind(
- this,
- );
- this.handleOnChangeAutoComplete = this.handleOnChangeAutoComplete.bind(
- this,
- );
- this.handleExploreBtnClick = this.handleExploreBtnClick.bind(this);
- }
-
- async componentDidMount() {
- // only do this the first time the component is rendered/mounted
- this.reRunQueryIfSessionTimeoutErrorOnMount();
- const userDatasetsOwned = await this.getUserDatasets();
- this.setState({ userDatasetOptions: userDatasetsOwned });
- }
-
- UNSAFE_componentWillReceiveProps(nextProps: ResultSetProps) {
- // when new results comes in, save them locally and clear in store
+const getDefaultDatasetName = (tab: string | null) =>
+ `${tab} ${moment().format('MM/DD/YYYY HH:mm:ss')}`;
+
+export default function ResultSet({
+ cache = false,
+ csv = true,
+ database = {},
+ search = true,
+ showSql = false,
+ visualize = true,
+ query,
+ ...props
+}: ResultSetProps) {
+ const [searchText, setSearchText] = useState<string>('');
+ const [stateData, setData] = useState<Record<string, any>[]>([]);
+ const [showSaveDatasetModal, setShowSaveDatasetModal] = useState<boolean>(
+ false,
+ );
+ const [newSaveDatasetName, setNewSaveDatasetName] = useState<string>(
+ getDefaultDatasetName(query.tab),
+ );
+ const [
+ saveDatasetRadioBtnState,
+ setSaveDatasetRadioBtnState,
+ ] = useState<DatasetRadioState>(DatasetRadioState.SAVE_NEW);
+ const [shouldOverwriteDataSet, setShouldOverwriteDataSet] =
useState<boolean>(
+ false,
+ );
+ const [datasetToOverwrite, setDatasetToOverwrite] = useState<
+ Record<string, any> | { datasetId: string }
+ >({});
+ const [userDatasetOptions, setUserDatasetOptions] = useState<
+ DatasetOptionAutocomplete[]
+ >([]);
+ const cacheRef = useRef(cache);
+ const resultsKeyRef = useRef(query.resultsKey);
+ const putDataset = useDatasetPut({
+ datasetId: datasetToOverwrite.datasetId,
+ overrideColumns: true,
Review comment:
Here's the new hook. This endpoint doesn't return anything, so there's
no useSelector in this POC, just useDispatch.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]