2018-04-27 08:42:35 -05:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
|
2018-07-26 07:04:12 -05:00
|
|
|
import QueryField from './PromQueryField';
|
2018-04-27 08:42:35 -05:00
|
|
|
|
2018-08-02 09:43:33 -05:00
|
|
|
class QueryRow extends PureComponent<any, {}> {
|
2018-08-05 16:07:05 -05:00
|
|
|
onChangeQuery = (value, override?: boolean) => {
|
2018-04-27 08:42:35 -05:00
|
|
|
const { index, onChangeQuery } = this.props;
|
|
|
|
if (onChangeQuery) {
|
2018-08-05 16:07:05 -05:00
|
|
|
onChangeQuery(value, index, override);
|
2018-04-27 08:42:35 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-04 04:58:54 -05:00
|
|
|
onClickAddButton = () => {
|
2018-04-27 08:42:35 -05:00
|
|
|
const { index, onAddQueryRow } = this.props;
|
|
|
|
if (onAddQueryRow) {
|
|
|
|
onAddQueryRow(index);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-04 04:58:54 -05:00
|
|
|
onClickClearButton = () => {
|
2018-08-05 16:07:05 -05:00
|
|
|
this.onChangeQuery('', true);
|
2018-08-04 04:58:54 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
onClickRemoveButton = () => {
|
2018-04-27 08:42:35 -05:00
|
|
|
const { index, onRemoveQueryRow } = this.props;
|
|
|
|
if (onRemoveQueryRow) {
|
|
|
|
onRemoveQueryRow(index);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-04 04:58:54 -05:00
|
|
|
onPressEnter = () => {
|
2018-04-27 08:42:35 -05:00
|
|
|
const { onExecuteQuery } = this.props;
|
|
|
|
if (onExecuteQuery) {
|
|
|
|
onExecuteQuery();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2018-08-02 09:43:33 -05:00
|
|
|
const { edited, history, query, request } = this.props;
|
2018-04-27 08:42:35 -05:00
|
|
|
return (
|
|
|
|
<div className="query-row">
|
2018-08-05 16:07:05 -05:00
|
|
|
<div className="query-row-field">
|
2018-04-27 11:21:20 -05:00
|
|
|
<QueryField
|
|
|
|
initialQuery={edited ? null : query}
|
2018-08-02 09:43:33 -05:00
|
|
|
history={history}
|
2018-06-11 10:36:45 -05:00
|
|
|
portalPrefix="explore"
|
2018-08-04 04:58:54 -05:00
|
|
|
onPressEnter={this.onPressEnter}
|
|
|
|
onQueryChange={this.onChangeQuery}
|
2018-04-27 11:21:20 -05:00
|
|
|
request={request}
|
|
|
|
/>
|
2018-04-27 08:42:35 -05:00
|
|
|
</div>
|
2018-08-05 16:07:05 -05:00
|
|
|
<div className="query-row-tools">
|
|
|
|
<button className="btn navbar-button navbar-button--tight" onClick={this.onClickClearButton}>
|
|
|
|
<i className="fa fa-times" />
|
|
|
|
</button>
|
|
|
|
<button className="btn navbar-button navbar-button--tight" onClick={this.onClickAddButton}>
|
|
|
|
<i className="fa fa-plus" />
|
|
|
|
</button>
|
|
|
|
<button className="btn navbar-button navbar-button--tight" onClick={this.onClickRemoveButton}>
|
|
|
|
<i className="fa fa-minus" />
|
|
|
|
</button>
|
|
|
|
</div>
|
2018-04-27 08:42:35 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-02 09:43:33 -05:00
|
|
|
export default class QueryRows extends PureComponent<any, {}> {
|
2018-04-27 08:42:35 -05:00
|
|
|
render() {
|
|
|
|
const { className = '', queries, ...handlers } = this.props;
|
|
|
|
return (
|
2018-04-27 11:21:20 -05:00
|
|
|
<div className={className}>
|
2018-08-03 03:20:13 -05:00
|
|
|
{queries.map((q, index) => (
|
|
|
|
<QueryRow key={q.key} index={index} query={q.query} edited={q.edited} {...handlers} />
|
|
|
|
))}
|
2018-04-27 11:21:20 -05:00
|
|
|
</div>
|
2018-04-27 08:42:35 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|