mirror of
https://github.com/strapi/strapi.git
synced 2025-11-18 02:58:05 +00:00
Merge pull request #16298 from strapi/fix/out-of-range-value-when-reordering-relation
This commit is contained in:
commit
9542f27484
@ -121,6 +121,28 @@ describe('Given I have some relations in the database', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('When you connect a relation before one with null order', () => {
|
||||||
|
test('Then it replaces null order values to 1 and properly reorders relations', () => {
|
||||||
|
const orderer = relationsOrderer(
|
||||||
|
[
|
||||||
|
{ id: 2, order: null },
|
||||||
|
{ id: 3, order: null },
|
||||||
|
],
|
||||||
|
'id',
|
||||||
|
'order'
|
||||||
|
);
|
||||||
|
|
||||||
|
orderer.connect([{ id: 4, position: { before: 3 } }, { id: 5 }]);
|
||||||
|
|
||||||
|
expect(orderer.get()).toMatchObject([
|
||||||
|
{ id: 2, order: 1 },
|
||||||
|
{ id: 4, order: 0.5 },
|
||||||
|
{ id: 3, order: 1 },
|
||||||
|
{ id: 5, order: 1.5 },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Given there are no relations in the database', () => {
|
describe('Given there are no relations in the database', () => {
|
||||||
|
|||||||
@ -135,7 +135,7 @@ const relationsOrderer = (initArr, idColumn, orderColumn, strict) => {
|
|||||||
const computedRelations = _.castArray(initArr || []).map((r) => ({
|
const computedRelations = _.castArray(initArr || []).map((r) => ({
|
||||||
init: true,
|
init: true,
|
||||||
id: r[idColumn],
|
id: r[idColumn],
|
||||||
order: r[orderColumn],
|
order: r[orderColumn] || 1,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const maxOrder = _.maxBy('order', computedRelations)?.order || 0;
|
const maxOrder = _.maxBy('order', computedRelations)?.order || 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user