Files
Davide Silvestri 0aa7147db3 Collapsible group-by grid view (#5470)
* feat: add collapsible group-by grid view

* fix: address copilot feedback, plus some other cleanup/fixes

* fix: harden grid e2e navigation

* Add e2e tests; improve performance; clean up code

* feat: show resolved values for reference fields in group-by headers

- Resolve collaborator, link-row and select group values to renderable display
  objects in the group-by data API, batched once per field per page (O(1) lookups,
  no per-group queries).
- Order many-to-many groups identically to the rows via correlated-subquery
  ordering, since the relation column is shadowed by the aggregated array
  annotation in group-by queries.
- Render the display values as chips in the group-by banner via dedicated
  multiple-select / multiple-collaborators components; shrink the collaborator
  badge, reduce the field-name size and keep the label on one line.

* fix: group many-to-many fields by their set of values

Grouping a grid by a collaborator, multiple-select or link-row field
produced empty groups with orphaned rows and duplicate headers for the
same set of values. The group key (an id array) was order-sensitive: the
backend's aggregated array order was unstable row-to-row and the cell
appends new values, so an optimistically-created group's key diverged
from the server's and rows were rejected by rowBelongsToGroupBySection.

- pathKey and the group-row Vue keys now sort m2m id arrays numerically,
  so a group is identified by its set of ids, not their order.
- The backend aggregates the group value ordered by related id and sorts
  the group's unique value, making grouping deterministic and set-based.
- Optimistically-emptied groups (row_count 0) are no longer rendered (the
  node is kept for reconciliation), and the leading group gap is fixed so
  the first visible group has no spurious gap.
- A newly created collaborator group resolves its badge name from the
  workspace store instead of requiring the name on the value.

* fix: keep cell multi-select when dragging in a group-by view

A multi-select drag ends with a click whose target is the rows
container (the common ancestor of the dragged cells). cancelMultiSelect-
IfActive cancels the selection unless that container is recognised as
part of the rows area, but its whitelist only knew the flat-grid classes
(grid-view__rows / grid-view__row). The collapsible group-by feature
renders rows in grid-view__group-by-rows containers, so the post-drag
click was treated as "outside the rows" and the selection was cleared on
mouseup. Add the group-by row containers to the whitelist.

* test: expect emptied group-by banners to disappear

The optimistic empty-group hiding (a group disappears once its last row
moves out) made the e2e contract that kept the emptied source group
visible at row_count 0 obsolete. Update the 2.2.7/2.4.4 assertions to
expect the emptied group's banner to be gone (new expectNoGroupByBanner
helper), and correct the tree-maintenance comments: the node is still
kept for reconciliation, but the layout no longer renders its banner.

* perf: load the collapsible group-by grid in one bounded request

Grouping a wide table by many fields took several seconds and a request
waterfall to render the first screen. The group tree was fetched one HTTP
request per depth, a budget that ran out before reaching any leaf forced
a per-parent fallback, and the rows endpoint resolved group-by metadata
unconditionally.

Backend
- Walk the descendant tree with one batched windowed query per group-by
  level (get_group_by_data_for_parents) instead of one query per parent,
  so a single include_descendants request returns the whole visible
  subtree in O(depth) queries.
- Scale the descent window to the viewport: row_budget = ceil(limit /
  depth). A deep group-by stacks each leaf row under its ancestor
  banners, so far fewer leaf rows fill the first screen; the window now
  returns a viewport-sized slice (~264 -> ~68 groups on a 12-level grid)
  and the rest lazy-loads on scroll.
- Gate the rows endpoint's group-by metadata behind
  include=group_by_metadata so it is not computed when unused.
- Resolve reference/link-row display values in one id__in query per field
  across all pages instead of once per page.

Frontend
- Initial load issues one group-by-data prefetch and one viewport rows
  request; expand mode no longer takes the per-depth path.
- Cap the banner indent (<=50px) and shrink the per-level arrow spacing
  as the group-by count grows, keeping the count aligned and the field
  name ellipsised; render multi-level loading skeletons for the
  not-yet-loaded levels.
- Guard walkPage against a cyclic page-resolution stack overflow and keep
  activeGroupBys filtered to fields that still exist.

Plus e2e env isolation (configurable ports, cookie prefix) and docs.

* fix: address review feedback

Addresses the review comments on the collapsible group-by grid PR.

- Gate the group-by add-row "+" on the same condition as the flat grid
  (not read-only, not a one-way data sync, has create-row permission), so
  it no longer renders buttons that error on click for data-sync tables.
- Show the "(Empty)" label for empty array-valued groups (multiple select,
  link row, collaborators), matching the text-field behaviour.
- Stop the flat-grid row placeholder from rendering in group-by mode
  (v-else-if instead of v-else).
- Render formula group-by headers via the result field type's group-by
  component instead of RowCardFieldFormula, removing the dev-only
  "Missing required prop: row" Vue warning.
- Keep the cell selected at the first/last field for both Tab and arrow
  keys (restore the pre-refactor behaviour); navigating past the edge no
  longer drops the selection in either flat or group-by mode.
- Re-enable and de-flake the "sorted add outside buffer" e2e test: assert
  on the re-resolved last row instead of a snapshotted renderedRowCount()
  index, which raced with the create-confirmation re-render in CI.

* fix: keep rows inserted below in a grouped grid view in their group

Insert-below and add-row in a grouped view now derive the new row's group
path from the neighbouring row, so it inherits all writable group-by values
and lands in the same group; `before` is set only when the next row shares
that group.

* feat: soft-cap adding group-bys at 5 in the view UI

Once a view reaches 5 group-bys the add button is disabled with a tooltip;
views that already have more keep working and only offer to remove them.

* limit group-bys; fix css

* refactor: polish code and comments

* fix: address Bram's feedback

* feat: add vertical gap between sibling sub-groups and indent banner labels with their chevron

* fix: address remaining feedback

* fix: row-coloring and fixed-height for add-row

* fix: address Bram's feedback v2

* fix regression in last commit

* fix: address grid group review comments
2026-07-03 09:09:52 +02:00

238 lines
8.3 KiB
Makefile

# Baserow Web-Frontend Justfile
# NOTE: All recipes here must work the same inside Docker and on local dev setups
# without requiring any changes. Please make sure to not add docker-specific
# commands or assumptions here.
# Uses yarn for Node.js package management
# Import personal recipes if they exist (not tracked in git)
import? 'local.just'
# Note: just doesn't support dynamic dotenv-filename, so we handle env loading in recipes
_load_env := 'if [ -f "../.env.local" ]; then set -a; source "../.env.local"; set +a; fi'
# Default recipe - show help
default:
@just --list
# Show documentation links for each command group
[group('0 - help')]
help:
@echo "Baserow Web-Frontend - Documentation Links"
@echo "==========================================="
@echo ""
@echo "Setup & Development:"
@echo " docs/development/running-the-dev-env-locally.md - Local development setup"
@echo " docs/development/running-the-dev-env-with-docker.md - Docker development setup"
@echo " docs/development/directory-structure.md - Project structure"
@echo ""
@echo "Testing:"
@echo " docs/development/running-tests.md - Running frontend tests"
@echo " docs/development/e2e-testing.md - End-to-end testing"
@echo ""
@echo "Code Quality:"
@echo " docs/development/code-quality.md - Linting and formatting"
@echo ""
@echo "Build & Production:"
@echo " docs/development/building-and-running-production-images.md - Production images"
@echo ""
@echo "IDE Setup:"
@echo " docs/development/vscode-setup.md - VS Code configuration"
@echo ""
@echo "Other:"
@echo " docs/development/justfile.md - Just command reference"
@echo ""
@echo "Quick shortcuts: l=lint, t=test, dev=run-dev-server"
# Allow `just frontend <cmd>` or `just f <cmd>` to work (for consistency with root justfile)
frontend *ARGS:
@just {{ ARGS }}
# Common shortcuts
alias t := test
alias dev := run-dev-server
alias serve := run-dev-server
# Pass-through to yarn
[group('7 - passthrough')]
yarn *ARGS:
yarn {{ ARGS }}
# Pass-through to npm
[group('7 - passthrough')]
npm *ARGS:
npm {{ ARGS }}
# =============================================================================
# Setup & Installation
# =============================================================================
# Install dependencies
[group('1 - setup')]
install:
yarn install
# =============================================================================
# Code Quality & Linting
# =============================================================================
# Run all linters (eslint + stylelint + prettier). Pass file paths to lint only those files
# (repo-root-relative, e.g. web-frontend/modules/foo.js). Paths outside the three
# frontend trees are silently skipped.
#
# Each tool is invoked in the same cwd as the matching yarn script:
# - eslint runs from the repo root (where eslint.config.mjs lives and where
# "files: [premium/web-frontend/**/*]" path patterns can match correctly)
# - stylelint and prettier run from web-frontend/ so their .stylelintignore and
# .prettierignore files (which live there) get auto-discovered
# Per-file results therefore match the no-args path, with one intentional
# difference: eslint is invoked with `--no-warn-ignored` so that when
# pre-commit (or a manual diff-driven invocation) passes a file that lives in
# an eslint-ignored location, we don't emit a noisy warning per file. The
# no-args path doesn't need this flag because it walks directories.
[group('4 - code-quality')]
[positional-arguments]
check *ARGS:
#!/usr/bin/env bash
set -euo pipefail
if [ $# -eq 0 ]; then
yarn run lint
exit 0
fi
JS_FILES=() # repo-root-relative, for eslint (run from repo root)
SCSS_FILES=() # web-frontend-relative, for stylelint (run from web-frontend/)
PRETTIER_FILES=() # web-frontend-relative, for prettier (run from web-frontend/)
for f in "$@"; do
case "$f" in
web-frontend/*) rel="${f#web-frontend/}" ;;
premium/web-frontend/*|enterprise/web-frontend/*) rel="../$f" ;;
*) continue ;;
esac
case "$f" in
*.js|*.jsx|*.ts|*.tsx|*.vue|*.mjs|*.cjs) JS_FILES+=("$f"); PRETTIER_FILES+=("$rel") ;;
*.scss) SCSS_FILES+=("$rel"); PRETTIER_FILES+=("$rel") ;;
*.css|*.json|*.md|*.html|*.yml|*.yaml) PRETTIER_FILES+=("$rel") ;;
esac
done
if [ ${#JS_FILES[@]} -gt 0 ]; then
[ -f .nuxt/eslint.config.mjs ] || yarn postinstall
(cd .. && web-frontend/node_modules/.bin/eslint --no-warn-ignored --cache --cache-location=web-frontend/.cache/eslint "${JS_FILES[@]}")
fi
if [ ${#SCSS_FILES[@]} -gt 0 ]; then
./node_modules/.bin/stylelint --cache --cache-location=.cache/stylelint "${SCSS_FILES[@]}"
fi
if [ ${#PRETTIER_FILES[@]} -gt 0 ]; then
./node_modules/.bin/prettier --check --log-level=warn --cache --cache-location=.cache/prettier "${PRETTIER_FILES[@]}"
fi
alias lint := check
alias l := check
# Fix code style issues. Pass file paths to fix only those files (repo-root-relative,
# e.g. web-frontend/modules/foo.js). Paths outside the three frontend trees are
# silently skipped. See `lint` above for the per-tool cwd rationale.
[group('4 - code-quality')]
[positional-arguments]
fix *ARGS:
#!/usr/bin/env bash
set -euo pipefail
if [ $# -eq 0 ]; then
yarn run fix
exit 0
fi
JS_FILES=()
SCSS_FILES=()
PRETTIER_FILES=()
for f in "$@"; do
case "$f" in
web-frontend/*) rel="${f#web-frontend/}" ;;
premium/web-frontend/*|enterprise/web-frontend/*) rel="../$f" ;;
*) continue ;;
esac
case "$f" in
*.js|*.jsx|*.ts|*.tsx|*.vue|*.mjs|*.cjs) JS_FILES+=("$f"); PRETTIER_FILES+=("$rel") ;;
*.scss) SCSS_FILES+=("$rel"); PRETTIER_FILES+=("$rel") ;;
*.css|*.json|*.md|*.html|*.yml|*.yaml) PRETTIER_FILES+=("$rel") ;;
esac
done
if [ ${#JS_FILES[@]} -gt 0 ]; then
[ -f .nuxt/eslint.config.mjs ] || yarn postinstall
(cd .. && web-frontend/node_modules/.bin/eslint --no-warn-ignored --cache --cache-location=web-frontend/.cache/eslint --fix "${JS_FILES[@]}")
fi
if [ ${#SCSS_FILES[@]} -gt 0 ]; then
./node_modules/.bin/stylelint --cache --cache-location=.cache/stylelint --fix "${SCSS_FILES[@]}"
fi
if [ ${#PRETTIER_FILES[@]} -gt 0 ]; then
./node_modules/.bin/prettier --write --log-level=warn --cache --cache-location=.cache/prettier "${PRETTIER_FILES[@]}"
fi
alias format := fix
alias f := fix
# =============================================================================
# Testing
# =============================================================================
# Run tests
[group('3 - testing')]
test *ARGS:
yarn test {{ ARGS }}
# Run tests with coverage (for CI)
[group('3 - testing')]
ci-test:
yarn test:coverage
# Update Vitest snapshots
[group('3 - testing')]
update-snapshots:
EXTRA_VITEST_PARAMS="--update" yarn test
# =============================================================================
# Development
# =============================================================================
# Run development server
[group('2 - development')]
run-dev-server:
#!/usr/bin/env bash
set -euo pipefail
{{ _load_env }}
NUXT_HOST="${BASEROW_NUXT_HOST:-0.0.0.0}"
NUXT_PORT="${BASEROW_NUXT_PORT:-3000}"
yarn run dev --host "$NUXT_HOST" --port "$NUXT_PORT"
# Run Storybook
[group('2 - development')]
storybook:
#!/usr/bin/env bash
set -euo pipefail
{{ _load_env }}
STORYBOOK_HOST="${BASEROW_STORYBOOK_HOST:-0.0.0.0}"
STORYBOOK_PORT="${BASEROW_STORYBOOK_PORT:-6006}"
yarn run storybook --host "$STORYBOOK_HOST" -p "$STORYBOOK_PORT"
# Build Nuxt for production
[group('5 - build')]
build-nuxt:
yarn run build
# =============================================================================
# Cleanup
# =============================================================================
# Clean Nuxt build artifacts
[group('6 - cleanup')]
clean-nuxt:
rm -rf .nuxt/ dist/
# Clean all (Nuxt build artifacts + node_modules)
[group('6 - cleanup')]
clean-all: clean-nuxt
rm -rf node_modules/