Skip to content

Commit

Permalink
Update logTable to accept an optional type argument for table class
Browse files Browse the repository at this point in the history
  • Loading branch information
snowak-cb committed Jul 13, 2017
1 parent 2fe9ef5 commit 6b0fb4e
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Properties you can pass to the console element
| log | (...messages: any)=>void | Log messages to the console. If string, print the value, otherwise, print the JSON value of the message.
| updateLastLog| (...messages: any)=>void | Replace the last message in the console. Useful for progress indicators.
| logX | (type: string, ...messages: any)=>void | Log messages of a particular type to the console. The messages will be given the class `react-console-message-{type}`.
| logTable | (tableObject: Object)=>void | Log tabular data to the console. `tableObject` has the format `{ headers: ['header 1', 'header 2'], rows: [['row 1, col 1', 'row 1, col 2'], ['row 2, col 1', 'row 2, col 2']]}`. `headers` is optional.
| logTable | (tableObject: Object[, type: string])=>void | Log tabular data to the console. `tableObject` has the format `{ headers: ['header 1', 'header 2'], rows: [['row 1, col 1', 'row 1, col 2'], ['row 2, col 1', 'row 2, col 2']]}`. `headers` is optional. The optional `type` argument will be handled the same as in `logX`
| return | ()=>void | Signal the current command has finished and a new prompt should be displayed.
| clearScreen | ()=>void | Clear the visible log in the console. Does not clear command history.

Expand Down
Binary file modified dist/dist-min.tar.gz
Binary file not shown.
Binary file modified dist/dist-min.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/dist-min/react-console.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dist-min/react-console.min.js.map

Large diffs are not rendered by default.

Binary file modified dist/dist.tar.gz
Binary file not shown.
Binary file modified dist/dist.zip
Binary file not shown.
11 changes: 8 additions & 3 deletions dist/dist/react-console.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/dist/react-console.js.map

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions lib/react-console.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/react-console.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/react-console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ interface ConsoleMessageProps {
let ConsoleMessage: React.SFC<ConsoleMessageProps> = function(props: ConsoleMessageProps) {
if(props.isTable){
const data = props.value[0];
return <div className="react-console-message react-console-table">
return <div className={"react-console-message react-console-table" + (props.type?" react-console-message-"+props.type:"")}>
<table>
<ConsoleTableHeader headers={data.headers} />
<tbody>
Expand Down Expand Up @@ -246,9 +246,13 @@ export default class extends React.Component<ConsoleProps,ConsoleState> {
log: log,
}, this.scrollIfBottom() );
}
logTable = (tableData: ConsoleTableObject) => {
logTable = (tableData: ConsoleTableObject, type?: string) => {
let log = this.state.log;
log[this.state.log.length-1].message.push({isTable: true, value: [tableData]});
if(type){
log[this.state.log.length-1].message.push({isTable: true, type: type, value: [tableData]});
}else{
log[this.state.log.length-1].message.push({isTable: true, value: [tableData]});
}
this.setState({
log: log,
}, this.scrollIfBottom() );
Expand Down

0 comments on commit 6b0fb4e

Please sign in to comment.