mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 00:08:25 +00:00
* feat: add columns layout to grouped grid views * test: strengthen Columns layout coverage * fix: remove doubled vertical border on group column spans The group-by divider already draws a full-height line at each level boundary, so the span's own border-right rendered a second adjacent line in the body but not in the header. * chore: renumber group_by_layout migration after rebase Develop added 0221 and 0222 in the meantime, so the branch migration forked the graph into two leaf nodes. * refactor: rename banner group layout to section
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
/**
|
|
* Returns the widths to use when rendering group-by columns in the available space.
|
|
* The configured widths are left untouched so they can be restored exactly when the
|
|
* viewport grows again. If the columns need to shrink, only the space above the
|
|
* minimum width is scaled, which also preserves columns explicitly set to the
|
|
* minimum.
|
|
*/
|
|
export function fitGroupByWidths(groupBys, availableWidth, minimumWidth) {
|
|
const widths = groupBys.map((groupBy) =>
|
|
Math.max(groupBy.width, minimumWidth)
|
|
)
|
|
const totalWidth = widths.reduce((total, width) => total + width, 0)
|
|
|
|
if (
|
|
availableWidth === null ||
|
|
availableWidth === undefined ||
|
|
totalWidth <= availableWidth
|
|
) {
|
|
return widths
|
|
}
|
|
|
|
const minimumTotalWidth = minimumWidth * widths.length
|
|
if (availableWidth <= minimumTotalWidth) {
|
|
return widths.map(() => minimumWidth)
|
|
}
|
|
|
|
const flexibleWidth = totalWidth - minimumTotalWidth
|
|
const availableFlexibleWidth = availableWidth - minimumTotalWidth
|
|
const scale = availableFlexibleWidth / flexibleWidth
|
|
|
|
return widths.map((width) => minimumWidth + (width - minimumWidth) * scale)
|
|
}
|