Skip to content

Commit fbda6b8

Browse files
committed
feat: improve tab visibility and tooltip display
- Enhanced the Tabs component to ensure newly created pads are visible by adjusting the start pad index based on the current pads in the query cache. - Updated tooltip logic to display truncated pad names more effectively, improving user experience with long pad names.
1 parent 975b83d commit fbda6b8

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/frontend/src/ui/Tabs.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,25 @@ const Tabs: React.FC<TabsProps> = ({
188188

189189
// Set the active pad ID in the component state
190190
setActivePadId(newPad.id);
191+
192+
// Get the current pads from the query cache
193+
const currentPads = queryClient.getQueryData<PadData[]>(['allPads']);
194+
195+
if (currentPads) {
196+
// Find the index of the newly created pad
197+
const newPadIndex = currentPads.findIndex(pad => pad.id === newPad.id);
198+
199+
if (newPadIndex !== -1) {
200+
// Calculate the appropriate startPadIndex to ensure the new pad is visible
201+
// We want to position the view so that the new pad is visible
202+
// Ideally, we want the new pad to be the last visible pad in the view
203+
const newStartIndex = Math.max(0, Math.min(newPadIndex - PADS_PER_PAGE + 1, currentPads.length - PADS_PER_PAGE));
204+
205+
// Update both the component state and the stored value
206+
setStartPadIndex(newStartIndex);
207+
setScrollIndex(newStartIndex);
208+
}
209+
}
191210
} catch (error) {
192211
console.error('Error creating new pad:', error);
193212
} finally {
@@ -320,14 +339,14 @@ const Tabs: React.FC<TabsProps> = ({
320339
}}
321340
>
322341
{/* Only show tooltip if name is likely to be truncated (more than ~15 characters) */}
323-
{pad.display_name.length > 8 ? (
342+
{pad.display_name.length > 11 ? (
324343
<Tooltip label={pad.display_name} children={
325344
<Button
326345
onSelect={() => handlePadSelect(pad)}
327346
className={activePadId === pad.id ? "active-pad" : ""}
328347
children={
329348
<div className="tab-content">
330-
{pad.display_name}
349+
{pad.display_name.length > 8 ? `${pad.display_name.substring(0, 11)}...` : pad.display_name}
331350
<span className="tab-position">{startPadIndex + pads.slice(startPadIndex, startPadIndex + PADS_PER_PAGE).indexOf(pad) + 1}</span>
332351
</div>
333352
}

0 commit comments

Comments
 (0)