[fix] Remedying filter-box w/ invalid metrics (#8722)

This commit is contained in:
John Bodley 2019-12-04 11:34:56 -08:00 committed by GitHub
parent 5b934bb377
commit 3d2117809f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 21 deletions

View File

@ -76,10 +76,15 @@ export default class FilterBoxItemControl extends React.Component {
value={this.state.column}
name="column"
clearable={false}
options={this.props.datasource.columns.map(col => ({
value: col.column_name,
label: col.column_name,
}))}
options={this.props.datasource.columns
.filter(col => col !== this.state.column)
.map(col => ({
value: col.column_name,
label: col.column_name,
}))
.concat([
{ value: this.state.column, label: this.state.column },
])}
onChange={v => this.onControlChange('column', v)}
/>
}
@ -116,10 +121,15 @@ export default class FilterBoxItemControl extends React.Component {
<SelectControl
value={this.state.metric}
name="column"
options={this.props.datasource.metrics.map(m => ({
value: m.metric_name,
label: m.metric_name,
}))}
options={this.props.datasource.metrics
.filter(metric => metric !== this.state.metric)
.map(m => ({
value: m.metric_name,
label: m.metric_name,
}))
.concat([
{ value: this.state.metric, label: this.state.metric },
])}
onChange={v => this.onControlChange('metric', v)}
/>
}

View File

@ -1832,19 +1832,21 @@ class FilterBoxViz(BaseViz):
col = flt.get("column")
metric = flt.get("metric")
df = self.dataframes.get(col)
if metric:
df = df.sort_values(
utils.get_metric_name(metric), ascending=flt.get("asc")
)
d[col] = [
{"id": row[0], "text": row[0], "metric": row[1]}
for row in df.itertuples(index=False)
]
else:
df = df.sort_values(col, ascending=flt.get("asc"))
d[col] = [
{"id": row[0], "text": row[0]} for row in df.itertuples(index=False)
]
if df is not None:
if metric:
df = df.sort_values(
utils.get_metric_name(metric), ascending=flt.get("asc")
)
d[col] = [
{"id": row[0], "text": row[0], "metric": row[1]}
for row in df.itertuples(index=False)
]
else:
df = df.sort_values(col, ascending=flt.get("asc"))
d[col] = [
{"id": row[0], "text": row[0]}
for row in df.itertuples(index=False)
]
return d