Commit 7f0d316a authored by Petter Goksøyr Åsen's avatar Petter Goksøyr Åsen
Browse files

DEICH-5604 rework Meta.Row and outlisting of work fields

parent 85cb7994
......@@ -11,8 +11,6 @@ function LinkList({ dataType, data }) {
let labelText;
if (dataType.valueKey) {
labelText = item[dataType.valueKey];
} else if (dataType.postTransformation) {
labelText = dataType.postTransformation(item);
} else {
labelText = item;
}
......
import React from "react";
import PropTypes from "prop-types";
import Link from "next/link";
import guid from "../../../utilities/guid";
import { translations as TRANSLATIONS } from "../../../constants/translations";
import { fullTitle } from "../../../utilities/title";
const relationDisplayName = (relation, relationType) => {
if (relationType !== "relatedWork") {
return fullTitle(relation);
}
let displayName = fullTitle(relation);
const mainEntryContributor = relation.contributors.find(c =>
c.type.includes("MainEntry")
);
if (mainEntryContributor) {
displayName = `${displayName} / ${mainEntryContributor.agent.name}`;
}
if (relation.literaryForms && relation.literaryForms.length > 0) {
const formattedLiteraryForms = relation.literaryForms
.map(lf => TRANSLATIONS[lf])
.sort((a, b) => a.localeCompare(b))
.join(", ");
displayName = `${displayName} (${formattedLiteraryForms})`;
}
return displayName;
};
function RelationList({ dataType, data }) {
return (
<ul>
{data.map(item => {
let linkHref;
let linkAs;
if (item.publicationId) {
linkHref = "/utgivelse/[publicationId]";
linkAs = `/utgivelse/${item.publicationId}`
}
if (!item.publicationId && item.type === "WorkSeries") {
linkHref = "/sok/[searchQuery]";
linkAs = `/sok/series: "${item.mainTitle}"`
}
return (
<li className="meta-value__item" key={guid()}>
{linkHref &&
<Link
href={linkHref}
as={linkAs}
>
<a>{relationDisplayName(item, dataType)}</a>
</Link>
}
{!linkHref &&
<span>{relationDisplayName(item, dataType)}</span>
}
</li>
);
})}
</ul>
);
}
RelationList.propTypes = {
dataType: PropTypes.object.isRequired,
data: PropTypes.array.isRequired
};
export default RelationList;
......@@ -6,6 +6,7 @@ import META_TYPES from "../../../constants/metaTypes";
import List from "./List";
import LinkList from "./LinkList";
import String from "./String";
import RelationList from "./RelationList";
/**
* Find correct component to render value into based on data shape (array etc)
......@@ -31,6 +32,10 @@ const Value = ({ type, data }) => {
markup = <LinkList dataType={dataType} data={processedData} />;
}
if (dataType.shape === "RelationList") {
markup = <RelationList dataType={dataType} data={processedData} />;
}
if (dataType.shape === "String") {
markup = <String data={processedData} />;
}
......
......@@ -2,16 +2,12 @@ import React from "react";
import PropTypes from "prop-types";
import Link from "next/link";
import { isEmpty } from "../../utilities/object";
import { fullTitle } from "../../utilities/title";
import { translations as TRANSLATIONS } from "../../constants/translations";
import Meta from "../Meta";
import {
Block,
Flex,
Grid,
GridItem,
Table,
......@@ -21,28 +17,6 @@ import {
import "./styles.css";
const relationDisplayName = (relation, relationType) => {
if (relationType !== "http://data.deichman.no/relationType#relatedWork") {
return fullTitle(relation);
}
let displayName = fullTitle(relation);
const mainEntryContributor = relation.contributors.find(c =>
c.type.includes("MainEntry")
);
if (mainEntryContributor) {
displayName = `${displayName} / ${mainEntryContributor.agent.name}`;
}
if (relation.literaryForms && relation.literaryForms.length > 0) {
const formattedLiteraryForms = relation.literaryForms
.map(lf => TRANSLATIONS[lf])
.sort((a, b) => a.localeCompare(b))
.join(", ");
displayName = `${displayName} (${formattedLiteraryForms})`;
}
return displayName;
};
// Scan all publications for ageLimit specifications, return the biggest/highest
function getAgeLimit(publications) {
if (publications) {
......@@ -56,77 +30,92 @@ function getAgeLimit(publications) {
}
}
const commonFields = [
"publicationTitle",
"untranscribedTitle",
"publicationYear",
"languages",
"parallelTextLanguage",
"contributors",
"workTitle",
"workSeries",
"workRelations",
"workLanguages",
"audiences",
"literaryForms",
"genres",
"compositionTypes",
"adaptations",
"biographies",
"countriesOfOrigin",
"classifications",
"fictionNonfiction",
"formats",
"extents",
"numberOfPages",
"binding",
"illustrativeMatter",
"colorations",
"writingSystem",
"notes",
"edition",
"publishers",
"placeOfPublication",
"serialIssues",
"isbn",
"issn",
"ismn",
"ean",
"recordId",
"duration",
"scoreTypes",
"keys",
"instrumentations",
const fieldOrder = [
"title",
"untranscribedTitle",
"publicationYear",
"productionYear",
"languages",
"parallelTextLanguage",
"contributors",
"workSeries",
"continuedIn",
"continuationOf",
"relatedWork",
"partOf",
"originalTitle",
"workPublicationYear",
"workLanguages",
"audiences",
"scoreTypes",
"instrumentations",
"keys",
"ageLimit",
"literaryForms",
"genres",
"compositionTypes",
"adaptations",
"biographies",
"countriesOfOrigin",
"classifications",
"fictionNonfiction",
"formats",
"extents",
"duration",
"numberOfPages",
"binding",
"illustrativeMatter",
"colorations",
"writingSystem",
"notes",
"edition",
"publishers",
"placeOfPublication",
"serialIssues",
"isbn",
"issn",
"ismn",
"ean",
"recordId"
]
const fieldsByMediaType = {
const fieldsToRemoveByMediaType = {
"Audiobook": [
"workPublicationYear"
"productionYear"
],
"Book": [
"workPublicationYear"
"productionYear"
],
"ComicBook": [
"workPublicationYear"
"productionYear"
],
"E-book": [
"workPublicationYear"
"productionYear"
],
"Film": [
"productionYear"
"publicationYear",
"workPublicationYear"
],
"Game": [
"productionYear"
"publicationYear",
"workPublicationYear"
],
"LanguageCourse": [
"publicationYear"
],
"LanguageCourse": [],
"MusicRecording": [
"productionYear"
"publicationYear",
"workPublicationYear"
],
"Other": [
"productionYear"
],
"Periodical": [],
"SheetMusic": []
"Periodical": [
"productionYear",
],
"SheetMusic": [
"publicationYear"
]
}
const WorkDetails = ({ work, publication }) => {
......@@ -138,7 +127,7 @@ const WorkDetails = ({ work, publication }) => {
const { mediaType } = publication;
const allFields = {
publicationTitle: fullTitle(publication),
title: fullTitle(publication),
untranscribedTitle: publication.untranscribedTitle,
publicationYear: publication.publicationYear,
languages: publication.languages,
......@@ -147,6 +136,10 @@ const WorkDetails = ({ work, publication }) => {
workTitle: fullTitle(work),
contributors: work.contributors.concat(publication.contributors),
workSeries: work.workSeries,
continuedIn: work.workRelations["http://data.deichman.no/relationType#continuedIn"],
continuationOf: work.workRelations["http://data.deichman.no/relationType#continuationOf"],
relatedWork: work.workRelations["http://data.deichman.no/relationType#relatedWork"],
partOf: work.workRelations["http://data.deichman.no/relationType#partOf"],
workRelations: work.workRelations,
workLanguages: work.languages,
audiences: work.audiences,
......@@ -180,18 +173,12 @@ const WorkDetails = ({ work, publication }) => {
scoreTypes: work.scoreTypes,
keys: work.keys,
instrumentations: work.instrumentations,
ageLimit: getAgeLimit(publications)
}
const fields = {}
commonFields.forEach(f => {
fields[f] = allFields[f]
})
// strip 'http://data.deichman.no/mediaType#'
const mediaTypeShort = mediaType.slice(34)
fieldsByMediaType[mediaTypeShort].forEach(f => {
fields[f] = allFields[f]
})
const hasWorkSeries = fields.workSeries.length > 0;
const hasRelations = !isEmpty(fields.workRelations);
const hasClassification = fields.classifications.length > 0;
const fields = fieldOrder.filter(f => !fieldsToRemoveByMediaType[mediaTypeShort].includes(f))
return (
<section
......@@ -212,125 +199,9 @@ const WorkDetails = ({ work, publication }) => {
<Block>
<Table vertical condensed responsive>
<Table.Body>
<Meta.Row type="title" data={fields.publicationTitle} />
<Meta.Row type="untranscribedTitle" data={fields.untranscribedTitle} />
<Meta.Row type="publicationYear" data={fields.publicationYear} />
<Meta.Row type="productionYear" data={fields.productionYear} />
<Meta.Row type="languages" data={fields.languages} />
<Meta.Row type="parallelTextLanguage" data={fields.parallelTextLanguage} />
<Meta.Row type="contributors" data={fields.contributors} />
{hasWorkSeries && (
<Table.Row>
<Table.Cell isHeadCell>Inngår i serien</Table.Cell>
<Table.Cell>
<Flex wrap>
{fields.workSeries.map(series => (
<Block right={2} key={series.id}>
<Link
href="/serie/[workSeriesId]"
as={`/serie/${series.id}`}
>
<a>
{series.mainTitle}
{series.numberInSeries && (
<span> ({series.numberInSeries})</span>
)}
</a>
</Link>
</Block>
))}
</Flex>
</Table.Cell>
</Table.Row>
)}
{hasRelations &&
Object.keys(fields.workRelations).map(key => (
<Table.Row key={key}>
<Table.Cell isHeadCell>{TRANSLATIONS[key]}</Table.Cell>
<Table.Cell>
<Flex wrap>
{fields.workRelations[key].map(relation => (
<Block right={2} key={relation.id}>
{relation.publicationId && (
<Link
href="/utgivelse/[publicationId]"
as={`/utgivelse/${relation.publicationId}`}
>
<a>{relationDisplayName(relation, key)}</a>
</Link>
)}
{!relation.publicationId &&
relation.type === "WorkSeries" && (
<Link
href="/sok/[searchQuery]"
as={`/sok/series: "${relation.mainTitle}"`}
>
<a>{relationDisplayName(relation)}</a>
</Link>
)}
{!relation.publicationId &&
relation.type !== "WorkSeries" && (
<span>{relationDisplayName(relation)}</span>
)}
</Block>
))}
</Flex>
</Table.Cell>
</Table.Row>
))}
<Meta.Row type="originalTitle" data={fields.workTitle} />
<Meta.Row type="workPublicationYear" data={fields.workPublicationYear} />
<Meta.Row type="workLanguages" data={fields.workLanguages} />
<Meta.Row type="audiences" data={fields.audiences} />
<Meta.Row type="scoreTypes" data={fields.scoreTypes} />
<Meta.Row type="instrumentations" data={fields.instrumentations} />
<Meta.Row type="keys" data={fields.keys} />
<Meta.Row type="ageLimit" data={getAgeLimit(publications)} />
<Meta.Row type="literaryForms" data={fields.literaryForms} />
<Meta.Row type="genres" data={fields.genres} />
<Meta.Row type="compositionTypes" data={fields.compositionTypes} />
<Meta.Row type="adaptations" data={fields.adaptations} />
<Meta.Row type="biographies" data={fields.biographies} />
<Meta.Row type="countriesOfOrigin" data={fields.countriesOfOrigin} />
{hasClassification && (
<Table.Row>
<Table.Cell isHeadCell>Klassifikasjon:</Table.Cell>
<Table.Cell>
<Flex wrap>
{fields.classifications.map(classification => (
<Block right={2} key={classification}>
<Link
href="/sok/[searchQuery]"
as={`/sok/klasse: "${classification}"`}
>
<a>{classification}</a>
</Link>
</Block>
))}
</Flex>
</Table.Cell>
</Table.Row>
{fields.map(fieldName =>
<Meta.Row key={fieldName} type={fieldName} data={allFields[fieldName]} />
)}
<Meta.Row type="fictionNonfiction" data={fields.fictionNonfiction} />
<Meta.Row type="formats" data={fields.formats} />
<Meta.Row type="extents" data={fields.extents} />
<Meta.Row type="duration" data={fields.duration} />
<Meta.Row type="numberOfPages" data={fields.numberOfPages} />
<Meta.Row type="binding" data={fields.binding} />
<Meta.Row type="illustrativeMatter" data={fields.illustrativeMatter} />
<Meta.Row type="colorations" data={fields.colorations} />
<Meta.Row type="writingSystem" data={fields.writingSystem} />
<Meta.Row type="notes" data={fields.notes} />
<Meta.Row type="edition" data={fields.edition} />
<Meta.Row type="publishers" data={fields.publishers} />
<Meta.Row type="placeOfPublication" data={fields.placeOfPublication} />
<Meta.Row type="serialIssues" data={fields.serialIssues} />
<Meta.Row type="isbn" data={fields.isbn} />
<Meta.Row type="issn" data={fields.issn} />
<Meta.Row type="ismn" data={fields.ismn} />
<Meta.Row type="ean" data={fields.ean} />
<Meta.Row type="recordId" data={fields.recordId} />
</Table.Body>
</Table>
</Block>
......
......@@ -22,6 +22,15 @@ function transformSerialIssues(issues = []) {
}));
}
function transfromWorkSeries(workSeries = []) {
return workSeries.map(s => ({
id: s.id,
name: s.mainTitle,
type: "workSeries",
numberInSeries: s.numberInSeries
}));
}
function transformInstrumentations(instrumentations = []) {
return instrumentations.map(i => {
if (i.number) {
......@@ -241,7 +250,7 @@ export default {
shape: "List"
},
writingSystem: {
label: "Språksystem",
label: "Skriftsystem",
shape: "String",
transformation: translateString
},
......@@ -256,5 +265,34 @@ export default {
productionYear: {
label: "Produksjonsår",
shape: "String"
}
},
classifications: {
label: "Klasifikkasjon",
shape: "LinkList",
searchQuery: "klasse"
},
workSeries: {
label: "Inngår i serien",
shape: "LinkList",
valueKey: "name",
linkToPage: true,
extraText: "numberInSeries",
transformation: transfromWorkSeries
},
continuedIn: {
label: "Fortsettes i",
shape: "RelationList"
},
continuationOf: {
label: "Fortsettelse av",
shape: "RelationList"
},
relatedWork: {
label: "Relatert til",
shape: "RelationList"
},
partOf: {
label: "Del av",
shape: "RelationList"
},
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment