Skip to content

Commit

Permalink
Grid displays table content
Browse files Browse the repository at this point in the history
  • Loading branch information
jooohhn committed Jan 25, 2018
1 parent 655e4fd commit 1842f0f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/components/Content.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { TableType } from '../types/TableType';
// import Footer from './Footer';

type Props = {
table: Array<TableType>
table: TableType
};

type State = {
Expand Down
49 changes: 30 additions & 19 deletions app/components/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import type { TableType } from '../types/TableType';
// https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/Grid.example.js

type Props = {
table: Array<TableType>
table: TableType
};

type State = {

};

export default class GridExample extends PureComponent<Props, State> {
export default class GridWrapper extends PureComponent<Props, State> {
constructor(props, context) {
super(props, context);

Expand All @@ -23,7 +23,7 @@ export default class GridExample extends PureComponent<Props, State> {
overscanColumnCount: 0,
overscanRowCount: 10,
rowHeight: 40,
rowCount: props.table.rows.length,
rowCount: props.table.rows.length + 1, // + 1 for column labels
scrollToColumn: undefined,
scrollToRow: undefined,
useDynamicRowHeight: false,
Expand All @@ -45,7 +45,6 @@ export default class GridExample extends PureComponent<Props, State> {
console.log(this.props);
const {
columnCount,
height,
overscanColumnCount,
overscanRowCount,
rowHeight,
Expand All @@ -55,11 +54,11 @@ export default class GridExample extends PureComponent<Props, State> {
useDynamicRowHeight,
} = this.state;

return (<AutoSizer disableHeight>
{({ width }) => (
return (<AutoSizer >
{({ height, width }) => (
<Grid
cellRenderer={this._cellRenderer}
columnWidth={this._getColumnWidth}
columnWidth={width / columnCount}
columnCount={columnCount}
height={height}
noContentRenderer={this._noContentRenderer}
Expand All @@ -78,7 +77,9 @@ export default class GridExample extends PureComponent<Props, State> {
_cellRenderer({
columnIndex, key, rowIndex, style
}) {
return this._renderBodyCell({
return rowIndex === 0 ? this._renderHeaderCell({
columnIndex, key, rowIndex, style
}) : this._renderBodyCell({
columnIndex, key, rowIndex, style
});
}
Expand Down Expand Up @@ -106,6 +107,14 @@ export default class GridExample extends PureComponent<Props, State> {
}

_getRowClassName(row) {
return {
borderStyle: 'solid',
borderWidth: '1px',
backgroundColor: row % 2 == 1 ? '#e6e6e6' : 'white',
display: 'flex',
justifyContent: 'center', /* align horizontal */
alignItems: 'center' /* align vertical */
};
// return row % 2 === 0 ? styles.evenRow : styles.oddRow;
}

Expand All @@ -123,19 +132,21 @@ export default class GridExample extends PureComponent<Props, State> {
const rowClass = this._getRowClassName(rowIndex);
const datum = this._getDatum(rowIndex);

let content;
// rowIndex - 1 to compensate for header
return (<div key={key} style={{ ...style, ...rowClass }}>
{this.props.table.rows[rowIndex - 1].value[columnIndex]}
</div>);
}

switch (columnIndex) {
default:
content = `r:${rowIndex}, c:${columnIndex}`;
break;
}
_renderHeaderCell({
columnIndex, key, rowIndex, style
}) {
const rowClass = this._getRowClassName(rowIndex);
const datum = this._getDatum(rowIndex);

return (
<div key={key} style={style}>
{content}
</div>
);
return (<div key={key} style={{ ...style, ...rowClass }}>
<h3>{this.props.table.columns[columnIndex]}</h3>
</div>);
}

_updateUseDynamicRowHeights(value) {
Expand Down
1 change: 1 addition & 0 deletions app/components/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import TableType from '../types/TableType';

type Props = {
databaseName: string,
onSelectTable: (event) => void,
tables: Array<TableType>
};

Expand Down
2 changes: 1 addition & 1 deletion app/containers/ContentPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Content from '../components/Content';
import type { TableType } from '../types/TableType';

type Props = {
table: Array<TableType>
table: TableType
};

type State = {
Expand Down
6 changes: 5 additions & 1 deletion app/containers/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class HomePage extends Component<Props, State> {
});
};

onSelectTable = (event) => {
console.log(event.target.value);
};

render() {
console.log(this.state);
if (!this.state.selectedTable) return <div />;
Expand All @@ -126,7 +130,7 @@ class HomePage extends Component<Props, State> {
axis="x"
>
{/* Currently only supports one database file at a time (since using SQLite only) */}
<Sidebar tables={this.state.tables} databaseName={this.state.databaseName} />
<Sidebar databaseName={this.state.databaseName} tables={this.state.tables} onSelectTable={this.onSelectTable} />
</ResizableBox>
<div className="Grid" style={{ position: 'relative', width: this.state.widthGrid }}>
<Switch>
Expand Down

0 comments on commit 1842f0f

Please sign in to comment.