mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Only pass needed values when sorting (#16283)
* only pass needed values when sorting * fix sort for files Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
This commit is contained in:
@@ -135,7 +135,7 @@ import DrawerCollection from '@/views/private/components/drawer-collection.vue';
|
||||
import Draggable from 'vuedraggable';
|
||||
import { getAssetUrl } from '@/utils/get-asset-url';
|
||||
import { adjustFieldsForDisplays } from '@/utils/adjust-fields-for-displays';
|
||||
import { get, clamp, isEmpty } from 'lodash';
|
||||
import { get, clamp, isEmpty, isNil, set } from 'lodash';
|
||||
import { usePermissionsStore } from '@/stores/permissions';
|
||||
import { useUserStore } from '@/stores/user';
|
||||
import { getFieldsFromTemplate } from '@directus/shared/utils';
|
||||
@@ -244,13 +244,32 @@ function getDeselectIcon(item: DisplayItem) {
|
||||
}
|
||||
|
||||
function sortItems(items: DisplayItem[]) {
|
||||
const sortField = relationInfo.value?.sortField;
|
||||
if (!sortField) return;
|
||||
const info = relationInfo.value;
|
||||
const sortField = info?.sortField;
|
||||
if (!info || !sortField) return;
|
||||
|
||||
const sortedItems = items.map((item, index) => {
|
||||
const junctionId = item?.[info.junctionPrimaryKeyField.field];
|
||||
const relatedId = item?.[info.junctionField.field]?.[info.relatedPrimaryKeyField.field];
|
||||
|
||||
const changes: Record<string, any> = {
|
||||
$index: item.$index,
|
||||
$type: item.$type,
|
||||
$edits: item.$edits,
|
||||
...getItemEdits(item),
|
||||
[sortField]: index + 1,
|
||||
};
|
||||
|
||||
if (!isNil(junctionId)) {
|
||||
changes[info.junctionPrimaryKeyField.field] = junctionId;
|
||||
}
|
||||
if (!isNil(relatedId)) {
|
||||
set(changes, info.junctionField.field + '.' + info.relatedPrimaryKeyField.field, relatedId);
|
||||
}
|
||||
|
||||
return changes;
|
||||
});
|
||||
|
||||
const sortedItems = items.map((item, index) => ({
|
||||
...item,
|
||||
[sortField]: index + 1,
|
||||
}));
|
||||
update(...sortedItems);
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ import DrawerCollection from '@/views/private/components/drawer-collection.vue';
|
||||
import DrawerItem from '@/views/private/components/drawer-item.vue';
|
||||
import { Filter } from '@directus/shared/types';
|
||||
import { getFieldsFromTemplate } from '@directus/shared/utils';
|
||||
import { clamp, get, isEmpty } from 'lodash';
|
||||
import { clamp, get, isEmpty, isNil, set } from 'lodash';
|
||||
import { computed, ref, toRefs, unref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import Draggable from 'vuedraggable';
|
||||
@@ -246,13 +246,33 @@ function getDeselectIcon(item: DisplayItem) {
|
||||
}
|
||||
|
||||
function sortItems(items: DisplayItem[]) {
|
||||
const sortField = relationInfo.value?.sortField;
|
||||
if (!sortField) return;
|
||||
const info = relationInfo.value;
|
||||
const sortField = info?.sortField;
|
||||
if (!info || !sortField) return;
|
||||
|
||||
const sortedItems = items.map((item, index) => ({
|
||||
...item,
|
||||
[sortField]: index + 1,
|
||||
}));
|
||||
const sortedItems = items.map((item, index) => {
|
||||
const junctionId = item?.[info.junctionPrimaryKeyField.field];
|
||||
const collection = item?.[info.collectionField.field];
|
||||
const pkField = info.relationPrimaryKeyFields[collection].field;
|
||||
const relatedId = item?.[info.junctionField.field]?.[pkField];
|
||||
|
||||
const changes: Record<string, any> = {
|
||||
$index: item.$index,
|
||||
$type: item.$type,
|
||||
$edits: item.$edits,
|
||||
...getItemEdits(item),
|
||||
[sortField]: index + 1,
|
||||
};
|
||||
|
||||
if (!isNil(junctionId)) {
|
||||
changes[info.junctionPrimaryKeyField.field] = junctionId;
|
||||
}
|
||||
if (!isNil(relatedId)) {
|
||||
set(changes, info.junctionField.field + '.' + pkField, relatedId);
|
||||
}
|
||||
|
||||
return changes;
|
||||
});
|
||||
update(...sortedItems);
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ import DrawerCollection from '@/views/private/components/drawer-collection.vue';
|
||||
import { Sort } from '@/components/v-table/types';
|
||||
import Draggable from 'vuedraggable';
|
||||
import { adjustFieldsForDisplays } from '@/utils/adjust-fields-for-displays';
|
||||
import { isEmpty, get, clamp } from 'lodash';
|
||||
import { isEmpty, get, clamp, isNil, set } from 'lodash';
|
||||
import { usePermissionsStore } from '@/stores/permissions';
|
||||
import { useUserStore } from '@/stores/user';
|
||||
import { useFieldsStore } from '@/stores/fields';
|
||||
@@ -435,13 +435,32 @@ function getDeselectTooltip(item: DisplayItem) {
|
||||
}
|
||||
|
||||
function sortItems(items: DisplayItem[]) {
|
||||
const sortField = relationInfo.value?.sortField;
|
||||
if (!sortField) return;
|
||||
const info = relationInfo.value;
|
||||
const sortField = info?.sortField;
|
||||
if (!info || !sortField) return;
|
||||
|
||||
const sortedItems = items.map((item, index) => {
|
||||
const junctionId = item?.[info.junctionPrimaryKeyField.field];
|
||||
const relatedId = item?.[info.junctionField.field]?.[info.relatedPrimaryKeyField.field];
|
||||
|
||||
const changes: Record<string, any> = {
|
||||
$index: item.$index,
|
||||
$type: item.$type,
|
||||
$edits: item.$edits,
|
||||
...getItemEdits(item),
|
||||
[sortField]: index + 1,
|
||||
};
|
||||
|
||||
if (!isNil(junctionId)) {
|
||||
changes[info.junctionPrimaryKeyField.field] = junctionId;
|
||||
}
|
||||
if (!isNil(relatedId)) {
|
||||
set(changes, info.junctionField.field + '.' + info.relatedPrimaryKeyField.field, relatedId);
|
||||
}
|
||||
|
||||
return changes;
|
||||
});
|
||||
|
||||
const sortedItems = items.map((item, index) => ({
|
||||
...item,
|
||||
[sortField]: index + 1,
|
||||
}));
|
||||
update(...sortedItems);
|
||||
}
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ import DrawerCollection from '@/views/private/components/drawer-collection.vue';
|
||||
import { Sort } from '@/components/v-table/types';
|
||||
import Draggable from 'vuedraggable';
|
||||
import { adjustFieldsForDisplays } from '@/utils/adjust-fields-for-displays';
|
||||
import { isEmpty, clamp, get } from 'lodash';
|
||||
import { isEmpty, clamp, get, isNil } from 'lodash';
|
||||
import { usePermissionsStore } from '@/stores/permissions';
|
||||
import { useUserStore } from '@/stores/user';
|
||||
import { useFieldsStore } from '@/stores/fields';
|
||||
@@ -410,13 +410,28 @@ function getDeselectTooltip(item: DisplayItem) {
|
||||
}
|
||||
|
||||
function sortItems(items: DisplayItem[]) {
|
||||
const sortField = relationInfo.value?.sortField;
|
||||
if (!sortField) return;
|
||||
const info = relationInfo.value;
|
||||
const sortField = info?.sortField;
|
||||
if (!info || !sortField) return;
|
||||
|
||||
const sortedItems = items.map((item, index) => {
|
||||
const relatedId = item?.[info.relatedPrimaryKeyField.field];
|
||||
|
||||
const changes: Record<string, any> = {
|
||||
$index: item.$index,
|
||||
$type: item.$type,
|
||||
$edits: item.$edits,
|
||||
...getItemEdits(item),
|
||||
[sortField]: index + 1,
|
||||
};
|
||||
|
||||
if (!isNil(relatedId)) {
|
||||
changes[info.relatedPrimaryKeyField.field] = relatedId;
|
||||
}
|
||||
|
||||
return changes;
|
||||
});
|
||||
|
||||
const sortedItems = items.map((item, index) => ({
|
||||
...item,
|
||||
[sortField]: index + 1,
|
||||
}));
|
||||
update(...sortedItems);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user