-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c51ebda
commit 7b4abea
Showing
13 changed files
with
403 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import BaseApi from './BaseApi' | ||
|
||
import { encodeParams } from 'daiquiri/core/assets/js/utils/api' | ||
|
||
export default class CoreApi extends BaseApi { | ||
|
||
static fetchDataLinks(dataLinkId) { | ||
const params = { | ||
'ID': dataLinkId, | ||
'RESPONSEFORMAT': 'application/json' | ||
} | ||
|
||
return this.get(`/datalink/links?${encodeParams(params)}`).then(response => response.links) | ||
} | ||
|
||
static fetchNote(url) { | ||
return this.getText(url) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,59 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
const TableCell = ({ column, value }) => { | ||
import { getBasename, getFileUrl, getLinkUrl, getReferenceUrl, | ||
isModalColumn, isFileColumn, isLinkColumn } from '../../utils/table.js' | ||
|
||
const TableCell = ({ column, value, rowIndex, columnIndex, onClick }) => { | ||
|
||
const handleClick = (event) => { | ||
event.preventDefault() | ||
event.stopPropagation() | ||
onClick(rowIndex, columnIndex) | ||
} | ||
|
||
const renderCell = () => { | ||
if (column.ucd && column.ucd.includes('meta.ref')) { | ||
if (isModalColumn(column)) { | ||
// render the modal | ||
return ( | ||
<a href={getFileUrl(column, value)} onClick={handleClick}>{value}</a> | ||
) | ||
} else if (isFileColumn(column)) { | ||
// render a file link | ||
return ( | ||
<a href={getFileUrl(column, value)} target="_blank" rel="noreferrer">{getBasename(value)}</a> | ||
) | ||
} else if (isLinkColumn(column)) { | ||
// render a regular link | ||
return ( | ||
<a href={getLinkUrl(column, value)} target="_blank" rel="noreferrer">{value}</a> | ||
) | ||
} else { | ||
// render a link to the resolver | ||
return ( | ||
<a href={getReferenceUrl(column, value)} target="_blank" rel="noreferrer">{value}</a> | ||
) | ||
} | ||
} else { | ||
// this is not a reference, just render the value | ||
return value | ||
} | ||
} | ||
|
||
return ( | ||
<div className="dq-table-cell"> | ||
{value} | ||
<div className="dq-table-cell" onClick={handleClick}> | ||
{renderCell()} | ||
</div> | ||
) | ||
} | ||
|
||
TableCell.propTypes = { | ||
column: PropTypes.number.isRequired, | ||
value: PropTypes.array.isRequired | ||
column: PropTypes.object.isRequired, | ||
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), | ||
rowIndex: PropTypes.number.isRequired, | ||
columnIndex: PropTypes.number.isRequired, | ||
onClick: PropTypes.func.isRequired | ||
} | ||
|
||
export default TableCell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import { useDataLinksQuery, useNoteQuery } from '../../hooks/queries' | ||
|
||
import TableModalNavigation from './TableModalNavigation' | ||
|
||
const TableModal = ({ modalRef, modalValues, onNavigation, onClose }) => { | ||
|
||
const { data: dataLinks } = useDataLinksQuery(modalValues.dataLinkId) | ||
const { data: note } = useNoteQuery(modalValues.noteUrl) | ||
|
||
return ( | ||
<div ref={modalRef} className="dq-table-modal modal" tabIndex="-1"> | ||
<div className="modal-dialog modal-lg"> | ||
{ | ||
modalValues && ( | ||
<div className="modal-content"> | ||
<div className="modal-header"> | ||
<h5 className="modal-title">{modalValues.title}</h5> | ||
<button type="button" className="btn-close" onClick={onClose}></button> | ||
</div> | ||
<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> | ||
) | ||
} | ||
{ | ||
note && <pre>{note}</pre> | ||
} | ||
{ | ||
modalValues.imageSrc && ( | ||
<img className="d-block mx-auto" src={modalValues.imageSrc} alt={modalValues.title} /> | ||
) | ||
} | ||
</div> | ||
</div> | ||
) | ||
} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
TableModal.propTypes = { | ||
modalRef: PropTypes.object, | ||
modalValues: PropTypes.object, | ||
onNavigation: PropTypes.func.isRequired, | ||
onClose: PropTypes.func.isRequired | ||
} | ||
|
||
export default TableModal |
Oops, something went wrong.