Skip to content

Commit

Permalink
NickAkhmetov/CAT-736 Convert sample detail page to TSX (#3592)
Browse files Browse the repository at this point in the history
* CAT-736 Convert sample detail page to TSX

* add appropriate annotation to avoid assertions
  • Loading branch information
NickAkhmetov authored Nov 5, 2024
1 parent 4a8111c commit df33e55
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-cat-736.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Converted sample detail page to TypeScript.
1 change: 1 addition & 0 deletions context/app/static/js/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export interface Sample extends Entity {
organ: string;
origin_samples_unique_mapped_organs: string[];
origin_samples: Sample[];
protocol_url: string;
}

export type CreationAction =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ import DerivedDatasetsSection from 'js/components/detailPage/derivedEntities/Der
import useTrackID from 'js/hooks/useTrackID';
import MetadataSection from 'js/components/detailPage/MetadataSection';
import { useEntitiesData } from 'js/hooks/useEntityData';
import { isSample, Sample } from 'js/components/types';

function SampleDetail() {
const { entity } = useFlaskDataContext();

if (!isSample(entity)) {
// This should never happen; the Flask API should only return a Sample entity for this page.
throw new Error(`Invalid entity type: expected Sample, got ${entity.entity_type}`);
}

const {
uuid,
protocol_url,
Expand All @@ -30,9 +37,10 @@ function SampleDetail() {
entity_type,
descendant_counts,
ancestor_ids,
mapped_data_access_level,
} = entity;

const [entities, loadingEntities] = useEntitiesData([uuid, ...ancestor_ids]);
const [entities, loadingEntities] = useEntitiesData<Sample>([uuid, ...ancestor_ids]);
const entitiesWithMetadata = entities.filter((e) =>
hasMetadata({ targetEntityType: e.entity_type, currentEntity: e }),
);
Expand All @@ -53,7 +61,10 @@ function SampleDetail() {

useTrackID({ entity_type, hubmap_id });

const detailContext = useMemo(() => ({ hubmap_id, uuid }), [hubmap_id, uuid]);
const detailContext = useMemo(
() => ({ hubmap_id, uuid, mapped_data_access_level }),
[hubmap_id, uuid, mapped_data_access_level],
);

if (loadingEntities) {
return null;
Expand Down
File renamed without changes.

0 comments on commit df33e55

Please sign in to comment.