mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 00:08:25 +00:00
* refactor: extract grid view common test helpers
* refactor: extract row-lifecycle helpers and migrate grid store
Add computeRowInsertPosition to utils/row.js (expresses insert
position by row identity rather than flat array index).
Add handleRowCreated, handleRowDeleted, handleRowUpdated to
rowLifecycle.js. Each takes a store-supplied mutations adapter so
the decision logic (filter matching, sort position) is shared
between the flat-array grid store and the upcoming collapsible
group-by store.
Migrate createdNewRow, updatedExistingRow, deletedExistingRow in
grid.js to delegate through the new helpers via inline adapter
closures that translate position descriptors to the existing
flat-buffer Vuex mutations. Observable behaviour is unchanged;
search gating is preserved in each Vuex action.
Also includes grid view e2e test additions (section 1.5 task queue,
section 7.7 row identifier type, section 10.1 hover actions) and
grid test plan updates from the refactor/grid-view-common-e2e work.
* chore: fix CI
* chore: cleanup
* refactor: remove dead grid e2e search helpers and dedupe row-lifecycle guards
- Drop the unused openSearch/typeInSearch/clearSearch/toggleHideNotMatchingRows
methods from GridPage; the richer, used variants live in
grid_view_options.spec.ts. This also removes the placeholder/getByText
selectors flagged in review (the remaining 'Delete row' selector stays scoped
to the visible context menu).
- Centralize the repeated 'applyMatchFlags ?? noop' / 'rowsForMatchCheck ??
emptyRows' guards into a single normalizeMutations() helper. No behavior change.
* refactor: remove dead updateMatchFilters/updateMatchSortings grid actions
Both grid store actions lost all production callers in the row-lifecycle
migration (match flags are now computed via onRowChange/reapplyMatchFlags and
direct computeRowMatchFlags calls). Repoint the remaining viewFilters test at
the live onRowChange path instead of the orphaned updateMatchFilters action.
* docs: note field-constraint create/edit coverage in grid view test plan
Add 1.6.x and 2.6.x TODO entries describing add/edit behavior under unique and
unique-with-empty field constraints (backend validation error surfaced +
optimistic rollback; empty values exempt from uniqueness).
* test: await route registration in failNextRequest
failNextRequest fired page.route() without awaiting it, so the intercept
could register after the caller already triggered the request. Make it async
and await registration before returning (mirroring pauseNextRequestWithSignal);
it now returns { done } and the 3 callers await it.
* test: scope grid_interaction serial mode per-describe
Replace the single file-level serial config with a per-describe one (matching
the other two grid specs) so a failure in one block no longer skips the rest and
independent blocks can run in parallel.
* docs: document createRowLifecycleContext and clarify escape wording
- Add a docstring to createRowLifecycleContext.
- Reword the Deferred/Escape note in the grid view test plan.
* fix(e2e): return created rows from createRows helper
setupGrid expected createRows to return the created rows to collect their
ids, but the helper returned void and discarded the batch-create response,
so created.map() threw 'Cannot read properties of undefined' and every
grid_interaction spec failed deterministically. Return response.data.items.
* revert publicView changes
214 lines
6.6 KiB
JavaScript
214 lines
6.6 KiB
JavaScript
/**
|
|
* Shared row-lifecycle helpers for row visibility, positioning, and
|
|
* post-mutation match-flag re-evaluation.
|
|
*
|
|
* Callers provide:
|
|
* - `context`: shared grid inputs (`client`, `registry`, `table`, `view`,
|
|
* `fields`, optional `groupBys`)
|
|
* - `mutations`: store-specific row operations (`insertAtPosition`,
|
|
* `replaceAtPosition`, `remove`, `applyMatchFlags`, `rowsForMatchCheck`)
|
|
*
|
|
* The lifecycle code owns the common decision rules; the store owns where rows
|
|
* are inserted or patched.
|
|
*/
|
|
import {
|
|
computeRowInsertPosition,
|
|
computeRowMatchFlags,
|
|
} from '@baserow/modules/database/utils/row'
|
|
|
|
const noop = () => {}
|
|
const emptyRows = () => []
|
|
|
|
/**
|
|
* Build the shared context object the row-lifecycle handlers expect, bundling
|
|
* registry/view/fields/group-bys with a default empty `groupBys` so callers
|
|
* don't have to pass it.
|
|
*/
|
|
export function createRowLifecycleContext({
|
|
registry,
|
|
view,
|
|
fields,
|
|
groupBys = [],
|
|
}) {
|
|
return { registry, view, fields, groupBys }
|
|
}
|
|
|
|
function resolveContext(context) {
|
|
return context.groupBys === undefined ? { ...context, groupBys: [] } : context
|
|
}
|
|
|
|
/**
|
|
* Fill in the optional `mutations` callbacks with no-op defaults so the
|
|
* lifecycle functions can call `applyMatchFlags`/`rowsForMatchCheck`
|
|
* unconditionally instead of guarding each call site.
|
|
*/
|
|
function normalizeMutations(mutations) {
|
|
return {
|
|
...mutations,
|
|
applyMatchFlags: mutations.applyMatchFlags ?? noop,
|
|
rowsForMatchCheck: mutations.rowsForMatchCheck ?? emptyRows,
|
|
}
|
|
}
|
|
|
|
function applyCurrentMatchFlags(context, row, mutations) {
|
|
const flags = computeRowMatchFlags({
|
|
row,
|
|
view: context.view,
|
|
fields: context.fields,
|
|
registry: context.registry,
|
|
rowsInSortingGroup: mutations.rowsForMatchCheck(row),
|
|
groupBys: context.groupBys,
|
|
})
|
|
|
|
mutations.applyMatchFlags(row.id, flags)
|
|
return flags
|
|
}
|
|
|
|
/**
|
|
* Re-evaluate `matchFilters` and `matchSortings` for a row and apply the
|
|
* resulting warning flags through the caller's store adapter.
|
|
*/
|
|
export function reapplyMatchFlags({ context, mutations, row }) {
|
|
if (!row) {
|
|
return
|
|
}
|
|
applyCurrentMatchFlags(
|
|
resolveContext(context),
|
|
row,
|
|
normalizeMutations(mutations)
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Handle a row that was deleted externally (e.g. via a real-time event).
|
|
* Removes the row only if it was visible in the current view.
|
|
*/
|
|
export function handleRowDeleted({ context, mutations, row }) {
|
|
const lifecycleContext = resolveContext(context)
|
|
const lifecycleMutations = normalizeMutations(mutations)
|
|
|
|
const flags = computeRowMatchFlags({
|
|
row,
|
|
view: lifecycleContext.view,
|
|
fields: lifecycleContext.fields,
|
|
registry: lifecycleContext.registry,
|
|
rowsInSortingGroup: lifecycleMutations.rowsForMatchCheck(row),
|
|
groupBys: lifecycleContext.groupBys,
|
|
})
|
|
|
|
if (!flags.matchFilters) {
|
|
return
|
|
}
|
|
|
|
lifecycleMutations.remove(row.id)
|
|
}
|
|
|
|
/**
|
|
* Handle a row that was updated externally (e.g. via a real-time event).
|
|
*
|
|
* Four cases based on whether the old and new row match the current view:
|
|
*
|
|
* | oldRow in view | newRow in view | Action |
|
|
* |----------------|----------------|---------------------------------------|
|
|
* | yes | no | remove |
|
|
* | no | yes | insertAtPosition + applyMatchFlags |
|
|
* | no | no | noop |
|
|
* | yes | yes | replaceAtPosition + applyMatchFlags |
|
|
*/
|
|
export function handleRowUpdated({ context, mutations, oldRow, newRow }) {
|
|
const lifecycleContext = resolveContext(context)
|
|
const lifecycleMutations = normalizeMutations(mutations)
|
|
|
|
const oldFlags = computeRowMatchFlags({
|
|
row: oldRow,
|
|
view: lifecycleContext.view,
|
|
fields: lifecycleContext.fields,
|
|
registry: lifecycleContext.registry,
|
|
rowsInSortingGroup: lifecycleMutations.rowsForMatchCheck(oldRow),
|
|
groupBys: lifecycleContext.groupBys,
|
|
})
|
|
|
|
// Compute newRow flags using rows that exclude newRow itself, so the row
|
|
// is not compared against its own position when deciding where it belongs.
|
|
const rowsExcludingNew = lifecycleMutations
|
|
.rowsForMatchCheck(newRow)
|
|
.filter((r) => r.id !== newRow.id)
|
|
const newFlags = computeRowMatchFlags({
|
|
row: newRow,
|
|
view: lifecycleContext.view,
|
|
fields: lifecycleContext.fields,
|
|
registry: lifecycleContext.registry,
|
|
rowsInSortingGroup: rowsExcludingNew,
|
|
groupBys: lifecycleContext.groupBys,
|
|
})
|
|
|
|
const wasInView = oldFlags.matchFilters
|
|
const isInView = newFlags.matchFilters
|
|
|
|
if (wasInView && !isInView) {
|
|
// Row moved out of the view — remove it.
|
|
lifecycleMutations.remove(newRow.id)
|
|
} else if (!wasInView && isInView) {
|
|
// Row moved into the view — insert at its new position.
|
|
const position = computeRowInsertPosition(
|
|
newRow,
|
|
rowsExcludingNew,
|
|
lifecycleContext.view.sortings ?? [],
|
|
lifecycleContext.fields,
|
|
lifecycleContext.registry,
|
|
lifecycleContext.groupBys
|
|
)
|
|
lifecycleMutations.insertAtPosition(newRow, position)
|
|
lifecycleMutations.applyMatchFlags(newRow.id, newFlags)
|
|
} else if (!wasInView && !isInView) {
|
|
// Row was not and is still not visible — nothing to do.
|
|
} else {
|
|
// Row stays in the view — update its position and flags.
|
|
const position = computeRowInsertPosition(
|
|
newRow,
|
|
rowsExcludingNew,
|
|
lifecycleContext.view.sortings ?? [],
|
|
lifecycleContext.fields,
|
|
lifecycleContext.registry,
|
|
lifecycleContext.groupBys
|
|
)
|
|
lifecycleMutations.replaceAtPosition(newRow.id, newRow, position)
|
|
lifecycleMutations.applyMatchFlags(newRow.id, newFlags)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handle a row that was created externally (e.g. via a real-time event).
|
|
* Inserts the row only if it matches the current view; skips silently otherwise.
|
|
*/
|
|
export function handleRowCreated({ context, mutations, row }) {
|
|
const lifecycleContext = resolveContext(context)
|
|
const lifecycleMutations = normalizeMutations(mutations)
|
|
const existingRows = lifecycleMutations.rowsForMatchCheck(row)
|
|
|
|
const flags = computeRowMatchFlags({
|
|
row,
|
|
view: lifecycleContext.view,
|
|
fields: lifecycleContext.fields,
|
|
registry: lifecycleContext.registry,
|
|
rowsInSortingGroup: existingRows,
|
|
groupBys: lifecycleContext.groupBys,
|
|
})
|
|
|
|
if (!flags.matchFilters) {
|
|
return
|
|
}
|
|
|
|
const position = computeRowInsertPosition(
|
|
row,
|
|
existingRows,
|
|
lifecycleContext.view.sortings ?? [],
|
|
lifecycleContext.fields,
|
|
lifecycleContext.registry,
|
|
lifecycleContext.groupBys
|
|
)
|
|
|
|
lifecycleMutations.insertAtPosition(row, position)
|
|
lifecycleMutations.applyMatchFlags(row.id, flags)
|
|
}
|