Skip to content

Commit

Permalink
Fix rendering of filepath for files and images
Browse files Browse the repository at this point in the history
  • Loading branch information
kimakan committed Dec 9, 2024
1 parent f6d6cf2 commit d30829b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion daiquiri/core/assets/js/components/table/TableCell.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'

import { getBasename, getFileUrl, getLinkUrl, getReferenceUrl,
import { getBasename, getFileUrl, getLinkUrl, getReferenceUrl, isImageColumn,
isModalColumn, isFileColumn, isLinkColumn } from '../../utils/table.js'

const TableCell = ({ column, value, rowIndex, columnIndex, setActive, showModal }) => {
Expand All @@ -10,6 +10,9 @@ const TableCell = ({ column, value, rowIndex, columnIndex, setActive, showModal
if (column.ucd && column.ucd.includes('meta.ref')) {
if (isModalColumn(column)) {
// render the modal
if (isImageColumn(column)) {
value = getBasename(value)
}
return (
<a href={getFileUrl(column, value)} onClick={(event) => {
event.preventDefault()
Expand Down
8 changes: 7 additions & 1 deletion daiquiri/core/assets/js/utils/table.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { baseUrl } from './meta'

export const getBasename = (string) => string.replace(/^.*[\\/]/, '')
export const getBasename = (string) => {
if (typeof string === 'string' || string instanceof String){
return string.replace(/^.*[\\/]/, '')
} else {
return string
}
}

export const getFileUrl = (column, value) => `${baseUrl}/files/${value}`

Expand Down

0 comments on commit d30829b

Please sign in to comment.