gantt-task-react-v 1.6.15 → 1.6.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -256,6 +256,33 @@ A slide-in panel for viewing task/arrow details with built-in "Go to" navigation
256
256
 
257
257
  The `goToTask(taskId)` function scrolls both horizontally and vertically to center the target task and selects it. Built-in "Go to" buttons also appear automatically in the drawer header for arrow-type panels and task-type panels.
258
258
 
259
+ ### Opening the drawer programmatically
260
+
261
+ Pass `openDrawerTaskId` inside the `drawer` prop to open the drawer for a specific task without any user interaction. When the value changes the drawer updates to show the new task.
262
+
263
+ ```tsx
264
+ const [inspect, setInspect] = useState<string | undefined>(undefined);
265
+
266
+ <Gantt
267
+ tasks={tasks}
268
+ drawer={{
269
+ enableDrawer: true,
270
+ openDrawerTaskId: inspect,
271
+ renderDrawerContent: data => {
272
+ if (data.type === "task") return <div>{data.task.name}</div>;
273
+ return null;
274
+ },
275
+ }}
276
+ />;
277
+
278
+ {
279
+ /* Open drawer for a specific task from anywhere in your UI */
280
+ }
281
+ <button onClick={() => setInspect("task-1")}>Inspect Task 1</button>;
282
+ ```
283
+
284
+ > **Note:** `openDrawerTaskId` is only honoured when `enableDrawer` is `true`.
285
+
259
286
  ## Scroll To Task
260
287
 
261
288
  Programmatically scroll to and select any task by id.
@@ -643,11 +670,12 @@ const tasks: Task[] = [
643
670
 
644
671
  ### GanttDrawerProps
645
672
 
646
- | Prop | Type | Default | Description |
647
- | --------------------- | --------------------- | ------- | ----------------------- |
648
- | `enableDrawer` | `boolean` | `false` | Enable drawer panel |
649
- | `drawerWidth` | `number` | `360` | Panel width in px |
650
- | `renderDrawerContent` | `RenderDrawerContent` | — | Custom content renderer |
673
+ | Prop | Type | Default | Description |
674
+ | --------------------- | --------------------- | ------- | ---------------------------------------------------------- |
675
+ | `enableDrawer` | `boolean` | `false` | Enable drawer panel |
676
+ | `drawerWidth` | `number` | `360` | Panel width in px |
677
+ | `renderDrawerContent` | `RenderDrawerContent` | — | Custom content renderer |
678
+ | `openDrawerTaskId` | `string` | — | Programmatically open the drawer for the task with this id |
651
679
 
652
680
  `RenderDrawerContent = (data: GanttDrawerData, goToTask: (taskId: string) => void) => ReactNode`
653
681
 
@@ -19811,6 +19811,7 @@ const Gantt = (props) => {
19811
19811
  const enableDrawer = (drawerProps == null ? void 0 : drawerProps.enableDrawer) ?? false;
19812
19812
  const drawerWidth = (drawerProps == null ? void 0 : drawerProps.drawerWidth) ?? 360;
19813
19813
  const renderDrawerContent = drawerProps == null ? void 0 : drawerProps.renderDrawerContent;
19814
+ const openDrawerTaskId = drawerProps == null ? void 0 : drawerProps.openDrawerTaskId;
19814
19815
  const [drawerData, setDrawerData] = useState(null);
19815
19816
  const [activeArrowKey, setActiveArrowKey] = useState(null);
19816
19817
  const [activeTaskId, setActiveTaskId] = useState(null);
@@ -20143,6 +20144,24 @@ const Gantt = (props) => {
20143
20144
  setScrollYProgrammatically,
20144
20145
  selectTask
20145
20146
  ]);
20147
+ const prevOpenDrawerTaskIdRef = useRef(void 0);
20148
+ useEffect(() => {
20149
+ if (!enableDrawer || !openDrawerTaskId)
20150
+ return;
20151
+ if (openDrawerTaskId === prevOpenDrawerTaskIdRef.current)
20152
+ return;
20153
+ prevOpenDrawerTaskIdRef.current = openDrawerTaskId;
20154
+ for (const [, levelMap] of tasksMap) {
20155
+ const task = levelMap.get(openDrawerTaskId);
20156
+ if (!task || task.type === "empty")
20157
+ continue;
20158
+ setActiveArrowKey(null);
20159
+ setActiveTaskId(openDrawerTaskId);
20160
+ setDrawerData({ type: "task", task });
20161
+ selectTask(openDrawerTaskId);
20162
+ break;
20163
+ }
20164
+ }, [enableDrawer, openDrawerTaskId, tasksMap, selectTask]);
20146
20165
  const { contextMenu, handleCloseContextMenu, handleOpenContextMenu } = useContextMenu(wrapperRef, scrollToTask);
20147
20166
  const [ganttContextMenu, setGanttContextMenu] = useState({
20148
20167
  task: null,
@@ -19828,6 +19828,7 @@
19828
19828
  const enableDrawer = (drawerProps == null ? void 0 : drawerProps.enableDrawer) ?? false;
19829
19829
  const drawerWidth = (drawerProps == null ? void 0 : drawerProps.drawerWidth) ?? 360;
19830
19830
  const renderDrawerContent = drawerProps == null ? void 0 : drawerProps.renderDrawerContent;
19831
+ const openDrawerTaskId = drawerProps == null ? void 0 : drawerProps.openDrawerTaskId;
19831
19832
  const [drawerData, setDrawerData] = React.useState(null);
19832
19833
  const [activeArrowKey, setActiveArrowKey] = React.useState(null);
19833
19834
  const [activeTaskId, setActiveTaskId] = React.useState(null);
@@ -20160,6 +20161,24 @@
20160
20161
  setScrollYProgrammatically,
20161
20162
  selectTask
20162
20163
  ]);
20164
+ const prevOpenDrawerTaskIdRef = React.useRef(void 0);
20165
+ React.useEffect(() => {
20166
+ if (!enableDrawer || !openDrawerTaskId)
20167
+ return;
20168
+ if (openDrawerTaskId === prevOpenDrawerTaskIdRef.current)
20169
+ return;
20170
+ prevOpenDrawerTaskIdRef.current = openDrawerTaskId;
20171
+ for (const [, levelMap] of tasksMap) {
20172
+ const task = levelMap.get(openDrawerTaskId);
20173
+ if (!task || task.type === "empty")
20174
+ continue;
20175
+ setActiveArrowKey(null);
20176
+ setActiveTaskId(openDrawerTaskId);
20177
+ setDrawerData({ type: "task", task });
20178
+ selectTask(openDrawerTaskId);
20179
+ break;
20180
+ }
20181
+ }, [enableDrawer, openDrawerTaskId, tasksMap, selectTask]);
20163
20182
  const { contextMenu, handleCloseContextMenu, handleOpenContextMenu } = useContextMenu(wrapperRef, scrollToTask);
20164
20183
  const [ganttContextMenu, setGanttContextMenu] = React.useState({
20165
20184
  task: null,
@@ -24,6 +24,12 @@ export interface GanttDrawerProps {
24
24
  * Render function for custom drawer content
25
25
  */
26
26
  renderDrawerContent?: RenderDrawerContent;
27
+ /**
28
+ * When set (or changed), the drawer will open and display the details of the
29
+ * task with this id. Requires `enableDrawer: true`.
30
+ * Set to `undefined` or change to a new id to control the drawer imperatively.
31
+ */
32
+ openDrawerTaskId?: string;
27
33
  }
28
34
  export type RenderTopHeader = (date: Date, viewMode: ViewMode, dateSetup: DateSetup) => ReactNode;
29
35
  export type RenderCustomLabel = (task: RenderTask, x1: number, width: number, taskHeight: number, arrowIndent: number, taskYOffset: number, movingAction: TaskBarMoveAction | null, viewMode: ViewMode, rtl?: boolean) => ReactNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gantt-task-react-v",
3
- "version": "1.6.15",
3
+ "version": "1.6.16",
4
4
  "description": "Interactive Gantt Chart for React with TypeScript.",
5
5
  "author": "aguilanbon",
6
6
  "homepage": "https://github.com/aguilanbon/gantt-task-react-v",