Skip to content

Commit

Permalink
Support onClick in table
Browse files Browse the repository at this point in the history
It also support the empty task selection

Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
  • Loading branch information
lfasani committed Mar 11, 2024
1 parent caeec77 commit 8930034
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/components/gantt/gantt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1791,8 +1791,10 @@ export const Gantt: React.FC<GanttProps> = ({
]
);

const onClickTask = (task: Task) => {
onClick(task);
const onClickTask = (task: TaskOrEmpty) => {
if (onClick) {
onClick(task);
}
};

const barProps: TaskGanttContentProps = useMemo(
Expand Down Expand Up @@ -1925,6 +1927,7 @@ export const Gantt: React.FC<GanttProps> = ({
icons,
isShowTaskNumbers,
mapTaskToNestedIndex,
onClick: onClickTask,
onExpanderClick: handleExpanderClick,
scrollToBottomStep,
scrollToTopStep,
Expand Down
8 changes: 5 additions & 3 deletions src/components/task-list/task-list-table-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type TaskListTableRowProps = {
isEven: boolean;
isSelected: boolean;
isShowTaskNumbers: boolean;
onClick: (task: TaskOrEmpty) => void;
onExpanderClick: (task: Task) => void;
scrollToTask: (task: Task) => void;
selectTaskOnMouseDown: (taskId: string, event: MouseEvent) => void;
Expand Down Expand Up @@ -79,6 +80,7 @@ const TaskListTableRowInner: React.FC<TaskListTableRowProps> = ({
isEven,
isSelected,
isShowTaskNumbers,
onClick,
onExpanderClick,
scrollToTask,
selectTaskOnMouseDown,
Expand All @@ -96,12 +98,12 @@ const TaskListTableRowInner: React.FC<TaskListTableRowProps> = ({
return;
}

if (task.type === "empty") {
return;
if (task.type !== "empty") {
scrollToTask(task);
}

scrollToTask(task);
selectTaskOnMouseDown(task.id, event);
onClick(task);
},
[scrollToTask, selectTaskOnMouseDown, task]
);
Expand Down
2 changes: 2 additions & 0 deletions src/components/task-list/task-list-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const TaskListTableDefaultInner: React.FC<TaskListTableProps> = ({
icons,
isShowTaskNumbers,
mapTaskToNestedIndex,
onClick,
onExpanderClick,
renderedIndexes,
scrollToTask,
Expand Down Expand Up @@ -107,6 +108,7 @@ const TaskListTableDefaultInner: React.FC<TaskListTableProps> = ({
isEven={index % 2 === 1}
isSelected={selectedIdsMirror[id]}
isShowTaskNumbers={isShowTaskNumbers}
onClick={onClick}
onExpanderClick={onExpanderClick}
scrollToTask={scrollToTask}
selectTaskOnMouseDown={selectTaskOnMouseDown}
Expand Down
3 changes: 3 additions & 0 deletions src/components/task-list/task-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type TaskListProps = {
icons?: Partial<Icons>;
isShowTaskNumbers: boolean;
mapTaskToNestedIndex: MapTaskToNestedIndex;
onClick?: (task: TaskOrEmpty) => void;
onExpanderClick: (task: Task) => void;
scrollToBottomStep: () => void;
scrollToTask: (task: Task) => void;
Expand Down Expand Up @@ -97,6 +98,7 @@ const TaskListInner: React.FC<TaskListProps> = ({
isShowTaskNumbers,
mapTaskToNestedIndex,
onExpanderClick,
onClick,
scrollToTask,
selectTaskOnMouseDown,
selectedIdsMirror,
Expand Down Expand Up @@ -241,6 +243,7 @@ const TaskListInner: React.FC<TaskListProps> = ({
icons={icons}
isShowTaskNumbers={isShowTaskNumbers}
mapTaskToNestedIndex={mapTaskToNestedIndex}
onClick={onClick}
onExpanderClick={onExpanderClick}
renderedIndexes={renderedIndexes}
scrollToTask={scrollToTask}
Expand Down
3 changes: 2 additions & 1 deletion src/types/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export interface EventOption {
/**
* Invokes on bar click.
*/
onClick?: (task: Task) => void;
onClick?: (task: TaskOrEmpty) => void;
/**
* Recount descedents of a group task when moving
*/
Expand Down Expand Up @@ -593,6 +593,7 @@ export interface TaskListTableProps {
icons?: Partial<Icons>;
isShowTaskNumbers: boolean;
mapTaskToNestedIndex: MapTaskToNestedIndex;
onClick: (task: TaskOrEmpty) => void;
onExpanderClick: (task: Task) => void;
renderedIndexes: OptimizedListParams | null;
scrollToTask: (task: Task) => void;
Expand Down
2 changes: 1 addition & 1 deletion stories/Comparison.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const Comparison: React.FC<AppProps> = props => {
alert("On Double Click event Id:" + task.id);
}, []);

const handleClick = useCallback((task: Task) => {
const handleClick = useCallback((task: TaskOrEmpty) => {
console.log("On Click event Id:" + task.id);
}, []);

Expand Down
2 changes: 1 addition & 1 deletion stories/CriticalPath.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const CriticalPath: React.FC<AppProps> = props => {
alert("On Double Click event Id:" + task.id);
}, []);

const handleClick = useCallback((task: Task) => {
const handleClick = useCallback((task: TaskOrEmpty) => {
console.log("On Click event Id:" + task.id);
}, []);

Expand Down
2 changes: 1 addition & 1 deletion stories/CustomColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const CustomColumns: React.FC<AppProps> = props => {
alert("On Double Click event Id:" + task.id);
}, []);

const handleClick = useCallback((task: Task) => {
const handleClick = useCallback((task: TaskOrEmpty) => {
console.log("On Click event Id:" + task.id);
}, []);

Expand Down
2 changes: 1 addition & 1 deletion stories/CustomIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const CustomIcons: React.FC<AppProps> = props => {
alert("On Double Click event Id:" + task.id);
}, []);

const handleClick = useCallback((task: Task) => {
const handleClick = useCallback((task: TaskOrEmpty) => {
console.log("On Click event Id:" + task.id);
}, []);

Expand Down
2 changes: 1 addition & 1 deletion stories/CustomPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const CustomPalette: React.FC<AppProps> = props => {
alert("On Double Click event Id:" + task.id);
}, []);

const handleClick = useCallback((task: Task) => {
const handleClick = useCallback((task: TaskOrEmpty) => {
console.log("On Click event Id:" + task.id);
}, []);

Expand Down
2 changes: 1 addition & 1 deletion stories/Simple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const Simple: React.FC<AppProps> = props => {
alert("On Double Click event Id:" + task.id);
}, []);

const handleClick = useCallback((task: Task) => {
const handleClick = useCallback((task: TaskOrEmpty) => {
console.log("On Click event Id:" + task.id);
}, []);

Expand Down
2 changes: 1 addition & 1 deletion stories/StressTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const StressTest: React.FC<AppProps> = ({
alert("On Double Click event Id:" + task.id);
}, []);

const handleClick = useCallback((task: Task) => {
const handleClick = useCallback((task: TaskOrEmpty) => {
console.log("On Click event Id:" + task.id);
}, []);

Expand Down
2 changes: 1 addition & 1 deletion stories/Warnings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const Warnings: React.FC<AppProps> = props => {
alert("On Double Click event Id:" + task.id);
}, []);

const handleClick = useCallback((task: Task) => {
const handleClick = useCallback((task: TaskOrEmpty) => {
console.log("On Click event Id:" + task.id);
}, []);

Expand Down

0 comments on commit 8930034

Please sign in to comment.