danylokhodus commited on
Commit
85d90fc
·
1 Parent(s): 3dad87e

feat: implement styled collaborator list and multi-assignee face-pile support on canvas nodes

Browse files
src/features/canvas/components/nodes/SketchNode.jsx CHANGED
@@ -116,6 +116,20 @@ const SketchNode = ({ id, data, selected }) => {
116
 
117
  const progressValue = data.progress !== undefined ? data.progress : 0;
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  return (
120
  <div
121
  onDoubleClick={openConfigureModal}
@@ -204,12 +218,27 @@ const SketchNode = ({ id, data, selected }) => {
204
  </span>
205
  <div className="flex items-center gap-2">
206
  {data.ai && <Sparkles size={12} className="text-secondary animate-pulse" />}
207
- {data.assignee && (
208
  <div
209
- title={`${data.assignee.displayName || data.assignee.email || t('canvas.assignee', 'Assignee')}`}
210
- className="w-6 h-6 rounded-full border border-primary bg-secondary/10 text-primary flex items-center justify-center text-[9px] font-bold shadow-[1px_1px_0px_0px_var(--color-primary)] relative group cursor-help transition-transform hover:scale-105"
211
  >
212
- {getInitials(data.assignee.displayName, data.assignee.email)}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  </div>
214
  )}
215
  </div>
 
116
 
117
  const progressValue = data.progress !== undefined ? data.progress : 0;
118
 
119
+ const assignees = data.assignees && Array.isArray(data.assignees)
120
+ ? data.assignees
121
+ : (data.assignee ? [data.assignee] : []);
122
+
123
+ const tooltipText = assignees.map(a => {
124
+ const name = a.displayName || t('canvas.collaborator', 'Collaborator');
125
+ return a.email ? `${name} (${a.email})` : name;
126
+ }).join(', ');
127
+
128
+ const maxVisible = 3;
129
+ const shouldTruncate = assignees.length > maxVisible;
130
+ const visibleAssignees = shouldTruncate ? assignees.slice(0, 2) : assignees;
131
+ const remainingCount = assignees.length - visibleAssignees.length;
132
+
133
  return (
134
  <div
135
  onDoubleClick={openConfigureModal}
 
218
  </span>
219
  <div className="flex items-center gap-2">
220
  {data.ai && <Sparkles size={12} className="text-secondary animate-pulse" />}
221
+ {assignees.length > 0 && (
222
  <div
223
+ title={tooltipText}
224
+ className="flex items-center -space-x-1.5 flex-row-reverse cursor-help"
225
  >
226
+ {shouldTruncate && (
227
+ <div
228
+ className="w-6 h-6 rounded-full border border-primary bg-secondary/20 text-primary flex items-center justify-center text-[8px] font-extrabold shadow-[1px_1px_0px_0px_var(--color-primary)] relative transition-transform hover:scale-105 z-0"
229
+ >
230
+ +{remainingCount}
231
+ </div>
232
+ )}
233
+ {visibleAssignees.slice().reverse().map((assignee, index) => (
234
+ <div
235
+ key={assignee.sharedWithUserId || assignee.email || index}
236
+ className="w-6 h-6 rounded-full border border-primary bg-secondary/10 text-primary flex items-center justify-center text-[9px] font-bold shadow-[1px_1px_0px_0px_var(--color-primary)] relative transition-transform hover:scale-105 hover:z-10"
237
+ style={{ zIndex: index + 1 }}
238
+ >
239
+ {getInitials(assignee.displayName, assignee.email)}
240
+ </div>
241
+ ))}
242
  </div>
243
  )}
244
  </div>
src/features/canvas/hooks/useCanvasLogic.js CHANGED
@@ -594,7 +594,7 @@ export const useCanvasLogic = (projectId, user) => {
594
  }
595
  }
596
  } else if (n.type === 'sketch') {
597
- let assignee = null;
598
  if (n.decision && n.decision.startsWith('{')) {
599
  try {
600
  const parsed = JSON.parse(n.decision);
@@ -602,7 +602,11 @@ export const useCanvasLogic = (projectId, user) => {
602
  progress = parsed.progress || 0;
603
  showProgress = !!parsed.showProgress;
604
  decision = parsed.decision || 'bottom';
605
- assignee = parsed.assignee || null;
 
 
 
 
606
  } catch (e) {
607
  console.error('Failed to parse sketch decision JSON', e);
608
  }
@@ -624,7 +628,7 @@ export const useCanvasLogic = (projectId, user) => {
624
  description: description || '',
625
  progress: progress,
626
  showProgress: showProgress,
627
- assignee,
628
  updateNodeData: updateNodeDataCallback
629
  }
630
  };
@@ -751,7 +755,7 @@ export const useCanvasLogic = (projectId, user) => {
751
  progress: n.data.progress || 0,
752
  showProgress: !!n.data.showProgress,
753
  decision: n.data.decision || 'bottom',
754
- assignee: n.data.assignee || null
755
  })
756
  : n.data.decision
757
  })),
 
594
  }
595
  }
596
  } else if (n.type === 'sketch') {
597
+ let assignees = [];
598
  if (n.decision && n.decision.startsWith('{')) {
599
  try {
600
  const parsed = JSON.parse(n.decision);
 
602
  progress = parsed.progress || 0;
603
  showProgress = !!parsed.showProgress;
604
  decision = parsed.decision || 'bottom';
605
+ if (parsed.assignees && Array.isArray(parsed.assignees)) {
606
+ assignees = parsed.assignees;
607
+ } else if (parsed.assignee) {
608
+ assignees = [parsed.assignee];
609
+ }
610
  } catch (e) {
611
  console.error('Failed to parse sketch decision JSON', e);
612
  }
 
628
  description: description || '',
629
  progress: progress,
630
  showProgress: showProgress,
631
+ assignees,
632
  updateNodeData: updateNodeDataCallback
633
  }
634
  };
 
755
  progress: n.data.progress || 0,
756
  showProgress: !!n.data.showProgress,
757
  decision: n.data.decision || 'bottom',
758
+ assignees: n.data.assignees || []
759
  })
760
  : n.data.decision
761
  })),
src/pages/CanvasPage.jsx CHANGED
@@ -57,7 +57,7 @@ const getTransformForBoundsCustom = (bounds, width, height, minZoom, maxZoom, pa
57
  import Sidebar from '../components/Sidebar';
58
  import { useAuth } from '../context/AuthContext';
59
  import { useTheme } from '../context/ThemeContext';
60
- import { Maximize2, Play, Settings, Save, ChevronLeft, ChevronDown, Loader2, Trash2, Target, GitFork, Image, X, Plus, Timer, Milestone, Share2, User, Copy, Scissors, Clipboard } from 'lucide-react';
61
 
62
  // Feature components
63
  import SketchNode from '../features/canvas/components/nodes/SketchNode';
@@ -482,7 +482,7 @@ const SketchSettingsModal = ({ node, onClose, onSave, collaborators = [] }) => {
482
  const [description, setDescription] = useState(node.data.description || '');
483
  const [showProgress, setShowProgress] = useState(!!node.data.showProgress);
484
  const [progress, setProgress] = useState(node.data.progress || 0);
485
- const [assignee, setAssignee] = useState(node.data.assignee || null);
486
 
487
  const handleSave = () => {
488
  let finalProgress = Number(progress);
@@ -500,7 +500,7 @@ const SketchSettingsModal = ({ node, onClose, onSave, collaborators = [] }) => {
500
  showProgress,
501
  progress: finalProgress,
502
  status,
503
- assignee
504
  });
505
  };
506
 
@@ -548,73 +548,69 @@ const SketchSettingsModal = ({ node, onClose, onSave, collaborators = [] }) => {
548
  />
549
  </div>
550
 
551
- {/* Assignee Input */}
552
- <div>
553
- <label className="block text-[11px] font-bold uppercase tracking-widest text-primary/60 mb-2">
554
- {t('canvas.assignee_label', 'Виконавець')}
555
  </label>
556
- <div className="relative">
557
- <select
558
- value={assignee ? (assignee.sharedWithUserId || 'owner') : 'none'}
559
- onChange={(e) => {
560
- const val = e.target.value;
561
- if (val === 'none') {
562
- setAssignee(null);
563
- } else {
564
- const selectedCollab = collaborators.find(c => (c.sharedWithUserId || 'owner') === val);
565
- if (selectedCollab) {
566
- setAssignee({
567
- email: selectedCollab.email,
568
- displayName: selectedCollab.displayName,
569
- sharedWithUserId: selectedCollab.sharedWithUserId
570
- });
571
- }
572
- }
573
- }}
574
- className="w-full px-4 py-3 bg-secondary/10 border-2 border-primary rounded-xl font-bold text-primary focus:outline-none focus:bg-surface-container-lowest transition-all shadow-[2px_2px_0px_0px_rgba(49,54,63,0.1)] appearance-none cursor-pointer pr-10 text-xs font-sans"
575
- >
576
- <option value="none" className="bg-surface-container-lowest text-primary font-bold">
577
- {t('canvas.assignee_none', 'Не призначено')}
578
- </option>
579
- {collaborators.map((c) => {
580
- const labelStr = c.displayName
581
- ? `${c.displayName} (${c.email})`
582
- : c.email;
583
- const val = c.sharedWithUserId || 'owner';
584
  return (
585
- <option key={val} value={val} className="bg-surface-container-lowest text-primary font-bold">
586
- {labelStr} {c.permission === 'Owner' ? `(${t('canvas.owner', 'Власник')})` : ''}
587
- </option>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
588
  );
589
- })}
590
- </select>
591
- <div className="pointer-events-none absolute inset-y-0 right-0 flex items-center px-4 text-primary">
592
- <ChevronDown size={16} />
593
- </div>
594
  </div>
595
-
596
- {assignee && (
597
- <div className="mt-3 flex items-center gap-3 p-3 bg-success/5 border-2 border-success/30 rounded-xl animate-fade-in">
598
- <div className="w-8 h-8 rounded-full border-2 border-primary bg-secondary/15 text-primary flex items-center justify-center text-[10px] font-extrabold shadow-[2px_2px_0px_0px_var(--color-primary)] shrink-0">
599
- {getAssigneeInitials(assignee.displayName, assignee.email)}
600
- </div>
601
- <div className="flex-1 min-w-0">
602
- <span className="block font-bold text-[11px] text-primary truncate">
603
- {assignee.displayName || t('canvas.collaborator', 'Співавтор')}
604
- </span>
605
- <span className="block text-[9px] text-primary/60 truncate">
606
- {assignee.email}
607
- </span>
608
- </div>
609
- <button
610
- onClick={() => setAssignee(null)}
611
- className="p-1 hover:bg-red-500/10 border-2 border-transparent hover:border-red-500/30 rounded-lg text-primary/60 hover:text-red-500 transition-all cursor-pointer shrink-0"
612
- title={t('common.remove', 'Видалити')}
613
- >
614
- <X size={14} />
615
- </button>
616
- </div>
617
- )}
618
  </div>
619
 
620
  {/* Show Progress Toggle */}
 
57
  import Sidebar from '../components/Sidebar';
58
  import { useAuth } from '../context/AuthContext';
59
  import { useTheme } from '../context/ThemeContext';
60
+ import { Maximize2, Play, Settings, Save, ChevronLeft, ChevronDown, Loader2, Trash2, Target, GitFork, Image, X, Plus, Timer, Milestone, Share2, User, Copy, Scissors, Clipboard, Check } from 'lucide-react';
61
 
62
  // Feature components
63
  import SketchNode from '../features/canvas/components/nodes/SketchNode';
 
482
  const [description, setDescription] = useState(node.data.description || '');
483
  const [showProgress, setShowProgress] = useState(!!node.data.showProgress);
484
  const [progress, setProgress] = useState(node.data.progress || 0);
485
+ const [assignees, setAssignees] = useState(node.data.assignees || []);
486
 
487
  const handleSave = () => {
488
  let finalProgress = Number(progress);
 
500
  showProgress,
501
  progress: finalProgress,
502
  status,
503
+ assignees
504
  });
505
  };
506
 
 
548
  />
549
  </div>
550
 
551
+ {/* Assignees Input (Styled custom visual list) */}
552
+ <div className="border-2 border-primary rounded-2xl p-4 bg-secondary/5 space-y-2">
553
+ <label className="block text-[11px] font-bold uppercase tracking-widest text-primary/60">
554
+ {t('canvas.assignees_label', 'Призначити виконавців')}
555
  </label>
556
+
557
+ <div className="space-y-1.5 max-h-[160px] overflow-y-auto pr-1">
558
+ {collaborators.length === 0 ? (
559
+ <p className="text-xs font-accent-note italic text-primary/50 text-center py-4">
560
+ {t('canvas.no_collaborators_found', 'Немає доступних учасників')}
561
+ </p>
562
+ ) : (
563
+ collaborators.map((c) => {
564
+ const collabVal = c.sharedWithUserId || 'owner';
565
+ const isSelected = assignees.some(a => (a.sharedWithUserId || 'owner') === collabVal);
566
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
567
  return (
568
+ <div
569
+ key={collabVal}
570
+ onClick={() => {
571
+ if (isSelected) {
572
+ setAssignees(assignees.filter(a => (a.sharedWithUserId || 'owner') !== collabVal));
573
+ } else {
574
+ setAssignees([...assignees, {
575
+ email: c.email,
576
+ displayName: c.displayName,
577
+ sharedWithUserId: c.sharedWithUserId
578
+ }]);
579
+ }
580
+ }}
581
+ className={`flex items-center justify-between p-2.5 rounded-xl border-2 transition-all cursor-pointer select-none ${
582
+ isSelected
583
+ ? 'bg-success/10 border-success shadow-[2px_2px_0px_0px_rgba(34,197,94,0.3)]'
584
+ : 'bg-surface-container-lowest border-primary/20 hover:border-primary/50 hover:bg-secondary/5'
585
+ }`}
586
+ >
587
+ <div className="flex items-center gap-3 min-w-0">
588
+ <div className={`w-8 h-8 rounded-full border-2 ${isSelected ? 'border-success bg-success/20 text-success' : 'border-primary bg-secondary/15 text-primary'} flex items-center justify-center text-[10px] font-extrabold shadow-[1.5px_1.5px_0px_0px_var(--color-primary)] shrink-0`}>
589
+ {getAssigneeInitials(c.displayName, c.email)}
590
+ </div>
591
+ <div className="min-w-0">
592
+ <span className="block font-bold text-xs text-primary truncate leading-tight">
593
+ {c.displayName || t('canvas.collaborator', 'Співавтор')}
594
+ </span>
595
+ <span className="block text-[9px] text-primary/60 truncate leading-none mt-0.5">
596
+ {c.email}
597
+ </span>
598
+ </div>
599
+ </div>
600
+ <div className="shrink-0 flex items-center pr-1">
601
+ {isSelected ? (
602
+ <div className="w-5 h-5 rounded-md bg-success border-2 border-success flex items-center justify-center text-white">
603
+ <Check size={12} strokeWidth={3} />
604
+ </div>
605
+ ) : (
606
+ <div className="w-5 h-5 rounded-md border-2 border-primary/30 bg-surface-container-lowest" />
607
+ )}
608
+ </div>
609
+ </div>
610
  );
611
+ })
612
+ )}
 
 
 
613
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
614
  </div>
615
 
616
  {/* Show Progress Toggle */}