mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Fix loading all fields (#17395)
* Fix loading all fields * fix linter --------- Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,12 @@ import { defineDisplay, getFieldsFromTemplate } from '@directus/shared/utils';
|
||||
import { get, set } from 'lodash';
|
||||
import DisplayTranslations from './translations.vue';
|
||||
import { useExtension } from '@/composables/use-extension';
|
||||
import { adjustFieldsForDisplays } from '@/utils/adjust-fields-for-displays';
|
||||
|
||||
type Options = {
|
||||
template: string;
|
||||
languageField: string;
|
||||
};
|
||||
|
||||
export default defineDisplay({
|
||||
id: 'translations',
|
||||
@@ -155,5 +161,40 @@ export default defineDisplay({
|
||||
},
|
||||
types: ['alias'],
|
||||
localTypes: ['translations'],
|
||||
fields: ['*'],
|
||||
fields: (options: Options | null, { field, collection }) => {
|
||||
const fieldsStore = useFieldsStore();
|
||||
const relationsStore = useRelationsStore();
|
||||
const relations = relationsStore.getRelationsForField(collection, field);
|
||||
|
||||
const translationsRelation = relations.find(
|
||||
(relation) => relation.related_collection === collection && relation.meta?.one_field === field
|
||||
);
|
||||
|
||||
const languagesRelation = relations.find((relation) => relation !== translationsRelation);
|
||||
|
||||
const translationCollection = translationsRelation?.related_collection;
|
||||
const languagesCollection = languagesRelation?.related_collection;
|
||||
|
||||
if (!translationCollection || !languagesCollection) return [];
|
||||
|
||||
const languagesPrimaryKeyField = fieldsStore.getPrimaryKeyFieldForCollection(languagesCollection);
|
||||
|
||||
const fields = new Set<string>();
|
||||
fields.add('*');
|
||||
|
||||
if (options?.template) {
|
||||
const templateFields = adjustFieldsForDisplays(getFieldsFromTemplate(options.template), translationCollection);
|
||||
templateFields.forEach((field) => fields.add(field));
|
||||
}
|
||||
|
||||
if (languagesRelation && languagesPrimaryKeyField && !fields.has(languagesRelation.field)) {
|
||||
fields.add(`${languagesRelation.field}.${languagesPrimaryKeyField.field}`);
|
||||
|
||||
if (options?.languageField) {
|
||||
fields.add(`${languagesRelation.field}.${options.languageField}`);
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(fields);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user