diff --git a/apps/portals/src/configurations/elportal/synapseConfigs/cohortbuilder.ts b/apps/portals/src/configurations/elportal/synapseConfigs/cohortbuilder.ts index dc2df8eb88..25200600a1 100644 --- a/apps/portals/src/configurations/elportal/synapseConfigs/cohortbuilder.ts +++ b/apps/portals/src/configurations/elportal/synapseConfigs/cohortbuilder.ts @@ -140,6 +140,8 @@ export const filesView: SynapseConfig = { tableConfiguration: { showAccessColumn: true, showDownloadColumn: true, + rowEntityIDColumnName: 'id', + rowEntityVersionColumnName: 'fileVersion', columnLinks: [ { matchColumnName: 'Study', diff --git a/packages/synapse-react-client/src/components/DirectDownload/FileEntityDirectDownload.tsx b/packages/synapse-react-client/src/components/DirectDownload/FileEntityDirectDownload.tsx index d219540f40..9bbb09580d 100644 --- a/packages/synapse-react-client/src/components/DirectDownload/FileEntityDirectDownload.tsx +++ b/packages/synapse-react-client/src/components/DirectDownload/FileEntityDirectDownload.tsx @@ -10,7 +10,7 @@ export type FileEntityDirectDownloadProps = Omit< 'associatedObjectId' | 'associatedObjectType' | 'fileHandleId' > & { entityId: string - entityVersionNumber?: number + entityVersionNumber?: string } export default function FileEntityDirectDownload( diff --git a/packages/synapse-react-client/src/components/SynapseTable/SynapseTable.tsx b/packages/synapse-react-client/src/components/SynapseTable/SynapseTable.tsx index 9ad9bbe507..d3df0f156b 100644 --- a/packages/synapse-react-client/src/components/SynapseTable/SynapseTable.tsx +++ b/packages/synapse-react-client/src/components/SynapseTable/SynapseTable.tsx @@ -58,6 +58,10 @@ export type SynapseTableProps = { hideAddToDownloadListColumn?: boolean /** Configuration to override cell renderers with e.g. a link to a portals detail page */ columnLinks?: LabelLinkConfig + /** If provided, will use the value in this column instead of the rowID for the access column, download column, etc */ + rowEntityIDColumnName?: string + /** If provided, will use the value in this column instead of the row version number for the access column, download column, etc */ + rowEntityVersionColumnName?: string } const columnHelper = createColumnHelper() @@ -69,6 +73,8 @@ export function SynapseTable(props: SynapseTableProps) { showDirectDownloadColumn = showDownloadColumn, hideAddToDownloadListColumn = hideDownload, columnLinks, + rowEntityIDColumnName, + rowEntityVersionColumnName, } = props const { getCurrentQueryRequest } = useQueryContext() const data = useAtomValue(tableQueryDataAtom) @@ -91,12 +97,15 @@ export function SynapseTable(props: SynapseTableProps) { const isShowingAccessColumn: boolean = Boolean( showAccessColumn && entity && - isEntityViewOrDataset(entity) && - allRowsHaveId(data), + ((isEntityViewOrDataset(entity) && allRowsHaveId(data)) || + rowEntityIDColumnName), ) const rowsAreDownloadable = - entity && isFileViewOrDataset(entity) && isLoggedIn && allRowsHaveId(data) + entity && + isLoggedIn && + ((isFileViewOrDataset(entity) && allRowsHaveId(data)) || + rowEntityIDColumnName) const isShowingDirectDownloadColumn = Boolean( rowsAreDownloadable && showDirectDownloadColumn, @@ -107,6 +116,16 @@ export function SynapseTable(props: SynapseTableProps) { !hideAddToDownloadListColumn && !isRowSelectionVisible, ) + const rowEntityIDColumnIndex = rowEntityIDColumnName + ? data?.queryResult?.queryResults.headers.findIndex( + col => col.name == rowEntityIDColumnName, + ) + : undefined + const rowEntityVersionColumnIndex = rowEntityVersionColumnName + ? data?.queryResult?.queryResults.headers.findIndex( + col => col.name == rowEntityVersionColumnName, + ) + : undefined const columns: ColumnDef[] = useMemo( () => [ @@ -168,6 +187,11 @@ export function SynapseTable(props: SynapseTableProps) { sorting: sort, columnVisibility: columnVisibility, }, + meta: { + // make the rowEntityIDColumnIndex available to all cell renderers + rowEntityIDColumnIndex, + rowEntityVersionColumnIndex, + }, }) const { dataHasBeenPrefetched } = usePrefetchTableData() diff --git a/packages/synapse-react-client/src/components/SynapseTable/SynapseTableRenderers.tsx b/packages/synapse-react-client/src/components/SynapseTable/SynapseTableRenderers.tsx index b1b8fa679e..0dfbfd47fa 100644 --- a/packages/synapse-react-client/src/components/SynapseTable/SynapseTableRenderers.tsx +++ b/packages/synapse-react-client/src/components/SynapseTable/SynapseTableRenderers.tsx @@ -2,6 +2,7 @@ import { CellContext, createColumnHelper, HeaderContext, + Table, } from '@tanstack/react-table' import { ColumnTypeEnum, @@ -81,17 +82,19 @@ export const rowSelectionColumn = columnHelper.display({ }) function AddToDownloadListCell(props: CellContext) { - const { row } = props - const { data: entityHeader } = useGetEntityHeader(`syn${row.original.rowId!}`) + const entityId = getEntityId(props) + const versionNumberString = getEntityVersion(props) + const versionNumber = versionNumberString + ? parseInt(versionNumberString) + : undefined + const { data: entityHeader } = useGetEntityHeader(entityId) return (
{entityHeader?.type === 'org.sagebionetworks.repo.model.FileEntity' && ( + entityId={entityId} + entityVersionNumber={versionNumber} + /> )}
) @@ -108,12 +111,14 @@ export const addToDownloadListColumn = columnHelper.display({ }) function DirectDownloadCell(props: CellContext) { - const { row } = props + const entityId = getEntityId(props) + const versionNumber = getEntityVersion(props) + return (
@@ -130,14 +135,35 @@ export const directDownloadColumn = columnHelper.display({ }, }) +const getEntityId = (props: CellContext): string => { + const { row, table } = props + const rowEntityIDColumnIndex: number | undefined = (table.options.meta as any) + .rowEntityIDColumnIndex + const entityId = rowEntityIDColumnIndex + ? row.original.values[rowEntityIDColumnIndex]! + : row.original.rowId!.toString() + return entityId +} +const getEntityVersion = (props: CellContext): string => { + const { row, table } = props + const rowEntityVersionColumnIndex: number | undefined = ( + table.options.meta as any + ).rowEntityVersionColumnIndex + const versionNumber = rowEntityVersionColumnIndex + ? row.original.values[rowEntityVersionColumnIndex]! + : row.original.versionNumber!.toString() + return versionNumber +} + function AccessCell(props: CellContext) { - const { row } = props + const entityId = getEntityId(props) + const versionNumber = getEntityVersion(props) return (
)