Replace No data error with help message (#9249)
This commit is contained in:
parent
fc64c37724
commit
f34e9e393a
|
|
@ -19,14 +19,14 @@
|
|||
import { FORM_DATA_DEFAULTS, NUM_METRIC } from './visualizations/shared.helper';
|
||||
import readResponseBlob from '../../utils/readResponseBlob';
|
||||
|
||||
describe('Error', () => {
|
||||
describe('No Results', () => {
|
||||
beforeEach(() => {
|
||||
cy.login();
|
||||
cy.server();
|
||||
cy.route('POST', '/superset/explore_json/**').as('getJson');
|
||||
});
|
||||
|
||||
it('No data error message shows up', () => {
|
||||
it('No results message shows up', () => {
|
||||
const formData = {
|
||||
...FORM_DATA_DEFAULTS,
|
||||
metrics: [NUM_METRIC],
|
||||
|
|
@ -46,14 +46,8 @@ describe('Error', () => {
|
|||
|
||||
cy.visitChartByParams(JSON.stringify(formData));
|
||||
cy.wait('@getJson').then(async xhr => {
|
||||
expect(xhr.status).to.eq(400);
|
||||
|
||||
const responseBody = await readResponseBlob(xhr.response.body);
|
||||
|
||||
if (responseBody.error) {
|
||||
expect(responseBody.error).to.eq('No data');
|
||||
}
|
||||
expect(xhr.status).to.eq(200);
|
||||
});
|
||||
cy.get('div.alert').contains('No data');
|
||||
cy.get('div.chart-container').contains('No Results');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -52,7 +52,7 @@
|
|||
"dependencies": {
|
||||
"@babel/runtime-corejs3": "^7.8.4",
|
||||
"@data-ui/sparkline": "^0.0.54",
|
||||
"@superset-ui/chart": "^0.12.8",
|
||||
"@superset-ui/chart": "^0.12.11",
|
||||
"@superset-ui/chart-composition": "^0.12.8",
|
||||
"@superset-ui/color": "^0.12.8",
|
||||
"@superset-ui/connection": "^0.12.8",
|
||||
|
|
|
|||
|
|
@ -383,10 +383,7 @@ class BaseViz:
|
|||
|
||||
df = payload.get("df")
|
||||
if self.status != utils.QueryStatus.FAILED:
|
||||
if df is not None and df.empty:
|
||||
payload["error"] = "No data"
|
||||
else:
|
||||
payload["data"] = self.get_data(df)
|
||||
payload["data"] = self.get_data(df)
|
||||
if "df" in payload:
|
||||
del payload["df"]
|
||||
return payload
|
||||
|
|
@ -651,6 +648,9 @@ class TimeTableViz(BaseViz):
|
|||
return d
|
||||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
fd = self.form_data
|
||||
columns = None
|
||||
values = self.metric_labels
|
||||
|
|
@ -704,6 +704,9 @@ class PivotTableViz(BaseViz):
|
|||
return d
|
||||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
if self.form_data.get("granularity") == "all" and DTTM_ALIAS in df:
|
||||
del df[DTTM_ALIAS]
|
||||
|
||||
|
|
@ -813,6 +816,9 @@ class TreemapViz(BaseViz):
|
|||
return result
|
||||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
df = df.set_index(self.form_data.get("groupby"))
|
||||
chart_data = [
|
||||
{"name": metric, "children": self._nest(metric, df)}
|
||||
|
|
@ -923,6 +929,9 @@ class BoxPlotViz(NVD3Viz):
|
|||
return chart_data
|
||||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
form_data = self.form_data
|
||||
|
||||
# conform to NVD3 names
|
||||
|
|
@ -1010,6 +1019,9 @@ class BubbleViz(NVD3Viz):
|
|||
return d
|
||||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
df["x"] = df[[utils.get_metric_name(self.x_metric)]]
|
||||
df["y"] = df[[utils.get_metric_name(self.y_metric)]]
|
||||
df["size"] = df[[utils.get_metric_name(self.z_metric)]]
|
||||
|
|
@ -1178,7 +1190,7 @@ class NVD3TimeSeriesViz(NVD3Viz):
|
|||
chart_data.append(d)
|
||||
return chart_data
|
||||
|
||||
def process_data(self, df, aggregate=False):
|
||||
def process_data(self, df: pd.DataFrame, aggregate: bool = False) -> VizData:
|
||||
fd = self.form_data
|
||||
if fd.get("granularity") == "all":
|
||||
raise Exception(_("Pick a time granularity for your time series"))
|
||||
|
|
@ -1403,6 +1415,9 @@ class NVD3DualLineViz(NVD3Viz):
|
|||
return chart_data
|
||||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
fd = self.form_data
|
||||
|
||||
if self.form_data.get("granularity") == "all":
|
||||
|
|
@ -1439,6 +1454,9 @@ class NVD3TimePivotViz(NVD3TimeSeriesViz):
|
|||
return d
|
||||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
fd = self.form_data
|
||||
df = self.process_data(df)
|
||||
freq = to_offset(fd.get("freq"))
|
||||
|
|
@ -1497,6 +1515,8 @@ class DistributionPieViz(NVD3Viz):
|
|||
is_timeseries = False
|
||||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
if df.empty:
|
||||
return None
|
||||
metric = self.metric_labels[0]
|
||||
df = df.pivot_table(index=self.groupby, values=[metric])
|
||||
df.sort_values(by=metric, ascending=False, inplace=True)
|
||||
|
|
@ -1538,6 +1558,9 @@ class HistogramViz(BaseViz):
|
|||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
"""Returns the chart data"""
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
chart_data = []
|
||||
if len(self.groupby) > 0:
|
||||
groups = df.groupby(self.groupby)
|
||||
|
|
@ -1578,6 +1601,9 @@ class DistributionBarViz(DistributionPieViz):
|
|||
return d
|
||||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
fd = self.form_data
|
||||
metrics = self.metric_labels
|
||||
columns = fd.get("columns") or []
|
||||
|
|
@ -1744,6 +1770,9 @@ class ChordViz(BaseViz):
|
|||
return qry
|
||||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
df.columns = ["source", "target", "value"]
|
||||
|
||||
# Preparing a symetrical matrix like d3.chords calls for
|
||||
|
|
@ -1907,7 +1936,7 @@ class IFrameViz(BaseViz):
|
|||
return pd.DataFrame()
|
||||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
return {}
|
||||
return {"iframe": True}
|
||||
|
||||
|
||||
class ParallelCoordinatesViz(BaseViz):
|
||||
|
|
@ -1956,6 +1985,9 @@ class HeatmapViz(BaseViz):
|
|||
return d
|
||||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
fd = self.form_data
|
||||
x = fd.get("all_columns_x")
|
||||
y = fd.get("all_columns_y")
|
||||
|
|
@ -2065,6 +2097,7 @@ class MapboxViz(BaseViz):
|
|||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
fd = self.form_data
|
||||
label_col = fd.get("mapbox_label")
|
||||
has_custom_metric = label_col is not None and len(label_col) > 0
|
||||
|
|
@ -2546,6 +2579,9 @@ class DeckArc(BaseDeckGLViz):
|
|||
}
|
||||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
d = super().get_data(df)
|
||||
|
||||
return {
|
||||
|
|
@ -2607,6 +2643,10 @@ class PairedTTestViz(BaseViz):
|
|||
], ...
|
||||
}
|
||||
"""
|
||||
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
fd = self.form_data
|
||||
groups = fd.get("groupby")
|
||||
metrics = self.metric_labels
|
||||
|
|
@ -2647,6 +2687,9 @@ class RoseViz(NVD3TimeSeriesViz):
|
|||
is_timeseries = True
|
||||
|
||||
def get_data(self, df: pd.DataFrame) -> VizData:
|
||||
if df.empty:
|
||||
return None
|
||||
|
||||
data = super().get_data(df)
|
||||
result: Dict = {}
|
||||
for datum in data: # type: ignore
|
||||
|
|
|
|||
|
|
@ -875,7 +875,7 @@ class CoreTests(SupersetTestCase):
|
|||
rendered_query = str(table.get_from_clause())
|
||||
self.assertEqual(clean_query, rendered_query)
|
||||
|
||||
def test_slice_payload_no_data(self):
|
||||
def test_slice_payload_no_results(self):
|
||||
self.login(username="admin")
|
||||
slc = self.get_slice("Girls", db.session)
|
||||
json_endpoint = "/superset/explore_json/"
|
||||
|
|
@ -895,7 +895,7 @@ class CoreTests(SupersetTestCase):
|
|||
)
|
||||
data = self.get_json_resp(json_endpoint, {"form_data": json.dumps(form_data)})
|
||||
self.assertEqual(data["status"], utils.QueryStatus.SUCCESS)
|
||||
self.assertEqual(data["error"], "No data")
|
||||
self.assertEqual(data["error"], None)
|
||||
|
||||
def test_slice_payload_invalid_query(self):
|
||||
self.login(username="admin")
|
||||
|
|
|
|||
Loading…
Reference in New Issue