diff --git a/src/firefly/html/test/tests-main.html b/src/firefly/html/test/tests-main.html index 5048db1d1c..912a17da26 100644 --- a/src/firefly/html/test/tests-main.html +++ b/src/firefly/html/test/tests-main.html @@ -182,9 +182,9 @@
Using META-INFO API to show cell value as links
@@ -195,7 +195,8 @@ function onFireflyLoaded(firefly) { tblReq1 = firefly.util.table.makeFileRequest(null, 'http://web.ipac.caltech.edu/staff/roby/demo/WiseDemoTable.tbl',null, { META_INFO: { - "col.band.Links": [{href: "https://irsa.ipac.caltech.edu/?id="}, {href: "http://ivoa.net/?id=", value: 'ivoa'}] + "col.band.Links": [{href: "https://irsa.ipac.caltech.edu/?id="}], + "col.in_row_id.Links": [{href: "https://irsa.ipac.caltech.edu/?id="}, {href: "http://ivoa.net/?id=", value: 'ivoa'}] }}); firefly.showTable('tables-1', tblReq1); } diff --git a/src/firefly/js/tables/ui/BasicTableView.jsx b/src/firefly/js/tables/ui/BasicTableView.jsx index 2c8ef697c5..ab4ea96c4d 100644 --- a/src/firefly/js/tables/ui/BasicTableView.jsx +++ b/src/firefly/js/tables/ui/BasicTableView.jsx @@ -361,7 +361,7 @@ function makeColumnTag(props, col, idx) { key={col.name} columnKey={idx} header={} - cell={} + cell={} fixed={fixed} width={columnWidths[idx]} isResizable={true} diff --git a/src/firefly/js/tables/ui/TablePanel.css b/src/firefly/js/tables/ui/TablePanel.css index 4e85a216f7..73766bafba 100644 --- a/src/firefly/js/tables/ui/TablePanel.css +++ b/src/firefly/js/tables/ui/TablePanel.css @@ -310,6 +310,10 @@ padding: 3px; } +.public_fixedDataTableCell_cellContent.right_align { + text-align: right; +} + .public_fixedDataTableCell_columnResizerKnob { background-color: #0284ff } diff --git a/src/firefly/js/tables/ui/TableRenderer.js b/src/firefly/js/tables/ui/TableRenderer.js index dc92772a44..8938e4ba67 100644 --- a/src/firefly/js/tables/ui/TableRenderer.js +++ b/src/firefly/js/tables/ui/TableRenderer.js @@ -2,7 +2,7 @@ * License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt */ -import React, {Component, PureComponent, Fragment, useRef, useCallback} from 'react'; +import React, {Component, PureComponent, useRef, useCallback} from 'react'; import FixedDataTable from 'fixed-data-table-2'; import {set, get, isEqual, pick} from 'lodash'; @@ -11,7 +11,7 @@ import {isNumericType, tblDropDownId, getTblById, getColumn} from '../TableUtil. import {SortInfo} from '../SortInfo.js'; import {InputField} from '../../ui/InputField.jsx'; import {SORT_ASC, UNSORTED} from '../SortInfo'; -import {toBoolean} from '../../util/WebUtil.js'; +import {toBoolean, isNumeric} from '../../util/WebUtil.js'; import ASC_ICO from 'html/images/sort_asc.gif'; import DESC_ICO from 'html/images/sort_desc.gif'; @@ -241,11 +241,14 @@ export class TextCell extends Component { // } // render() { - var val = getValue(this.props) || ''; - const lineHeight = this.props.height - 6 + 'px'; // 6 is the top/bottom padding. + const {col={}, style, height} = this.props; + const isNumeric = isNumericType(col); + let val = getValue(this.props) || ''; + const lineHeight = height - 6 + 'px'; // 6 is the top/bottom padding. val = (val.search && val.search(html_regex) >= 0) ?
: val; + const className = 'public_fixedDataTableCell_cellContent' + (isNumeric ? ' right_align' : ''); return ( -
{val}
+
{val}
); } } @@ -255,29 +258,39 @@ export class TextCell extends Component { * LinkCell is implementing A.4 using link substitution based on A.1 */ export const LinkCell = React.memo((props) => { - const {tbl_id, col={}, rowIndex, height, style={}} = props; + const {tbl_id, col={}, rowIndex, style={}} = props; const val = getValue(props) || ''; - - const mStyle = {lineHeight: `${height - 6}px`, ...style}; + let mStyle = style; + let className = 'public_fixedDataTableCell_cellContent'; if (col.links) { const tableModel = getTblById(tbl_id); + if (col.links.length === 1) { + const rval = resolveHRefVal(tableModel, get(col, 'links.0.value', val), rowIndex); + className += isNumeric(rval) ? ' right_align' : ''; + } return ( - +
{ col.links.map( (link={}, idx) => { const {href, title, value=val, action} = link; const target = action || '_blank'; const rvalue = resolveHRefVal(tableModel, value, rowIndex); const rhref = resolveHRefVal(tableModel, href, rowIndex, val); + if (idx > 0) mStyle = {marginLeft: 3, ...mStyle}; return (); }) } - +
); } else { - return ; + className += isNumeric(val) ? ' right_align' : ''; + return ( +
+ +
+ ); } }); @@ -366,10 +379,6 @@ const ATag = React.memo(({value='', title, href, target, style={}}) => { value = imageStubMap[imgStubKey] || ; // if a src is given but, not found.. show bad img. } - return ( - - ); + return {value} ; }); diff --git a/src/firefly/js/util/WebUtil.js b/src/firefly/js/util/WebUtil.js index fc0328961e..60169dfcb3 100644 --- a/src/firefly/js/util/WebUtil.js +++ b/src/firefly/js/util/WebUtil.js @@ -836,4 +836,8 @@ export function hashCode(str) { * integers. Since we want the results to be always positive, convert the * signed int to an unsigned by doing an unsigned bitshift. */ return hash >>> 0; +} + +export function isNumeric(n) { + return !isNaN(parseFloat(n)) && isFinite(n); } \ No newline at end of file