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

Commit

Permalink
Table row selection (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred Lefévère-Laoide authored and Fred Lefévère-Laoide committed Nov 30, 2023
1 parent 5d2d9b4 commit 660da7f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
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 @@ import {
getRowIndex,
getTooltip,
defaultColumns,
OnRowClick,
} from "./tableUtils";
import {
useClassNames,
Expand All @@ -85,6 +86,7 @@ interface RowData {
onValidation?: OnCellValidation;
onDeletion?: OnRowDeletion;
onRowSelection?: OnRowSelection;
onRowClick?: OnRowClick;
lineStyle?: string;
nanValue?: string;
}
Expand All @@ -104,6 +106,7 @@ const Row = ({
onValidation,
onDeletion,
onRowSelection,
onRowClick,
lineStyle,
nanValue,
},
Expand All @@ -122,6 +125,7 @@ const Row = ({
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 @@ -413,7 +417,7 @@ const AutoLoadingTable = (props: TaipyTableProps) => {
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 AutoLoadingTable = (props: TaipyTableProps) => {
);

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 @@ const AutoLoadingTable = (props: TaipyTableProps) => {
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 @@ const AutoLoadingTable = (props: TaipyTableProps) => {
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 @@ import {
OnRowSelection,
getRowIndex,
getTooltip,
OnRowClick,
} from "./tableUtils";
import {
useClassNames,
Expand Down Expand Up @@ -304,7 +305,7 @@ const PaginatedTable = (props: TaipyPaginatedTableProps) => {
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 PaginatedTable = (props: TaipyPaginatedTableProps) => {
);

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 @@ const PaginatedTable = (props: TaipyPaginatedTableProps) => {
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

0 comments on commit 660da7f

Please sign in to comment.