From 984dce88d4c6eca67ebc913d8e80ef07fd3efd55 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Fri, 10 Mar 2023 18:56:36 -0600 Subject: [PATCH] Starting support for timeframe=custom --- src/qqq/components/widgets/Widget.tsx | 25 ++++- .../widgets/components/DropdownMenu.tsx | 93 +++++++++++++++++-- 2 files changed, 109 insertions(+), 9 deletions(-) diff --git a/src/qqq/components/widgets/Widget.tsx b/src/qqq/components/widgets/Widget.tsx index cd24a89..0a1b463 100644 --- a/src/qqq/components/widgets/Widget.tsx +++ b/src/qqq/components/widgets/Widget.tsx @@ -130,6 +130,7 @@ function Widget(props: React.PropsWithChildren): JSX.Element const navigate = useNavigate(); const [dropdownData, setDropdownData] = useState([]); const [counter, setCounter] = useState(0); + const [fullScreenWidgetClassName, setFullScreenWidgetClassName] = useState(""); function openEditForm(table: QTableMetaData, id: any = null, defaultValues: any, disabledFields: any) { @@ -175,6 +176,7 @@ function Widget(props: React.PropsWithChildren): JSX.Element return ( ): JSX.Element } }, [counter]); + const toggleFullScreenWidget = () => + { + if(fullScreenWidgetClassName) + { + setFullScreenWidgetClassName(""); + } + else + { + setFullScreenWidgetClassName("fullScreenWidget"); + } + } + const hasPermission = props.widgetData?.hasPermission === undefined || props.widgetData?.hasPermission === true; const widgetContent = @@ -336,17 +350,22 @@ function Widget(props: React.PropsWithChildren): JSX.Element // first look for a label in the widget data, which would override that in the metadata // ////////////////////////////////////////////////////////////////////////////////////////// hasPermission && props.widgetData?.label? ( - + {props.widgetData.label} ) : ( hasPermission && props.widgetMetaData?.label && ( - + {props.widgetMetaData.label} ) ) } + {/* + + */} { hasPermission && ( props.labelAdditionalComponentsLeft.map((component, i) => @@ -384,7 +403,7 @@ function Widget(props: React.PropsWithChildren): JSX.Element } ; - return props.widgetMetaData?.isCard ? {widgetContent} : widgetContent; + return props.widgetMetaData?.isCard ? {widgetContent} : widgetContent; } export default Widget; diff --git a/src/qqq/components/widgets/components/DropdownMenu.tsx b/src/qqq/components/widgets/components/DropdownMenu.tsx index 48ba447..d5ce522 100644 --- a/src/qqq/components/widgets/components/DropdownMenu.tsx +++ b/src/qqq/components/widgets/components/DropdownMenu.tsx @@ -19,10 +19,14 @@ * along with this program. If not, see . */ -import {Theme} from "@mui/material"; +import {Collapse, Theme} from "@mui/material"; import Autocomplete from "@mui/material/Autocomplete"; +import Box from "@mui/material/Box"; import TextField from "@mui/material/TextField"; import {SxProps} from "@mui/system"; +import {Field, Form, Formik, useFormik} from "formik"; +import React, {useState} from "react"; +import MDInput from "qqq/components/legacy/MDInput"; export interface DropdownOption @@ -36,6 +40,7 @@ export interface DropdownOption ///////////////////////// interface Props { + name: string; defaultValue?: any; label?: string; dropdownOptions?: DropdownOption[]; @@ -43,23 +48,98 @@ interface Props sx?: SxProps; } -function DropdownMenu({defaultValue, label, dropdownOptions, onChangeCallback, sx}: Props): JSX.Element +function parseCustomTimeValuesFromDefaultValue(defaultValue: any): any { + const customTimeValues: { [key: string]: string } = {}; + if(defaultValue && defaultValue.id) + { + var parts = defaultValue.id.split(","); + if(parts.length >= 2) + { + customTimeValues["startDate"] = parts[1]; + } + if(parts.length >= 3) + { + customTimeValues["endDate"] = parts[2]; + } + } + + return (customTimeValues); +} + +function DropdownMenu({name, defaultValue, label, dropdownOptions, onChangeCallback, sx}: Props): JSX.Element +{ + const [customTimesVisible, setCustomTimesVisible] = useState(defaultValue && defaultValue.id && defaultValue.id.startsWith("custom,")); + const [customTimeValues, setCustomTimeValues] = useState(parseCustomTimeValuesFromDefaultValue(defaultValue) as any); + const handleOnChange = (event: any, newValue: any, reason: string) => { - onChangeCallback(label, newValue); + const isTimeframeCustom = name == "timeframe" && newValue && newValue.id == "custom" + setCustomTimesVisible(isTimeframeCustom); + + if(isTimeframeCustom) + { + callOnChangeCallbackIfCustomTimeframeHasDateValues(); + } + else + { + onChangeCallback(label, newValue); + } + }; + + const callOnChangeCallbackIfCustomTimeframeHasDateValues = () => + { + if(customTimeValues["startDate"] && customTimeValues["endDate"]) + { + onChangeCallback(label, {id: `custom,${customTimeValues["startDate"]},${customTimeValues["endDate"]}`, label: "Custom"}); + } + } + + let customTimes = <>; + if (name == "timeframe") + { + const handleSubmit = async (values: any, actions: any) => + { + }; + + const dateChanged = (fieldName: string, event: any) => + { + console.log(event.target.value); + customTimeValues[fieldName] = event.target.value; + console.log(customTimeValues); + + callOnChangeCallbackIfCustomTimeframeHasDateValues(); + }; + + customTimes = + + + {({ + values, + errors, + touched, + isSubmitting, + }) => ( +
+ dateChanged("startDate", event)} /> + dateChanged("endDate", event)} /> + + )} +
+
+
; } return ( dropdownOptions ? ( - + option.id === value.id} renderInput={(params: any) => } @@ -67,9 +147,10 @@ function DropdownMenu({defaultValue, label, dropdownOptions, onChangeCallback, s
  • {option.label}
  • )} /> + {customTimes}
    ) : null - ) + ); } export default DropdownMenu;