Skip to content

Commit e85a900

Browse files
committed
add publication button to column format
1 parent af6b4da commit e85a900

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/components/data-display/SearchUI/types.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ export enum ColumnFormat {
139139
EMAIL = 'EMAIL',
140140
TAG = 'TAG',
141141
DICT = 'DICT',
142-
CONTRIBS_FILES_DOWNLOAD = 'CONTRIBS_FILES_DOWNLOAD'
142+
CONTRIBS_FILES_DOWNLOAD = 'CONTRIBS_FILES_DOWNLOAD',
143+
PUBLICATION = 'PUBLICATION'
143144
}
144145

145146
/**

src/utils/table.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { joinUrl } from './navigation';
1111
import { FaEnvelope } from 'react-icons/fa';
1212
import { FaDownload } from 'react-icons/fa';
1313
import axios from 'axios';
14+
import { PublicationButton } from '../components/publications/PublicationButton';
1415

1516
const emptyCellPlaceholder = '-';
1617

@@ -335,6 +336,42 @@ export const initColumns = (columns: Column[], disableRichColumnHeaders?: boolea
335336
}
336337
} else return null;
337338
};
339+
return c
340+
case ColumnFormat.PUBLICATION:
341+
c.cell = (row: any) => {
342+
if (hasFormatOptions && c.formatOptions) {
343+
const rowValue = getRowValueFromSelectorString(c.selector, row);
344+
if (Array.isArray(rowValue)) {
345+
return (
346+
<div>
347+
{rowValue.map((item: any) => (
348+
<PublicationButton
349+
key={item.doi}
350+
doi={item.doi}
351+
showTooltip={
352+
c.formatOptions.showTooltip ? c.formatOptions.showTooltip : false
353+
}
354+
compact={c.formatOptions.compact ? c.formatOptions.compact : false}
355+
target="_blank"
356+
/>
357+
))}
358+
</div>
359+
);
360+
} else if (rowValue) {
361+
return (
362+
<PublicationButton
363+
doi={rowValue}
364+
showTooltip={c.formatOptions.showTooltip ? c.formatOptions.showTooltip : false}
365+
compact={c.formatOptions.compact ? c.formatOptions.compact : false}
366+
target="_blank"
367+
/>
368+
);
369+
} else {
370+
return null;
371+
}
372+
}
373+
return null;
374+
};
338375
return c;
339376
default:
340377
c.format = (row: any) => {

0 commit comments

Comments
 (0)