Merge pull request #4844 from appsmithorg/FIX/3899-typeerror-in-custom-chart

FIX #3899 : added supported custom chart types list, validate chart t…
This commit is contained in:
Somangshu Goswami 2021-06-08 18:12:00 +05:30 committed by GitHub
commit ebacb9e11d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 78 deletions

View File

@ -0,0 +1,64 @@
export const CUSTOM_CHART_TYPES = [
"column2d",
"column3d",
"line",
"area",
"bar2d",
"bar3d",
"pie2d",
"pie3d",
"doughnut2d",
"doughnut3d",
"pareto2d",
"pareto3d",
"scrollcombidy2d",
"scrollcombi2d",
"scrollstackedcolumn2d",
"scrollmsstackedcolumn2d",
"scrollmsstackedcolumn2dlinedy",
"scrollstackedbar2d",
"scrollarea2d",
"scrollline2d",
"scrollcolumn2d",
"scrollbar2d",
"bubble",
"scatter",
"msstackedcolumn2d",
"stackedarea2d",
"stackedbar3d",
"stackedbar2d",
"stackedcolumn3d",
"stackedcolumn2d",
"msstackedcolumn2dlinedy",
"stackedcolumn3dlinedy",
"mscolumn3dlinedy",
"mscombidy2d",
"mscombidy3d",
"stackedcolumn3dline",
"stackedcolumn2dline",
"mscolumnline3d",
"mscombi3d",
"mscombi2d",
"marimekko",
"msarea",
"msbar3d",
"msbar2d",
"msline",
"mscolumn3d",
"mscolumn2d",
"spline",
"splinearea",
"msspline",
"mssplinedy",
"mssplinearea",
"stackedcolumn2dlinedy",
"stackedarea2dlinedy",
];
export const CUSTOM_CHART_DEFAULT_PARSED = {
type: "",
dataSource: {
chart: {},
data: [],
},
};

View File

@ -126,7 +126,7 @@ describe("Chart Custom Config validator", () => {
const cases = [
{
input: {
type: "area2d",
type: "area",
dataSource: {
chart: {
caption: "Countries With Most Oil Reserves [2017-18]",
@ -175,7 +175,7 @@ describe("Chart Custom Config validator", () => {
output: {
isValid: true,
parsed: {
type: "area2d",
type: "area",
dataSource: {
chart: {
caption: "Countries With Most Oil Reserves [2017-18]",
@ -222,7 +222,7 @@ describe("Chart Custom Config validator", () => {
},
transformed: {
type: "area2d",
type: "area",
dataSource: {
chart: {
caption: "Countries With Most Oil Reserves [2017-18]",
@ -310,83 +310,14 @@ describe("Chart Custom Config validator", () => {
},
},
output: {
isValid: true,
isValid: false,
message:
'This value does not evaluate to type "{type: string, dataSource: { chart: object, data: Array<{label: string, value: number}>}}"',
parsed: {
type: "area2d",
type: "",
dataSource: {
data: [
{
label: "Venezuela",
value: "290",
},
{
label: "Saudi",
value: "260",
},
{
label: "Canada",
value: "180",
},
{
label: "Iran",
value: "140",
},
{
label: "Russia",
value: "115",
},
{
label: "UAE",
value: "100",
},
{
label: "US",
value: "30",
},
{
label: "China",
value: "30",
},
],
},
},
transformed: {
type: "area2d",
dataSource: {
data: [
{
label: "Venezuela",
value: "290",
},
{
label: "Saudi",
value: "260",
},
{
label: "Canada",
value: "180",
},
{
label: "Iran",
value: "140",
},
{
label: "Russia",
value: "115",
},
{
label: "UAE",
value: "100",
},
{
label: "US",
value: "30",
},
{
label: "China",
value: "30",
},
],
chart: {},
data: [],
},
},
},

View File

@ -7,6 +7,7 @@ import {
import { DataTree } from "../entities/DataTree/dataTreeFactory";
import _, {
every,
indexOf,
isBoolean,
isNil,
isNumber,
@ -18,6 +19,10 @@ import _, {
toString,
} from "lodash";
import { WidgetProps } from "../widgets/BaseWidget";
import {
CUSTOM_CHART_TYPES,
CUSTOM_CHART_DEFAULT_PARSED,
} from "../constants/CustomChartConstants";
import moment from "moment";
export function validateDateString(
@ -416,6 +421,15 @@ export const VALIDATORS: Record<VALIDATION_TYPES, Validator> = {
message: `${WIDGET_TYPE_VALIDATION_ERROR} "{type: string, dataSource: { chart: object, data: Array<{label: string, value: number}>}}"`,
};
}
// check custom chart exist or not
const typeExist = indexOf(CUSTOM_CHART_TYPES, parsed.type) !== -1;
if (!typeExist) {
return {
isValid: false,
parsed: { ...CUSTOM_CHART_DEFAULT_PARSED },
message: `${WIDGET_TYPE_VALIDATION_ERROR} "{type: string, dataSource: { chart: object, data: Array<{label: string, value: number}>}}"`,
};
}
return { isValid, parsed, transformed: parsed };
},
[VALIDATION_TYPES.MARKERS]: (