Skip to content

Commit de438ec

Browse files
allow option in table to enable editing on single/double click
1 parent 0af140d commit de438ec

File tree

7 files changed

+30
-2
lines changed

7 files changed

+30
-2
lines changed

client/packages/lowcoder/src/components/table/EditableCell.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface CellProps {
3737
candidateStatus?: { text: string; status: StatusType }[];
3838
textOverflow?: boolean;
3939
cellTooltip?: string;
40+
editMode?: string;
4041
onTableEvent?: (eventName: any) => void;
4142
}
4243

@@ -94,13 +95,15 @@ export function EditableCell<T extends JSONValue>(props: EditableCellProps<T>) {
9495
candidateTags,
9596
// tagColors
9697
candidateStatus,
98+
editMode,
9799
onTableEvent,
98100
} = props;
99101
const status = _.isNil(changeValue) ? "normal" : "toSave";
100102
const editable = editViewFn ? props.editable : false;
101103
const { isEditing, setIsEditing } = useContext(TableCellContext);
102104
const value = changeValue ?? baseValue!;
103105
const [tmpValue, setTmpValue] = useState<T | null>(value);
106+
const singleClickEdit = editMode === 'single';
104107

105108
useEffect(() => {
106109
setTmpValue(value);
@@ -175,8 +178,8 @@ export function EditableCell<T extends JSONValue>(props: EditableCellProps<T>) {
175178
width: '100%',
176179
height: '100%',
177180
}}
178-
// onDoubleClick={enterEditFn}
179-
onClick={enterEditFn}
181+
onDoubleClick={!singleClickEdit ? enterEditFn : undefined}
182+
onClick={singleClickEdit ? enterEditFn : undefined}
180183
>
181184
</div>
182185
</CellWrapper>

client/packages/lowcoder/src/comps/comps/tableComp/tableCompView.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ export function TableCompView(props: {
768768
const inlineAddNewRow = useMemo(() => compChildren.inlineAddNewRow.getView(), [compChildren.inlineAddNewRow]);
769769
const pagination = useMemo(() => compChildren.pagination.getView(), [compChildren.pagination]);
770770
const size = useMemo(() => compChildren.size.getView(), [compChildren.size]);
771+
const editModeClicks = useMemo(() => compChildren.editModeClicks.getView(), [compChildren.editModeClicks]);
771772
const onEvent = useMemo(() => compChildren.onEvent.getView(), [compChildren.onEvent]);
772773
const dynamicColumn = compChildren.dynamicColumn.getView();
773774
const dynamicColumnConfig = useMemo(
@@ -786,6 +787,7 @@ export function TableCompView(props: {
786787
dynamicColumn,
787788
dynamicColumnConfig,
788789
columnsAggrData,
790+
editModeClicks,
789791
onEvent,
790792
),
791793
[
@@ -796,6 +798,7 @@ export function TableCompView(props: {
796798
dynamicColumn,
797799
dynamicColumnConfig,
798800
columnsAggrData,
801+
editModeClicks,
799802
]
800803
);
801804

client/packages/lowcoder/src/comps/comps/tableComp/tableDynamicColumn.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const expectColumn = (
4545
comp.children.dynamicColumn.getView(),
4646
dynamicColumnConfig,
4747
comp.columnAggrData,
48+
comp.children.editModeClicks.getView(),
4849
onEvent,
4950
);
5051
expect(columnViews.length).toBeGreaterThanOrEqual(antdColumns.length);

client/packages/lowcoder/src/comps/comps/tableComp/tablePropertyView.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,10 @@ export function compTablePropertyView<T extends MultiBaseComp<TableChildrenType>
562562
label: trans("table.dynamicColumnConfig"),
563563
tooltip: trans("table.dynamicColumnConfigDesc"),
564564
})}
565+
{comp.children.editModeClicks.propertyView({
566+
label: trans("table.editMode"),
567+
radioButton: true,
568+
})}
565569
{comp.children.searchText.propertyView({
566570
label: trans("table.searchText"),
567571
tooltip: trans("table.searchTextTooltip"),

client/packages/lowcoder/src/comps/comps/tableComp/tableTypes.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ import { PaginationControl } from "./paginationControl";
3737
import { SelectionControl } from "./selectionControl";
3838
import { AutoHeightControl } from "comps/controls/autoHeightControl";
3939

40+
const editModeClickOptions = [
41+
{
42+
label: trans("table.singleClick"),
43+
value: "single",
44+
},
45+
{
46+
label: trans("table.doubleClick"),
47+
value: "double",
48+
},
49+
] as const;
50+
4051
const summarRowsOptions = [
4152
{
4253
label: "1",
@@ -248,6 +259,7 @@ const tableChildrenMap = {
248259
expansion: ExpansionControl,
249260
selectedCell: stateComp<JSONObject>({}),
250261
inlineAddNewRow: BoolControl,
262+
editModeClicks: dropdownControl(editModeClickOptions, "single"),
251263
};
252264

253265
export const TableInitComp = (function () {

client/packages/lowcoder/src/comps/comps/tableComp/tableUtils.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ export function columnsToAntdFormat(
295295
dynamicColumn: boolean,
296296
dynamicColumnConfig: Array<string>,
297297
columnsAggrData: ColumnsAggrData,
298+
editMode: string,
298299
onTableEvent: (eventName: any) => void,
299300
): Array<CustomColumnType<RecordType>> {
300301
const customColumns = columns.filter(col => col.isCustom).map(col => col.dataIndex);
@@ -392,6 +393,7 @@ export function columnsToAntdFormat(
392393
currentRow: row,
393394
currentIndex: index,
394395
}),
396+
editMode,
395397
onTableEvent,
396398
});
397399
},

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,9 @@ export const en = {
20022002
"showSummary": "Show Summary Row",
20032003
"totalSummaryRows": "Total Rows",
20042004
"inlineAddNewRow": "Inline Add New Row",
2005+
"editMode": "Edit Mode",
2006+
"singleClick": "Single Click",
2007+
"doubleClick": "Double Click",
20052008
},
20062009

20072010

0 commit comments

Comments
 (0)