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:
commit
ebacb9e11d
64
app/client/src/constants/CustomChartConstants.ts
Normal file
64
app/client/src/constants/CustomChartConstants.ts
Normal 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: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
@ -126,7 +126,7 @@ describe("Chart Custom Config validator", () => {
|
||||||
const cases = [
|
const cases = [
|
||||||
{
|
{
|
||||||
input: {
|
input: {
|
||||||
type: "area2d",
|
type: "area",
|
||||||
dataSource: {
|
dataSource: {
|
||||||
chart: {
|
chart: {
|
||||||
caption: "Countries With Most Oil Reserves [2017-18]",
|
caption: "Countries With Most Oil Reserves [2017-18]",
|
||||||
|
|
@ -175,7 +175,7 @@ describe("Chart Custom Config validator", () => {
|
||||||
output: {
|
output: {
|
||||||
isValid: true,
|
isValid: true,
|
||||||
parsed: {
|
parsed: {
|
||||||
type: "area2d",
|
type: "area",
|
||||||
dataSource: {
|
dataSource: {
|
||||||
chart: {
|
chart: {
|
||||||
caption: "Countries With Most Oil Reserves [2017-18]",
|
caption: "Countries With Most Oil Reserves [2017-18]",
|
||||||
|
|
@ -222,7 +222,7 @@ describe("Chart Custom Config validator", () => {
|
||||||
},
|
},
|
||||||
|
|
||||||
transformed: {
|
transformed: {
|
||||||
type: "area2d",
|
type: "area",
|
||||||
dataSource: {
|
dataSource: {
|
||||||
chart: {
|
chart: {
|
||||||
caption: "Countries With Most Oil Reserves [2017-18]",
|
caption: "Countries With Most Oil Reserves [2017-18]",
|
||||||
|
|
@ -310,83 +310,14 @@ describe("Chart Custom Config validator", () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
output: {
|
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: {
|
parsed: {
|
||||||
type: "area2d",
|
type: "",
|
||||||
dataSource: {
|
dataSource: {
|
||||||
data: [
|
chart: {},
|
||||||
{
|
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",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import {
|
||||||
import { DataTree } from "../entities/DataTree/dataTreeFactory";
|
import { DataTree } from "../entities/DataTree/dataTreeFactory";
|
||||||
import _, {
|
import _, {
|
||||||
every,
|
every,
|
||||||
|
indexOf,
|
||||||
isBoolean,
|
isBoolean,
|
||||||
isNil,
|
isNil,
|
||||||
isNumber,
|
isNumber,
|
||||||
|
|
@ -18,6 +19,10 @@ import _, {
|
||||||
toString,
|
toString,
|
||||||
} from "lodash";
|
} from "lodash";
|
||||||
import { WidgetProps } from "../widgets/BaseWidget";
|
import { WidgetProps } from "../widgets/BaseWidget";
|
||||||
|
import {
|
||||||
|
CUSTOM_CHART_TYPES,
|
||||||
|
CUSTOM_CHART_DEFAULT_PARSED,
|
||||||
|
} from "../constants/CustomChartConstants";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
|
|
||||||
export function validateDateString(
|
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}>}}"`,
|
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 };
|
return { isValid, parsed, transformed: parsed };
|
||||||
},
|
},
|
||||||
[VALIDATION_TYPES.MARKERS]: (
|
[VALIDATION_TYPES.MARKERS]: (
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user