2017-06-13 03:50:41 -05:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
|
|
|
// Copyright (C) 2013 - 2017, The pgAdmin Development Team
|
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
import React from 'react';
|
2017-06-27 09:55:57 -05:00
|
|
|
import SplitPane from 'react-split-pane';
|
2017-06-13 03:50:41 -05:00
|
|
|
import QueryHistoryEntry from './query_history_entry';
|
2017-06-27 09:55:57 -05:00
|
|
|
import QueryHistoryDetail from './query_history_detail';
|
|
|
|
import Shapes from '../react_shapes';
|
2017-06-13 03:50:41 -05:00
|
|
|
|
2017-06-27 09:55:57 -05:00
|
|
|
const queryEntryListDivStyle = {
|
|
|
|
overflowY: 'auto',
|
|
|
|
};
|
|
|
|
const queryDetailDivStyle = {
|
|
|
|
display: 'flex',
|
|
|
|
};
|
2017-06-13 03:50:41 -05:00
|
|
|
const liStyle = {
|
|
|
|
borderBottom: '1px solid #cccccc',
|
|
|
|
};
|
|
|
|
|
|
|
|
export default class QueryHistory extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
history: [],
|
2017-06-27 09:55:57 -05:00
|
|
|
selectedEntry: 0,
|
2017-06-13 03:50:41 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
2017-06-27 09:55:57 -05:00
|
|
|
this.resetCurrentHistoryDetail(this.props.historyCollection.historyList);
|
|
|
|
this.props.historyCollection.onChange((historyList) => {
|
|
|
|
this.resetCurrentHistoryDetail(historyList);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.resetCurrentHistoryDetail(this.state.history);
|
|
|
|
}
|
|
|
|
|
|
|
|
getCurrentHistoryDetail() {
|
|
|
|
return this.state.currentHistoryDetail;
|
|
|
|
}
|
|
|
|
|
|
|
|
setCurrentHistoryDetail(index, historyList) {
|
|
|
|
this.setState({
|
|
|
|
history: historyList,
|
|
|
|
currentHistoryDetail: this.retrieveOrderedHistory().value()[index],
|
|
|
|
selectedEntry: index,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
resetCurrentHistoryDetail(historyList) {
|
|
|
|
this.setCurrentHistoryDetail(0, historyList);
|
|
|
|
}
|
|
|
|
|
|
|
|
retrieveOrderedHistory() {
|
|
|
|
return _.chain(this.state.history)
|
|
|
|
.sortBy(historyEntry => historyEntry.start_time)
|
|
|
|
.reverse();
|
|
|
|
}
|
|
|
|
|
|
|
|
onClickHandler(index) {
|
|
|
|
this.setCurrentHistoryDetail(index, this.state.history);
|
2017-06-13 03:50:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-06-27 09:55:57 -05:00
|
|
|
return (
|
|
|
|
<SplitPane defaultSize="50%" split="vertical" pane1Style={queryEntryListDivStyle}
|
|
|
|
pane2Style={queryDetailDivStyle}>
|
|
|
|
<div id='query_list'>
|
|
|
|
<ul>
|
|
|
|
{this.retrieveOrderedHistory()
|
|
|
|
.map((entry, index) =>
|
|
|
|
<li key={index} style={liStyle} onClick={this.onClickHandler.bind(this, index)}>
|
|
|
|
<QueryHistoryEntry historyEntry={entry} isSelected={index == this.state.selectedEntry}/>
|
|
|
|
</li>)
|
|
|
|
.value()
|
|
|
|
}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<QueryHistoryDetail historyEntry={this.getCurrentHistoryDetail()}/>
|
|
|
|
</SplitPane>);
|
2017-06-13 03:50:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QueryHistory.propTypes = {
|
2017-06-27 09:55:57 -05:00
|
|
|
historyCollection: Shapes.historyCollectionClass.isRequired,
|
2017-06-13 03:50:41 -05:00
|
|
|
};
|