Skip to content
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 form components
  • Loading branch information
raheeliftikhar5 committed May 22, 2025
commit 05ee98b8e434daef35247568c49c9b8c835d3cca
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,16 @@ export const InnerGrid = React.memo((props: ViewPropsWithSelect) => {
);

const dispatchPositionParamsTimerRef = useRef(0);

// Add cleanup for timeout
useEffect(() => {
return () => {
if (dispatchPositionParamsTimerRef.current) {
window.clearTimeout(dispatchPositionParamsTimerRef.current);
}
};
}, []);

const onResize = useCallback(
({width, height}: ResizePayload) => {
if(!width || !height) return;
Expand Down Expand Up @@ -444,20 +454,35 @@ export const InnerGrid = React.memo((props: ViewPropsWithSelect) => {
props.dispatch,
]
);
const setSelectedNames = useCallback(
(names: Set<string>) => {
editorState?.setSelectedCompNames(names);
},
[editorState?.setSelectedCompNames]
);

// Cleanup resize detector
const { width, ref } = useResizeDetector({
onResize,
handleHeight: isRowCountLocked,
refreshMode: 'debounce',
refreshRate: 100,
});

const setSelectedNames = useCallback(
(names: Set<string>) => {
editorState?.setSelectedCompNames(names);
},
[editorState?.setSelectedCompNames]
);

// Cleanup item references when items are removed
useEffect(() => {
const currentKeys = new Set(Object.keys(props.items));
const refKeys = new Set(Object.keys(itemViewRef.current));

// Remove references to items that no longer exist
refKeys.forEach(key => {
if (!currentKeys.has(key)) {
delete itemViewRef.current[key];
}
});
}, [props.items]);

const itemViewRef = useRef<GirdItemViewRecord>({});
const itemViews = useMemo(() => {
const newView: GirdItemViewRecord = {};
Expand Down
58 changes: 41 additions & 17 deletions client/packages/lowcoder/src/comps/comps/formComp/createForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TacoButton,
} from "lowcoder-design";
import _ from "lodash";
import { useEffect, useState } from "react";
import { useEffect, useState, useCallback } from "react";
import { useDispatch, useSelector } from "react-redux";
import { AppState } from "redux/reducers";
import { fetchDatasourceStructure } from "redux/reduxActions/datasourceActions";
Expand Down Expand Up @@ -552,13 +552,22 @@ const CreateFormBody = (props: { onCreate: CreateHandler }) => {
const dataSourceId: string | undefined = Form.useWatch("dataSourceId", form);
const dataSourceItems = useDataSourceItems();
const dataSourceItem = dataSourceItems.find((t) => t.dataSource.id === dataSourceId);

// Cleanup form on unmount
useEffect(() => {
return () => {
form.resetFields();
};
}, [form]);

// default to the first item
useEffect(() => {
if (!dataSourceItem) {
const id = dataSourceItems.length > 0 ? dataSourceItems[0].dataSource.id : undefined;
form.setFieldsValue({ dataSourceId: id });
}
}, [dataSourceItems]);
}, [dataSourceItems, dataSourceItem, form]);

// Refetch when changed
const dispatch = useDispatch();
useEffect(() => {
Expand All @@ -570,25 +579,27 @@ const CreateFormBody = (props: { onCreate: CreateHandler }) => {
const tableName: string | undefined = Form.useWatch("tableName", form);
const tableStructures = useTableStructures(dataSourceId);
const tableStructure = tableStructures.find((t) => t.name === tableName);

// default to the first one
useEffect(() => {
if (!tableStructure) {
const name = tableStructures.length > 0 ? tableStructures[0].name : undefined;
form.setFieldsValue({ tableName: name });
}
}, [tableStructures]);
}, [tableStructures, tableStructure, form]);

// Columns of the data table, saved to support drag and drop
const [items, setItems] = useState<RowItem[]>([]);
const dataSourceTypeConfig = dataSourceItem?.typeConfig;

useEffect(() => {
const { initItems, initColumns } = getInitItemsAndColumns(dataSourceTypeConfig, tableStructure);
// Set the initial value by the method. Because if another table has the same column name, setting via initialValue is invalid.
form.setFieldsValue({ columns: initColumns });
setItems(initItems);
}, [dataSourceTypeConfig, tableStructure]);
}, [dataSourceTypeConfig, tableStructure, form]);

const handleDragEnd = (e: { active: { id: string }; over: { id: string } | null }) => {
console.log('handleDragEnd', e);
const handleDragEnd = useCallback((e: { active: { id: string }; over: { id: string } | null }) => {
if (!e.over) {
return;
}
Expand All @@ -603,7 +614,7 @@ const CreateFormBody = (props: { onCreate: CreateHandler }) => {
newData.splice(toIndex, 0, movedItem);

setItems(newData);
};
}, [items]);

const emptyText = getEmptyText(dataSourceItems.length, tableStructures.length, items.length);

Expand Down Expand Up @@ -688,27 +699,40 @@ const CreateFormBody = (props: { onCreate: CreateHandler }) => {

export const CreateForm = (props: { onCreate: CreateHandler }) => {
const [visible, setVisible] = useState(false);

const handleMouseDown = useCallback((e: React.MouseEvent) => {
setVisible(true);
e.stopPropagation();
}, []);

const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
e.stopPropagation();
}, []);

const handleClick = useCallback((e: React.MouseEvent) => {
e.stopPropagation();
}, []);

const handleCancel = useCallback(() => {
setVisible(false);
}, []);

return (
<>
<OpenDialogButton
onMouseDown={(e) => {
setVisible(true);
e.stopPropagation();
}}
>
<OpenDialogButton onMouseDown={handleMouseDown}>
{trans("formComp.openDialogButton")}
</OpenDialogButton>
<div
onKeyDown={(e) => e.stopPropagation()}
onMouseDown={(e) => e.stopPropagation()}
onClick={(e) => e.stopPropagation()}
onKeyDown={handleKeyDown}
onMouseDown={handleMouseDown}
onClick={handleClick}
>
<CustomModal
open={visible}
destroyOnClose={true}
title={trans("formComp.generateForm")}
footer={null}
onCancel={() => setVisible(false)}
onCancel={handleCancel}
width="600px"
children={<CreateFormBody {...props} />}
styles={{ body: {padding: 0} }}
Expand Down
10 changes: 7 additions & 3 deletions client/packages/lowcoder/src/comps/comps/formComp/formComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,18 @@ function onCreate(
const BodyPlaceholder = (props: FormProps) => {
const editorState = useContext(EditorContext);
const formName = useContext(CompNameContext);

const handleCreate = (data: CreateData) => {
const result = onCreate(data, props, editorState, formName);
return Promise.resolve(result);
};

return (
<ContainerPlaceholder>
{trans("formComp.containerPlaceholder")}
<br />
<CreateForm
onCreate={(data: CreateData) =>
Promise.resolve(onCreate(data, props, editorState, formName))
}
onCreate={handleCreate}
/>
</ContainerPlaceholder>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RecordConstructorToComp } from "lowcoder-core";
import { StringControl } from "comps/controls/codeControl";
import { CompNameContext, EditorContext } from "comps/editorState";
import { Section } from "lowcoder-design";
import { ReactNode } from "react";
import { ReactNode, useContext, useMemo } from "react";
import { trans } from "i18n";

export interface IForm {
Expand All @@ -17,24 +17,26 @@ export const formDataChildren = {

type FormDataComp = RecordConstructorToComp<typeof formDataChildren>;

export const FormDataPropertyView = (children: FormDataComp) => (
<EditorContext.Consumer>
{(editorState) => (
<CompNameContext.Consumer>
{(name) => (
<>
{editorState?.findUIParentContainer(name, "form") && (
<Section name={trans("form")}>
{children.formDataKey.propertyView({
label: trans("formComp.name"),
placeholder: name,
tooltip: trans("formComp.nameTooltip"),
})}
</Section>
)}
</>
)}
</CompNameContext.Consumer>
)}
</EditorContext.Consumer>
);
export const FormDataPropertyView = (children: FormDataComp) => {
const editorState = useContext(EditorContext);
const name = useContext(CompNameContext);

const isFormParent = useMemo(() =>
editorState?.findUIParentContainer(name, "form"),
[editorState, name]
);

if (!isFormParent) {
return null;
}

return (
<Section name={trans("form")}>
{children.formDataKey.propertyView({
label: trans("formComp.name"),
placeholder: name,
tooltip: trans("formComp.nameTooltip"),
})}
</Section>
);
};
Loading