@cu-mkp/editioncrafter 1.3.0 → 1.3.1-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -216,6 +216,7 @@ function parseSingleManifest(manifest, transcriptionTypes, document) {
216
216
  annotations: canvas.annotations
217
217
  ? canvas.annotations.filter(a => a.motivation === 'tagging')
218
218
  : [],
219
+ metadata: canvas.metadata,
219
220
  }
220
221
 
221
222
  folios.push(folio)
@@ -4,12 +4,11 @@ import { createReducer } from '../model/ReduxStore'
4
4
  import DiplomaticActions from './DiplomaticActions'
5
5
  import DocumentActions from './DocumentActions'
6
6
  import GlossaryActions from './GlossaryActions'
7
- import NotesActions from './NotesActions'
8
-
9
7
  import diplomaticInitialState from './initialState/diplomaticInitialState'
10
8
  import documentInitialState from './initialState/documentInitialState'
11
9
  import glossaryInitialState from './initialState/glossaryInitialState'
12
10
  import notesInitialState from './initialState/notesInitialState'
11
+ import NotesActions from './NotesActions'
13
12
 
14
13
  export default function rootReducer(config) {
15
14
  const {
@@ -30,8 +29,14 @@ export default function rootReducer(config) {
30
29
  derivativesInfo[key] = config.documentInfo[key].documentName
31
30
  })
32
31
  }
33
- const transcriptionTypes = variorum ? transcriptionTypesInfo : config.transcriptionTypes
34
- const iiifManifest = variorum ? manifestInfo : config.iiifManifest
32
+
33
+ // handle the case that there's exactly one document in documentInfo
34
+ let docConfig = config
35
+ if (documentInfo && Object.keys(documentInfo).length === 1) {
36
+ docConfig = Object.values(documentInfo)[0]
37
+ }
38
+ const transcriptionTypes = variorum ? transcriptionTypesInfo : docConfig.transcriptionTypes
39
+ const iiifManifest = variorum ? manifestInfo : docConfig.iiifManifest
35
40
  const derivativeNames = variorum && derivativesInfo
36
41
  return combineReducers({
37
42
  diplomatic: createReducer('DiplomaticActions', DiplomaticActions, diplomaticInitialState),
@@ -0,0 +1,13 @@
1
+ export default function ImageMetadata(props) {
2
+ const { data } = props
3
+
4
+ return (
5
+ <div className="image-metadata">
6
+ { Object.keys(data)?.map(key => (
7
+ <div key={key}>
8
+ { `${key}: ${data[key]}` }
9
+ </div>
10
+ ))}
11
+ </div>
12
+ )
13
+ }
@@ -10,6 +10,7 @@ import {
10
10
  useSearchParams,
11
11
  } from 'react-router-dom'
12
12
  import TagFilterContext from '../context/TagFilterContext'
13
+ import ImageMetadata from './ImageMetadata'
13
14
  import ImageZoomControl from './ImageZoomControl'
14
15
  import Navigation from './Navigation'
15
16
 
@@ -187,6 +188,11 @@ function ImageView(props) {
187
188
  initViewer={initViewer}
188
189
  loading={folio.loading}
189
190
  />
191
+ {
192
+ folio.metadata && (
193
+ <ImageMetadata data={folio.metadata} />
194
+ )
195
+ }
190
196
  </div>
191
197
  )
192
198
  : (
@@ -107,8 +107,6 @@ function htmlToReactParserOptions(selectedZone, selectedTags) {
107
107
  function TranscriptionView(props) {
108
108
  const [searchParams] = useSearchParams()
109
109
 
110
- const { tags } = useContext(TagFilterContext)
111
-
112
110
  const {
113
111
  side,
114
112
  folioID,
@@ -118,6 +116,9 @@ function TranscriptionView(props) {
118
116
  documentViewActions,
119
117
  } = props
120
118
 
119
+ const { tagsLeft, tagsRight } = useContext(TagFilterContext)
120
+ const tags = side === 'left' ? tagsLeft : tagsRight
121
+
121
122
  if (folioID === '-1') {
122
123
  return (
123
124
  <Watermark
@@ -55,10 +55,16 @@ function TagFilterProvider(props) {
55
55
  }
56
56
  }
57
57
 
58
+ const clearTags = () => {
59
+ setTagsRight([])
60
+ setTagsLeft([])
61
+ }
62
+
58
63
  return {
59
64
  tagsLeft,
60
65
  tagsRight,
61
66
  toggleTag,
67
+ clearTags,
62
68
  }
63
69
  }, [location.pathname, navigate, searchParams, tagParamsLeft, tagParamsRight, tagsLeft, tagsRight])
64
70
 
@@ -4,6 +4,7 @@ const TagFilterContext = createContext({
4
4
  tagsLeft: [],
5
5
  tagsRight: [],
6
6
  toggleTag: () => null,
7
+ clearTags: () => null,
7
8
  })
8
9
 
9
10
  export default TagFilterContext
@@ -131,7 +131,7 @@ function* resolveFolio(pathSegments) {
131
131
  folioIDs.push(thirdID)
132
132
 
133
133
  for (const folioID of folioIDs) {
134
- const folioData = document.folioIndex[folioID]
134
+ const folioData = document.folioIndex[folioID] || document.folioIndex[decodeURI(folioID)]
135
135
  if (folioData && !folioData.loading) {
136
136
  // wait for folio to load and then advance state
137
137
  const folio = yield loadFolio(folioData)
@@ -0,0 +1,16 @@
1
+ .editioncrafter {
2
+
3
+ .image-metadata {
4
+ position: absolute;
5
+ bottom: 8px;
6
+ left: 8px;
7
+ background-color: rgba(128, 128, 128, 0.5);
8
+ color: white;
9
+ display: flex;
10
+ flex-direction: row;
11
+ gap: 16px;
12
+ flex-wrap: wrap;
13
+ padding: 4px 6px;
14
+ }
15
+
16
+ }
@@ -99,6 +99,7 @@ animation: #{$str};
99
99
 
100
100
  @import "diplomatic";
101
101
  @import "imageGridView";
102
+ @import "imageMetadata";
102
103
  @import "splitPaneView";
103
104
  @import "imageView";
104
105
  @import "imageZoomControl";
@@ -1,16 +1,19 @@
1
1
  function InsertLeft() {
2
2
  return (
3
3
  <svg width="28" height="21" viewBox="0 0 16 12" fill="none" xmlns="http://www.w3.org/2000/svg">
4
- <g id="fluent:document-one-page-20-regular" clipPath="url(#clip0_527_47401)">
4
+ <g
5
+ // id="fluent:document-one-page-20-regular"
6
+ // clipPath="url(#clip0_527_47401)"
7
+ >
5
8
  <path id="Vector" d="M1.26984 0H6.34921C6.68599 0 7.00898 0.158035 7.24712 0.43934C7.48526 0.720644 7.61905 1.10218 7.61905 1.5V10.5C7.61905 10.8978 7.48526 11.2794 7.24712 11.5607C7.00898 11.842 6.68599 12 6.34921 12H1.26984C0.933058 12 0.610069 11.842 0.371928 11.5607C0.133786 11.2794 0 10.8978 0 10.5V1.5C0 1.10218 0.133786 0.720644 0.371928 0.43934C0.610069 0.158035 0.933058 0 1.26984 0ZM1.26984 0.75C1.10145 0.75 0.939955 0.829018 0.820885 0.96967C0.701814 1.11032 0.634921 1.30109 0.634921 1.5V10.5C0.634921 10.6989 0.701814 10.8897 0.820885 11.0303C0.939955 11.171 1.10145 11.25 1.26984 11.25H6.34921C6.5176 11.25 6.67909 11.171 6.79816 11.0303C6.91723 10.8897 6.98413 10.6989 6.98413 10.5V1.5C6.98413 1.30109 6.91723 1.11032 6.79816 0.96967C6.67909 0.829018 6.5176 0.75 6.34921 0.75H1.26984Z" fill="white" />
6
9
  <path id="Vector_2" opacity="0.4" d="M9.6507 0H14.7301C15.0668 0 15.3898 0.158035 15.628 0.43934C15.8661 0.720644 15.9999 1.10218 15.9999 1.5V10.5C15.9999 10.8978 15.8661 11.2794 15.628 11.5607C15.3898 11.842 15.0668 12 14.7301 12H9.6507C9.31392 12 8.99093 11.842 8.75279 11.5607C8.51465 11.2794 8.38086 10.8978 8.38086 10.5V1.5C8.38086 1.10218 8.51465 0.720644 8.75279 0.43934C8.99093 0.158035 9.31392 0 9.6507 0ZM9.6507 0.75C9.48231 0.75 9.32081 0.829018 9.20174 0.96967C9.08267 1.11032 9.01578 1.30109 9.01578 1.5V10.5C9.01578 10.6989 9.08267 10.8897 9.20174 11.0303C9.32081 11.171 9.48231 11.25 9.6507 11.25H14.7301C14.8985 11.25 15.06 11.171 15.179 11.0303C15.2981 10.8897 15.365 10.6989 15.365 10.5V1.5C15.365 1.30109 15.2981 1.11032 15.179 0.96967C15.06 0.829018 14.8985 0.75 14.7301 0.75H9.6507Z" fill="white" />
7
10
  <path id="Vector_3" d="M5.82826 6.11765C5.82826 6.16445 5.81101 6.20934 5.7803 6.24243C5.74959 6.27553 5.70794 6.29412 5.66451 6.29412H4.02709V8.05882C4.02709 8.10563 4.00984 8.15051 3.97913 8.18361C3.94842 8.2167 3.90677 8.23529 3.86335 8.23529C3.81992 8.23529 3.77827 8.2167 3.74756 8.18361C3.71686 8.15051 3.6996 8.10563 3.6996 8.05882V6.29412H2.06218C2.01875 6.29412 1.9771 6.27553 1.9464 6.24243C1.91569 6.20934 1.89844 6.16445 1.89844 6.11765C1.89844 6.07084 1.91569 6.02596 1.9464 5.99286C1.9771 5.95977 2.01875 5.94118 2.06218 5.94118H3.6996V4.17647C3.6996 4.12967 3.71686 4.08478 3.74756 4.05169C3.77827 4.01859 3.81992 4 3.86335 4C3.90677 4 3.94842 4.01859 3.97913 4.05169C4.00984 4.08478 4.02709 4.12967 4.02709 4.17647V5.94118H5.66451C5.70794 5.94118 5.74959 5.95977 5.7803 5.99286C5.81101 6.02596 5.82826 6.07084 5.82826 6.11765Z" fill="white" />
8
11
  </g>
9
- <defs>
12
+ {/* <defs>
10
13
  <clipPath id="clip0_527_47401">
11
14
  <rect width="16" height="12" fill="white" />
12
15
  </clipPath>
13
- </defs>
16
+ </defs> */}
14
17
  </svg>
15
18
  )
16
19
  }
@@ -1,16 +1,18 @@
1
1
  function InsertRight() {
2
2
  return (
3
3
  <svg width="28" height="21" viewBox="0 0 16 12" fill="none" xmlns="http://www.w3.org/2000/svg">
4
- <g clipPath="url(#clip0_527_47406)">
4
+ <g
5
+ // clipPath="url(#clip0_527_47406)"
6
+ >
5
7
  <path opacity="0.4" d="M1.27 0H6.35C6.68682 0 7.00985 0.158035 7.24802 0.43934C7.4862 0.720644 7.62 1.10218 7.62 1.5V10.5C7.62 10.8978 7.4862 11.2794 7.24802 11.5607C7.00985 11.842 6.68682 12 6.35 12H1.27C0.933175 12 0.610146 11.842 0.371974 11.5607C0.133803 11.2794 0 10.8978 0 10.5V1.5C0 1.10218 0.133803 0.720644 0.371974 0.43934C0.610146 0.158035 0.933175 0 1.27 0ZM1.27 0.75C1.10159 0.75 0.940073 0.829018 0.820987 0.96967C0.701902 1.11032 0.635 1.30109 0.635 1.5V10.5C0.635 10.6989 0.701902 10.8897 0.820987 11.0303C0.940073 11.171 1.10159 11.25 1.27 11.25H6.35C6.51841 11.25 6.67993 11.171 6.79901 11.0303C6.9181 10.8897 6.985 10.6989 6.985 10.5V1.5C6.985 1.30109 6.9181 1.11032 6.79901 0.96967C6.67993 0.829018 6.51841 0.75 6.35 0.75H1.27Z" fill="white" />
6
8
  <path d="M9.64988 0H14.7299C15.0667 0 15.3897 0.158035 15.6279 0.43934C15.8661 0.720644 15.9999 1.10218 15.9999 1.5V10.5C15.9999 10.8978 15.8661 11.2794 15.6279 11.5607C15.3897 11.842 15.0667 12 14.7299 12H9.64988C9.31306 12 8.99003 11.842 8.75186 11.5607C8.51369 11.2794 8.37988 10.8978 8.37988 10.5V1.5C8.37988 1.10218 8.51369 0.720644 8.75186 0.43934C8.99003 0.158035 9.31306 0 9.64988 0ZM9.64988 0.75C9.48147 0.75 9.31996 0.829018 9.20087 0.96967C9.08178 1.11032 9.01488 1.30109 9.01488 1.5V10.5C9.01488 10.6989 9.08178 10.8897 9.20087 11.0303C9.31996 11.171 9.48147 11.25 9.64988 11.25H14.7299C14.8983 11.25 15.0598 11.171 15.1789 11.0303C15.298 10.8897 15.3649 10.6989 15.3649 10.5V1.5C15.3649 1.30109 15.298 1.11032 15.1789 0.96967C15.0598 0.829018 14.8983 0.75 14.7299 0.75H9.64988Z" fill="white" />
7
9
  <path d="M14.2096 6.10028C14.2096 6.1404 14.1924 6.17887 14.1616 6.20724C14.1309 6.23561 14.0893 6.25154 14.0458 6.25154H12.4082V7.76415C12.4082 7.80426 12.391 7.84274 12.3603 7.87111C12.3295 7.89947 12.2879 7.91541 12.2445 7.91541C12.201 7.91541 12.1594 7.89947 12.1287 7.87111C12.0979 7.84274 12.0807 7.80426 12.0807 7.76415V6.25154H10.4431C10.3996 6.25154 10.358 6.23561 10.3273 6.20724C10.2966 6.17887 10.2793 6.1404 10.2793 6.10028C10.2793 6.06017 10.2966 6.02169 10.3273 5.99332C10.358 5.96496 10.3996 5.94902 10.4431 5.94902H12.0807V4.43642C12.0807 4.3963 12.0979 4.35783 12.1287 4.32946C12.1594 4.30109 12.201 4.28516 12.2445 4.28516C12.2879 4.28516 12.3295 4.30109 12.3603 4.32946C12.391 4.35783 12.4082 4.3963 12.4082 4.43642V5.94902H14.0458C14.0893 5.94902 14.1309 5.96496 14.1616 5.99332C14.1924 6.02169 14.2096 6.06017 14.2096 6.10028Z" fill="white" />
8
10
  </g>
9
- <defs>
11
+ {/* <defs>
10
12
  <clipPath id="clip0_527_47406">
11
13
  <rect width="16" height="12" fill="white" />
12
14
  </clipPath>
13
- </defs>
15
+ </defs> */}
14
16
  </svg>
15
17
  )
16
18
  }
@@ -85,21 +85,25 @@ function Thumbnail(props) {
85
85
  <figure className="surface-thumbnail-figure">
86
86
  {isLeft
87
87
  ? (
88
- <div className="surface-thumbnail-overlay-selected left">
89
- <div>
90
- <Left />
91
- <Typography>Left</Typography>
88
+ <a onDoubleClick={onClick.right} title="Double click to insert right">
89
+ <div className="surface-thumbnail-overlay-selected left">
90
+ <div>
91
+ <Left />
92
+ <Typography>Left</Typography>
93
+ </div>
92
94
  </div>
93
- </div>
95
+ </a>
94
96
  )
95
97
  : isRight
96
98
  ? (
97
- <div className="surface-thumbnail-overlay-selected right">
98
- <div>
99
- <Right />
100
- <Typography>Right</Typography>
99
+ <a onDoubleClick={onClick.left} title="Double click to insert left">
100
+ <div className="surface-thumbnail-overlay-selected right">
101
+ <div>
102
+ <Right />
103
+ <Typography>Right</Typography>
104
+ </div>
101
105
  </div>
102
- </div>
106
+ </a>
103
107
  )
104
108
  : (
105
109
  <div className="surface-thumbnail-overlay">
@@ -195,29 +199,32 @@ function DocumentDetail(props) {
195
199
  updatePageCount(surfaces?.length)
196
200
  }, [surfaces, updatePageCount, tags])
197
201
 
198
- return (
199
- <Accordion>
200
- <AccordionSummary
201
- expandIcon={<ExpandMoreIcon />}
202
- aria-controls={`document-detail-${documentID}-content`}
203
- id={`document-detail-${documentID}`}
204
- className="accordion-summary"
205
- >
206
- <Typography>{documentName}</Typography>
207
- <Typography>{surfaces?.length || ''}</Typography>
208
- </AccordionSummary>
209
- <AccordionDetails
210
- className="accordion-detail"
211
- >
212
- <ThumbnailGrid
213
- navigateToSelection={navigateToSelection}
214
- documentLocalID={documentLocalID}
215
- surfaces={surfaces}
216
- selection={selection}
217
- >
218
- </ThumbnailGrid>
219
- </AccordionDetails>
220
- </Accordion>
202
+ return ((!tags.length || surfaces.length)
203
+ ? (
204
+ <Accordion>
205
+ <AccordionSummary
206
+ expandIcon={<ExpandMoreIcon />}
207
+ aria-controls={`document-detail-${documentID}-content`}
208
+ id={`document-detail-${documentID}`}
209
+ className="accordion-summary"
210
+ >
211
+ <Typography>{documentName}</Typography>
212
+ <Typography>{surfaces?.length || ''}</Typography>
213
+ </AccordionSummary>
214
+ <AccordionDetails
215
+ className="accordion-detail"
216
+ >
217
+ <ThumbnailGrid
218
+ navigateToSelection={navigateToSelection}
219
+ documentLocalID={documentLocalID}
220
+ surfaces={surfaces}
221
+ selection={selection}
222
+ >
223
+ </ThumbnailGrid>
224
+ </AccordionDetails>
225
+ </Accordion>
226
+ )
227
+ : null
221
228
  )
222
229
  }
223
230
 
@@ -0,0 +1,293 @@
1
+ import { Checkbox, FormControlLabel, FormGroup, Typography } from '@material-ui/core'
2
+ import { useCallback, useEffect, useMemo, useState } from 'react'
3
+ import { getObjs } from '../../common/lib/sql'
4
+
5
+ function getData(db) {
6
+ const rolesStmt = db.prepare(`
7
+ SELECT * FROM roles
8
+ `)
9
+ const agentStmt = db.prepare(`
10
+ SELECT
11
+ people.name as name,
12
+ roles.name as role,
13
+ people.id as person_id,
14
+ roles.id as role_id
15
+ FROM
16
+ agents
17
+ LEFT JOIN people
18
+ ON people.id = agents.person
19
+ LEFT JOIN roles
20
+ ON roles.id = agents.role
21
+ GROUP BY
22
+ roles.name, people.name, people.id, roles.id
23
+ `)
24
+
25
+ const keywordsStmt = db.prepare(`
26
+ SELECT * FROM keywords
27
+ `)
28
+
29
+ const typesStmt = db.prepare(`
30
+ SELECT type FROM keywords GROUP BY type
31
+ `)
32
+
33
+ const langStmt = db.prepare(`SELECT * FROM languages`)
34
+ const locStmt = db.prepare(`SELECT * FROM locations`)
35
+
36
+ return {
37
+ agents: getObjs(agentStmt),
38
+ roles: getObjs(rolesStmt),
39
+ types: getObjs(typesStmt),
40
+ keywords: getObjs(keywordsStmt),
41
+ languages: getObjs(langStmt),
42
+ locations: getObjs(locStmt),
43
+ }
44
+ }
45
+
46
+ function DocumentFilters(props) {
47
+ const { filters, query } = props
48
+ const fullData = useMemo(() => getData(props.db), [props.db])
49
+ const [expanded, setExpanded] = useState(fullData.roles?.map(() => (false)))
50
+ const [keywordExpanded, setKeywordExpanded] = useState(fullData.types?.map(() => (false)))
51
+ const [langExpanded, setLangExpanded] = useState(false)
52
+ const [locExpanded, setLocExpanded] = useState(false)
53
+ const [displayedTags, setDisplayedTags] = useState({})
54
+
55
+ const data = useMemo(() => {
56
+ const agents = fullData.agents?.filter(ag => (!query || !query.length || ag.name?.toLowerCase().includes(query.toLowerCase())))
57
+ const keywords = fullData.keywords?.filter(term => (!query || !query.length || term.name?.toLowerCase().includes(query.toLowerCase())))
58
+ const languages = fullData.languages?.filter(lang => (!query || !query.length || lang.name.toLowerCase().includes(query.toLowerCase())))
59
+ const locations = fullData.locations?.filter(loc => (!query || !query.length || loc.name.toLowerCase().includes(query.toLowerCase())))
60
+ return ({
61
+ agents,
62
+ keywords,
63
+ languages,
64
+ locations,
65
+ types: fullData.types,
66
+ roles: fullData.roles,
67
+ })
68
+ }, [fullData, query])
69
+
70
+ useEffect(() => {
71
+ const tags = {}
72
+ for (let i = 0; i < data.roles.length; i++) {
73
+ const tax = data.roles[i]
74
+ const tagList = expanded[i] ? data.agents.filter(t => (t.role_id === tax.id)) : data.agents.filter(t => (t.role_id === tax.id))?.slice(0, 5)
75
+ tags[tax.id] = tagList
76
+ }
77
+ setDisplayedTags(tags)
78
+ }, [expanded, data])
79
+
80
+ const onToggleAgent = useCallback((role, person) => {
81
+ const current = [...filters.agents.data]
82
+ if (current.find(f => (f.role === role && f.person === person))) {
83
+ filters.agents.onUpdate(current => (current.filter(item => (item.role !== role || item.person !== person))))
84
+ }
85
+ else {
86
+ filters.agents.onUpdate(current => [...current, { role, person }])
87
+ }
88
+ }, [filters])
89
+
90
+ const onToggleKeyword = useCallback((type, term) => {
91
+ const current = [...filters.keywords.data]
92
+ if (current.find(f => (f.type === type && f.term === term))) {
93
+ filters.keywords.onUpdate(current => (current.filter(item => (item.type !== type || item.term !== term))))
94
+ }
95
+ else {
96
+ filters.keywords.onUpdate(current => [...current, { type, term }])
97
+ }
98
+ }, [filters])
99
+
100
+ const onToggleLanguage = useCallback((item_id) => {
101
+ const current = [...filters.langs.data]
102
+ if (current.includes(item_id)) {
103
+ filters.langs.onUpdate(current => (current.filter(i => (i !== item_id))))
104
+ }
105
+ else {
106
+ filters.langs.onUpdate(current => [...current, item_id])
107
+ }
108
+ }, [filters])
109
+
110
+ const onToggleLocation = useCallback((item_id) => {
111
+ const current = [...filters.locations.data]
112
+ if (current.includes(item_id)) {
113
+ filters.locations.onUpdate(current => (current.filter(i => (i !== item_id))))
114
+ }
115
+ else {
116
+ filters.locations.onUpdate(current => [...current, item_id])
117
+ }
118
+ }, [filters])
119
+
120
+ return (
121
+ <div className="tag-list">
122
+ <FormGroup>
123
+ { data.roles.map((tax, idx) => {
124
+ const tagList = displayedTags[tax.id]
125
+ return tagList?.length
126
+ ? (
127
+ <div key={tax.id}>
128
+ <Typography>{tax.name}</Typography>
129
+ <ul>
130
+ { tagList?.map(tag => (
131
+ <FormControlLabel
132
+ as="li"
133
+ control={(
134
+ <Checkbox
135
+ checked={!!filters.agents.data.find(ag => (ag.role === tax.id && ag.person === tag.person_id))}
136
+ onChange={() => {
137
+ onToggleAgent(tax.id, tag.person_id)
138
+ }}
139
+ />
140
+ )}
141
+ key={tag.person_id}
142
+ label={tag.name}
143
+ />
144
+ ))}
145
+ </ul>
146
+ { (data.agents.filter(t => (t.role_id === tax.id))?.length && data.agents.filter(t => (t.role_id === tax.id)).length >= 6)
147
+ ? (
148
+ <button
149
+ className="tag-filter-button"
150
+ type="button"
151
+ onClick={() => {
152
+ const newState = [...expanded]
153
+ newState[idx] = !expanded[idx]
154
+ setExpanded(newState)
155
+ }}
156
+ >
157
+ { expanded[idx] ? 'Show less' : 'Show more'}
158
+ </button>
159
+ )
160
+ : null }
161
+ </div>
162
+ )
163
+ : null
164
+ })}
165
+ { data.types.map((tax, idx) => {
166
+ const tagList = data.keywords.filter(term => (term.type === tax.type))
167
+ return tagList?.length
168
+ ? (
169
+ <div key={tax.type}>
170
+ <Typography>
171
+ {tax.type[0].toUpperCase()}
172
+ {tax.type.slice(1)}
173
+ </Typography>
174
+ <ul>
175
+ { tagList?.map(tag => (
176
+ <FormControlLabel
177
+ as="li"
178
+ control={(
179
+ <Checkbox
180
+ checked={!!filters.keywords.data.find(item => (item.type === tax.type && item.term === tag.id))}
181
+ onChange={() => {
182
+ onToggleKeyword(tax.type, tag.id)
183
+ }}
184
+ />
185
+ )}
186
+ key={tag.id}
187
+ label={tag.name}
188
+ />
189
+ ))}
190
+ </ul>
191
+ { tagList.length >= 6
192
+ ? (
193
+ <button
194
+ className="tag-filter-button"
195
+ type="button"
196
+ onClick={() => {
197
+ const newState = [...keywordExpanded]
198
+ newState[idx] = !keywordExpanded[idx]
199
+ setKeywordExpanded(newState)
200
+ }}
201
+ >
202
+ { keywordExpanded[idx] ? 'Show less' : 'Show more'}
203
+ </button>
204
+ )
205
+ : null}
206
+ </div>
207
+ )
208
+ : null
209
+ })}
210
+ { data.languages?.length
211
+ ? (
212
+ <div>
213
+ <Typography>
214
+ Language
215
+ </Typography>
216
+ <ul>
217
+ { data.languages.map(tag => (
218
+ <FormControlLabel
219
+ as="li"
220
+ control={(
221
+ <Checkbox
222
+ checked={filters.langs.data.includes(tag.id)}
223
+ onChange={() => {
224
+ onToggleLanguage(tag.id)
225
+ }}
226
+ />
227
+ )}
228
+ key={tag.id}
229
+ label={tag.name}
230
+ />
231
+ ))}
232
+ </ul>
233
+ { data.languages.length >= 6
234
+ ? (
235
+ <button
236
+ className="tag-filter-button"
237
+ type="button"
238
+ onClick={() => {
239
+ setLangExpanded(current => !current)
240
+ }}
241
+ >
242
+ { langExpanded ? 'Show less' : 'Show more'}
243
+ </button>
244
+ )
245
+ : null}
246
+ </div>
247
+ )
248
+ : null }
249
+ { data.locations?.length
250
+ ? (
251
+ <div>
252
+ <Typography>
253
+ Location of Publication
254
+ </Typography>
255
+ <ul>
256
+ { data.locations.map(tag => (
257
+ <FormControlLabel
258
+ as="li"
259
+ control={(
260
+ <Checkbox
261
+ checked={filters.locations.data.includes(tag.id)}
262
+ onChange={() => {
263
+ onToggleLocation(tag.id)
264
+ }}
265
+ />
266
+ )}
267
+ key={tag.id}
268
+ label={tag.name}
269
+ />
270
+ ))}
271
+ </ul>
272
+ { data.locations.length >= 6
273
+ ? (
274
+ <button
275
+ className="tag-filter-button"
276
+ type="button"
277
+ onClick={() => {
278
+ setLocExpanded(current => !current)
279
+ }}
280
+ >
281
+ { locExpanded ? 'Show less' : 'Show more'}
282
+ </button>
283
+ )
284
+ : null}
285
+ </div>
286
+ )
287
+ : null }
288
+ </FormGroup>
289
+ </div>
290
+ )
291
+ }
292
+
293
+ export default DocumentFilters