Skip to content

Commit

Permalink
add new isRowEntityColumn boolean to flag this scenario, and do speci…
Browse files Browse the repository at this point in the history
…al treatment of the name and id column
  • Loading branch information
jay-hodgson committed Oct 19, 2023
1 parent f4df50f commit 39e8f97
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ export type SynapseTableCellProps = {
selectColumns?: SelectColumn[]
columnModels?: ColumnModel[]
rowData: Row['values']
rowId?: number | string
rowId?: string
rowVersionNumber?: number
isRowEntityColumn?: boolean
}

function SynapseTableCell(props: SynapseTableCellProps) {
Expand All @@ -58,13 +59,9 @@ function SynapseTableCell(props: SynapseTableCellProps) {
rowData,
rowId,
rowVersionNumber,
isRowEntityColumn,
} = props
const entity = useAtomValue(tableQueryEntityAtom)
const rowIdIsString = typeof rowId === 'string'
let rowSynId: string | undefined = undefined
if (rowId !== undefined) {
rowSynId = rowIdIsString ? rowId : `syn${rowId.toString()}`
}
if (!columnValue) {
return <p className="SRC-inactive"> {NOT_SET_DISPLAY_VALUE}</p>
}
Expand All @@ -79,7 +76,7 @@ function SynapseTableCell(props: SynapseTableCellProps) {
isHeader={false}
labelLink={columnLinkConfig}
rowData={rowData}
rowId={rowSynId}
rowId={rowId}
/>
)
}
Expand All @@ -91,15 +88,15 @@ function SynapseTableCell(props: SynapseTableCellProps) {
entity &&
(isEntityView(entity) || isDataset(entity) || isDatasetCollection(entity))
if (
(tableRowRepresentsEntity || rowIdIsString) &&
(tableRowRepresentsEntity || isRowEntityColumn) &&
(columnName === 'id' || columnName === 'name') &&
rowSynId &&
rowId &&
rowVersionNumber
) {
return (
<p>
<EntityLink
entity={rowSynId}
entity={rowId}
versionNumber={rowVersionNumber}
className={`${isBold}`}
showIcon={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ const getEntityOrRowId = (
: row.original.rowId?.toString()
return entityId
}

/**
* Given the (tanstack react) Table CellContext, return true if the table configuration defines a row entity version column name.
* This will be used as the entity that represents the current Row.
* @param props
* @returns
*/
const isRowEntityColumn = (props: CellContext<Row, unknown>): boolean => {
const { table } = props
return (table.options.meta as any).rowEntityVersionColumnIndex !== undefined
}

/**
* Given the (tanstack react) Table CellContext, return the version of the current Synapse Table Row.
* If a rowEntityVersionColumnName was provided in the table config, then instead return the version found in
Expand Down Expand Up @@ -308,6 +320,7 @@ export function TableDataCell(props: CellContext<Row, string | null>) {
columnModels={columnModels}
rowId={entityOrRowId}
rowVersionNumber={versionNumber}
isRowEntityColumn={isRowEntityColumn(props)}
/>
)
} else return <td key={cell.id}></td>
Expand Down

0 comments on commit 39e8f97

Please sign in to comment.