Skip to content

Commit 8e92c78

Browse files
authored
Merge pull request #2427 from appwrite/fix-width
2 parents d42bac7 + 3aa2e2b commit 8e92c78

File tree

1 file changed

+60
-37
lines changed
  • src/routes/(console)/project-[region]-[project]/databases/database-[database]/(suggestions)

1 file changed

+60
-37
lines changed

src/routes/(console)/project-[region]-[project]/databases/database-[database]/(suggestions)/empty.svelte

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,8 @@
156156
const actionsRect = actionsCell.getBoundingClientRect();
157157
const left = Math.round(idRect.right - containerRect.left);
158158
const actionsLeft = actionsRect.left - containerRect.left;
159-
const width = Math.min(
160-
customColumns.length * 180, // estimated minimum placeholder width
161-
actionsLeft - left // don't exceed actions column
162-
);
159+
160+
const width = actionsLeft - left;
163161
164162
spreadsheetContainer.style.setProperty('--group-left', `${left - 2}px`);
165163
spreadsheetContainer.style.setProperty('--group-width', `${width + 2}px`);
@@ -219,27 +217,22 @@
219217
220218
const left = Math.round(startLeft - containerRect.left);
221219
222-
// maximum possible width of all custom columns
223-
const totalFullWidth = customColumns.reduce(
224-
(total, col) => total + getColumnWidth(col.key),
225-
0
226-
);
227-
228220
// get the actions column and use its left border as the boundary
229221
const actionsCell = headerElement!.querySelector<HTMLElement>(
230222
'[role="cell"][data-column-id="actions"]'
231223
);
232-
const rawVisibleWidth = Math.round(visibleRight - idRect.right);
233-
let maxAllowedWidth = rawVisibleWidth;
234224
235-
if (actionsCell) {
236-
const actionsRect = actionsCell.getBoundingClientRect();
237-
const actionsLeft = actionsRect.left - containerRect.left;
238-
maxAllowedWidth = Math.min(rawVisibleWidth, actionsLeft - left);
225+
if (!actionsCell) {
226+
if (rangeOverlayEl) {
227+
rangeOverlayEl.style.display = 'none';
228+
}
229+
return;
239230
}
240231
241-
// Set overlay width to not exceed actions column boundary
242-
const width = Math.min(totalFullWidth, maxAllowedWidth);
232+
const actionsRect = actionsCell.getBoundingClientRect();
233+
const actionsLeft = actionsRect.left - containerRect.left;
234+
235+
const width = actionsLeft - left;
243236
244237
// Apply overlay positioning
245238
spreadsheetContainer.style.setProperty('--group-left', `${left - 2}px`);
@@ -338,25 +331,55 @@
338331
});
339332
});
340333
341-
const getRowColumns = (): Column[] => [
342-
{
343-
id: '$id',
344-
title: '$id',
345-
type: 'string',
346-
width: 180,
347-
icon: IconFingerPrint,
348-
...baseColProps
349-
},
350-
...customSuggestedColumns,
351-
{
352-
id: 'actions',
353-
title: '',
354-
type: 'string' as Column['type'],
355-
width: 40,
356-
isAction: true,
357-
...baseColProps
358-
}
359-
];
334+
const getRowColumns = (): Column[] => {
335+
const minColumnWidth = 180;
336+
const fixedWidths = { id: minColumnWidth, actions: 40, selection: 40 };
337+
338+
// calculate base widths and total
339+
const columnsWithBase = customSuggestedColumns.map((col) => ({
340+
...col,
341+
baseWidth: Math.max(minColumnWidth, getColumnWidth(col.id))
342+
}));
343+
344+
const totalUsed =
345+
fixedWidths.id +
346+
fixedWidths.actions +
347+
fixedWidths.selection +
348+
columnsWithBase.reduce((sum, col) => sum + col.baseWidth, 0);
349+
350+
// distribute excess space equally across custom columns
351+
const viewportWidth =
352+
spreadsheetContainer?.clientWidth ||
353+
(typeof window !== 'undefined' ? window.innerWidth : totalUsed);
354+
355+
const extraPerColumn =
356+
Math.max(0, viewportWidth - totalUsed) / (columnsWithBase.length || 1);
357+
358+
const finalCustomColumns = columnsWithBase.map((col) => ({
359+
...col,
360+
width: { min: col.baseWidth + extraPerColumn }
361+
}));
362+
363+
return [
364+
{
365+
id: '$id',
366+
title: '$id',
367+
type: 'string',
368+
width: fixedWidths.id,
369+
icon: IconFingerPrint,
370+
...baseColProps
371+
},
372+
...finalCustomColumns,
373+
{
374+
id: 'actions',
375+
title: '',
376+
type: 'string' as Column['type'],
377+
width: fixedWidths.actions,
378+
isAction: true,
379+
...baseColProps
380+
}
381+
];
382+
};
360383
361384
// Handle browser back/forward navigation
362385
const handleBeforeUnload = (event: BeforeUnloadEvent) => {

0 commit comments

Comments
 (0)