mirror of https://github.com/apache/superset.git
[sql lab] search to use fist&last name instead of username (#4628)
In our environment username are not readable coming out of oauth, so we'd rather use first&last when available.
This commit is contained in:
parent
1435840e38
commit
fc47729233
|
@ -31,6 +31,17 @@ class QuerySearch extends React.PureComponent {
|
|||
queriesArray: [],
|
||||
queriesLoading: true,
|
||||
};
|
||||
this.userMutator = this.userMutator.bind(this);
|
||||
this.changeUser = this.changeUser.bind(this);
|
||||
this.dbMutator = this.dbMutator.bind(this);
|
||||
this.onChange = this.onChange.bind(this);
|
||||
this.changeSearch = this.changeSearch.bind(this);
|
||||
this.changeFrom = this.changeFrom.bind(this);
|
||||
this.changeTo = this.changeTo.bind(this);
|
||||
this.changeStatus = this.changeStatus.bind(this);
|
||||
this.refreshQueries = this.refreshQueries.bind(this);
|
||||
this.onUserClicked = this.onUserClicked.bind(this);
|
||||
this.onDbClicked = this.onDbClicked.bind(this);
|
||||
}
|
||||
componentDidMount() {
|
||||
this.refreshQueries();
|
||||
|
@ -90,10 +101,16 @@ class QuerySearch extends React.PureComponent {
|
|||
changeSearch(event) {
|
||||
this.setState({ searchText: event.target.value });
|
||||
}
|
||||
userLabel(user) {
|
||||
if (user.first_name && user.last_name) {
|
||||
return user.first_name + ' ' + user.last_name;
|
||||
}
|
||||
return user.username;
|
||||
}
|
||||
userMutator(data) {
|
||||
const options = [];
|
||||
for (let i = 0; i < data.pks.length; i++) {
|
||||
options.push({ value: data.pks[i], label: data.result[i].username });
|
||||
options.push({ value: data.pks[i], label: this.userLabel(data.result[i]) });
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
@ -135,21 +152,21 @@ class QuerySearch extends React.PureComponent {
|
|||
dataEndpoint="/users/api/read"
|
||||
mutator={this.userMutator}
|
||||
value={this.state.userId}
|
||||
onChange={this.changeUser.bind(this)}
|
||||
onChange={this.changeUser}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-sm-2">
|
||||
<AsyncSelect
|
||||
onChange={this.onChange.bind(this)}
|
||||
onChange={this.onChange}
|
||||
dataEndpoint="/databaseasync/api/read?_flt_0_expose_in_sqllab=1"
|
||||
value={this.state.databaseId}
|
||||
mutator={this.dbMutator.bind(this)}
|
||||
mutator={this.dbMutator}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-sm-4">
|
||||
<input
|
||||
type="text"
|
||||
onChange={this.changeSearch.bind(this)}
|
||||
onChange={this.changeSearch}
|
||||
className="form-control input-sm"
|
||||
placeholder={t('Search Results')}
|
||||
/>
|
||||
|
@ -162,7 +179,7 @@ class QuerySearch extends React.PureComponent {
|
|||
.slice(1, TIME_OPTIONS.length).map(xt => ({ value: xt, label: xt }))}
|
||||
value={this.state.from}
|
||||
autosize={false}
|
||||
onChange={this.changeFrom.bind(this)}
|
||||
onChange={this.changeFrom}
|
||||
/>
|
||||
|
||||
<Select
|
||||
|
@ -171,7 +188,7 @@ class QuerySearch extends React.PureComponent {
|
|||
options={TIME_OPTIONS.map(xt => ({ value: xt, label: xt }))}
|
||||
value={this.state.to}
|
||||
autosize={false}
|
||||
onChange={this.changeTo.bind(this)}
|
||||
onChange={this.changeTo}
|
||||
/>
|
||||
|
||||
<Select
|
||||
|
@ -181,10 +198,10 @@ class QuerySearch extends React.PureComponent {
|
|||
value={this.state.status}
|
||||
isLoading={false}
|
||||
autosize={false}
|
||||
onChange={this.changeStatus.bind(this)}
|
||||
onChange={this.changeStatus}
|
||||
/>
|
||||
|
||||
<Button bsSize="small" bsStyle="success" onClick={this.refreshQueries.bind(this)}>
|
||||
<Button bsSize="small" bsStyle="success" onClick={this.refreshQueries}>
|
||||
{t('Search')}
|
||||
</Button>
|
||||
</div>
|
||||
|
@ -203,8 +220,8 @@ class QuerySearch extends React.PureComponent {
|
|||
'state', 'db', 'user', 'time',
|
||||
'progress', 'rows', 'sql', 'querylink',
|
||||
]}
|
||||
onUserClicked={this.onUserClicked.bind(this)}
|
||||
onDbClicked={this.onDbClicked.bind(this)}
|
||||
onUserClicked={this.onUserClicked}
|
||||
onDbClicked={this.onDbClicked}
|
||||
queries={this.state.queriesArray}
|
||||
actions={this.props.actions}
|
||||
/>
|
||||
|
|
|
@ -19,7 +19,7 @@ from sqlalchemy.orm import backref, relationship
|
|||
|
||||
from superset import sm
|
||||
from superset.models.helpers import AuditMixinNullable
|
||||
from superset.utils import QueryStatus
|
||||
from superset.utils import QueryStatus, user_label
|
||||
|
||||
install_aliases()
|
||||
|
||||
|
@ -109,7 +109,7 @@ class Query(Model):
|
|||
'tab': self.tab_name,
|
||||
'tempTable': self.tmp_table_name,
|
||||
'userId': self.user_id,
|
||||
'user': self.user.username,
|
||||
'user': user_label(self.user),
|
||||
'limit_reached': self.limit_reached,
|
||||
'resultsKey': self.results_key,
|
||||
'trackingUrl': self.tracking_url,
|
||||
|
|
|
@ -825,3 +825,12 @@ def merge_request_params(form_data, params):
|
|||
def get_update_perms_flag():
|
||||
val = os.environ.get('SUPERSET_UPDATE_PERMS')
|
||||
return val.lower() not in ('0', 'false', 'no') if val else True
|
||||
|
||||
|
||||
def user_label(user):
|
||||
"""Given a user ORM FAB object, returns a label"""
|
||||
if user:
|
||||
if user.first_name and user.last_name:
|
||||
return user.first_name + ' ' + user.last_name
|
||||
else:
|
||||
return user.username
|
||||
|
|
Loading…
Reference in New Issue