mirror of https://github.com/apache/superset.git
[fix] Remedying filter-box w/ invalid metrics (#8722)
This commit is contained in:
parent
5b934bb377
commit
3d2117809f
|
@ -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)}
|
||||
/>
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue