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

Austenem/CAT-934 fix metadata table #3555

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG-fix-metadata-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix issue of sample metadata not showing up in the sample detail page metadata table.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { useTrackEntityPageEvent } from 'js/components/detailPage/useTrackEntity
import { tableToDelimitedString, createDownloadUrl } from 'js/helpers/functions';
import { useMetadataFieldDescriptions } from 'js/hooks/useUBKG';
import { getMetadata, hasMetadata } from 'js/helpers/metadata';
import { ESEntityType, isDataset } from 'js/components/types';
import { useProcessedDatasets } from 'js/pages/Dataset/hooks';
import { Dataset, Donor, ESEntityType, Sample, isDataset, isSample } from 'js/components/types';
import { ProcessedDatasetInfo, useProcessedDatasets } from 'js/pages/Dataset/hooks';
import { entityIconMap } from 'js/shared-styles/icons/entityIconMap';
import withShouldDisplay from 'js/helpers/withShouldDisplay';
import { sectionIconMap } from 'js/shared-styles/icons/sectionIconMap';
import { SearchHit } from '@elastic/elasticsearch/lib/api/types';
import { DownloadIcon, StyledWhiteBackgroundIconButton } from '../MetadataTable/style';
import MetadataTabs from '../multi-assay/MultiAssayMetadataTabs';
import { Columns, defaultTSVColumns } from './columns';
Expand Down Expand Up @@ -147,6 +148,57 @@ function getEntityIcon(entity: { entity_type: ESEntityType; is_component?: boole
return entityIconMap[entity.entity_type];
}

function getEntityLabel(entity: ProcessedDatasetInfo | Donor | Sample, sampleCategoryCounts: Record<string, number>) {
if (isSample(entity)) {
// If samples have the same category, add the HuBMAP ID to the label
if (sampleCategoryCounts[entity.sample_category] > 1) {
return `${entity.sample_category} ${entity.hubmap_id}`;
}
return entity.sample_category;
}
if (isDataset(entity)) {
return entity.assay_display_name;
}
return entity.entity_type;
}

function getTableEntities(
entity: Dataset,
datasetsWithMetadata: Required<SearchHit<ProcessedDatasetInfo>>[],
fieldDescriptions: Record<string, string>,
) {
const { donor, source_samples } = entity;

const entitiesWithMetadata = [entity, ...datasetsWithMetadata.map((d) => d._source), ...source_samples, donor].filter(
(e) => hasMetadata({ targetEntityType: e.entity_type, currentEntity: e }),
);

// Check whether there are multiple samples with the same sample category
const sampleCategoryCounts: Record<string, number> = {};
entitiesWithMetadata.forEach((e) => {
if (isSample(e)) {
sampleCategoryCounts[e.sample_category] = (sampleCategoryCounts[e.sample_category] || 0) + 1;
}
});

return entitiesWithMetadata.map((e) => {
const label = getEntityLabel(e, sampleCategoryCounts);
return {
uuid: e.uuid,
label,
icon: getEntityIcon(e),
tableRows: buildTableData(
getMetadata({
targetEntityType: e.entity_type,
currentEntity: e,
}),
fieldDescriptions,
{ hubmap_id: e.hubmap_id, label },
),
};
});
}

interface MetadataProps {
metadata?: Record<string, string>;
}
Expand All @@ -165,27 +217,7 @@ function Metadata({ metadata }: MetadataProps) {
return null;
}

const { donor, source_samples } = entity;

const entities = [entity, ...datasetsWithMetadata.map((d) => d._source), ...source_samples, donor]
.filter((e) => hasMetadata({ targetEntityType: e.entity_type, currentEntity: e }))
.map((e) => {
const label = isDataset(e) ? e.assay_display_name : e.entity_type;
return {
uuid: e.uuid,
label,
icon: getEntityIcon(e),
tableRows: buildTableData(
getMetadata({
targetEntityType: e.entity_type,
currentEntity: e,
}),
fieldDescriptions,
{ hubmap_id: e.hubmap_id, label },
),
};
});

const entities = getTableEntities(entity, datasetsWithMetadata, fieldDescriptions);
const allTableRows = entities.map((d) => d.tableRows).flat();

return (
Expand Down
2 changes: 1 addition & 1 deletion context/app/static/js/pages/Sample/Sample.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function SampleDetail() {
const origin_sample = origin_samples[0];
const { mapped_organ } = origin_sample;

const combinedMetadata = combineMetadata(donor, undefined, metadata);
const combinedMetadata = combineMetadata(donor, origin_samples, metadata);

const shouldDisplaySection = {
summary: true,
Expand Down
Loading