Fix components ordering

This commit is contained in:
Alexandre Bodin 2021-09-22 20:10:48 +02:00
parent 549773698a
commit 704ff5a612
2 changed files with 29 additions and 6 deletions

View File

@ -226,7 +226,7 @@ const createQueryBuilder = (uid, db) => {
});
const orderByColumns = state.orderBy.map(({ column }) => column);
state.select = _.uniq([...state.select, ...orderByColumns, ...joinsOrderByColumns]);
state.select = _.uniq([...joinsOrderByColumns, ...orderByColumns, ...state.select]);
}
},

View File

@ -131,11 +131,26 @@ const updateComponents = async (uid, entityToUpdate, data) => {
componentValue.map(value => updateOrCreateComponent(componentUID, value))
);
// TODO: add order
componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }) => id);
componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }, idx) => {
return {
id,
__pivot: {
order: idx + 1,
field: attributeName,
component_type: componentUID,
},
};
});
} else {
const component = await updateOrCreateComponent(componentUID, componentValue);
componentBody[attributeName] = component && component.id;
componentBody[attributeName] = component && {
id: component.id,
__pivot: {
order: 1,
field: attributeName,
component_type: componentUID,
},
};
}
continue;
@ -151,9 +166,17 @@ const updateComponents = async (uid, entityToUpdate, data) => {
}
componentBody[attributeName] = await Promise.all(
dynamiczoneValues.map(async value => {
dynamiczoneValues.map(async (value, idx) => {
const { id } = await updateOrCreateComponent(value.__component, value);
return { id, __component: value.__component };
return {
id,
__component: value.__component,
__pivot: {
order: idx + 1,
field: attributeName,
},
};
})
);