Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sql lab] search to use fist&last name instead of username #4628

Merged
merged 1 commit into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions superset/assets/javascripts/SqlLab/components/QuerySearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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')}
/>
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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>
Expand All @@ -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}
/>
Expand Down
4 changes: 2 additions & 2 deletions superset/models/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from superset import sm
from superset.models.helpers import AuditMixinNullable
from superset.utils import QueryStatus
from superset.utils import QueryStatus, user_label

install_aliases()

Expand Down Expand Up @@ -109,7 +109,7 @@ def to_dict(self):
'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,
Expand Down
9 changes: 9 additions & 0 deletions superset/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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