@lukstei/dsh-client-kanban 0.0.0-stage → 0.2.2-rc.5.3

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.
@@ -0,0 +1,606 @@
1
+ import type { WorkspaceId } from "@deepseek-ai/dsh-api-workspace-controller/client";
2
+ import {
3
+ IconCloseOutlineRegular,
4
+ IconFullscreenOutlineRegular,
5
+ IconRefreshOutlineRegular,
6
+ } from "@deepseek-ai/dsh-client-ui-primitives";
7
+ import type { SidebarSectionOwnerProps } from "@deepseek-ai/dsh-client-ui-sidebar/client";
8
+ import type { InjectFace } from "@deepseek-ai/dsh-client-ui-slots";
9
+ import type { SessionId } from "@deepseek-ai/dsh-session/types";
10
+ import { useEffect, useState, useSyncExternalStore } from "react";
11
+ import type { KanbanLane } from "../types.ts";
12
+ import { KanbanIcon } from "./KanbanIcon.tsx";
13
+ import type { KanbanPaneInjected } from "./KanbanPane.tsx";
14
+ import { KanbanStatusDot } from "./KanbanStatusDot.tsx";
15
+ import { SessionLinks } from "./SessionLinks.tsx";
16
+ import { sidebarModeStore } from "./sidebar-mode.ts";
17
+ import {
18
+ formatKanbanAlertLabel,
19
+ formatRelativeTime,
20
+ getKanbanSessionTitle,
21
+ getSessionRecency,
22
+ setStoredKanbanWorkspace,
23
+ } from "./store.ts";
24
+ import { useKanban } from "./use-kanban.ts";
25
+
26
+ function IconCheck({ size = 14 }: { size?: number }) {
27
+ return (
28
+ <svg
29
+ width={size}
30
+ height={size}
31
+ viewBox="0 0 16 16"
32
+ fill="none"
33
+ stroke="currentColor"
34
+ strokeWidth="1.3"
35
+ strokeLinecap="round"
36
+ strokeLinejoin="round"
37
+ aria-hidden="true"
38
+ >
39
+ <path d="M2.25 8.5L5.49732 11.7473C5.90519 12.1552 6.57263 12.1344 6.95426 11.7018L13.75 4" />
40
+ </svg>
41
+ );
42
+ }
43
+
44
+ function IconPause({ size = 14 }: { size?: number }) {
45
+ return (
46
+ <svg
47
+ width={size}
48
+ height={size}
49
+ viewBox="0 0 16 16"
50
+ fill="none"
51
+ stroke="currentColor"
52
+ strokeWidth="1.3"
53
+ aria-hidden="true"
54
+ >
55
+ <path d="M8 14.5C11.5899 14.5 14.5 11.5899 14.5 8C14.5 4.41015 11.5899 1.5 8 1.5C4.41015 1.5 1.5 4.41015 1.5 8C1.5 11.5899 4.41015 14.5 8 14.5Z" />
56
+ <path d="M6.5 5.5V10.5" strokeLinecap="round" />
57
+ <path d="M9.5 5.5V10.5" strokeLinecap="round" />
58
+ </svg>
59
+ );
60
+ }
61
+
62
+ export interface InFlightSidebarInjected extends KanbanPaneInjected {
63
+ readonly navigation: {
64
+ readonly subscribe: (listener: () => void) => () => void;
65
+ readonly getSnapshot: () => {
66
+ readonly sessionIds: readonly SessionId[];
67
+ readonly focusedSessionId: SessionId | undefined;
68
+ readonly maximizedSessionId: SessionId | undefined;
69
+ readonly suspended: boolean;
70
+ };
71
+ readonly toggleSession: (id: SessionId) => void;
72
+ readonly removeSession: (id: SessionId) => void;
73
+ readonly toggleMaximize: (id: SessionId) => void;
74
+ readonly setHoveredSession: (id: SessionId | undefined) => void;
75
+ };
76
+ }
77
+
78
+ export type InFlightSidebarProps = SidebarSectionOwnerProps &
79
+ InjectFace<InFlightSidebarInjected>;
80
+
81
+ function laneLabel(lane: KanbanLane): string {
82
+ switch (lane) {
83
+ case "active":
84
+ return "In Progress";
85
+ case "review":
86
+ return "In Review";
87
+ case "todo":
88
+ return "On Hold";
89
+ case "done":
90
+ return "Done";
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Purpose: Render a dedicated in-flight Kanban preview in the left sidebar grouped by workspace.
96
+ * Contract:
97
+ * - Inputs: InFlightSidebarProps containing sidebar geometry (wide, expandSidebar) and injected Kanban data/actions.
98
+ * - Outputs: Rendered JSX element for the sidebar browsing region.
99
+ * - Throws / Errors: Never throws.
100
+ */
101
+ export function InFlightSidebar({
102
+ wide,
103
+ expandSidebar: _expandSidebar,
104
+ sessionsList,
105
+ workspacesList,
106
+ sessionStatus,
107
+ currentSessionId: _currentSessionId,
108
+ selectPanel,
109
+ selectSession,
110
+ navigation,
111
+ startTask,
112
+ markDone,
113
+ reopen,
114
+ holdSession,
115
+ }: InFlightSidebarProps) {
116
+ const [now, setNow] = useState<number>(() => Date.now());
117
+ const splitState = useSyncExternalStore(
118
+ navigation.subscribe,
119
+ navigation.getSnapshot,
120
+ );
121
+
122
+ useEffect(() => {
123
+ const timer = setInterval(() => {
124
+ setNow(Date.now());
125
+ }, 10_000);
126
+ return () => {
127
+ clearInterval(timer);
128
+ };
129
+ }, []);
130
+
131
+ const board = useKanban(
132
+ sessionsList,
133
+ workspacesList,
134
+ sessionStatus,
135
+ now,
136
+ splitState.sessionIds,
137
+ );
138
+ const { sidebarSessions, workspaceGroups, activeSessionId } = board;
139
+ const activeCount = board.totalCounts.running;
140
+ const reviewCount = board.totalCounts.inReview;
141
+ const alertCount = board.totalCounts.alerts;
142
+ const totalInFlight = sidebarSessions.length;
143
+
144
+ const switchToWorkspaces = () => {
145
+ sidebarModeStore.setMode("workspaces");
146
+ selectPanel(null);
147
+ };
148
+
149
+ const handleOpenWorkspaceKanban = (workspaceId: string) => {
150
+ setStoredKanbanWorkspace(workspaceId);
151
+ selectPanel("kanban");
152
+ };
153
+
154
+ const handleSelectSession = (sessionId: SessionId, e: React.MouseEvent) => {
155
+ if (e.detail > 1) return;
156
+ if (e.metaKey || e.ctrlKey) {
157
+ e.preventDefault();
158
+ navigation.toggleSession(sessionId);
159
+ return;
160
+ }
161
+ selectSession(sessionId);
162
+ };
163
+
164
+ const handleDoubleClick = (sessionId: SessionId, e: React.MouseEvent) => {
165
+ e.stopPropagation();
166
+ if (e.metaKey || e.ctrlKey) return;
167
+ navigation.toggleMaximize(sessionId);
168
+ };
169
+
170
+ if (!wide) {
171
+ return (
172
+ <nav
173
+ className="dsh-inflight-sidebar-rail"
174
+ aria-label="In-flight sidebar rail"
175
+ >
176
+ <button
177
+ type="button"
178
+ className="dsh-inflight-rail-switcher-btn is-active"
179
+ onClick={() => {
180
+ selectPanel("kanban");
181
+ }}
182
+ title={`Open Kanban (${totalInFlight})`}
183
+ aria-label={`Open Kanban (${totalInFlight})`}
184
+ >
185
+ <KanbanIcon size={18} />
186
+ {(activeCount > 0 || reviewCount > 0 || alertCount > 0) && (
187
+ <span className="dsh-inflight-rail-badges">
188
+ {alertCount > 0 && (
189
+ <span
190
+ className="dsh-kanban-ws-badge dsh-kanban-ws-badge-alert"
191
+ title={`${alertCount} requiring attention`}
192
+ >
193
+ {alertCount}
194
+ </span>
195
+ )}
196
+ {activeCount > 0 && (
197
+ <span
198
+ className="dsh-kanban-ws-badge dsh-kanban-ws-badge-top"
199
+ title={`${activeCount} in progress`}
200
+ >
201
+ {activeCount}
202
+ </span>
203
+ )}
204
+ {reviewCount > 0 && (
205
+ <span
206
+ className="dsh-kanban-ws-badge dsh-kanban-ws-badge-bottom"
207
+ title={`${reviewCount} in review`}
208
+ >
209
+ {reviewCount}
210
+ </span>
211
+ )}
212
+ </span>
213
+ )}
214
+ </button>
215
+ <div className="dsh-inflight-rail-divider" />
216
+ {sidebarSessions.map((session) => {
217
+ const lane = board.getLane(session.id);
218
+ const alert = board.getAlert(session.id);
219
+ const isSplitActive =
220
+ splitState.sessionIds.length > 0 && !splitState.suspended;
221
+ const isInSplit =
222
+ isSplitActive && splitState.sessionIds.includes(session.id);
223
+ const isFocused =
224
+ splitState.sessionIds.length > 1 &&
225
+ !splitState.suspended &&
226
+ session.id === splitState.focusedSessionId;
227
+ const isCurrent = isSplitActive
228
+ ? isInSplit
229
+ : session.id === activeSessionId;
230
+ const alertLabel =
231
+ alert !== undefined ? formatKanbanAlertLabel(alert) : undefined;
232
+ const statusLabel = alertLabel ?? laneLabel(lane);
233
+ const sessionTitle = getKanbanSessionTitle(session);
234
+
235
+ return (
236
+ <button
237
+ key={session.id}
238
+ type="button"
239
+ aria-current={isFocused ? "true" : undefined}
240
+ className={`dsh-inflight-rail-session-dot ${
241
+ isCurrent ? "is-current" : ""
242
+ } ${isFocused ? "is-focused" : ""}`}
243
+ onClick={(e) => {
244
+ handleSelectSession(session.id, e);
245
+ }}
246
+ title={`${sessionTitle} (${statusLabel})`}
247
+ aria-label={`${sessionTitle} (${statusLabel})`}
248
+ >
249
+ {isSplitActive && splitState.maximizedSessionId === session.id ? (
250
+ <IconFullscreenOutlineRegular size={14} />
251
+ ) : (
252
+ <KanbanStatusDot state={alert ? "alert" : lane} />
253
+ )}
254
+ </button>
255
+ );
256
+ })}
257
+ </nav>
258
+ );
259
+ }
260
+
261
+ return (
262
+ <div className="dsh-inflight-sidebar">
263
+ <div className="dsh-inflight-sidebar-header">
264
+ <button
265
+ type="button"
266
+ className="dsh-inflight-header-clickable"
267
+ onClick={() => selectPanel("kanban")}
268
+ title="Open Kanban"
269
+ >
270
+ <span className="dsh-inflight-header-icon">
271
+ <KanbanIcon size={16} />
272
+ </span>
273
+ <span className="dsh-inflight-sidebar-title">Kanban</span>
274
+ {(activeCount > 0 || reviewCount > 0 || alertCount > 0) && (
275
+ <span className="dsh-inflight-badges">
276
+ {alertCount > 0 && (
277
+ <span
278
+ className="dsh-kanban-badge is-alert"
279
+ title={`${alertCount} requiring attention`}
280
+ >
281
+ {alertCount}
282
+ </span>
283
+ )}
284
+ {activeCount > 0 && (
285
+ <span
286
+ className="dsh-kanban-badge is-active"
287
+ title={`${activeCount} in progress`}
288
+ >
289
+ {activeCount}
290
+ </span>
291
+ )}
292
+ {reviewCount > 0 && (
293
+ <span
294
+ className="dsh-kanban-badge is-review"
295
+ title={`${reviewCount} in review`}
296
+ >
297
+ {reviewCount}
298
+ </span>
299
+ )}
300
+ </span>
301
+ )}
302
+ </button>
303
+ <button
304
+ type="button"
305
+ className="dsh-inflight-btn-close"
306
+ onClick={switchToWorkspaces}
307
+ title="Close Kanban"
308
+ aria-label="Close Kanban"
309
+ >
310
+ ✕
311
+ </button>
312
+ </div>
313
+
314
+ <div className="dsh-inflight-sidebar-list">
315
+ {workspaceGroups.map((group) => {
316
+ const counts =
317
+ group.workspaceId === "ungrouped"
318
+ ? undefined
319
+ : board.workspaceCounts.get(group.workspaceId as WorkspaceId);
320
+ let wsActiveCount = counts ? counts.running : 0;
321
+ let wsReviewCount = counts ? counts.inReview : 0;
322
+ let wsAlertCount = counts ? counts.alerts : 0;
323
+ if (group.workspaceId === "ungrouped") {
324
+ for (const s of group.sessions) {
325
+ const lane = board.getLane(s.id);
326
+ const alert = board.getAlert(s.id);
327
+ if (alert !== undefined) wsAlertCount += 1;
328
+ if (lane === "active") wsActiveCount += 1;
329
+ else if (lane === "review" && alert === undefined)
330
+ wsReviewCount += 1;
331
+ }
332
+ }
333
+
334
+ return (
335
+ <div key={group.workspaceId} className="dsh-inflight-ws-group">
336
+ <div className="dsh-inflight-ws-header-row">
337
+ <button
338
+ type="button"
339
+ className="dsh-inflight-ws-header"
340
+ onClick={() => handleOpenWorkspaceKanban(group.workspaceId)}
341
+ title={`Open ${group.title} in Kanban`}
342
+ >
343
+ <span className="dsh-inflight-ws-icon">
344
+ <svg
345
+ width="14"
346
+ height="14"
347
+ viewBox="0 0 16 16"
348
+ fill="currentColor"
349
+ aria-hidden="true"
350
+ >
351
+ <path d="M1.5 3A1.5 1.5 0 0 0 0 4.5v7A1.5 1.5 0 0 0 1.5 13h13a1.5 1.5 0 0 0 1.5-1.5V6a1.5 1.5 0 0 0-1.5-1.5H8.414l-1.707-1.707A1 1 0 0 0 6 2.5H1.5z" />
352
+ </svg>
353
+ </span>
354
+ <span className="dsh-inflight-ws-title">{group.title}</span>
355
+ {(wsActiveCount > 0 ||
356
+ wsReviewCount > 0 ||
357
+ wsAlertCount > 0) && (
358
+ <span className="dsh-inflight-badges">
359
+ {wsAlertCount > 0 && (
360
+ <span
361
+ className="dsh-kanban-badge is-alert"
362
+ title={`${wsAlertCount} requiring attention`}
363
+ >
364
+ {wsAlertCount}
365
+ </span>
366
+ )}
367
+ {wsActiveCount > 0 && (
368
+ <span
369
+ className="dsh-kanban-badge is-active"
370
+ title={`${wsActiveCount} in progress`}
371
+ >
372
+ {wsActiveCount}
373
+ </span>
374
+ )}
375
+ {wsReviewCount > 0 && (
376
+ <span
377
+ className="dsh-kanban-badge is-review"
378
+ title={`${wsReviewCount} in review`}
379
+ >
380
+ {wsReviewCount}
381
+ </span>
382
+ )}
383
+ </span>
384
+ )}
385
+ </button>
386
+ <button
387
+ type="button"
388
+ className="dsh-inflight-btn-add-task"
389
+ onClick={(e) => {
390
+ e.stopPropagation();
391
+ void startTask(
392
+ group.workspaceId === "ungrouped"
393
+ ? undefined
394
+ : (group.workspaceId as WorkspaceId),
395
+ );
396
+ }}
397
+ title={`Add task in ${group.title}`}
398
+ aria-label={`Add task in ${group.title}`}
399
+ >
400
+ <svg
401
+ width="14"
402
+ height="14"
403
+ viewBox="0 0 16 16"
404
+ fill="none"
405
+ stroke="currentColor"
406
+ strokeWidth="1.75"
407
+ strokeLinecap="round"
408
+ aria-hidden="true"
409
+ >
410
+ <path d="M8 3v10M3 8h10" />
411
+ </svg>
412
+ </button>
413
+ </div>
414
+ {group.sessions.length > 0 && (
415
+ <div className="dsh-inflight-ws-cards">
416
+ {group.sessions.map((session) => {
417
+ const lane = board.getLane(session.id);
418
+ const alert = board.getAlert(session.id);
419
+ const isInProgress = lane === "active" || session.running;
420
+ const isSplitActive =
421
+ splitState.sessionIds.length > 0 && !splitState.suspended;
422
+ const isInSplit =
423
+ isSplitActive &&
424
+ splitState.sessionIds.includes(session.id);
425
+ const isFocused =
426
+ splitState.sessionIds.length > 1 &&
427
+ !splitState.suspended &&
428
+ session.id === splitState.focusedSessionId;
429
+ const isCurrent = isSplitActive
430
+ ? isInSplit
431
+ : session.id === activeSessionId;
432
+ const alertLabel =
433
+ alert !== undefined
434
+ ? formatKanbanAlertLabel(alert)
435
+ : undefined;
436
+ const statusTitle = alertLabel ?? laneLabel(lane);
437
+ const values = session.projectionValues;
438
+ const record =
439
+ values === undefined ? undefined : values.kanban;
440
+
441
+ const isMaximized =
442
+ isSplitActive &&
443
+ splitState.maximizedSessionId === session.id;
444
+
445
+ const canClosePane = isInSplit && !isMaximized;
446
+ const sessionTitle = getKanbanSessionTitle(
447
+ session,
448
+ group.title,
449
+ );
450
+
451
+ return (
452
+ <div
453
+ key={session.id}
454
+ className={`dsh-inflight-card ${isCurrent ? "is-current" : ""} ${isFocused ? "is-focused" : ""} ${alert ? "is-alert" : ""} ${canClosePane ? "has-slot-close" : ""}`}
455
+ onPointerEnter={() => {
456
+ if (isInSplit)
457
+ navigation.setHoveredSession(session.id);
458
+ }}
459
+ onPointerLeave={() => {
460
+ navigation.setHoveredSession(undefined);
461
+ }}
462
+ >
463
+ {isMaximized ? (
464
+ <button
465
+ type="button"
466
+ aria-pressed="true"
467
+ className="dsh-inflight-card-slot dsh-inflight-btn-fullscreen-toggle is-active is-pressed"
468
+ onClick={(e) => {
469
+ e.stopPropagation();
470
+ navigation.toggleMaximize(session.id);
471
+ }}
472
+ title="Restore split layout"
473
+ aria-label={`Restore split layout for ${sessionTitle}`}
474
+ >
475
+ <IconFullscreenOutlineRegular size={14} />
476
+ </button>
477
+ ) : (
478
+ <span className="dsh-inflight-card-slot">
479
+ <span
480
+ className="dsh-inflight-card-slot-status"
481
+ aria-hidden="true"
482
+ title={statusTitle}
483
+ >
484
+ <KanbanStatusDot state={alert ? "alert" : lane} />
485
+ </span>
486
+ {canClosePane && (
487
+ <button
488
+ type="button"
489
+ className="dsh-inflight-btn-slot-close"
490
+ onClick={(e) => {
491
+ e.stopPropagation();
492
+ navigation.removeSession(session.id);
493
+ }}
494
+ title={`Close ${sessionTitle} in split view`}
495
+ aria-label={`Close ${sessionTitle} in split view`}
496
+ >
497
+ <IconCloseOutlineRegular size={14} />
498
+ </button>
499
+ )}
500
+ </span>
501
+ )}
502
+ <div className="dsh-inflight-card-content">
503
+ {record !== undefined && record !== null && (
504
+ <SessionLinks links={record.links} />
505
+ )}
506
+ <button
507
+ type="button"
508
+ className="dsh-inflight-card-main"
509
+ aria-current={isFocused ? "true" : undefined}
510
+ onClick={(e) => handleSelectSession(session.id, e)}
511
+ onDoubleClick={(e) =>
512
+ handleDoubleClick(session.id, e)
513
+ }
514
+ aria-label={`${sessionTitle} (${statusTitle})`}
515
+ >
516
+ <span className="dsh-inflight-card-title">
517
+ {sessionTitle}
518
+ </span>
519
+ </button>
520
+ </div>
521
+ <span className="dsh-inflight-card-time">
522
+ {formatRelativeTime(getSessionRecency(session), now)
523
+ .replace("just now", "now")
524
+ .replace(" ago", "")}
525
+ </span>
526
+ <div className="dsh-inflight-card-actions">
527
+ {lane === "done" ? (
528
+ <button
529
+ type="button"
530
+ className="dsh-inflight-btn-action"
531
+ onClick={(e) => {
532
+ e.stopPropagation();
533
+ void reopen(session.id);
534
+ }}
535
+ title="Reopen task"
536
+ aria-label="Reopen task"
537
+ >
538
+ <IconRefreshOutlineRegular size={14} />
539
+ </button>
540
+ ) : (
541
+ <>
542
+ <button
543
+ type="button"
544
+ className={`dsh-inflight-btn-action is-hold ${
545
+ isInProgress ? "is-disabled" : ""
546
+ }`}
547
+ disabled={isInProgress}
548
+ onClick={(e) => {
549
+ e.stopPropagation();
550
+ if (!isInProgress) {
551
+ void holdSession(session.id);
552
+ }
553
+ }}
554
+ title={
555
+ isInProgress
556
+ ? "Session is in progress"
557
+ : "Put on hold"
558
+ }
559
+ aria-label={
560
+ isInProgress
561
+ ? "Session is in progress"
562
+ : "Put on hold"
563
+ }
564
+ >
565
+ <IconPause size={14} />
566
+ </button>
567
+ <button
568
+ type="button"
569
+ className={`dsh-inflight-btn-action is-done ${
570
+ isInProgress ? "is-disabled" : ""
571
+ }`}
572
+ disabled={isInProgress}
573
+ onClick={(e) => {
574
+ e.stopPropagation();
575
+ if (!isInProgress) {
576
+ void markDone(session.id);
577
+ }
578
+ }}
579
+ title={
580
+ isInProgress
581
+ ? "Session is in progress"
582
+ : "Mark task done"
583
+ }
584
+ aria-label={
585
+ isInProgress
586
+ ? "Session is in progress"
587
+ : "Mark task done"
588
+ }
589
+ >
590
+ <IconCheck size={14} />
591
+ </button>
592
+ </>
593
+ )}
594
+ </div>
595
+ </div>
596
+ );
597
+ })}
598
+ </div>
599
+ )}
600
+ </div>
601
+ );
602
+ })}
603
+ </div>
604
+ </div>
605
+ );
606
+ }