Skip to content

Commit

Permalink
in progress (not functional atm)
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-hodgson committed Oct 17, 2023
1 parent 2977850 commit e3edb75
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ export const filesView: SynapseConfig = {
tableConfiguration: {
showAccessColumn: true,
showDownloadColumn: true,
rowEntityIDColumnName: 'id',
rowEntityVersionColumnName: 'fileVersion',
columnLinks: [
{
matchColumnName: 'Study',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type FileEntityDirectDownloadProps = Omit<
'associatedObjectId' | 'associatedObjectType' | 'fileHandleId'
> & {
entityId: string
entityVersionNumber?: number
entityVersionNumber?: string
}

export default function FileEntityDirectDownload(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Row>()
Expand All @@ -69,6 +73,8 @@ export function SynapseTable(props: SynapseTableProps) {
showDirectDownloadColumn = showDownloadColumn,
hideAddToDownloadListColumn = hideDownload,
columnLinks,
rowEntityIDColumnName,
rowEntityVersionColumnName,
} = props
const { getCurrentQueryRequest } = useQueryContext()
const data = useAtomValue(tableQueryDataAtom)
Expand All @@ -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,
Expand All @@ -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<Row, string | null>[] = useMemo(
() => [
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
CellContext,
createColumnHelper,
HeaderContext,
Table,
} from '@tanstack/react-table'
import {
ColumnTypeEnum,
Expand Down Expand Up @@ -81,17 +82,19 @@ export const rowSelectionColumn = columnHelper.display({
})

function AddToDownloadListCell(props: CellContext<Row, unknown>) {
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 (
<div data-testid={'AddToDownloadListCell'}>
{entityHeader?.type === 'org.sagebionetworks.repo.model.FileEntity' && (
<AddToDownloadListV2
entityId={row.original.rowId!.toString()}
entityVersionNumber={parseInt(
row.original.versionNumber!.toString()!,
)}
></AddToDownloadListV2>
entityId={entityId}
entityVersionNumber={versionNumber}
/>
)}
</div>
)
Expand All @@ -108,12 +111,14 @@ export const addToDownloadListColumn = columnHelper.display({
})

function DirectDownloadCell(props: CellContext<Row, unknown>) {
const { row } = props
const entityId = getEntityId(props)
const versionNumber = getEntityVersion(props)

return (
<div data-testid={'DirectDownloadCell'}>
<FileEntityDirectDownload
entityId={row.original.rowId!.toString()}
entityVersionNumber={row.original.versionNumber}
entityId={entityId}
entityVersionNumber={versionNumber}
iconSvgPropOverrides={{ sx: { color: 'primary.main' } }}
/>
</div>
Expand All @@ -130,14 +135,35 @@ export const directDownloadColumn = columnHelper.display({
},
})

const getEntityId = (props: CellContext<Row, unknown>): 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<Row, unknown>): 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<Row, unknown>) {
const { row } = props
const entityId = getEntityId(props)
const versionNumber = getEntityVersion(props)
return (
<div data-testid={'AccessCell'}>
<HasAccessV2
key={row.original.rowId!.toString()}
entityId={row.original.rowId!.toString()}
entityVersionNumber={row.original.versionNumber!.toString()}
key={entityId}
entityId={entityId}
entityVersionNumber={versionNumber}
/>
</div>
)
Expand Down

0 comments on commit e3edb75

Please sign in to comment.