mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
* feat: report when a button's row action points at the trash * fix: keep a row action's mapping on a trashed field across edits * fix: update buttons in other tables when their target is trashed * feat: disable a button cell that needs reconfiguring * feat: flag a row action that writes to a trashed field * docs: describe the button reconfigure state in ADR 006 * test: cover a button healing when its mapped field is restored * test: keep failing-click tests clickable under the reconfigure state Give "Broken" and "BrokenChain" a table-targeting action that fails at dispatch instead of one with no table, so requires_reconfiguration stays false and the original click/toast assertions still run. * perf: look up a button's own services in the reconfigure check The uncorrelated subqueries scanned every upsert row service in the instance, which the builder and automations share. * perf: load mapped fields in one query when saving and serializing mappings Update responses and realtime payloads read each mapping's field for `trashed`, and saving looked each field up separately. * fix: let undo restore the values of a mapping on a trashed field The kept mapping was skipped, so replaying the exported mappings left its current value and enabled flag in place. * perf: skip the button lookup when no service depends on a trashed item Every table and application created, and every field trashed, joined all button fields and their actions even when no service pointed at it. * fix: only offer restoring the field to heal a trashed field mapping A permanent delete is cleaned up later without a broadcast, so an open page never learns the action works again. * fix: show the full label of a grid button that needs reconfiguring The tooltip span shrink-wrapped the button, so its 90% max width resolved against the span and cut the label short. * fix: put a button using a trashed integration in the reconfigure state The dispatch refuses a service whose integration is in the trash, so the button now says so up front and open grids update on trash and restore. * fix: update open grids when emptying the trash heals a button Permanently deleting a trashed field or integration ends the reconfigure state without any broadcast, so the cell stayed disabled until a reload. * docs: note trashed integrations and permanent deletion in ADR 006 * fix: count a missing integration a button action needs Deleting a trashed Slack bot left the action with none and re-enabled a button that still fails. Also skips integrations outside a database, keeps service lookups as subqueries, and stops a failed deletion leaking state. * docs: note a missing required integration in ADR 006 * test: wait for a button field save to finish before moving on The save sends the field update and each action call in sequence. A test that navigated right after clicking Save could cancel the order call, so the Stale button kept its old order and never navigated. * fix: replace a row action's mappings with exactly what the payload sends Keeping trashed mappings the payload left out stopped undo from removing them and made undo raise on a mapping it had removed. The editor now sends them back. * fix: leave the reconfigure flag out when the field refresh after a save fails The mount-time value was written over whatever a broadcast had set since. * fix: update buttons mapping a link field to a table that is trashed Trashing a table trashes the link fields to it in other tables without a field_deleted signal. * perf: send the buttons of a table in one message with their flags annotated Every field_updated refreshes the grid, and an unannotated button cost queries of its own. * fix: put a button whose target table is in a trashed workspace in the reconfigure state An action can target a table in another workspace, and the dispatch refuses one whose workspace is trashed. * fix: leave the buttons of a new table or database out of its broadcast Duplication, template installs and imports send the created signals too, and nobody has the copy open. * perf: pair each button service lookup only with the actions it backs Also stop the early check deduplicating its UNION, and test that permanently deleting a builder integration never looks up buttons. * fix: name each action that needs reconfiguring in the button editor The field flag is now whether any action has the per-action flag, so the editor can point at a trashed table, database or integration too. * fix: keep the button flags out of the cached table model They depend on other tables, so a model cached for the button's table served them stale. They are now annotated only where fields are fetched to serialize. * test: make the shared grid view private again after the public view test A public view hides a field created in it until its editor closes, so the retry test that runs later never saw its column. * fix: update buttons mapping a link field to a table deleted from the trash Deleting the table deletes the link fields to it and their mappings, with no signal of their own. * fix: send a restored workspace's dependent buttons once and leave its own out The once-per-restore check now keys the waiting on-commit callback by workspace id instead of relying on a shared Workspace instance. * perf: leave a button's action state out of a service's table schema The grouped aggregate rebuilds that schema uncached per property, and each flag now cost a query per button. Nothing reads them from the schema. * refactor: read an action's reconfigure flag straight from its definition * fix: update buttons mapping a link field whose related field is purged Emptying the trash for a link field also deletes its related field and that field's mappings, which left buttons mapping it disabled until reload. * fix: drop a mapping whose field was deleted from the trash on save An open editor or an undo still sends the purged field's id, so every save failed until reload. Fields that still exist elsewhere are still refused. * fix: match no button for a lookup with no action model An empty model list left the action filter empty, which matched every action and would have sent every button in the instance. * test: describe mappings replaced by the payload after a table change The table change test sent no mappings, so it did not show a new table's mapping replacing the old table's trashed one. * fix: name a button action's trashed table instead of its fields Trashing a table marks all its fields trashed, so the editor asked to restore a field that only restoring the table brings back. The 404 from the fields fetch now marks the table missing, and the action says so rather than a toast. * fix: drop a mapping on another workspace's field instead of refusing it Refusing it told the editor that the field exists. * perf: send a button's state on its own realtime message A `field_updated` makes the client refetch the whole grid, which for a flag that says nothing about the rows throws away what someone is typing. The signal also gives the enterprise restricted views a place to mirror from. * fix: update buttons when a workspace is purged without being trashed `delete_expired_users` and the admin panel delete a workspace outright, so the `workspace_deleted` that would have flagged the buttons pointing into it never goes out. A snapshot's application expires the same way. * fix: flag an update row action that names no row Every click on it is refused, so to the person clicking it is no different to a target in the trash, but the button stayed enabled. * fix: clear the server's reconfigure verdict when an action is edited It describes the action as it was read, so the warning stayed up after a fix until the save landed. Changing the type already dropped it by rebuilding. * docs: name every cause of the button reconfigure state The field and action descriptions each left one out, so they disagreed with ADR 006 and with each other. * test: expect the rowless button to render disabled The server now flags an update row action with no row id, so the click the test made never lands. * perf: serialize button fields once for all restricted views Each serialization runs the reconfigure and action queries, which repeated for every view. * perf: skip purged buttons and merge purge broadcasts Buttons deleted with their container were collected for nothing, and a workspace purge also purges its tables, so one button could be sent twice. * fix: bump the global cache version The button field schema dropped its action state, and cached schemas would keep the old shape. * fix: keep the reconfigure verdict while the integration is unchanged A trashed integration is missing from the list, so the verdict is the only warning.
296 lines
8.9 KiB
JavaScript
296 lines
8.9 KiB
JavaScript
import {
|
|
countUndoSteps,
|
|
rebaseWorkflowActions,
|
|
reconcileWorkflowActions,
|
|
workflowActionConfig,
|
|
} from '@baserow/modules/database/utils/workflowActionReconciliation'
|
|
|
|
describe('reconcileWorkflowActions', () => {
|
|
test('an unchanged list produces no work', () => {
|
|
const server = [
|
|
{ id: 1, type: 'local_baserow_create_row', service: { table_id: 3 } },
|
|
]
|
|
const local = [
|
|
{ id: 1, type: 'local_baserow_create_row', service: { table_id: 3 } },
|
|
]
|
|
|
|
const result = reconcileWorkflowActions(server, local)
|
|
|
|
expect(result.toCreate).toEqual([])
|
|
expect(result.toUpdate).toEqual([])
|
|
expect(result.toDelete).toEqual([])
|
|
expect(result.order).toEqual([1])
|
|
})
|
|
|
|
test('a new action is created', () => {
|
|
const local = [
|
|
{ type: 'local_baserow_delete_row', service: { table_id: 4 } },
|
|
]
|
|
|
|
const result = reconcileWorkflowActions([], local)
|
|
|
|
expect(result.toCreate).toEqual([
|
|
{ type: 'local_baserow_delete_row', service: { table_id: 4 } },
|
|
])
|
|
expect(result.order).toEqual([null])
|
|
})
|
|
|
|
test('a changed service config is updated', () => {
|
|
const server = [
|
|
{ id: 1, type: 'local_baserow_create_row', service: { table_id: 3 } },
|
|
]
|
|
const local = [
|
|
{ id: 1, type: 'local_baserow_create_row', service: { table_id: 9 } },
|
|
]
|
|
|
|
const result = reconcileWorkflowActions(server, local)
|
|
|
|
expect(result.toUpdate).toEqual([
|
|
{ id: 1, values: { service: { table_id: 9 } } },
|
|
])
|
|
expect(result.toCreate).toEqual([])
|
|
expect(result.toDelete).toEqual([])
|
|
})
|
|
|
|
test('a removed action is deleted', () => {
|
|
const server = [
|
|
{ id: 1, type: 'local_baserow_create_row', service: {} },
|
|
{ id: 2, type: 'local_baserow_delete_row', service: {} },
|
|
]
|
|
const local = [{ id: 2, type: 'local_baserow_delete_row', service: {} }]
|
|
|
|
const result = reconcileWorkflowActions(server, local)
|
|
|
|
expect(result.toDelete).toEqual([1])
|
|
expect(result.order).toEqual([2])
|
|
})
|
|
|
|
test('reordering alone produces only an order', () => {
|
|
const server = [
|
|
{ id: 1, type: 'local_baserow_create_row', service: {} },
|
|
{ id: 2, type: 'local_baserow_delete_row', service: {} },
|
|
]
|
|
const local = [server[1], server[0]]
|
|
|
|
const result = reconcileWorkflowActions(server, local)
|
|
|
|
expect(result.toCreate).toEqual([])
|
|
expect(result.toUpdate).toEqual([])
|
|
expect(result.toDelete).toEqual([])
|
|
expect(result.order).toEqual([2, 1])
|
|
})
|
|
|
|
test('a mixed edit produces every operation', () => {
|
|
const server = [
|
|
{ id: 1, type: 'local_baserow_create_row', service: { table_id: 3 } },
|
|
{ id: 2, type: 'local_baserow_delete_row', service: { table_id: 4 } },
|
|
]
|
|
const local = [
|
|
{ id: 2, type: 'local_baserow_delete_row', service: { table_id: 4 } },
|
|
{ id: 1, type: 'local_baserow_create_row', service: { table_id: 7 } },
|
|
{ type: 'local_baserow_update_row', service: { table_id: 8 } },
|
|
]
|
|
|
|
const result = reconcileWorkflowActions(server, local)
|
|
|
|
expect(result.toDelete).toEqual([])
|
|
expect(result.toUpdate).toEqual([
|
|
{ id: 1, values: { service: { table_id: 7 } } },
|
|
])
|
|
expect(result.toCreate).toEqual([
|
|
{ type: 'local_baserow_update_row', service: { table_id: 8 } },
|
|
])
|
|
expect(result.order).toEqual([2, 1, null])
|
|
})
|
|
|
|
test('emits a type change and keeps the position', () => {
|
|
const server = [
|
|
{ id: 1, type: 'local_baserow_create_row', service: { table_id: 5 } },
|
|
]
|
|
const local = [{ id: 1, type: 'open_url', url: { formula: "'x'" } }]
|
|
|
|
const { toUpdate, order } = reconcileWorkflowActions(server, local)
|
|
|
|
expect(toUpdate).toEqual([
|
|
{ id: 1, values: { type: 'open_url', url: { formula: "'x'" } } },
|
|
])
|
|
expect(order).toEqual([1])
|
|
})
|
|
|
|
test('a type change between two service types sends the new config', () => {
|
|
// The editor resets the config on a type change, so the service it hands
|
|
// over is empty and the old type's `table_id` must not carry across.
|
|
const server = [
|
|
{ id: 1, type: 'local_baserow_create_row', service: { table_id: 3 } },
|
|
]
|
|
const local = [{ id: 1, type: 'local_baserow_update_row', service: {} }]
|
|
|
|
const result = reconcileWorkflowActions(server, local)
|
|
|
|
expect(result.toUpdate).toEqual([
|
|
{ id: 1, values: { type: 'local_baserow_update_row', service: {} } },
|
|
])
|
|
})
|
|
|
|
test('the keys the api owns are never diffed or sent', () => {
|
|
// `order` and `field_id` belong to the server, not the editor. Diffing
|
|
// them would make a pure reorder look like a config change.
|
|
const server = [
|
|
{
|
|
id: 1,
|
|
type: 'local_baserow_create_row',
|
|
order: 1,
|
|
field_id: 7,
|
|
service: {},
|
|
},
|
|
]
|
|
const local = [
|
|
{
|
|
id: 1,
|
|
type: 'local_baserow_create_row',
|
|
order: 9,
|
|
field_id: 7,
|
|
service: {},
|
|
},
|
|
]
|
|
|
|
const result = reconcileWorkflowActions(server, local)
|
|
|
|
expect(result.toUpdate).toEqual([])
|
|
})
|
|
|
|
test('the reconfigure flag is the server answer, never an edit to send', () => {
|
|
const server = [
|
|
{
|
|
id: 1,
|
|
type: 'local_baserow_create_row',
|
|
requires_reconfiguration: true,
|
|
service: { table_id: 5 },
|
|
},
|
|
]
|
|
const local = [
|
|
{
|
|
id: 1,
|
|
type: 'local_baserow_create_row',
|
|
requires_reconfiguration: false,
|
|
service: { table_id: 6 },
|
|
},
|
|
]
|
|
|
|
const result = reconcileWorkflowActions(server, local)
|
|
|
|
expect(result.toUpdate).toEqual([
|
|
{ id: 1, values: { service: { table_id: 6 } } },
|
|
])
|
|
expect(workflowActionConfig(server[0])).toEqual({
|
|
service: { table_id: 5 },
|
|
})
|
|
})
|
|
|
|
test('a row whose type has not been chosen yet is not an action', () => {
|
|
// A row added but not yet given a type must produce no calls at all, and
|
|
// take no slot in the order.
|
|
const server = [{ id: 1, type: 'local_baserow_create_row', service: {} }]
|
|
const local = [
|
|
{ id: 1, type: 'local_baserow_create_row', service: {} },
|
|
{ type: null },
|
|
]
|
|
|
|
const result = reconcileWorkflowActions(server, local)
|
|
|
|
expect(result.toCreate).toEqual([])
|
|
expect(result.toUpdate).toEqual([])
|
|
expect(result.toDelete).toEqual([])
|
|
expect(result.order).toEqual([1])
|
|
})
|
|
|
|
test('an id the server does not know is treated as new', () => {
|
|
const local = [
|
|
{ id: 99, type: 'local_baserow_delete_row', service: { table_id: 4 } },
|
|
]
|
|
|
|
const result = reconcileWorkflowActions([], local)
|
|
|
|
expect(result.toUpdate).toEqual([])
|
|
// The id it had is carried along so the caller can point whatever
|
|
// references it at the id it is created under. `workflowActionConfig`
|
|
// leaves it out of the payload, so it never reaches the API.
|
|
expect(result.toCreate).toEqual([
|
|
{ id: 99, type: 'local_baserow_delete_row', service: { table_id: 4 } },
|
|
])
|
|
expect(workflowActionConfig(result.toCreate[0])).toEqual({
|
|
service: { table_id: 4 },
|
|
})
|
|
expect(result.order).toEqual([null])
|
|
})
|
|
})
|
|
|
|
describe('rebaseWorkflowActions', () => {
|
|
const action = (id, url) => ({ id, type: 'open_url', url, target: 'self' })
|
|
|
|
test('an action nobody touched follows the server', () => {
|
|
const base = [action(1, 'a')]
|
|
const fresh = [action(1, 'undone')]
|
|
|
|
expect(rebaseWorkflowActions(base, fresh, [action(1, 'a')])).toEqual([
|
|
action(1, 'undone'),
|
|
])
|
|
})
|
|
|
|
test('an untouched action the server lost goes, an edited one stays', () => {
|
|
const base = [action(1, 'a'), action(2, 'b')]
|
|
const fresh = []
|
|
const local = [action(1, 'a'), action(2, 'edited')]
|
|
|
|
expect(rebaseWorkflowActions(base, fresh, local)).toEqual([
|
|
action(2, 'edited'),
|
|
])
|
|
})
|
|
|
|
test('an action the server gained is added where the server has it', () => {
|
|
const base = [action(1, 'a'), action(3, 'c')]
|
|
const fresh = [action(1, 'a'), action(2, 'restored'), action(3, 'c')]
|
|
const local = [action(1, 'a'), action(3, 'edited')]
|
|
|
|
expect(rebaseWorkflowActions(base, fresh, local)).toEqual([
|
|
action(1, 'a'),
|
|
action(2, 'restored'),
|
|
action(3, 'edited'),
|
|
])
|
|
})
|
|
|
|
test('an action the user removed or added keeps that change', () => {
|
|
const base = [action(1, 'a'), action(2, 'b')]
|
|
const fresh = [action(1, 'a'), action(2, 'b')]
|
|
const added = { _clientId: 'new', type: 'open_url', url: 'c' }
|
|
const local = [action(1, 'a'), added]
|
|
|
|
expect(rebaseWorkflowActions(base, fresh, local)).toEqual([
|
|
action(1, 'a'),
|
|
added,
|
|
])
|
|
})
|
|
})
|
|
|
|
describe('countUndoSteps', () => {
|
|
test('counts one step per call, two for a type change with config', () => {
|
|
expect(
|
|
countUndoSteps({
|
|
toCreate: [{}, {}],
|
|
toUpdate: [
|
|
{ id: 1, values: { url: 'a' } },
|
|
{ id: 2, values: { type: 'open_url', service: {} } },
|
|
],
|
|
toDelete: [3],
|
|
order: [null, null, 1, 2],
|
|
})
|
|
).toBe(7)
|
|
})
|
|
|
|
test('an empty list needs no order call', () => {
|
|
expect(
|
|
countUndoSteps({ toCreate: [], toUpdate: [], toDelete: [4], order: [] })
|
|
).toBe(1)
|
|
})
|
|
})
|