Skip to content

Commit

Permalink
add study level persistence through local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Lai committed Nov 6, 2023
1 parent 6d8be11 commit 1abe082
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 32 deletions.
60 changes: 48 additions & 12 deletions src/pages/resultsView/ResultsViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ export class ResultsViewPageStore extends AnalysisStore
get cancerStudyIds() {
return this.urlWrapper.query.cancer_study_list.split(',');
}
@computed
get cancerStudyListSorted() {
return this.cancerStudyIds.sort().join(',');
}

@computed
get rppaScoreThreshold() {
Expand Down Expand Up @@ -574,11 +578,13 @@ export class ResultsViewPageStore extends AnalysisStore

@observable queryFormVisible: boolean = false;

@observable _userSelectedClinicalTracksColors: {
[label: string]: {
[value: string]: RGBAColor;
@observable _userSelectedStudiesToClinicalTracksColors: {
[studies: string]: {
[label: string]: {
[value: string]: RGBAColor;
};
};
} = {};
} = JSON.parse(localStorage.getItem('clinicalTracksColorConfig') || '{}');

@computed get doNonSelectedDownloadableMolecularProfilesExist() {
return (
Expand All @@ -603,20 +609,50 @@ export class ResultsViewPageStore extends AnalysisStore
// else, set the color in userSelectedClinicalAttributeColors
if (
!color &&
this._userSelectedClinicalTracksColors[label] &&
this._userSelectedClinicalTracksColors[label][value]
this._userSelectedStudiesToClinicalTracksColors[
this.cancerStudyListSorted
] &&
this._userSelectedStudiesToClinicalTracksColors[
this.cancerStudyListSorted
][label] &&
this._userSelectedStudiesToClinicalTracksColors[
this.cancerStudyListSorted
][label][value]
) {
delete this._userSelectedClinicalTracksColors[label][value];
delete this._userSelectedStudiesToClinicalTracksColors[
this.cancerStudyListSorted
][label][value];
} else if (color) {
if (!this._userSelectedClinicalTracksColors[label]) {
this._userSelectedClinicalTracksColors[label] = {};
if (
!this._userSelectedStudiesToClinicalTracksColors[
this.cancerStudyListSorted
]
) {
this._userSelectedStudiesToClinicalTracksColors[
this.cancerStudyListSorted
] = {};
}
this._userSelectedClinicalTracksColors[label][value] = color;
if (
!this._userSelectedStudiesToClinicalTracksColors[
this.cancerStudyListSorted
][label]
) {
this._userSelectedStudiesToClinicalTracksColors[
this.cancerStudyListSorted
][label] = {};
}
this._userSelectedStudiesToClinicalTracksColors[
this.cancerStudyListSorted
][label][value] = color;
}
localStorage.setItem(
'clinicalTracksColorConfig',
JSON.stringify(this._userSelectedStudiesToClinicalTracksColors)
);
}

@computed get userSelectedClinicalTracksColors() {
return this._userSelectedClinicalTracksColors;
@computed get userSelectedStudiesToClinicalTracksColors() {
return this._userSelectedStudiesToClinicalTracksColors;
}

@action.bound
Expand Down
27 changes: 13 additions & 14 deletions src/shared/components/oncoprint/OncoprintUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,15 @@ export function makeClinicalTracksMobxPromise(
Yes: true,
};
}
const userSelectedClinicalTracksColors =
oncoprint.props.store
.userSelectedStudiesToClinicalTracksColors[
oncoprint.props.store.cancerStudyListSorted
] &&
oncoprint.props.store
.userSelectedStudiesToClinicalTracksColors[
oncoprint.props.store.cancerStudyListSorted
][attribute.displayName];
if (attribute.datatype === 'NUMBER') {
ret.datatype = 'number';
if (
Expand Down Expand Up @@ -988,9 +997,7 @@ export function makeClinicalTracksMobxPromise(
(ret as any).category_to_color = Object.assign(
{},
_.mapValues(dataAndColors.categoryToColor, hexToRGBA),
oncoprint.props.store.userSelectedClinicalTracksColors[
attribute.displayName
]
userSelectedClinicalTracksColors
);
} else if (
attribute.clinicalAttributeId ===
Expand All @@ -1001,19 +1008,11 @@ export function makeClinicalTracksMobxPromise(
(ret as any).countsCategoryFills = MUTATION_SPECTRUM_FILLS.slice();
_.forEach((ret as any).countsCategoryLabels, (label, i) => {
if (
oncoprint.props.store
.userSelectedClinicalTracksColors[
attribute.displayName
] &&
oncoprint.props.store
.userSelectedClinicalTracksColors[
attribute.displayName
][label]
userSelectedClinicalTracksColors &&
userSelectedClinicalTracksColors[label]
) {
(ret as any).countsCategoryFills[i] =
oncoprint.props.store.userSelectedClinicalTracksColors[
attribute.displayName
][label];
userSelectedClinicalTracksColors[label];
}
});
}
Expand Down
16 changes: 10 additions & 6 deletions src/shared/components/oncoprint/ResultsViewOncoprint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ import { toDirectionString } from './SortUtils';
import { RestoreClinicalTracksMenu } from 'pages/resultsView/oncoprint/RestoreClinicalTracksMenu';
import { Modal } from 'react-bootstrap';
import ClinicalTrackColorPicker from './ClinicalTrackColorPicker';
import { hexToRGBA } from 'shared/lib/Colors';
import { hexToRGBA, rgbaToHex } from 'shared/lib/Colors';

interface IResultsViewOncoprintProps {
divId: string;
Expand Down Expand Up @@ -1993,12 +1993,16 @@ export default class ResultsViewOncoprint extends React.Component<
disabled={_.every(
this.selectedClinicalTrackValues,
v =>
getClinicalTrackColor(
this.selectedClinicalTrack!,
v as string
rgbaToHex(
getClinicalTrackColor(
this.selectedClinicalTrack!,
v as string
)
) ===
this.getDefaultSelectedClinicalTrackColor(
v
rgbaToHex(
this.getDefaultSelectedClinicalTrackColor(
v
) as RGBAColor
)
)}
onClick={() => {
Expand Down

0 comments on commit 1abe082

Please sign in to comment.