From ad0d049ed73dde660f109a296d4887f26e247b2c Mon Sep 17 00:00:00 2001 From: freddysundowner Date: Thu, 15 Feb 2024 11:40:52 +0300 Subject: [PATCH 1/4] fix:Date Range Component crashes when we remove Suffix Icon --- client/packages/lowcoder/src/comps/utils/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/packages/lowcoder/src/comps/utils/index.tsx b/client/packages/lowcoder/src/comps/utils/index.tsx index d0ff1dcb6..1dda47b1e 100644 --- a/client/packages/lowcoder/src/comps/utils/index.tsx +++ b/client/packages/lowcoder/src/comps/utils/index.tsx @@ -84,4 +84,4 @@ export function arrayMove(data: Array, start: number, end: number) { return result; } -export const hasIcon = (icon: ReactNode) => (icon as ReactElement).props.value; +export const hasIcon = (icon: ReactNode) => (icon as ReactElement).props?.value; From a314784bb616482224f67f7b6915d8694259b19b Mon Sep 17 00:00:00 2001 From: freddysundowner Date: Thu, 15 Feb 2024 15:13:19 +0300 Subject: [PATCH 2/4] fix:when using an external data source --- .../src/comps/generators/uiCompBuilder.tsx | 71 +++++++++++++++---- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/client/packages/lowcoder/src/comps/generators/uiCompBuilder.tsx b/client/packages/lowcoder/src/comps/generators/uiCompBuilder.tsx index 9cc05a154..bfa0f20cf 100644 --- a/client/packages/lowcoder/src/comps/generators/uiCompBuilder.tsx +++ b/client/packages/lowcoder/src/comps/generators/uiCompBuilder.tsx @@ -12,18 +12,26 @@ import { ToNodeType, ViewFnTypeForComp, } from "./multi"; -import { ChildrenToComp, ExposingConfig, withExposingConfigs } from "./withExposing"; +import { + ChildrenToComp, + ExposingConfig, + withExposingConfigs, +} from "./withExposing"; import { ExposeMethodCompConstructor, MethodConfigsType, withMethodExposing, } from "./withMethodExposing"; -export type NewChildren>> = ChildrenCompMap & { - hidden: InstanceType; -}; +export type NewChildren>> = + ChildrenCompMap & { + hidden: InstanceType; + }; -export function HidableView(props: { children: JSX.Element | React.ReactNode; hidden: boolean }) { +export function HidableView(props: { + children: JSX.Element | React.ReactNode; + hidden: boolean; +}) { const { readOnly } = useContext(ExternalEditorContext); if (readOnly) { return <>{props.children}; @@ -31,7 +39,9 @@ export function HidableView(props: { children: JSX.Element | React.ReactNode; hi return ( <> {props.hidden ? ( -
{props.children}
+
+ {props.children} +
) : ( <>{props.children} )} @@ -40,7 +50,9 @@ export function HidableView(props: { children: JSX.Element | React.ReactNode; hi } } -export function uiChildren>>( +export function uiChildren< + ChildrenCompMap extends Record>, +>( childrenMap: ToConstructor ): ToConstructor> { return { ...childrenMap, hidden: BoolCodeControl } as any; @@ -51,12 +63,17 @@ type ViewReturn = ReactNode; /** * UI components can be constructed with this class, providing the hidden interface */ -export class UICompBuilder>> { +export class UICompBuilder< + ChildrenCompMap extends Record>, +> { private childrenMap: ToConstructor; private viewFn: ViewFnTypeForComp>; - private propertyViewFn: PropertyViewFnTypeForComp> = () => null; + private propertyViewFn: PropertyViewFnTypeForComp< + NewChildren + > = () => null; private stateConfigs: ExposingConfig>[] = []; - private methodConfigs: MethodConfigsType> = []; + private methodConfigs: MethodConfigsType> = + []; /** * If viewFn is not placed in the constructor, the type of ViewReturn cannot be inferred @@ -69,18 +86,24 @@ export class UICompBuilder> this.viewFn = viewFn; } - setPropertyViewFn(propertyViewFn: PropertyViewFnTypeForComp>) { + setPropertyViewFn( + propertyViewFn: PropertyViewFnTypeForComp> + ) { this.propertyViewFn = propertyViewFn; return this; } - setExposeStateConfigs(configs: ExposingConfig>[]) { + setExposeStateConfigs( + configs: ExposingConfig>[] + ) { this.stateConfigs = configs; return this; } setExposeMethodConfigs( - configs: MethodConfigsType>> + configs: MethodConfigsType< + ExposeMethodCompConstructor> + > ) { this.methodConfigs = configs; return this; @@ -113,14 +136,18 @@ export class UICompBuilder> } override getPropertyView(): ReactNode { - return ; + return ( + + ); } } return withExposingConfigs( withMethodExposing( MultiTempComp, - this.methodConfigs as MethodConfigsType> + this.methodConfigs as MethodConfigsType< + ExposeMethodCompConstructor + > ) as typeof MultiTempComp, this.stateConfigs ); @@ -134,12 +161,26 @@ export const DisabledContext = React.createContext(false); */ function UIView(props: { comp: any; viewFn: any }) { const comp = props.comp; + console.log(comp); + + console.log(comp.children); + const childrenProps = childrenToProps(comp.children); const parentDisabled = useContext(DisabledContext); const disabled = childrenProps["disabled"]; if (disabled !== undefined && typeof disabled === "boolean") { childrenProps["disabled"] = disabled || parentDisabled; } + + //ADDED BY FRED + if (childrenProps.events) { + const events = childrenProps.events as { value?: any[] }; + if (!events.value || events.value.length === 0) { + events.value = []; + } + } + //END ADD BY FRED + return (