forked from folio-org/ui-inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
referenceFormatters.js
86 lines (77 loc) · 2.8 KB
/
referenceFormatters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React from 'react';
import { data as languagetable } from './data/languages';
export default {
identifiersFormatter: (r, identifierTypes) => {
const formatted = [];
if (r.identifiers && r.identifiers.length) {
r.identifiers.forEach((identifier) => {
const type = identifierTypes.find(it => it.id === identifier.identifierTypeId);
formatted.push(`${type ? `${type.name} ` : ''}${identifier.value}`);
});
}
return formatted.sort().map((id, i) => <div key={i}>{id}</div>);
},
contributorsFormatter: (r, contributorTypes) => {
let formatted = '';
if (r.contributors && r.contributors.length) {
for (let i = 0; i < r.contributors.length; i += 1) {
const contributor = r.contributors[i];
const type = contributorTypes.find(ct => ct.id === contributor.contributorNameTypeId);
formatted += (i > 0 ? ', ' : '') +
contributor.name +
(type ? ` (${type.name})` : '');
}
}
return formatted;
},
publishersFormatter: (r) => {
const formatted = [];
if (r.publication && r.publication.length) {
r.publication.forEach((pub) => {
formatted.push(`${pub.publisher}${pub.place ? `, ${pub.place}` : ''}${pub.dateOfPublication ? ` (${pub.dateOfPublication})` : ''}`);
});
}
return formatted.map((p, i) => <div key={i}>{p}</div>);
},
languagesFormatter: (r) => {
let formatted = '';
if (r.languages && r.languages.length) {
for (let i = 0; i < r.languages.length; i += 1) {
const languagecode = r.languages[i];
const language = languagetable.find(lang => lang.code === languagecode);
formatted += (i > 0 ? ', ' : '') + (language.name['#text'] || language.name);
}
}
return formatted;
},
instanceFormatsFormatter: (r, instanceFormats) => {
let formatted = '';
if (r.instanceFormatId) {
const format = instanceFormats.find(fmt => fmt.id === r.instanceFormatId);
if (format) {
formatted = format.name;
}
}
return formatted;
},
instanceTypesFormatter: (r, instanceTypes) => {
let formatted = '';
if (r.instanceTypeId) {
const qualifier = instanceTypes.find(type => type.id === r.instanceTypeId);
if (qualifier) {
formatted = qualifier.name;
}
}
return formatted;
},
classificationsFormatter: (r, classificationTypes) => {
const formatted = [];
if (r.classifications && r.classifications.length) {
r.classifications.forEach((classification) => {
const type = classificationTypes.find(ct => ct.id === classification.classificationTypeId);
formatted.push(`${type ? `${type.name} ` : ''}${classification.classificationNumber}`);
});
}
return formatted.sort().map((c, i) => <div key={i}>{c}</div>);
},
};