Skip to content

Commit

Permalink
#5 Remove hasValue/s filters from MetadataEditView
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Jul 31, 2020
1 parent a932813 commit 0304629
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions src/components/MetadataEditView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { compose, lifecycle, withState } from '@hypnosphi/recompose';
import { withApollo } from 'react-apollo';
import gql from 'graphql-tag';
import {
prop,
pipe,
length,
ifElse,
identity,
always,
Expand Down Expand Up @@ -162,12 +159,6 @@ const mapEvents = ({ Event: { id, eventTitle } }) => ({
id, name: eventTitle,
});

const propHasValue = (propName) => pipe(
prop(propName),
ifElse(Array.isArray, length, Boolean),
);
const hasValue = propHasValue('value');
const hasValues = propHasValue('values');
const formatIfValidDate = ifElse(identity, getFormattedDate, always(null));

const passValueAsChild = (Component, itemType) => {
Expand Down Expand Up @@ -205,7 +196,7 @@ const structureDocumentData = (data) => {
},
{ label: 'Creation date', value: formatIfValidDate(data.documentCreationDate) },
{ label: 'Publication date', value: formatIfValidDate(data.documentPublicationDate) },
].filter(hasValue),
],
};

const appearences = {
Expand All @@ -221,7 +212,7 @@ const structureDocumentData = (data) => {
value: data.mentionedLocations.map(mapLocation),
ValueComponent: passValueAsChild(Item, 'location'),
},
].filter(hasValue),
],
};
const categorization = {
groupLabel: 'Categorization',
Expand All @@ -233,14 +224,14 @@ const structureDocumentData = (data) => {
value: reOrganizeItems(data.documentTags, 'tag'),
ValueComponent: passValueAsChild(Tag),
},
].filter(hasValue),
],
};

return [
coreInformation,
appearences,
categorization,
].filter(hasValues);
];
};

const structureEventData = (data) => {
Expand All @@ -261,7 +252,7 @@ const structureEventData = (data) => {
{ label: 'Description', value: eventDescription },
{ label: 'Start date', value: formatIfValidDate(eventStartDate) },
{ label: 'End date', value: formatIfValidDate(eventEndDate) },
].filter(hasValue),
],
};

const appearences = {
Expand All @@ -277,7 +268,7 @@ const structureEventData = (data) => {
value: eventLocations.map(mapLocation),
ValueComponent: passValueAsChild(Item, 'location'),
},
].filter(hasValue),
],
};

const categorization = {
Expand All @@ -288,14 +279,14 @@ const structureEventData = (data) => {
value: reOrganizeItems(eventTags, 'tag'),
ValueComponent: passValueAsChild(Tag),
},
].filter(hasValue),
],
};

return [
coreInformation,
appearences,
categorization,
].filter(hasValues);
];
};

const structureStakeholderData = (data) => {
Expand All @@ -314,7 +305,7 @@ const structureStakeholderData = (data) => {
{ label: 'Title', value: stakeholderFullName },
{ label: 'Description', value: stakeholderDescription },
{ label: 'Wikipedia', value: stakeholderWikipediaUri },
].filter(hasValue),
],
};

const authored = {
Expand All @@ -325,7 +316,7 @@ const structureStakeholderData = (data) => {
value: documents.map(mapDocuments),
ValueComponent: passValueAsChild(Item, 'document'),
},
].filter(hasValue),
],
};

const appearences = {
Expand All @@ -341,14 +332,14 @@ const structureStakeholderData = (data) => {
value: eventsInvolvedIn.map(mapEvents),
ValueComponent: passValueAsChild(Item, 'event'),
},
].filter(hasValue),
],
};

return [
coreInformation,
authored,
appearences,
].filter(hasValues);
];
};

const structureLocationData = (data) => {
Expand All @@ -366,7 +357,7 @@ const structureLocationData = (data) => {
{ label: 'Title', value: locationName },
{ label: 'Description', value: locationDescription },
{ label: 'Wikipedia', value: locationWikipediaUri },
].filter(hasValue),
],
};

const appearences = {
Expand All @@ -382,13 +373,13 @@ const structureLocationData = (data) => {
value: locationEvents.map(mapEvents),
ValueComponent: passValueAsChild(Item, 'event'),
},
].filter(hasValue),
],
};

return [
coreInformation,
appearences,
].filter(hasValues);
];
};

const getStructuredData = (data, itemType) => {
Expand Down

0 comments on commit 0304629

Please sign in to comment.