Skip to content

Commit

Permalink
Show list values on object summary
Browse files Browse the repository at this point in the history
Fix #174
  • Loading branch information
kyoshino committed Jul 3, 2024
1 parent 1054eed commit 3ad7b9f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lib/services/contents/entry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getDateTimeParts } from '@sveltia/utils/datetime';
import { escapeRegExp } from '@sveltia/utils/string';
import moment from 'moment';
import { get } from 'svelte/store';
import { getReferencedOptionLabel } from '$lib/components/contents/details/widgets/relation/helper';
Expand All @@ -7,6 +8,7 @@ import { getAssetByPath } from '$lib/services/assets';
import { backend } from '$lib/services/backends';
import { siteConfig } from '$lib/services/config';
import { getCollection } from '$lib/services/contents';
import { getListFormatter } from '$lib/services/contents/i18n';
import { fillSlugTemplate } from '$lib/services/contents/slug';

/**
Expand Down Expand Up @@ -123,6 +125,24 @@ export const getFieldDisplayValue = ({ collectionName, fileName, valueMap, keyPa
});
}

if (fieldConfig?.widget === 'list') {
const { fields, types } = /** @type {ListField} */ (fieldConfig);

if (fields || types) {
// Ignore
} else {
// Concat values of single field list or simple list
value = getListFormatter(locale).format(
Object.entries(valueMap)
.filter(
([key, val]) =>
key.match(`^${escapeRegExp(keyPath)}\\.\\d+$`) && typeof val === 'string' && !!val,
)
.map(([, val]) => val),
);
}
}

return value ?? '';
};

Expand Down

0 comments on commit 3ad7b9f

Please sign in to comment.