mistercrunch closed pull request #4628: [sql lab] search to use fist&last name
instead of username
URL: https://github.com/apache/incubator-superset/pull/4628
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/superset/assets/javascripts/SqlLab/components/QuerySearch.jsx
b/superset/assets/javascripts/SqlLab/components/QuerySearch.jsx
index 10c1c88e79..a3e4bf4dfd 100644
--- a/superset/assets/javascripts/SqlLab/components/QuerySearch.jsx
+++ b/superset/assets/javascripts/SqlLab/components/QuerySearch.jsx
@@ -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}
/>
diff --git a/superset/models/sql_lab.py b/superset/models/sql_lab.py
index bf37db75f6..81ee41a160 100644
--- a/superset/models/sql_lab.py
+++ b/superset/models/sql_lab.py
@@ -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()
@@ -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,
diff --git a/superset/utils.py b/superset/utils.py
index bb43edcf1b..78fb12b669 100644
--- a/superset/utils.py
+++ b/superset/utils.py
@@ -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
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services