Skip to content

Commit

Permalink
Add TableModalDatalinks component
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Oct 11, 2024
1 parent cd70281 commit c0ffc30
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
13 changes: 2 additions & 11 deletions daiquiri/core/assets/js/components/table/TableModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'

import { useDataLinksQuery, useNoteQuery } from '../../hooks/queries'

import TableModalDatalinks from './TableModalDatalinks'
import TableModalNavigation from './TableModalNavigation'

const TableModal = ({ modalRef, modalValues, onNavigation, onClose }) => {
Expand All @@ -23,17 +24,7 @@ const TableModal = ({ modalRef, modalValues, onNavigation, onClose }) => {
<div className="modal-body">
<TableModalNavigation values={modalValues} onClick={onNavigation} />
{
dataLinks && (
<ul>
{
dataLinks.map((link, linkIndex) => (
<li key={linkIndex}>
<a href={link.href} target="_blank" rel="noreferrer">{link.text || link.href}</a>
</li>
))
}
</ul>
)
dataLinks && <TableModalDatalinks dataLinks={dataLinks} />
}
{
note && <pre>{note}</pre>
Expand Down
41 changes: 41 additions & 0 deletions daiquiri/core/assets/js/components/table/TableModalDatalinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import { upperFirst } from 'lodash'

const TableModalDatalinks = ({ dataLinks }) => {
const semanticsList = dataLinks.reduce((semanticsList, dataLink) => (
semanticsList.includes(dataLink.semantics) ? semanticsList : [...semanticsList, dataLink.semantics]
), []).sort()

return (
<>
{
semanticsList.map(semantics => {
const label = semantics.split('#')[1]

return (
<div key={semantics} className={classNames({'mt-2': semantics != semanticsList[0]})}>
<strong>{label ? upperFirst(label) : semantics}</strong>
<ul className="list-unstyled">
{
dataLinks.filter(dataLink => dataLink.semantics == semantics).map((dataLink, dataLinkIndex) => (
<li key={dataLinkIndex} className="list-group-item">
<a href={dataLink.access_url} target="_blank" rel="noreferrer">{dataLink.description || dataLink.access_url}</a>
</li>
))
}
</ul>
</div>
)
})
}
</>
)
}

TableModalDatalinks.propTypes = {
dataLinks: PropTypes.array
}

export default TableModalDatalinks
10 changes: 8 additions & 2 deletions daiquiri/datalink/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ def perform_sync_job(self, request, data):
return JsonResponse({
'links': [
{
'href': row[1],
'text': row[4]
'ID': row[0],
'access_url': row[1],
'service_def': row[2],
'error_message': row[3],
'description': row[4],
'semantics': row[5],
'content_type': row[6],
'content_length': row[7],
} for row in rows if not row[3]
]
})
Expand Down

0 comments on commit c0ffc30

Please sign in to comment.