2019-01-13 16:10:23 -06:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { hot } from 'react-hot-loader';
|
|
|
|
import { connect } from 'react-redux';
|
2019-08-26 01:11:07 -05:00
|
|
|
import { Collapse } from '@grafana/ui';
|
2019-01-13 16:10:23 -06:00
|
|
|
|
|
|
|
import { ExploreId, ExploreItemState } from 'app/types/explore';
|
|
|
|
import { StoreState } from 'app/types';
|
|
|
|
|
2019-01-22 06:59:58 -06:00
|
|
|
import { toggleTable } from './state/actions';
|
2019-01-13 16:10:23 -06:00
|
|
|
import Table from './Table';
|
|
|
|
import TableModel from 'app/core/table_model';
|
|
|
|
|
|
|
|
interface TableContainerProps {
|
|
|
|
exploreId: ExploreId;
|
|
|
|
loading: boolean;
|
2019-01-15 12:52:53 -06:00
|
|
|
onClickCell: (key: string, value: string) => void;
|
2019-01-13 16:10:23 -06:00
|
|
|
showingTable: boolean;
|
|
|
|
tableResult?: TableModel;
|
2019-01-22 06:59:58 -06:00
|
|
|
toggleTable: typeof toggleTable;
|
2019-01-13 16:10:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
export class TableContainer extends PureComponent<TableContainerProps> {
|
|
|
|
onClickTableButton = () => {
|
2019-02-11 05:56:37 -06:00
|
|
|
this.props.toggleTable(this.props.exploreId, this.props.showingTable);
|
2019-01-13 16:10:23 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2019-01-15 12:52:53 -06:00
|
|
|
const { loading, onClickCell, showingTable, tableResult } = this.props;
|
2019-01-28 06:09:51 -06:00
|
|
|
|
2019-01-13 16:10:23 -06:00
|
|
|
return (
|
2019-08-26 01:11:07 -05:00
|
|
|
<Collapse label="Table" loading={loading} collapsible isOpen={showingTable} onToggle={this.onClickTableButton}>
|
2019-05-17 05:45:11 -05:00
|
|
|
{tableResult && <Table data={tableResult} loading={loading} onClickCell={onClickCell} />}
|
2019-08-26 01:11:07 -05:00
|
|
|
</Collapse>
|
2019-01-13 16:10:23 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 08:49:32 -05:00
|
|
|
function mapStateToProps(state: StoreState, { exploreId }: { exploreId: string }) {
|
2019-01-13 16:10:23 -06:00
|
|
|
const explore = state.explore;
|
2019-07-30 08:49:32 -05:00
|
|
|
// @ts-ignore
|
2019-01-13 16:10:23 -06:00
|
|
|
const item: ExploreItemState = explore[exploreId];
|
2019-09-03 02:55:20 -05:00
|
|
|
const { loading: loadingInState, showingTable, tableResult } = item;
|
|
|
|
const loading = tableResult && tableResult.rows.length > 0 ? false : loadingInState;
|
2019-01-13 16:10:23 -06:00
|
|
|
return { loading, showingTable, tableResult };
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
2019-01-22 06:59:58 -06:00
|
|
|
toggleTable,
|
2019-01-13 16:10:23 -06:00
|
|
|
};
|
|
|
|
|
2019-02-19 08:41:35 -06:00
|
|
|
export default hot(module)(
|
|
|
|
connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(TableContainer)
|
|
|
|
);
|