PromucFlow_constructor/app/client/src/widgets/DatePickerWidget.tsx

67 lines
2.1 KiB
TypeScript
Raw Normal View History

2019-09-12 08:11:25 +00:00
import React from "react";
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
2019-11-25 05:07:27 +00:00
import { WidgetType } from "constants/WidgetConstants";
import { ActionPayload } from "constants/ActionConstants";
import DatePickerComponent from "components/designSystems/blueprint/DatePickerComponent";
2019-11-22 13:12:39 +00:00
import { WidgetPropertyValidationType } from "utils/ValidationFactory";
import { VALIDATION_TYPES } from "constants/WidgetValidation";
2019-09-12 08:11:25 +00:00
class DatePickerWidget extends BaseWidget<DatePickerWidgetProps, WidgetState> {
2019-11-22 13:12:39 +00:00
static getPropertyValidationMap(): WidgetPropertyValidationType {
return {
defaultDate: VALIDATION_TYPES.DATE,
selectedDate: VALIDATION_TYPES.DATE,
timezone: VALIDATION_TYPES.TEXT,
enableTimePicker: VALIDATION_TYPES.BOOLEAN,
dateFormat: VALIDATION_TYPES.TEXT,
label: VALIDATION_TYPES.TEXT,
datePickerType: VALIDATION_TYPES.TEXT,
maxDate: VALIDATION_TYPES.DATE,
minDate: VALIDATION_TYPES.DATE,
};
}
2019-09-12 08:11:25 +00:00
getPageView() {
2019-11-06 12:12:41 +00:00
return (
<DatePickerComponent
label={this.props.label}
dateFormat={this.props.dateFormat}
widgetId={this.props.widgetId}
2019-11-12 07:57:12 +00:00
timezone={this.props.timezone}
2019-11-06 12:12:41 +00:00
enableTimePicker={this.props.enableTimePicker}
defaultDate={this.props.defaultDate}
datePickerType={"DATE_PICKER"}
onDateSelected={this.onDateSelected}
selectedDate={this.props.selectedDate}
2019-12-03 04:41:10 +00:00
isLoading={this.props.isLoading}
2019-11-06 12:12:41 +00:00
/>
);
2019-09-12 08:11:25 +00:00
}
2019-11-06 12:12:41 +00:00
onDateSelected = (selectedDate: Date) => {
this.updateWidgetProperty("selectedDate", selectedDate);
2019-11-06 12:12:41 +00:00
super.executeAction(this.props.onDateSelected);
};
2019-09-12 08:11:25 +00:00
getWidgetType(): WidgetType {
return "DATE_PICKER_WIDGET";
}
}
export type DatePickerType = "DATE_PICKER" | "DATE_RANGE_PICKER";
2019-09-12 08:11:25 +00:00
export interface DatePickerWidgetProps extends WidgetProps {
defaultDate?: Date;
2019-11-06 12:12:41 +00:00
selectedDate: Date;
2019-11-12 07:57:12 +00:00
timezone?: string;
2019-11-06 12:12:41 +00:00
enableTimePicker: boolean;
dateFormat: string;
label: string;
datePickerType: DatePickerType;
onDateSelected: ActionPayload[];
onDateRangeSelected: ActionPayload[];
2019-11-06 12:12:41 +00:00
maxDate: Date;
minDate: Date;
2019-09-12 08:11:25 +00:00
}
export default DatePickerWidget;