Skip to content

Commit

Permalink
Show unique sample count on Cohorts page
Browse files Browse the repository at this point in the history
  • Loading branch information
qu8n authored and ao508 committed May 30, 2024
1 parent 867af01 commit a116a1e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
29 changes: 20 additions & 9 deletions frontend/src/components/RecordsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ErrorMessage, LoadingSpinner, Toolbar } from "../shared/tableElements";
interface IRecordsListProps {
colDefs: ColDef[];
dataName: DataName;
enableInfiniteScroll?: boolean;
lazyRecordsQuery: typeof useHookLazyGeneric;
lazyRecordsQueryAddlVariables?: Record<string, any>;
prepareDataForAgGrid?: (
Expand Down Expand Up @@ -63,6 +64,7 @@ interface IRecordsListProps {
export default function RecordsList({
colDefs,
dataName,
enableInfiniteScroll = true,
lazyRecordsQuery,
lazyRecordsQueryAddlVariables,
prepareDataForAgGrid,
Expand Down Expand Up @@ -90,6 +92,7 @@ export default function RecordsList({
const [unsavedChanges, setUnsavedChanges] = useState(false);
const [filterModel, setFilterModel] = useState<Record<string, any>>({});
const [rowCount, setRowCount] = useState<number>(0);
const [uniqueSampleCount, setUniqueSampleCount] = useState<number>(0);

const navigate = useNavigate();

Expand All @@ -109,8 +112,6 @@ export default function RecordsList({
return {
// called by the grid when more rows are required
getRows: (params: IServerSideGetRowsParams) => {
const noFilter = Object.keys(filterModel).length === 0;

const fetchInput = {
where: {
OR: queryFilterWhereVariables(parsedSearchVals),
Expand All @@ -119,10 +120,8 @@ export default function RecordsList({
OR: queryFilterWhereVariables(parsedSearchVals),
},
options: {
// Removing offset and limit leads to a full data fetch, but
// it enables us to perform complex filtering on the client side
offset: noFilter ? params.request.startRow : undefined,
limit: noFilter ? params.request.endRow : undefined,
offset: params.request.startRow,
limit: params.request.endRow,
sort: params.request.sortModel.map((sortModel) => {
return { [sortModel.colId]: sortModel.sort?.toUpperCase() };
}),
Expand All @@ -140,9 +139,15 @@ export default function RecordsList({

return thisFetch.then((d) => {
let data = d.data;
if (prepareDataForAgGrid)
if (prepareDataForAgGrid) {
data = prepareDataForAgGrid(data, filterModel);
}

if ("uniqueSampleCount" in data) {
setUniqueSampleCount(data.uniqueSampleCount);
}
setRowCount(data[totalCountNodeName].totalCount);

params.success({
rowData: data[dataName],
rowCount: data[totalCountNodeName].totalCount,
Expand Down Expand Up @@ -264,7 +269,13 @@ export default function RecordsList({
setParsedSearchVals([]);
}}
matchingResultsCount={`${rowCount?.toLocaleString()} matching ${
rowCount > 1 ? dataName : dataName.slice(0, -1)
rowCount !== 1 ? dataName : dataName.slice(0, -1)
}${
enableInfiniteScroll
? ""
: ` (${uniqueSampleCount.toLocaleString()} unique ${
uniqueSampleCount !== 1 ? "samples" : "sample"
})`
}`}
handleDownload={handleDownload}
customUI={customToolbarUI}
Expand All @@ -280,7 +291,7 @@ export default function RecordsList({
rowModelType={"serverSide"}
columnDefs={colDefs}
serverSideDatasource={datasource}
serverSideInfiniteScroll={true}
serverSideInfiniteScroll={enableInfiniteScroll}
cacheBlockSize={20}
debug={false}
context={{
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/cohorts/CohortsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export default function CohortsPage({
<RecordsList
colDefs={CohortsListColumns}
dataName={dataName}
enableInfiniteScroll={false}
lazyRecordsQuery={useCohortsListLazyQuery}
lazyRecordsQueryAddlVariables={
{
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/shared/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ export function prepareCohortDataForAgGrid(

const totalSamples = samplesConnection?.totalCount;

const smileSampleIds = samples?.map((s) => s.smileSampleId);

const allSamplesBilled =
samples.length > 0 &&
samples?.every((sample) => {
Expand All @@ -561,6 +563,7 @@ export function prepareCohortDataForAgGrid(
return {
cohortId,
totalSamples,
smileSampleIds,
billed,
initialCohortDeliveryDate: formatCohortRelatedDate(
initialCohortDeliveryDate
Expand Down Expand Up @@ -604,9 +607,17 @@ export function prepareCohortDataForAgGrid(
}
}

const uniqueSmileSampleIds: Set<string> = new Set();
newCohorts.forEach((cohort) => {
cohort.smileSampleIds.forEach((id) => {
uniqueSmileSampleIds.add(id);
});
});

return {
cohorts: newCohorts,
cohortsConnection: newCohortsConnection,
uniqueSampleCount: uniqueSmileSampleIds.size,
};
}

Expand Down

0 comments on commit a116a1e

Please sign in to comment.