Skip to content

Commit

Permalink
Merge branch 'staging' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
mfacar committed May 9, 2022
2 parents 818f82b + b51cb51 commit abdd41c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/react/Metadata/helpers/formater.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ export default {
return {
label: property.get('label'),
name: property.get('name'),
type: property.get('type'),
value,
showInCard,
translateContext: template.get('_id'),
Expand Down
5 changes: 3 additions & 2 deletions app/react/Viewer/pageAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ const formatPropertyValue = (
};

const formatProperty = (item: FormattedPropertyValueSchema) => {
const values: unknown[] = !isArray(item.value) ? [item] : item.value;
const values: unknown[] = !isArray(item.value) || !item.value.length ? [item] : item.value;

const formattedItem = values.map((target: any) => {
const relatedEntity = pickEntityFields(target.relatedEntity);
const metadataField = metadataFields(item);
const value = formatPropertyValue(target, metadataField);

return {
displayValue: get(target, metadataField.displayValue, target),
displayValue: get(target, metadataField.displayValue, value),
value,
name: item.name,
type: propertyDisplayType(item),
Expand All @@ -96,6 +96,7 @@ const formatEntityData = (formattedEntity: FormattedEntity) => {

return { ...entity, metadata: formattedMetadata };
};

const formatEntity = (formattedEntity: FormattedEntity) => {
const originalMetadata: MetadataObjectSchema[] = formattedEntity.metadata;
const metadata = originalMetadata.reduce(
Expand Down
21 changes: 21 additions & 0 deletions app/react/Viewer/specs/pageAssets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('pageAssets', () => {
},
]);
});

it('should return geolocation properties formatted', () => {
expect(entityData.metadata?.geolocation_geolocation).toEqual([
{
Expand All @@ -103,6 +104,7 @@ describe('pageAssets', () => {
},
]);
});

it('should return multi date range properties formatted', () => {
expect(entityData.metadata?.multi_date_range).toEqual([
{
Expand Down Expand Up @@ -155,5 +157,24 @@ describe('pageAssets', () => {
},
]);
});

it('should work when metadata value is not set', () => {
expect(entityData.metadata?.emptyText).toEqual([
{
name: 'emptyText',
type: 'text',
value: undefined,
displayValue: undefined,
},
]);
expect(entityData.metadata?.emptyRelation).toEqual([
{
name: 'emptyRelation',
type: 'inherit',
value: [],
displayValue: [],
},
]);
});
});
});
38 changes: 38 additions & 0 deletions app/react/Viewer/specs/pageAssetsFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,25 @@ const dbTemplates: IImmutable<TemplateSchema>[] = [
type: 'geolocation',
name: 'geolocation_geolocation',
},
{
_id: '6267e68226904c252518f915',
label: 'Empty text',
type: 'text',
name: 'emptyText',
filter: true,
},
{
_id: '6267e68226904c252518f916',
label: 'Empty Relation',
type: 'relationship',
name: 'emptyRelation',
content: '626c19238a46c11701b49a55',
relationType: '626c19088a46c11701b493e6',
inherit: {
property: '626c19498a46c11701b4a703',
type: 'select',
},
},
],
__v: 0,
default: true,
Expand Down Expand Up @@ -1099,6 +1118,25 @@ const expectedFormattedEntity = {
],
onlyForCards: false,
},
emptyText: {
label: 'Empty text',
name: 'emptyText',
type: 'text',
showInCard: undefined,
translateContext: '5bfbb1a0471dd0fc16ada146',
value: undefined,
},
emptyRelation: {
indexInTemplate: 16,
inheritedType: 'select',
label: 'Empty Relation',
name: 'emptyRelation',
noLabel: undefined,
onlyForCards: false,
translateContext: '626c19238a46c11701b49a55',
type: 'inherit',
value: [],
},
},
attachments: [
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uwazi",
"version": "1.65.0-rc4",
"version": "1.66.0-rc2",
"description": "Uwazi is a free, open-source solution for organising, analysing and publishing your documents.",
"keywords": [
"react"
Expand Down

0 comments on commit abdd41c

Please sign in to comment.