feat: Setup `supersetText` configuration to overwrite errors (#14256)

* Setup error message overwrite config`

* fix

* bad reabse

* bad rebase 2

* remove unneeded comment

* working dynamic importing

* saveeee

* working textUtil file

* add ignore tslint

* fix linting

* fix linting

* import order

* setup guard statements

* linting again

* linting again

Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
This commit is contained in:
Hugh A. Miles II 2021-04-27 15:03:35 -04:00 committed by GitHub
parent 40fb94dcca
commit 44c09b5383
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 145 additions and 634 deletions

1
.gitignore vendored
View File

@ -54,6 +54,7 @@ envpy3
env36
local_config.py
/superset_config.py
/superset_text.yml
superset.egg-info/
superset/bin/supersetc
tmp

File diff suppressed because it is too large Load Diff

View File

@ -118,6 +118,7 @@
"interweave": "^11.2.0",
"jquery": "^3.5.1",
"js-levenshtein": "^1.1.6",
"js-yaml-loader": "^1.2.2",
"json-bigint": "^1.0.0",
"json-stringify-pretty-compact": "^2.0.0",
"lodash": "^4.17.20",

View File

@ -0,0 +1,33 @@
/* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/* eslint-disable global-require */
const loadModule = () => {
let module;
try {
// @ts-ignore
module = require('../../../superset_text'); // eslint-disable-line import/no-unresolved
} catch (e) {
module = {};
}
return module;
};
const supersetText = loadModule();
export default supersetText;

View File

@ -28,6 +28,7 @@ import Chart from 'src/types/Chart';
import rison from 'rison';
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
import { FetchDataConfig } from 'src/components/ListView';
import SupersetText from 'src/utils/textUtils';
import { Dashboard, Filters, SavedQueryObject } from './types';
const createFetchResourceMethod = (method: string) => (
@ -159,6 +160,19 @@ export function createErrorHandler(
) {
return async (e: SupersetClientResponse | string) => {
const parsedError = await getClientErrorObject(e);
// Taking the first error returned from the API
// @ts-ignore
const errorsArray = parsedError?.errors;
const config = await SupersetText;
if (
errorsArray &&
errorsArray.length &&
config &&
config.ERRORS &&
errorsArray[0].error_type in config.ERRORS
) {
parsedError.message = config.ERRORS[errorsArray[0].error_type];
}
logging.error(e);
handleErrorFunc(parsedError.message || parsedError.error);
};

View File

@ -38,6 +38,7 @@ const packageConfig = require('./package.json');
const APP_DIR = path.resolve(__dirname, './');
// output dir
const BUILD_DIR = path.resolve(__dirname, '../superset/static/assets');
const ROOT_DIR = path.resolve(__dirname, '..');
const {
mode = 'development',
@ -286,7 +287,7 @@ const config = {
},
},
resolve: {
modules: [APP_DIR, 'node_modules'],
modules: [APP_DIR, 'node_modules', ROOT_DIR],
alias: {
'react-dom': '@hot-loader/react-dom',
// Force using absolute import path of some packages in the root node_modules,
@ -304,7 +305,7 @@ const config = {
'./node_modules/@superset-ui/chart-controls',
),
},
extensions: ['.ts', '.tsx', '.js', '.jsx'],
extensions: ['.ts', '.tsx', '.js', '.jsx', '.yml'],
symlinks: false,
},
context: APP_DIR, // to automatically find tsconfig.json
@ -438,6 +439,11 @@ const config = {
esModule: false,
},
},
{
test: /\.ya?ml$/,
include: ROOT_DIR,
loader: 'js-yaml-loader',
},
],
},
externals: {