mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Fix issue 4280 by initializing sortField when create new item (#4294)
* add more ignore pattern for git * revert the change for api/.gitignore * fix #4288 initialize sortField when create new item * init the maxSort counter as -1 * use more reliable way to check if sortField exists or not * reverted unexpected file changes * Use local previewValues for start sort index Co-authored-by: Jian Liao <jianliao@adobe.com> Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
@@ -303,9 +303,11 @@ export default defineComponent({
|
||||
if (o2mRelation.value?.sort_field) {
|
||||
return [
|
||||
...values
|
||||
.filter((val) => val[o2mRelation.value.sort_field!])
|
||||
.filter((val) => val.hasOwnProperty(o2mRelation.value.sort_field!))
|
||||
.sort((a, b) => a[o2mRelation.value.sort_field!] - b[o2mRelation.value.sort_field!]), // sort by sort field if it exists
|
||||
...values.filter((val) => !val[o2mRelation.value.sort_field!]).sort((a, b) => a.$index - b.$index), // sort the rest with $index
|
||||
...values
|
||||
.filter((val) => !val.hasOwnProperty(o2mRelation.value.sort_field!))
|
||||
.sort((a, b) => a.$index - b.$index), // sort the rest with $index
|
||||
];
|
||||
} else {
|
||||
return [...values.sort((a, b) => a.$index - b.$index)];
|
||||
@@ -560,6 +562,11 @@ export default defineComponent({
|
||||
[anyRelation.value.many_field]: {},
|
||||
};
|
||||
|
||||
if (previewValues.value && o2mRelation.value?.sort_field) {
|
||||
const maxSort = Math.max(-1, ...previewValues.value.map((val) => val[o2mRelation.value.sort_field!]));
|
||||
newItem[o2mRelation.value.sort_field!] = maxSort + 1;
|
||||
}
|
||||
|
||||
editsAtStart.value = newItem;
|
||||
relatedPrimaryKey.value = '+';
|
||||
currentlyEditing.value = '+';
|
||||
|
||||
Reference in New Issue
Block a user