Skip to content

Upgrade node packages + Optimisations to improve memory consumption #1697

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 23 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
80a2d08
upgrade react-resize-detector, replace ReactResizeDetector comp with …
raheeliftikhar5 Apr 29, 2025
e2a39ef
upgrade react-draggable, added missing nodeRef
raheeliftikhar5 Apr 29, 2025
2130263
replaced react-quill with react-quill-new
raheeliftikhar5 Apr 29, 2025
9ae9a9c
removed react-sortabled-hoc, used dnd-kit for sorting
raheeliftikhar5 Apr 29, 2025
8266951
fix icon comp, icon button when no icon is selected
raheeliftikhar5 Apr 29, 2025
61d5a45
added memoization on table comp
raheeliftikhar5 Apr 29, 2025
41f6276
upgrade comps
raheeliftikhar5 Apr 29, 2025
73c613b
build lowcoder-core after upgrading react version
raheeliftikhar5 Apr 29, 2025
e7c960b
upgraded react, react-dom in lowcoderc-comps + replaced ReactResizeDe…
raheeliftikhar5 Apr 29, 2025
2e1fd49
upgrade packages
raheeliftikhar5 Apr 29, 2025
eae5b3d
optimise drawer comp
raheeliftikhar5 May 21, 2025
9cac3cf
optimise lowcoder-design components
raheeliftikhar5 May 21, 2025
c2c88ec
optimise shared components
raheeliftikhar5 May 21, 2025
707e3e0
optimise table comp, toolbar, filters, summary rows and different col…
raheeliftikhar5 May 21, 2025
405822b
optimise button component
raheeliftikhar5 May 21, 2025
da075f5
optimise editor view
raheeliftikhar5 May 21, 2025
0543b12
optimise canvas view/inner grid, root comp, gridLayout, gridItem and …
raheeliftikhar5 May 21, 2025
05ee98b
optimise form components
raheeliftikhar5 May 21, 2025
c2680f3
optimise modal comp
raheeliftikhar5 May 21, 2025
371a9bc
optimise event handler control
raheeliftikhar5 May 21, 2025
6ef3c5e
remove antd's react 19 patch
raheeliftikhar5 May 21, 2025
6ab43b4
fixed query variable value when used with event handler control
raheeliftikhar5 May 21, 2025
0bdc38c
Merge branch 'dev' into feature/support-react-19
FalkWolsky May 22, 2025
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
optimise table comp, toolbar, filters, summary rows and different col…
…umn types
  • Loading branch information
raheeliftikhar5 committed May 22, 2025
commit 707e3e0a4f14d5a10414387faf7847da39b2f409
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class ColumnTypeCompBuilder<
RecordConstructorToComp<NewChildrenCtorMap<ChildrenCtorMap, T>>
>;
private editViewFn?: EditViewFn<T>;
private cleanupFunctions: (() => void)[] = [];

constructor(
childrenMap: ChildrenCtorMap,
Expand Down Expand Up @@ -93,22 +94,57 @@ export class ColumnTypeCompBuilder<
if (!this.propertyViewFn) {
throw new Error("need property view fn");
}

// Memoize the props processing
const memoizedViewFn = _.memoize(
(props: any, dispatch: any) => {
const baseValue = this.baseValueFn?.(props, dispatch);
const normalView = this.viewFn(props, dispatch);
return (
<EditableCell<T>
{...props}
normalView={normalView}
dispatch={dispatch}
baseValue={baseValue}
changeValue={props.changeValue as any}
editViewFn={this.editViewFn}
/>
);
},
(props) => {
let safeOptions = [];
let safeAvatars = [];
if(props.options) {
safeOptions = props.options.map((option: Record<string, any>) => {
const {prefixIcon, suffixIcon, ...safeOption} = option;
return safeOption;
})
}
if(props.avatars) {
safeAvatars = props.avatars.map((avatar: Record<string, any>) => {
const {AvatarIcon, ...safeAvatar} = avatar;
return safeAvatar;
})
}
const {
prefixIcon,
suffixIcon,
iconFalse,
iconTrue,
iconNull,
tagColors,
options,
avatars,
...safeProps
} = props;
return safeProps;
}
);

const viewFn: ColumnTypeViewFn<ChildrenCtorMap, T, CellViewReturn> =
(props, dispatch): CellViewReturn =>
(cellProps) => {
const baseValue = this.baseValueFn?.(props, dispatch);
const normalView = this.viewFn(props, dispatch);
return (
<EditableCell<T>
{...cellProps}
normalView={normalView}
dispatch={dispatch}
baseValue={baseValue}
changeValue={props.changeValue as any}
editViewFn={this.editViewFn}
/>
);
};
(cellProps) => memoizedViewFn({ ...props, ...cellProps } as any, dispatch);

const ColumnTypeCompTmp = new MultiCompBuilder(
this.childrenMap as ToConstructor<
RecordConstructorToComp<NewChildrenCtorMap<ChildrenCtorMap, T>>
Expand All @@ -117,12 +153,21 @@ export class ColumnTypeCompBuilder<
)
.setPropertyViewFn(this.propertyViewFn)
.build();

const displayValueFn = this.displayValueFn;
const editViewFn = this.editViewFn;

return class extends ColumnTypeCompTmp {
// table cell data
readonly displayValue: JSONValue = null;
private _displayValue: JSONValue = null;
private cleanupFunctions: (() => void)[] = [];
constructor(props: any) {
super(props);
this.cleanupFunctions.push(() => {
this._displayValue = null;
memoizedViewFn.cache.clear?.();
});
}

override extraNode() {
return {
Expand All @@ -134,7 +179,8 @@ export class ColumnTypeCompBuilder<
},
updateNodeFields: (value: any) => {
const displayValueFunc = value[__COLUMN_DISPLAY_VALUE_FN];
return { displayValue: displayValueFunc(value) };
this._displayValue = displayValueFunc(value);
return { displayValue: this._displayValue };
},
};
}
Expand All @@ -143,12 +189,24 @@ export class ColumnTypeCompBuilder<
* Get the data actually displayed by the table cell
*/
getDisplayValue() {
return this.displayValue;
return this._displayValue;
}

static canBeEditable() {
return !_.isNil(editViewFn);
}

componentWillUnmount() {
// Cleanup all registered cleanup functions
this.cleanupFunctions.forEach(cleanup => cleanup());
this.cleanupFunctions = [];
}
};
}

// Cleanup method to be called when the builder is no longer needed
cleanup() {
this.cleanupFunctions.forEach(cleanup => cleanup());
this.cleanupFunctions = [];
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { default as InputNumber } from "antd/es/input-number";
import React, { useState, useRef, useEffect, useCallback, useMemo, ReactNode } from "react";
import { default as InputNumber } from "antd/es/input-number";
import { NumberControl, RangeControl, StringControl } from "comps/controls/codeControl";
import { BoolControl } from "comps/controls/boolControl";
import { trans } from "i18n";
Expand Down Expand Up @@ -35,59 +36,123 @@ const childrenMap = {
suffix: StringControl,
};

let float = false;
let step = 1;
let precision = 0;
const getBaseValue: ColumnTypeViewFn<typeof childrenMap, number, number> = (props) => props.text;

const getBaseValue: ColumnTypeViewFn<typeof childrenMap, number, number> = (
props
) => {
return props.text
type NumberViewProps = {
value: number;
prefix: string;
suffix: string;
prefixIcon: ReactNode;
suffixIcon: ReactNode;
float: boolean;
precision: number;
};

type NumberEditProps = {
value: number;
onChange: (value: number) => void;
onChangeEnd: () => void;
step: number;
precision: number;
float: boolean;
};

const ColumnNumberView = React.memo((props: NumberViewProps) => {
const formattedValue = useMemo(() => {
let result = !props.float ? Math.floor(props.value) : props.value;
if (props.float) {
result = Number(result.toFixed(props.precision + 1));
}
return result;
}, [props.value, props.float, props.precision]);

return (
<>
{hasIcon(props.prefixIcon) && (
<span>{props.prefixIcon}</span>
)}
<span>{props.prefix + formattedValue + props.suffix}</span>
{hasIcon(props.suffixIcon) && (
<span>{props.suffixIcon}</span>
)}
</>
);
});

ColumnNumberView.displayName = 'ColumnNumberView';


const ColumnNumberEdit = React.memo((props: NumberEditProps) => {
const [currentValue, setCurrentValue] = useState(props.value);
const mountedRef = useRef(true);

// Cleanup on unmount
useEffect(() => {
return () => {
mountedRef.current = false;
setCurrentValue(0);
};
}, []);

const handleChange = useCallback((value: string | number | null) => {
if (!mountedRef.current) return;
const newValue = typeof value === 'number' ? value : 0;
const finalValue = !props.float ? Math.floor(newValue) : newValue;
props.onChange(finalValue);
setCurrentValue(finalValue);
}, [props.onChange, props.float]);

const handleBlur = useCallback(() => {
if (!mountedRef.current) return;
props.onChangeEnd();
}, [props.onChangeEnd]);

const handlePressEnter = useCallback(() => {
if (!mountedRef.current) return;
props.onChangeEnd();
}, [props.onChangeEnd]);

return (
<InputNumberWrapper>
<InputNumber
step={props.step}
value={currentValue}
autoFocus
variant="borderless"
onChange={handleChange}
precision={props.float ? props.precision : 0}
onBlur={handleBlur}
onPressEnter={handlePressEnter}
/>
</InputNumberWrapper>
);
});

ColumnNumberEdit.displayName = 'NumberEdit';

export const ColumnNumberComp = (function () {
return new ColumnTypeCompBuilder(
childrenMap,
(props, dispatch) => {
float = props.float;
step = props.step;
precision = props.precision;
const value = props.changeValue ?? getBaseValue(props, dispatch);
let formattedValue: string | number = !float ? Math.floor(value) : value;
if(float) {
formattedValue = formattedValue.toFixed(precision + 1);
}
return (
<>{hasIcon(props.prefixIcon) && (
<span>{props.prefixIcon}</span>
)}
<span>{props.prefix + formattedValue + props.suffix}</span>
{hasIcon(props.suffixIcon) && (
<span>{props.suffixIcon}</span>
)} </>
);
return <ColumnNumberView value={value} {...props} />;
},
(nodeValue) => nodeValue.text.value,
getBaseValue,
getBaseValue
)
.setEditViewFn((props) => {
const { value, onChange, onChangeEnd, otherProps } = props;
return (
<InputNumberWrapper>
<InputNumber
step={step}
defaultValue={props.value}
autoFocus
variant="borderless"
onChange={(value) => {
value = value ?? 0;
props.onChange(!float ? Math.floor(value) : value);
}}
precision={float ? precision : 0}
onBlur={props.onChangeEnd}
onPressEnter={props.onChangeEnd}
<ColumnNumberEdit
value={value}
onChange={onChange}
onChangeEnd={onChangeEnd}
step={otherProps?.step ?? 1}
precision={otherProps?.precision ?? 0}
float={otherProps?.float ?? false}
/>
</InputNumberWrapper>
)})
);
})
.setPropertyViewFn((children) => {
return (
<>
Expand All @@ -99,15 +164,15 @@ export const ColumnNumberComp = (function () {
label: trans("table.numberStep"),
tooltip: trans("table.numberStepTooltip"),
onFocus: (focused) => {
if(!focused) {
if (!focused) {
const value = children.step.getView();
const isFloat = children.float.getView();
const newValue = !isFloat ? Math.floor(value) : value;
children.step.dispatchChangeValueAction(String(newValue));
}
}
})}
{float && (
{children.float.getView() && (
children.precision.propertyView({
label: trans("table.precision"),
})
Expand Down
Loading