feat: Move cross filters to Dashboard (#22785)

This commit is contained in:
Geido
2023-01-25 18:01:06 +01:00
committed by GitHub
parent 262c947273
commit 9ed2326a20
87 changed files with 814 additions and 640 deletions

View File

@@ -41,6 +41,14 @@ interface TimeoutError {
timeout: number;
}
type ErrorType =
| SupersetClientResponse
| TimeoutError
| { response: Response }
| string;
type ErrorTextSource = 'dashboard' | 'chart' | 'query' | 'dataset' | 'database';
export function parseErrorJson(responseObject: JsonObject): ClientErrorObject {
let error = { ...responseObject };
// Backwards compatibility for old error renderers with the new error object
@@ -78,6 +86,29 @@ export function parseErrorJson(responseObject: JsonObject): ClientErrorObject {
return { ...error, error: error.error }; // explicit ClientErrorObject
}
/*
* Utility to get standardized error text for generic update failures
*/
export async function getErrorText(
errorObject: ErrorType,
source: ErrorTextSource,
) {
const { error, message } = await getClientErrorObject(errorObject);
let errorText = t('Sorry, an unknown error occurred.');
if (error) {
errorText = t(
'Sorry, there was an error saving this %s: %s',
source,
error,
);
}
if (typeof message === 'string' && message === 'Forbidden') {
errorText = t('You do not have permission to edit this %s', source);
}
return errorText;
}
export function getClientErrorObject(
response:
| SupersetClientResponse