mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 16:28:31 +00:00
* fix: restore builder element columns, menu items and options on undo The update action only snapshotted allowed_fields, so related rows saved in after_update (table columns, menu items, choice and property options) were left out and undo/redo had nothing to restore. * fix: snapshot only updated element values and skip deleted page links on undo Exporting every related collection on each update cost queries for unrelated changes, and replaying a link to a page deleted since made the whole undo fail. * fix: keep click actions and page links of builder elements through undo Undo hard-deleted the click actions of removed columns and menu items, trashed ones included, and replayed links to trashed pages or skipped style changes. * fix: keep trashed page links and replayed click actions through undo Clearing links to trashed pages unlinked them for good, click actions trashed by an undo or redo were never restored, and Kuma's formulas leaked into the undo snapshot through prefetched column configs. * fix(builder): keep click actions consistent across element update undo Undo could duplicate a restored action in the editor, leave it on the old page, delete nested or other elements' actions, or fail on an unused page link. * fix(builder): echo trashed click actions to the requester only on element updates A direct delete already removed the action in the requester's tab, and an echo could hide it again after a quick undo. Menu item uids kept by an update now come from one helper.
94 lines
3.1 KiB
JavaScript
94 lines
3.1 KiB
JavaScript
import workflowActionStore from '@baserow/modules/builder/store/builderWorkflowAction'
|
|
|
|
describe('builderWorkflowAction store', () => {
|
|
describe('ORDER_ITEMS', () => {
|
|
test("reordering one element's actions leaves another element's untouched", () => {
|
|
// Regression: reordering the actions of one element used to reset every other
|
|
// element's actions to order 0 (they fell into the `index === -1` branch),
|
|
// reshuffling them. The reorder must be scoped to the targeted element.
|
|
const page = {
|
|
workflowActions: [
|
|
{ id: 1, element_id: 10, order: 1 },
|
|
{ id: 2, element_id: 10, order: 2 },
|
|
{ id: 3, element_id: 20, order: 1 },
|
|
{ id: 4, element_id: 20, order: 2 },
|
|
],
|
|
}
|
|
|
|
// Reorder element 10's actions to [2, 1].
|
|
workflowActionStore.mutations.ORDER_ITEMS(
|
|
{},
|
|
{ page, order: [2, 1], elementId: 10 }
|
|
)
|
|
|
|
const orderById = Object.fromEntries(
|
|
page.workflowActions.map((w) => [w.id, w.order])
|
|
)
|
|
// Element 10's actions are reordered...
|
|
expect(orderById[2]).toBe(1)
|
|
expect(orderById[1]).toBe(2)
|
|
// ...while element 20's actions keep their original order.
|
|
expect(orderById[3]).toBe(1)
|
|
expect(orderById[4]).toBe(2)
|
|
})
|
|
|
|
test('without an elementId, every action on the page is reordered', () => {
|
|
const page = {
|
|
workflowActions: [
|
|
{ id: 1, element_id: 10, order: 1 },
|
|
{ id: 2, element_id: 10, order: 2 },
|
|
],
|
|
}
|
|
|
|
workflowActionStore.mutations.ORDER_ITEMS({}, { page, order: [2, 1] })
|
|
|
|
const orderById = Object.fromEntries(
|
|
page.workflowActions.map((w) => [w.id, w.order])
|
|
)
|
|
expect(orderById[2]).toBe(1)
|
|
expect(orderById[1]).toBe(2)
|
|
})
|
|
})
|
|
|
|
describe('ADD_ITEM', () => {
|
|
test('adding an action the page already has keeps one copy', () => {
|
|
// Undoing a column removal restores its click action, and every tab hears
|
|
// about it, the one that removed the column included.
|
|
const page = { workflowActions: [] }
|
|
const action = { id: 1, element_id: 10, event: 'uid_click', order: 1 }
|
|
|
|
workflowActionStore.mutations.ADD_ITEM(
|
|
{},
|
|
{ page, workflowAction: action }
|
|
)
|
|
workflowActionStore.mutations.DELETE_ITEM(
|
|
{},
|
|
{ page, workflowActionId: 1 }
|
|
)
|
|
expect(page.workflowActions).toHaveLength(0)
|
|
|
|
workflowActionStore.mutations.ADD_ITEM(
|
|
{},
|
|
{ page, workflowAction: action }
|
|
)
|
|
workflowActionStore.mutations.ADD_ITEM(
|
|
{},
|
|
{ page, workflowAction: { ...action, order: 2 } }
|
|
)
|
|
expect(page.workflowActions.map(({ id }) => id)).toEqual([1])
|
|
expect(page.workflowActions[0].order).toBe(2)
|
|
})
|
|
|
|
test('adding a new action appends it', () => {
|
|
const page = { workflowActions: [{ id: 1, element_id: 10, order: 1 }] }
|
|
|
|
workflowActionStore.mutations.ADD_ITEM(
|
|
{},
|
|
{ page, workflowAction: { id: 2, element_id: 10, order: 2 } }
|
|
)
|
|
|
|
expect(page.workflowActions.map(({ id }) => id)).toEqual([1, 2])
|
|
})
|
|
})
|
|
})
|