Skip to content

Commit

Permalink
CustomButtons: fix studyName missing when viewing under ResultsViewPa…
Browse files Browse the repository at this point in the history
…ge (#4982)

* CustomButton: add support for extracting studyName when loading in ResultsViewPage

- this adds to the current support for loading under GroupComparisonPage
- Prior to this, under ResultsViewPage, the CustomButton would launch with the generic value "studyName == cBioPortal Data"

* Prettier

---------

Co-authored-by: Denis Papp <[email protected]>
  • Loading branch information
pappde and pappde committed Aug 26, 2024
1 parent 76e378e commit 441a3d5
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/shared/components/CustomButton/CustomButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,41 @@ export class CustomButton extends React.Component<ICustomButtonProps, {}> {
};
}

// RETURNS: the name of the study for the current context, if exactly one study; null otherwise
/**
* extract the study name from the current context.
* @returns the name of the study for the current context; null if cannot be determined
*
* CODEP: There are two contexts we can handle:
* 1) GroupComparisonPage - stores reference in window.groupComparisonPage:
* groupComparisonPage.store.displayedStudies
* 2) ResultsViewPage - stores reference in window.resultsViewPageStore:
* resultsViewPageStore.queriedStudies
* Both are likely MobxPromiseInputParamsWithDefault<CustomStudy[]> objects.
*/
getSingleStudyName(): string | null {
// extract the study name from the current context
// CODEP: GroupComparisonPag stores a reference in the window, so when we are embedded there we can get details about which studies
var studies: CancerStudy[] | null = null;
const groupComparisonPage = (window as any).groupComparisonPage;
if (!groupComparisonPage) {
return null;
if (groupComparisonPage != null) {
studies = groupComparisonPage.store.displayedStudies.result;
} else {
const resultsViewPageStore = (window as any).resultsViewPageStore;
if (resultsViewPageStore != null) {
studies = resultsViewPageStore.queriedStudies.result;
}
}

const studies: CancerStudy[] =
groupComparisonPage.store.displayedStudies.result;

if (studies.length === 1) {
return studies[0].name;
} else {
if (studies == null) {
return null;
}

switch (studies.length) {
case 0:
return null;
case 1:
return studies[0].name;
default:
return 'Combined Studies';
}
}

openCustomUrl(urlParametersLaunch: CustomButtonUrlParameters) {
Expand Down

0 comments on commit 441a3d5

Please sign in to comment.