mirror of
https://github.com/strapi/strapi.git
synced 2025-11-16 10:07:55 +00:00
fix: transform null order values to 1 by default
This commit is contained in:
parent
155bb69ef6
commit
b4374e1a59
@ -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 is placed at the end with the correct order', () => {
|
||||||
|
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