PromucFlow_constructor/app/client/src/widgets/ChartWidget/index.tsx

107 lines
2.9 KiB
TypeScript
Raw Normal View History

import React, { lazy, Suspense } from "react";
import BaseWidget, { WidgetProps, WidgetState } from "widgets/BaseWidget";
import { WidgetType } from "constants/WidgetConstants";
import Skeleton from "components/utils/Skeleton";
import * as Sentry from "@sentry/react";
import { retryPromise } from "utils/AppsmithUtils";
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
import withMeta, { WithMeta } from "widgets/MetaHOC";
import propertyConfig from "widgets/ChartWidget/propertyConfig";
import { CustomFusionChartConfig } from "components/designSystems/appsmith/ChartComponent";
const ChartComponent = lazy(() =>
retryPromise(() =>
import(
/* webpackPrefetch: true, webpackChunkName: "charts" */ "components/designSystems/appsmith/ChartComponent"
),
),
);
class ChartWidget extends BaseWidget<ChartWidgetProps, WidgetState> {
List Widget Phase 2 (#4189) * update meta properties + default properties map * update widget registery * update get meta property * update metahoc + widgetfactory + data tree evaluator * try sending function as string to worker * revert data tree evaluator update * pass default props map from dataTreeWidget file * wip * save child meta properties * remove console.log * save meta and default map in list * update listwidget * remove console.log + unused variables * revert getMetaPropertiesMap function * fix data tree test * fix list widget test * fix entity definition test * fix overriting of item in updatedItems * remove todo comments * fix meta prop issue * revert making meta properties from undefiend to "" & fix filepicker bug * fix test case * change items to listData and updatedItems to items * remove console.log * fix test * extract derived properties to dervied.js * disabled top, left, right resize handler list widget container * add test for dervied js * add test for selectedItem * fix background color bug on hover * remove console.log * fix chart widget inside list widget * fix checkbox issue + points raised by yogesh * revert the createImmerReducer usage * fix parse derived properties * remove internal props object that fails the test * fix import typo * allow bottom resize handler * fix template height check * fix template height check * update template size check * fix the is visible invalid prop issue * fix migration of list widget phase 2 * fix migration * remove unused import * fix migration * fix migration * remove console.log * hide delete option for container in entity explorer * fix testcases * remove unused import * fix switch widget meta prop Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local>
2021-06-18 07:42:57 +00:00
static getMetaPropertiesMap(): Record<string, any> {
return {
selectedDataPoint: undefined,
};
}
static getPropertyPaneConfig() {
return propertyConfig;
}
onDataPointClick = (selectedDataPoint: { x: any; y: any }) => {
this.props.updateWidgetMetaProperty(
"selectedDataPoint",
selectedDataPoint,
{
2021-04-23 13:50:55 +00:00
triggerPropertyName: "onDataPointClick",
dynamicString: this.props.onDataPointClick,
event: {
type: EventType.ON_DATA_POINT_CLICK,
},
},
);
};
getPageView() {
return (
<Suspense fallback={<Skeleton />}>
<ChartComponent
allowHorizontalScroll={this.props.allowHorizontalScroll}
chartData={this.props.chartData}
chartName={this.props.chartName}
chartType={this.props.chartType}
customFusionChartConfig={this.props.customFusionChartConfig}
isVisible={this.props.isVisible}
key={this.props.widgetId}
onDataPointClick={this.onDataPointClick}
widgetId={this.props.widgetId}
xAxisName={this.props.xAxisName}
yAxisName={this.props.yAxisName}
/>
</Suspense>
);
}
getWidgetType(): WidgetType {
return "CHART_WIDGET";
}
}
export type ChartType =
| "LINE_CHART"
| "BAR_CHART"
| "PIE_CHART"
| "COLUMN_CHART"
| "AREA_CHART"
| "SCATTER_CHART"
| "CUSTOM_FUSION_CHART";
export interface ChartDataPoint {
x: any;
y: any;
}
export interface AllChartData {
[key: string]: ChartData;
}
export interface ChartData {
seriesName?: string;
data: ChartDataPoint[];
}
export interface ChartWidgetProps extends WidgetProps, WithMeta {
chartType: ChartType;
chartData: AllChartData;
customFusionChartConfig: CustomFusionChartConfig;
xAxisName: string;
yAxisName: string;
chartName: string;
isVisible?: boolean;
allowHorizontalScroll: boolean;
onDataPointClick?: string;
selectedDataPoint?: ChartDataPoint;
}
export default ChartWidget;
export const ProfiledChartWidget = Sentry.withProfiler(withMeta(ChartWidget));