feat: save active tabs in dashboard permalink (#19983)

This commit is contained in:
Jesse Yang
2022-06-29 09:43:52 -07:00
committed by GitHub
parent c5d3678a31
commit cadd259788
17 changed files with 274 additions and 103 deletions

View File

@@ -50,10 +50,15 @@ export function parseErrorJson(responseObject: JsonObject): ClientErrorObject {
}
// Marshmallow field validation returns the error mssage in the format
// of { message: { field1: [msg1, msg2], field2: [msg], } }
if (error.message && typeof error.message === 'object' && !error.error) {
error.error =
Object.values(error.message as Record<string, string[]>)[0]?.[0] ||
t('Invalid input');
if (!error.error && error.message) {
if (typeof error.message === 'object') {
error.error =
Object.values(error.message as Record<string, string[]>)[0]?.[0] ||
t('Invalid input');
}
if (typeof error.message === 'string') {
error.error = error.message;
}
}
if (error.stack) {
error = {

View File

@@ -19,7 +19,6 @@
import { JsonObject, QueryFormData, SupersetClient } from '@superset-ui/core';
import rison from 'rison';
import { isEmpty } from 'lodash';
import { getClientErrorObject } from './getClientErrorObject';
import {
RESERVED_CHART_URL_PARAMS,
RESERVED_DASHBOARD_URL_PARAMS,
@@ -96,7 +95,7 @@ function getUrlParams(excludedParams: string[]): URLSearchParams {
return urlParams;
}
type UrlParamEntries = [string, string][];
export type UrlParamEntries = [string, string][];
function getUrlParamEntries(urlParams: URLSearchParams): UrlParamEntries {
const urlEntries: [string, string][] = [];
@@ -134,14 +133,7 @@ function getPermalink(endpoint: string, jsonPayload: JsonObject) {
return SupersetClient.post({
endpoint,
jsonPayload,
})
.then(result => result.json.url as string)
.catch(response =>
// @ts-ignore
getClientErrorObject(response).then(({ error, statusText }) =>
Promise.reject(error || statusText),
),
);
}).then(result => result.json.url as string);
}
export function getChartPermalink(
@@ -156,17 +148,30 @@ export function getChartPermalink(
export function getDashboardPermalink({
dashboardId,
filterState,
hash, // the anchor part of the link which corresponds to the tab/chart id
dataMask,
activeTabs,
anchor, // the anchor part of the link which corresponds to the tab/chart id
}: {
dashboardId: string | number;
filterState: JsonObject;
hash?: string;
/**
* Current applied data masks (for native filters).
*/
dataMask: JsonObject;
/**
* Current active tabs in the dashboard.
*/
activeTabs: string[];
/**
* The "anchor" component for the permalink. It will be scrolled into view
* and highlighted upon page load.
*/
anchor?: string;
}) {
// only encode filter box state if non-empty
return getPermalink(`/api/v1/dashboard/${dashboardId}/permalink`, {
filterState,
urlParams: getDashboardUrlParams(),
hash,
dataMask,
activeTabs,
anchor,
});
}