feat: fallback to title when identifier_field is missing (#5775)
Co-authored-by: doompadee <doompadee@users.noreply.github.com>
This commit is contained in:
parent
0258a5cb28
commit
bd46a75403
@ -383,7 +383,9 @@ describe('collections', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('selectEntryCollectionTitle', () => {
|
describe('selectEntryCollectionTitle', () => {
|
||||||
const entry = fromJS({ data: { title: 'entry title', otherField: 'other field' } });
|
const entry = fromJS({
|
||||||
|
data: { title: 'entry title', otherField: 'other field', emptyLinkTitle: '' },
|
||||||
|
});
|
||||||
|
|
||||||
it('should return the entry title if set', () => {
|
it('should return the entry title if set', () => {
|
||||||
const collection = fromJS({
|
const collection = fromJS({
|
||||||
@ -413,6 +415,24 @@ describe('collections', () => {
|
|||||||
expect(selectEntryCollectionTitle(collection, entry)).toEqual('other field');
|
expect(selectEntryCollectionTitle(collection, entry)).toEqual('other field');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return the entry title if identifier_field content is not defined in collection', () => {
|
||||||
|
const collection = fromJS({
|
||||||
|
identifier_field: 'missingLinkTitle',
|
||||||
|
fields: [{ name: 'title' }, { name: 'otherField' }],
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(selectEntryCollectionTitle(collection, entry)).toEqual('entry title');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the entry title if identifier_field content is empty', () => {
|
||||||
|
const collection = fromJS({
|
||||||
|
identifier_field: 'emptyLinkTitle',
|
||||||
|
fields: [{ name: 'title' }, { name: 'otherField' }, { name: 'emptyLinkTitle' }],
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(selectEntryCollectionTitle(collection, entry)).toEqual('entry title');
|
||||||
|
});
|
||||||
|
|
||||||
it('should return the entry label of a file collection', () => {
|
it('should return the entry label of a file collection', () => {
|
||||||
const labelEntry = fromJS({
|
const labelEntry = fromJS({
|
||||||
slug: 'entry-name',
|
slug: 'entry-name',
|
||||||
|
@ -378,7 +378,14 @@ export function selectEntryCollectionTitle(collection: Collection, entry: EntryM
|
|||||||
// try to infer a title field from the entry data
|
// try to infer a title field from the entry data
|
||||||
const entryData = entry.get('data');
|
const entryData = entry.get('data');
|
||||||
const titleField = selectInferedField(collection, 'title');
|
const titleField = selectInferedField(collection, 'title');
|
||||||
return titleField && entryData.getIn(keyToPathArray(titleField));
|
const result = titleField && entryData.getIn(keyToPathArray(titleField));
|
||||||
|
|
||||||
|
// if the custom field does not yield a result, fallback to 'title'
|
||||||
|
if (!result && titleField !== 'title') {
|
||||||
|
return entryData.getIn(keyToPathArray('title'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function selectDefaultSortableFields(
|
export function selectDefaultSortableFields(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user