Skip to content

Commit bc1a717

Browse files
refactor(embedding): refactoring embedding
1 parent 7e9fb00 commit bc1a717

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

superset-embedded-sdk/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ export type EmbeddedDashboard = {
8989
observeDataMask: (
9090
callbackFn: ObserveDataMaskCallbackFn,
9191
) => void;
92-
getDataMask: () => Record<string, any>;
92+
getDataMask: () => Promise<Record<string, any>>;
93+
getChartStates: () => Promise<Record<string, any>>;
9394
setThemeConfig: (themeConfig: Record<string, any>) => void;
9495
};
9596

@@ -244,6 +245,7 @@ export async function embedDashboard({
244245
ourPort.get<string>('getDashboardPermalink', { anchor });
245246
const getActiveTabs = () => ourPort.get<string[]>('getActiveTabs');
246247
const getDataMask = () => ourPort.get<Record<string, any>>('getDataMask');
248+
const getChartStates = () => ourPort.get<Record<string, any>>('getChartStates');
247249
const observeDataMask = (
248250
callbackFn: ObserveDataMaskCallbackFn,
249251
) => {
@@ -270,6 +272,7 @@ export async function embedDashboard({
270272
getActiveTabs,
271273
observeDataMask,
272274
getDataMask,
275+
getChartStates,
273276
setThemeConfig
274277
};
275278
}

superset/views/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ def dashboard_permalink(
826826
# native_filters doesnt need to be encoded here
827827
url = f"{url}&native_filters={param_val}"
828828
else:
829-
params = parse.urlencode([param_key, param_val]) # type: ignore
829+
params = parse.urlencode([(param_key, param_val)])
830830
url = f"{url}&{params}"
831831
if original_params := request.query_string.decode():
832832
url = f"{url}&{original_params}"

tests/integration_tests/sqla_models_tests.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,15 +1153,13 @@ def test_generic_metric_filtering_without_chart_flag(login_as_admin):
11531153
database=database,
11541154
)
11551155

1156-
# Add column
11571156
col = TableColumn(
11581157
column_name="name",
11591158
type="VARCHAR(255)",
11601159
table=table,
11611160
)
11621161
table.columns = [col]
11631162

1164-
# Add metric
11651163
metric = SqlMetric(
11661164
metric_name="count",
11671165
expression="COUNT(*)",
@@ -1173,7 +1171,6 @@ def test_generic_metric_filtering_without_chart_flag(login_as_admin):
11731171
db.session.commit()
11741172

11751173
try:
1176-
# Query with metric filter and NO is_ag_grid_chart flag
11771174
query_obj = {
11781175
"granularity": None,
11791176
"from_dttm": None,
@@ -1182,22 +1179,20 @@ def test_generic_metric_filtering_without_chart_flag(login_as_admin):
11821179
"metrics": ["count"],
11831180
"filter": [
11841181
{
1185-
"col": "count", # Filter on metric
1182+
"col": "count",
11861183
"op": ">",
11871184
"val": 0,
11881185
}
11891186
],
11901187
"is_timeseries": False,
1191-
"extras": {}, # No chart-specific flags
1188+
"extras": {},
11921189
}
11931190

1194-
# This should not raise an error
11951191
sqla_query = table.get_sqla_query(**query_obj)
11961192
sql = str(
11971193
sqla_query.sqla_query.compile(compile_kwargs={"literal_binds": True})
11981194
).lower()
11991195

1200-
# Verify HAVING clause is used
12011196
assert "having" in sql, "Metric filter should use HAVING clause. SQL: " + sql
12021197
finally:
12031198
db.session.delete(table)
@@ -1221,12 +1216,10 @@ def test_column_ordering_without_chart_flag(login_as_admin):
12211216
database=database,
12221217
)
12231218

1224-
# Add columns
12251219
col_a = TableColumn(column_name="col_a", type="VARCHAR(255)", table=table)
12261220
col_b = TableColumn(column_name="col_b", type="VARCHAR(255)", table=table)
12271221
table.columns = [col_a, col_b]
12281222

1229-
# Add metrics
12301223
metric_x = SqlMetric(metric_name="metric_x", expression="COUNT(*)", table=table)
12311224
metric_y = SqlMetric(metric_name="metric_y", expression="SUM(val)", table=table)
12321225
table.metrics = [metric_x, metric_y]
@@ -1235,7 +1228,6 @@ def test_column_ordering_without_chart_flag(login_as_admin):
12351228
db.session.commit()
12361229

12371230
try:
1238-
# Mock the database response with columns in one order
12391231
mock_df = pd.DataFrame(
12401232
{
12411233
"col_a": [1, 2],
@@ -1261,15 +1253,11 @@ def mock_get_df(sql, catalog=None, schema=None, mutator=None):
12611253
"metrics": ["metric_x", "metric_y"],
12621254
"filter": [],
12631255
"is_timeseries": False,
1264-
"extras": {
1265-
# Specify custom column order (no chart-specific flags)
1266-
"column_order": ["metric_y", "col_b", "metric_x", "col_a"]
1267-
},
1256+
"extras": {"column_order": ["metric_y", "col_b", "metric_x", "col_a"]},
12681257
}
12691258

12701259
result = table.query(query_obj)
12711260

1272-
# Verify columns are reordered
12731261
expected_order = ["metric_y", "col_b", "metric_x", "col_a"]
12741262
assert list(result.df.columns) == expected_order, (
12751263
f"Expected {expected_order}, got {list(result.df.columns)}"

0 commit comments

Comments
 (0)