Skip to content

Commit 70208f9

Browse files
authored
fix: kanban view create row sort bug (baserow#5407)
1 parent 057f5a1 commit 70208f9

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

premium/web-frontend/modules/baserow_premium/store/view/kanban.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ export const actions = {
484484

485485
const sortedRows = clone(stack.results)
486486
sortedRows.push(row)
487-
sortedRows.sort(getRowSortFunction($registry, [], fields))
487+
sortedRows.sort(getRowSortFunction($registry, view.sortings, fields))
488488
const index = sortedRows.findIndex((r) => r.id === row.id)
489489
const isLast = index === sortedRows.length - 1
490490

premium/web-frontend/test/unit/premium/store/view/kanban.spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,50 @@ describe('Kanban view store', () => {
9595
expect(store.state.kanban.stacks['1'].results[2].id).toBe(11)
9696
})
9797

98+
test('createdNewRow respects view sortings when placing the new row', async () => {
99+
// Stack '1' has 2 loaded rows out of 100. Rows are sorted by a number
100+
// field (field_2) ascending. The new row's field_2 value (10) falls
101+
// between the two loaded rows (5 and 15), so it must be inserted at
102+
// index 1, not appended to the end.
103+
const stacks = {
104+
null: { count: 0, results: [] },
105+
1: {
106+
count: 100,
107+
results: [
108+
{ id: 10, order: '1.00', field_1: { id: 1 }, field_2: 5 },
109+
{ id: 11, order: '2.00', field_1: { id: 1 }, field_2: 15 },
110+
],
111+
},
112+
}
113+
const state = Object.assign(kanbanStore.state(), {
114+
singleSelectFieldId: 1,
115+
stacks,
116+
})
117+
store.replaceState({ ...store.state, kanban: state })
118+
119+
const fields = [{ id: 2, type: 'number', number_decimal_places: 0 }]
120+
const sortedView = {
121+
filters: [],
122+
filters_disabled: false,
123+
sortings: [{ field: 2, order: 'ASC', type: 'default' }],
124+
}
125+
126+
// New row has order '3.00' (which would place it last without sortings),
127+
// but field_2=10 which is between 5 and 15, so with sortings it must land
128+
// at index 1.
129+
await store.dispatch('kanban/createdNewRow', {
130+
view: sortedView,
131+
values: { id: 9, order: '3.00', field_1: { id: 1 }, field_2: 10 },
132+
fields,
133+
})
134+
135+
expect(store.state.kanban.stacks['1'].count).toBe(101)
136+
expect(store.state.kanban.stacks['1'].results.length).toBe(3)
137+
expect(store.state.kanban.stacks['1'].results[0].id).toBe(10)
138+
expect(store.state.kanban.stacks['1'].results[1].id).toBe(9)
139+
expect(store.state.kanban.stacks['1'].results[2].id).toBe(11)
140+
})
141+
98142
test('deletedExistingRow', async () => {
99143
const stacks = {}
100144
stacks.null = {

0 commit comments

Comments
 (0)