Skip to content

Autocomplete Input resize & Calendar Bugfix #693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix:when using an external data source
  • Loading branch information
freddysundowner committed Feb 15, 2024
commit a314784bb616482224f67f7b6915d8694259b19b
71 changes: 56 additions & 15 deletions client/packages/lowcoder/src/comps/generators/uiCompBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,36 @@ 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 extends Record<string, Comp<unknown>>> = ChildrenCompMap & {
hidden: InstanceType<typeof BoolCodeControl>;
};
export type NewChildren<ChildrenCompMap extends Record<string, Comp<unknown>>> =
ChildrenCompMap & {
hidden: InstanceType<typeof BoolCodeControl>;
};

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}</>;
} else {
return (
<>
{props.hidden ? (
<div style={{ opacity: "50%", width: "100%", height: "100%" }}>{props.children}</div>
<div style={{ opacity: "50%", width: "100%", height: "100%" }}>
{props.children}
</div>
) : (
<>{props.children}</>
)}
Expand All @@ -40,7 +50,9 @@ export function HidableView(props: { children: JSX.Element | React.ReactNode; hi
}
}

export function uiChildren<ChildrenCompMap extends Record<string, Comp<unknown>>>(
export function uiChildren<
ChildrenCompMap extends Record<string, Comp<unknown>>,
>(
childrenMap: ToConstructor<ChildrenCompMap>
): ToConstructor<NewChildren<ChildrenCompMap>> {
return { ...childrenMap, hidden: BoolCodeControl } as any;
Expand All @@ -51,12 +63,17 @@ type ViewReturn = ReactNode;
/**
* UI components can be constructed with this class, providing the hidden interface
*/
export class UICompBuilder<ChildrenCompMap extends Record<string, Comp<unknown>>> {
export class UICompBuilder<
ChildrenCompMap extends Record<string, Comp<unknown>>,
> {
private childrenMap: ToConstructor<ChildrenCompMap>;
private viewFn: ViewFnTypeForComp<ViewReturn, NewChildren<ChildrenCompMap>>;
private propertyViewFn: PropertyViewFnTypeForComp<NewChildren<ChildrenCompMap>> = () => null;
private propertyViewFn: PropertyViewFnTypeForComp<
NewChildren<ChildrenCompMap>
> = () => null;
private stateConfigs: ExposingConfig<ChildrenToComp<ChildrenCompMap>>[] = [];
private methodConfigs: MethodConfigsType<ExposeMethodCompConstructor<any>> = [];
private methodConfigs: MethodConfigsType<ExposeMethodCompConstructor<any>> =
[];

/**
* If viewFn is not placed in the constructor, the type of ViewReturn cannot be inferred
Expand All @@ -69,18 +86,24 @@ export class UICompBuilder<ChildrenCompMap extends Record<string, Comp<unknown>>
this.viewFn = viewFn;
}

setPropertyViewFn(propertyViewFn: PropertyViewFnTypeForComp<NewChildren<ChildrenCompMap>>) {
setPropertyViewFn(
propertyViewFn: PropertyViewFnTypeForComp<NewChildren<ChildrenCompMap>>
) {
this.propertyViewFn = propertyViewFn;
return this;
}

setExposeStateConfigs(configs: ExposingConfig<ChildrenToComp<ChildrenCompMap>>[]) {
setExposeStateConfigs(
configs: ExposingConfig<ChildrenToComp<ChildrenCompMap>>[]
) {
this.stateConfigs = configs;
return this;
}

setExposeMethodConfigs(
configs: MethodConfigsType<ExposeMethodCompConstructor<MultiBaseComp<ChildrenCompMap>>>
configs: MethodConfigsType<
ExposeMethodCompConstructor<MultiBaseComp<ChildrenCompMap>>
>
) {
this.methodConfigs = configs;
return this;
Expand Down Expand Up @@ -113,14 +136,18 @@ export class UICompBuilder<ChildrenCompMap extends Record<string, Comp<unknown>>
}

override getPropertyView(): ReactNode {
return <PropertyView comp={this} propertyViewFn={builder.propertyViewFn} />;
return (
<PropertyView comp={this} propertyViewFn={builder.propertyViewFn} />
);
}
}

return withExposingConfigs(
withMethodExposing(
MultiTempComp,
this.methodConfigs as MethodConfigsType<ExposeMethodCompConstructor<MultiTempComp>>
this.methodConfigs as MethodConfigsType<
ExposeMethodCompConstructor<MultiTempComp>
>
) as typeof MultiTempComp,
this.stateConfigs
);
Expand All @@ -134,12 +161,26 @@ export const DisabledContext = React.createContext<boolean>(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 (
<HidableView hidden={childrenProps.hidden as boolean}>
{props.viewFn(childrenProps, comp.dispatch)}
Expand Down