Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not show empty columns in Data Availability table #716

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
285 changes: 171 additions & 114 deletions packages/data-portal-explore/src/components/DataAvailabilityTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ interface IDataAvailabilityTableProps {
publicationId: string;
}

interface ITableRowData {
tabId?: string;
rowName: string;
cdsDbgapCount: number;
cdsOpenAccessCount: number;
synapseOpenAccessCount: number;
comingSoonCount: number;
comingSoonText: string | number;
}

// In Coming Soon column, show 'TBD' if the assay is in customTBDGroup
// TODO: need to double check if we should update/remove any assay out of the list after a new data release
const customizedTBDGroup: { [group: string]: string[] } = {
Expand Down Expand Up @@ -44,13 +54,13 @@ export const LinkComponent: React.FunctionComponent<{
);
};

export const DataAvailabilityTable: React.FunctionComponent<IDataAvailabilityTableProps> = (
props
) => {
const tableRowGroups: { [rowName: string]: Entity[] } = _.reduce(
_.keys(props.assays),
function getTableRowGroups(assays: {
[assayName: string]: Entity[];
}): { [rowName: string]: Entity[] } {
return _.reduce(
_.keys(assays),
(acc, assayId) => {
const entities = props.assays[assayId];
const entities = assays[assayId];
const entityGroupByLevel = _.groupBy(
entities,
(entity) => entity.level
Expand All @@ -66,135 +76,182 @@ export const DataAvailabilityTable: React.FunctionComponent<IDataAvailabilityTab
},
{} as { [rowName: string]: Entity[] }
);
}

// If all groups have 0 in Coming Soon column, don't show the column
let showComingSoonColumn = false;
// Check if there is any entity has non-zero value in Coming Soon column
_.forEach(tableRowGroups, (entities) => {
const comingSoonCount = _.filter(
entities,
function getTableRowData(
tableRowGroups: { [rowName: string]: Entity[] },
publicationId: string
): ITableRowData[] {
return _.map(_.keys(tableRowGroups).sort(), (rowName) => {
const entities = tableRowGroups[rowName];
const tabId = entities.length > 0 ? entities[0]?.assayName : undefined;
const cdsDbgapCount = entities.filter(
(entity) => entity.downloadSource === DownloadSourceCategory.dbgap
).length;
const cdsOpenAccessCount = entities.filter(
(entity) => entity.downloadSource === DownloadSourceCategory.cds
).length;
const synapseOpenAccessCount = entities.filter(
(entity) => entity.downloadSource === DownloadSourceCategory.synapse
).length;
const comingSoonCount = entities.filter(
(entity) =>
entity.downloadSource === DownloadSourceCategory.comingSoon
).length;
if (comingSoonCount > 0) {
showComingSoonColumn = true;
return false;
}
// If the assay has 0 in Coming Soon column AND is in the customized TBD group, show 'TBD' instead of 0
const comingSoonText =
comingSoonCount === 0 &&
isInCustomizedTBDGroup(rowName, customizedTBDGroup, publicationId)
? 'TBD'
: comingSoonCount;

return {
tabId,
rowName,
cdsDbgapCount,
cdsOpenAccessCount,
synapseOpenAccessCount,
comingSoonCount,
comingSoonText,
};
});
}

const table = (
function getTotalCountByDownloadSource(tableRowData: ITableRowData[]) {
return _.mapValues(
{
[DownloadSourceCategory.dbgap]: 'cdsDbgapCount',
[DownloadSourceCategory.cds]: 'cdsOpenAccessCount',
[DownloadSourceCategory.synapse]: 'synapseOpenAccessCount',
[DownloadSourceCategory.comingSoon]: 'comingSoonCount',
},
(value) => _.sumBy(tableRowData, value)
);
}

export const DataAvailabilityTable: React.FunctionComponent<IDataAvailabilityTableProps> = (
props
) => {
const tableRowGroups = getTableRowGroups(props.assays);
const tableRowData = getTableRowData(tableRowGroups, props.publicationId);
const totalCountByDownloadSource = getTotalCountByDownloadSource(
tableRowData
);

return (
<Table bordered hover responsive style={{ width: '60%' }}>
<thead>
<tr>
<th>Files</th>
<th>
<a href="/data-access">
CDS/SB-CGC (dbGaP{' '}
<FontAwesomeIcon
color="#FF8C00"
icon={faLock}
/>
)
</a>
</th>
<th>
<a href="/data-access">
CDS/SB-CGC (Open Access{` `}
<FontAwesomeIcon
color="#00796B"
icon={faLockOpen}
/>
)
</a>
</th>
<th>
<a href="/data-access">
Synapse (Open Access{` `}
<FontAwesomeIcon
color="#00796B"
icon={faLockOpen}
/>
)
</a>
</th>
{showComingSoonColumn && (
{totalCountByDownloadSource[DownloadSourceCategory.dbgap] >
0 && (
<th>
<a href="/data-access">
CDS/SB-CGC (dbGaP{' '}
<FontAwesomeIcon
color="#FF8C00"
icon={faLock}
/>
)
</a>
</th>
)}
{totalCountByDownloadSource[DownloadSourceCategory.cds] >
0 && (
<th>
<a href="/data-access">
CDS/SB-CGC (Open Access{` `}
<FontAwesomeIcon
color="#00796B"
icon={faLockOpen}
/>
)
</a>
</th>
)}
{totalCountByDownloadSource[
DownloadSourceCategory.synapse
] > 0 && (
<th>
<a href="/data-access">
Synapse (Open Access{` `}
<FontAwesomeIcon
color="#00796B"
icon={faLockOpen}
/>
)
</a>
</th>
)}
{totalCountByDownloadSource[
DownloadSourceCategory.comingSoon
] > 0 && (
<th>
<a href="/data-access">Coming Soon</a>
</th>
)}
</tr>
</thead>
<tbody>
{_.map(_.keys(tableRowGroups).sort(), (rowName) => {
const entities = tableRowGroups[rowName];
const tabId =
entities.length > 0
? entities[0]?.assayName
: undefined;
const cdsDbgapCount = entities.filter(
(entity) =>
entity.downloadSource ===
DownloadSourceCategory.dbgap
).length;
const cdsOpenAccessCount = entities.filter(
(entity) =>
entity.downloadSource === DownloadSourceCategory.cds
).length;
const synapseOpenAccessConut = entities.filter(
(entity) =>
entity.downloadSource ===
DownloadSourceCategory.synapse
).length;
const comingSoonCount = entities.filter(
(entity) =>
entity.downloadSource ===
DownloadSourceCategory.comingSoon
).length;
// If the assay has 0 in Coming Soon column AND is in the customized TBD group, show 'TBD' instead of 0
const comingSoonText =
comingSoonCount === 0 &&
isInCustomizedTBDGroup(
rowName,
customizedTBDGroup,
props.publicationId
)
? 'TBD'
: comingSoonCount;

if (tabId) {
const link = generatePublicationPageTabUrl(
props.publicationId,
tabId
);
return (
<tr>
<td style={{ textAlign: 'left' }}>{rowName}</td>
<LinkComponent
link={link}
count={cdsDbgapCount}
/>
<LinkComponent
link={link}
count={cdsOpenAccessCount}
/>
<LinkComponent
link={link}
count={synapseOpenAccessConut}
/>
{showComingSoonColumn && (
<LinkComponent
link={link}
count={comingSoonText}
/>
)}
</tr>
);
{tableRowData.map(
({
tabId,
rowName,
cdsDbgapCount,
cdsOpenAccessCount,
synapseOpenAccessCount,
comingSoonText,
}) => {
if (tabId) {
const link = generatePublicationPageTabUrl(
props.publicationId,
tabId
);
return (
<tr>
<td style={{ textAlign: 'left' }}>
{rowName}
</td>
{totalCountByDownloadSource[
DownloadSourceCategory.dbgap
] > 0 && (
<LinkComponent
link={link}
count={cdsDbgapCount}
/>
)}
{totalCountByDownloadSource[
DownloadSourceCategory.cds
] > 0 && (
<LinkComponent
link={link}
count={cdsOpenAccessCount}
/>
)}
{totalCountByDownloadSource[
DownloadSourceCategory.synapse
] > 0 && (
<LinkComponent
link={link}
count={synapseOpenAccessCount}
/>
)}
{totalCountByDownloadSource[
DownloadSourceCategory.comingSoon
] > 0 && (
<LinkComponent
link={link}
count={comingSoonText}
/>
)}
</tr>
);
}
}
})}
)}
</tbody>
</Table>
);
return table;
};

export default DataAvailabilityTable;