Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Table row selection (#503) #1031

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 21 additions & 4 deletions frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
getRowIndex,
getTooltip,
defaultColumns,
OnRowClick,
} from "./tableUtils";
import {
useClassNames,
Expand All @@ -85,6 +86,7 @@
onValidation?: OnCellValidation;
onDeletion?: OnRowDeletion;
onRowSelection?: OnRowSelection;
onRowClick?: OnRowClick;
lineStyle?: string;
nanValue?: string;
}
Expand All @@ -104,6 +106,7 @@
onValidation,
onDeletion,
onRowSelection,
onRowClick,
lineStyle,
nanValue,
},
Expand All @@ -122,6 +125,7 @@
className={(classes && classes.row) + " " + getClassName(rows[index], lineStyle)}
data-index={index}
selected={selection.indexOf(index) > -1}
onClick={onRowClick}
>
{colsOrder.map((col, cidx) => (
<EditableCell
Expand Down Expand Up @@ -405,16 +409,16 @@

const onCellValidation: OnCellValidation = useCallback(
(value: RowValue, rowIndex: number, colName: string, userValue: string, tz?: string) =>
dispatch(
createSendActionNameAction(updateVarName, module, {
action: onEdit,
value: value,
index: getRowIndex(rows[rowIndex], rowIndex),
col: colName,
user_value: userValue,
tz: tz,
user_data: userData
user_data: userData,
})

Check warning on line 421 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
),
[dispatch, updateVarName, onEdit, rows, module, userData]
);
Expand All @@ -432,18 +436,29 @@
);

const onRowSelection: OnRowSelection = useCallback(
(rowIndex: number, colName: string) =>
(rowIndex: number, colName?: string) =>

Check warning on line 439 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
dispatch(
createSendActionNameAction(updateVarName, module, {
action: onAction,
index: getRowIndex(rows[rowIndex], rowIndex),
col: colName,
user_data: userData
col: colName === undefined ? null : colName,

Check warning on line 444 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 444 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
user_data: userData,
})

Check warning on line 446 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
),
[dispatch, updateVarName, onAction, rows, module, userData]
);

const onRowClick = useCallback(
(e: MouseEvent<HTMLTableRowElement>) => {

Check warning on line 452 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const { index } = e.currentTarget.dataset || {};

Check warning on line 453 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 453 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 453 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
const rowIndex = index === undefined ? NaN : Number(index);

Check warning on line 454 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 454 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 454 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
if (!isNaN(rowIndex)) {
onRowSelection(rowIndex);

Check warning on line 456 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 457 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 457 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
},
[onRowSelection]
);

const onTaipyItemsRendered = useCallback(
(onItemsR: (props: ListOnItemsRenderedProps) => undefined) =>
({ visibleStartIndex, visibleStopIndex }: { visibleStartIndex: number; visibleStopIndex: number }) => {
Expand Down Expand Up @@ -471,6 +486,7 @@
onValidation: active && onEdit ? onCellValidation : undefined,
onDeletion: active && onDelete ? onRowDeletion : undefined,
onRowSelection: active && onAction ? onRowSelection : undefined,
onRowClick: active && onAction ? onRowClick : undefined,

Check warning on line 489 in frontend/taipy-gui/src/components/Taipy/AutoLoadingTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
lineStyle: props.lineStyle,
nanValue: props.nanValue,
}),
Expand All @@ -488,6 +504,7 @@
onRowDeletion,
onAction,
onRowSelection,
onRowClick,
props.lineStyle,
props.nanValue,
size,
Expand Down
20 changes: 17 additions & 3 deletions frontend/taipy-gui/src/components/Taipy/PaginatedTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
OnRowSelection,
getRowIndex,
getTooltip,
OnRowClick,
} from "./tableUtils";
import {
useClassNames,
Expand Down Expand Up @@ -304,7 +305,7 @@
createSendActionNameAction(updateVarName, module, {
action: onAdd,
index: startIndex,
user_data: userData
user_data: userData,
})
),
[startIndex, dispatch, updateVarName, onAdd, module, userData]
Expand Down Expand Up @@ -378,18 +379,29 @@
);

const onRowSelection: OnRowSelection = useCallback(
(rowIndex: number, colName: string) =>
(rowIndex: number, colName?: string) =>
dispatch(
createSendActionNameAction(updateVarName, module, {
action: onAction,
index: getRowIndex(rows[rowIndex], rowIndex, startIndex),
col: colName,
col: colName === undefined ? null : colName,

Check warning on line 387 in frontend/taipy-gui/src/components/Taipy/PaginatedTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
user_data: userData,
})
),
[dispatch, updateVarName, onAction, rows, startIndex, module, userData]
);

const onRowClick: OnRowClick = useCallback(
(e: MouseEvent<HTMLTableRowElement>) => {

Check warning on line 395 in frontend/taipy-gui/src/components/Taipy/PaginatedTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const { index } = e.currentTarget.dataset || {};

Check warning on line 396 in frontend/taipy-gui/src/components/Taipy/PaginatedTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 396 in frontend/taipy-gui/src/components/Taipy/PaginatedTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 396 in frontend/taipy-gui/src/components/Taipy/PaginatedTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
const rowIndex = index === undefined ? NaN : Number(index);

Check warning on line 397 in frontend/taipy-gui/src/components/Taipy/PaginatedTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 397 in frontend/taipy-gui/src/components/Taipy/PaginatedTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 397 in frontend/taipy-gui/src/components/Taipy/PaginatedTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
if (!isNaN(rowIndex)) {
onRowSelection(rowIndex);

Check warning on line 399 in frontend/taipy-gui/src/components/Taipy/PaginatedTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 400 in frontend/taipy-gui/src/components/Taipy/PaginatedTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 400 in frontend/taipy-gui/src/components/Taipy/PaginatedTable.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
},
[onRowSelection]
);

const boxSx = useMemo(() => ({ ...baseBoxSx, width: width }), [width]);

return (
Expand Down Expand Up @@ -492,6 +504,8 @@
selected={sel > -1}
ref={sel == 0 ? selectedRowRef : undefined}
className={getClassName(row, props.lineStyle)}
data-index={index}
onClick={active && onAction ? onRowClick : undefined}
>
{colsOrder.map((col, cidx) => (
<EditableCell
Expand Down
19 changes: 13 additions & 6 deletions frontend/taipy-gui/src/components/Taipy/tableUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ export interface OnRowDeletion {
}

export interface OnRowSelection {
(rowIndex: number, colName: string): void;
(rowIndex: number, colName?: string): void;
}

export interface OnRowClick {
(e: MouseEvent<HTMLTableRowElement>): void;
}

interface EditableCellProps {
Expand Down Expand Up @@ -343,8 +347,8 @@ export const EditableCell = (props: EditableCellProps) => {

const onDeleteClick = useCallback(
(evt?: MouseEvent) => {
onDeletion && setDeletion((d) => !d);
evt && evt.stopPropagation();
onDeletion && setDeletion((d) => !d);
},
[onDeletion]
);
Expand All @@ -363,10 +367,13 @@ export const EditableCell = (props: EditableCellProps) => {
[onDeleteCheckClick, onDeleteClick]
);

const onSelect = useCallback(() => {
onSelection && onSelection(rowIndex, colDesc.dfid);
return false;
}, [onSelection, rowIndex, colDesc.dfid]);
const onSelect = useCallback(
(e: MouseEvent<HTMLDivElement>) => {
e.stopPropagation();
onSelection && onSelection(rowIndex, colDesc.dfid);
},
[onSelection, rowIndex, colDesc.dfid]
);

useEffect(() => {
!onValidation && setEdit(false);
Expand Down
Loading