[]) {
- const sField = sortField.value;
+ const sField = relation.value.sortField;
if (sField === null) return;
const itemsSorted = newItems.map((item, i) => {
diff --git a/app/src/interfaces/one-to-many/one-to-many.vue b/app/src/interfaces/one-to-many/one-to-many.vue
index 86ceca0e01..8b4c9234ef 100644
--- a/app/src/interfaces/one-to-many/one-to-many.vue
+++ b/app/src/interfaces/one-to-many/one-to-many.vue
@@ -13,8 +13,8 @@
@update:items="sortItems($event)"
@click:row="editItem"
:disabled="disabled"
- :show-manual-sort="sortField !== null"
- :manual-sort-key="sortField"
+ :show-manual-sort="relation.sort_field !== null"
+ :manual-sort-key="relation.sort_field"
>
,
default: () => [],
},
- sortField: {
- type: String,
- default: null,
- },
disabled: {
type: Boolean,
default: false,
@@ -141,16 +137,6 @@ export default defineComponent({
get,
};
- function getItem(id: string | number) {
- const pkField = relatedPrimaryKeyField.value.field;
- if (props.value === null) return null;
- return (
- props.value.find(
- (item) => (typeof item === 'object' && pkField in item && item[pkField] === id) || item === id
- ) || null
- );
- }
-
function getNewItems() {
const pkField = relatedPrimaryKeyField.value.field;
if (props.value === null) return [];
@@ -169,12 +155,6 @@ export default defineComponent({
>[];
}
- function getExistingItems() {
- if (props.value === null) return [];
- const pkField = relatedPrimaryKeyField.value.field;
- return props.value.filter((item) => typeof item === 'string' || typeof item === 'number');
- }
-
function getPrimaryKeys() {
if (props.value === null) return [];
const pkField = relatedPrimaryKeyField.value.field;
@@ -216,13 +196,13 @@ export default defineComponent({
}
function useSort() {
- const sort = ref({ by: props.sortField || props.fields[0], desc: false });
+ const sort = ref({ by: relation.value.sort_field || props.fields[0], desc: false });
function sortItems(newItems: Record[]) {
- if (props.sortField === null) return;
+ if (relation.value.sort_field === null) return;
const itemsSorted = newItems.map((item, i) => {
- item[props.sortField] = i;
+ item[relation.value.sort_field] = i;
return item;
});
@@ -230,10 +210,10 @@ export default defineComponent({
}
const sortedItems = computed(() => {
- if (props.sortField === null || sort.value.by !== props.sortField) return null;
+ if (relation.value.sort_field === null || sort.value.by !== relation.value.sort_field) return null;
const desc = sort.value.desc;
- const sorted = sortBy(items.value, [props.sortField]);
+ const sorted = sortBy(items.value, [relation.value.sort_field]);
return desc ? sorted.reverse() : sorted;
});
@@ -267,7 +247,7 @@ export default defineComponent({
watch(
() => props.value,
- async (newVal) => {
+ async () => {
loading.value = true;
const pkField = relatedPrimaryKeyField.value.field;
@@ -277,7 +257,8 @@ export default defineComponent({
fields.push(pkField);
}
- if (props.sortField !== null && fields.includes(props.sortField) === false) fields.push(props.sortField);
+ if (relation.value.sort_field !== null && fields.includes(relation.value.sort_field) === false)
+ fields.push(relation.value.sort_field);
try {
const endpoint = relatedCollection.value.collection.startsWith('directus_')
@@ -385,8 +366,6 @@ export default defineComponent({
function stageEdits(edits: any) {
const pkField = relatedPrimaryKeyField.value.field;
- const hasPrimaryKey = pkField in edits;
-
const newValue = (props.value || []).map((item) => {
if (typeof item === 'object' && pkField in item && pkField in edits && item[pkField] === edits[pkField]) {
return edits;
@@ -447,8 +426,6 @@ export default defineComponent({
return { stageSelection, selectModalActive, selectionFilters };
function stageSelection(newSelection: (number | string)[]) {
- const pkField = relatedPrimaryKeyField.value.field;
-
const selection = newSelection.filter((item) => selectedPrimaryKeys.value.includes(item) === false);
const newVal = [...selection, ...(props.value || [])];
diff --git a/app/src/interfaces/one-to-many/options.vue b/app/src/interfaces/one-to-many/options.vue
index 3be649808c..1161ba7fbb 100644
--- a/app/src/interfaces/one-to-many/options.vue
+++ b/app/src/interfaces/one-to-many/options.vue
@@ -11,22 +11,13 @@
:inject="relatedCollectionExists ? null : { fields: newFields, collections: newCollections, relations }"
/>
-
-
{{ $t('sort_field') }}
-
-
diff --git a/app/src/lang/translations/en-US.yaml b/app/src/lang/translations/en-US.yaml
index fe8e220943..c854d950f8 100644
--- a/app/src/lang/translations/en-US.yaml
+++ b/app/src/lang/translations/en-US.yaml
@@ -90,6 +90,7 @@ field_presentation: Presentation & Aliases
field_file: Single File
field_files: Multiple Files
field_m2o: M2O Relationship
+field_m2a: M2A Relationship
field_o2m: O2M Relationship
field_m2m: M2M Relationship
field_translations: Translations
@@ -367,6 +368,7 @@ collection_created: Collection Created
modified_on: Modified On
card_size: Card Size
sort_field: Sort Field
+add_sort_field: Add Sort Field
sort: Sort
status: Status
toggle_manual_sorting: Toggle Manual Sorting
diff --git a/app/src/modules/settings/routes/data-model/field-detail/components/relationship-m2a.vue b/app/src/modules/settings/routes/data-model/field-detail/components/relationship-m2a.vue
index f5b95d99b8..6dc9c413f2 100644
--- a/app/src/modules/settings/routes/data-model/field-detail/components/relationship-m2a.vue
+++ b/app/src/modules/settings/routes/data-model/field-detail/components/relationship-m2a.vue
@@ -192,13 +192,47 @@
+
+ {{ $t('sort_field') }}
+
+
+
+
+
+
+
+
+
+
+
+ {{ item.text }}
+
+
+
+
+
+
+
+
{{ $t('new_data_alert') }}
-
{{ data.name }}
- ({{ $t(data.isField ? 'new_field' : 'new_collection') }})
+ ({{ $t(data.type === 'field' ? 'new_field' : 'new_collection') }})
@@ -207,13 +241,12 @@