TableContainer.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import React, { PureComponent } from 'react';
  2. import { hot } from 'react-hot-loader';
  3. import { connect } from 'react-redux';
  4. import { ExploreId, ExploreItemState } from 'app/types/explore';
  5. import { StoreState } from 'app/types';
  6. import { toggleTable } from './state/actions';
  7. import Table from './Table';
  8. import Panel from './Panel';
  9. import TableModel from 'app/core/table_model';
  10. interface TableContainerProps {
  11. exploreId: ExploreId;
  12. loading: boolean;
  13. onClickCell: (key: string, value: string) => void;
  14. showingTable: boolean;
  15. tableResult?: TableModel;
  16. toggleTable: typeof toggleTable;
  17. }
  18. export class TableContainer extends PureComponent<TableContainerProps> {
  19. onClickTableButton = () => {
  20. this.props.toggleTable(this.props.exploreId, this.props.showingTable);
  21. };
  22. render() {
  23. const { loading, onClickCell, showingTable, tableResult } = this.props;
  24. if (!tableResult) {
  25. return null;
  26. }
  27. return (
  28. <Panel label="Table" loading={loading} isOpen={showingTable} onToggle={this.onClickTableButton}>
  29. <Table data={tableResult} loading={loading} onClickCell={onClickCell} />
  30. </Panel>
  31. );
  32. }
  33. }
  34. function mapStateToProps(state: StoreState, { exploreId }) {
  35. const explore = state.explore;
  36. const item: ExploreItemState = explore[exploreId];
  37. const { queryTransactions, showingTable, tableResult } = item;
  38. const loading = queryTransactions.some(qt => qt.resultType === 'Table' && !qt.done);
  39. return { loading, showingTable, tableResult };
  40. }
  41. const mapDispatchToProps = {
  42. toggleTable,
  43. };
  44. export default hot(module)(
  45. connect(
  46. mapStateToProps,
  47. mapDispatchToProps
  48. )(TableContainer)
  49. );