mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 16:45:43 -06:00
* first working example * Support sorting, adding types while waiting for official ones * using react-window for windowing * styles via emotion * sizing * set an offset for the table * change table export * fixing table cell widths * Explore: Use new table component in explore (#21031) * Explore: Use new table component in explore * enable oncellclick * only let filterable columns be clickable, refactor renderrow * remove explore table * Keep using old merge tables logic * prettier * remove unused typings file * fixing tests * Fixed explore table issue * NewTable: Updated styles * Fixed unit test * Updated TableModel * Minor update to explore table height * typing
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import React, { PureComponent } from 'react';
|
|
import { hot } from 'react-hot-loader';
|
|
import { connect } from 'react-redux';
|
|
import { DataFrame } from '@grafana/data';
|
|
import { Table, Collapse } from '@grafana/ui';
|
|
import { ExploreId, ExploreItemState } from 'app/types/explore';
|
|
import { StoreState } from 'app/types';
|
|
import { toggleTable } from './state/actions';
|
|
|
|
interface TableContainerProps {
|
|
exploreId: ExploreId;
|
|
loading: boolean;
|
|
width: number;
|
|
onClickCell: (key: string, value: string) => void;
|
|
showingTable: boolean;
|
|
tableResult?: DataFrame;
|
|
toggleTable: typeof toggleTable;
|
|
}
|
|
|
|
export class TableContainer extends PureComponent<TableContainerProps> {
|
|
onClickTableButton = () => {
|
|
this.props.toggleTable(this.props.exploreId, this.props.showingTable);
|
|
};
|
|
|
|
getTableHeight() {
|
|
const { tableResult } = this.props;
|
|
|
|
if (!tableResult || tableResult.length === 0) {
|
|
return 200;
|
|
}
|
|
|
|
// tries to estimate table height
|
|
return Math.max(Math.min(600, tableResult.length * 35) + 35);
|
|
}
|
|
|
|
render() {
|
|
const { loading, onClickCell, showingTable, tableResult, width } = this.props;
|
|
|
|
const height = this.getTableHeight();
|
|
const paddingWidth = 16;
|
|
const tableWidth = width - paddingWidth;
|
|
|
|
return (
|
|
<Collapse label="Table" loading={loading} collapsible isOpen={showingTable} onToggle={this.onClickTableButton}>
|
|
{tableResult && <Table data={tableResult} width={tableWidth} height={height} onCellClick={onClickCell} />}
|
|
</Collapse>
|
|
);
|
|
}
|
|
}
|
|
|
|
function mapStateToProps(state: StoreState, { exploreId }: { exploreId: string }) {
|
|
const explore = state.explore;
|
|
// @ts-ignore
|
|
const item: ExploreItemState = explore[exploreId];
|
|
const { loading: loadingInState, showingTable, tableResult } = item;
|
|
const loading = tableResult && tableResult.length > 0 ? false : loadingInState;
|
|
return { loading, showingTable, tableResult };
|
|
}
|
|
|
|
const mapDispatchToProps = {
|
|
toggleTable,
|
|
};
|
|
|
|
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(TableContainer));
|