Skip to content

Commit

Permalink
Expand first transcript consequence by default (#1123)
Browse files Browse the repository at this point in the history
  • Loading branch information
jyothishnt authored Apr 29, 2024
1 parent 7e32d06 commit 95ad505
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ type TranscriptInGene = Pick<
product_generating_contexts: ProductGeneratingContextInTranscriptInGene[];
};

type GeneInResponse = Pick<
export type GeneInResponse = Pick<
FullGene,
'stable_id' | 'unversioned_stable_id' | 'symbol'
> &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import { combineReducers } from 'redux';

import variantViewGeneralReducer from './general/variantViewGeneralSlice';
import transcriptConsequenceSliceReducer from './transcriptConsequenceSlice';

export default combineReducers({
general: variantViewGeneralReducer
general: variantViewGeneralReducer,
transcriptConsequences: transcriptConsequenceSliceReducer
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ export const getExpandedTranscriptConseqeuenceIds = (
variantId: string
) => {
const transcriptsSlice = getSliceForVariant(state, genomeId, variantId);
return transcriptsSlice?.expandedTranscriptConseqeuenceIds ?? [];
return transcriptsSlice?.expandTranscriptIds ?? [];
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type ViewName = (typeof views)[number];
export type StateForVariant = {
view: ViewName;
alleleId: string | null;
expandedTranscriptConseqeuenceIds: string[];
expandTranscriptIds: string[];
};

type VariantViewGeneralState = {
Expand All @@ -53,7 +53,7 @@ const ensurePresenceOfVariantState = (
state[genomeId][variantId] = {
view: 'default',
alleleId: null,
expandedTranscriptConseqeuenceIds: []
expandTranscriptIds: []
};
}
};
Expand Down Expand Up @@ -85,25 +85,10 @@ const variantViewGeneralSlice = createSlice({
const { genomeId, variantId, alleleId } = action.payload;
ensurePresenceOfVariantState(state, genomeId, variantId);
state[genomeId][variantId].alleleId = alleleId;
},
setExpandedTranscriptConsequenceIds(
state,
action: PayloadAction<{
genomeId: string;
variantId: string;
expandedTranscriptConseqeuenceIds: string[];
}>
) {
const { genomeId, variantId, expandedTranscriptConseqeuenceIds } =
action.payload;
ensurePresenceOfVariantState(state, genomeId, variantId);
state[genomeId][variantId].expandedTranscriptConseqeuenceIds =
expandedTranscriptConseqeuenceIds;
}
}
});

export const { setView, setAllele, setExpandedTranscriptConsequenceIds } =
variantViewGeneralSlice.actions;
export const { setView, setAllele } = variantViewGeneralSlice.actions;

export default variantViewGeneralSlice.reducer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { RootState } from 'src/store';

export const getExpandedTranscriptConseqeuenceIds = (
state: RootState,
genomeId: string,
variantId: string,
alleleId: string
) => {
return (
state.entityViewer.variantView.transcriptConsequences[genomeId]?.[
variantId
]?.[alleleId]?.expandedIds ?? null
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { PayloadAction, createSlice } from '@reduxjs/toolkit';

type TranscriptConsequenceState = {
[genomeId: string]: {
[variantId: string]: {
[alleleId: string]: {
expandedIds: string[] | null;
};
};
};
};

const ensurePresenceOfTranscriptConsequenceState = (
state: TranscriptConsequenceState,
genomeId: string,
variantId: string,
alleleId: string
) => {
if (!state[genomeId]) {
state[genomeId] = {};
}
if (!state[genomeId][variantId]) {
state[genomeId][variantId] = {};
}
if (!state[genomeId][variantId][alleleId]) {
state[genomeId][variantId][alleleId] = {
expandedIds: null
};
}
};

const transcriptConsequenceSlice = createSlice({
name: 'transcript-consequence-slice',
initialState: {} as TranscriptConsequenceState,
reducers: {
expandTranscript(
state,
action: PayloadAction<{
genomeId: string;
variantId: string;
alleleId: string;
transcriptId: string;
}>
) {
const { genomeId, variantId, alleleId, transcriptId } = action.payload;
ensurePresenceOfTranscriptConsequenceState(
state,
genomeId,
variantId,
alleleId
);

const expandedIds = state[genomeId][variantId][alleleId].expandedIds;
if (expandedIds) {
const uniqueIds = new Set(expandedIds);
uniqueIds.add(transcriptId);
state[genomeId][variantId][alleleId].expandedIds = [...uniqueIds];
} else {
state[genomeId][variantId][alleleId].expandedIds = [transcriptId];
}
},
collapseTranscript(
state,
action: PayloadAction<{
genomeId: string;
variantId: string;
alleleId: string;
transcriptId: string;
}>
) {
const { genomeId, variantId, alleleId, transcriptId } = action.payload;
ensurePresenceOfTranscriptConsequenceState(
state,
genomeId,
variantId,
alleleId
);

let expandedIds = state[genomeId][variantId][alleleId].expandedIds;
if (expandedIds) {
// this should always be the case in this reducer
expandedIds = expandedIds.filter((id) => id !== transcriptId);
state[genomeId][variantId][alleleId].expandedIds = expandedIds;
}
}
}
});

export const { expandTranscript, collapseTranscript } =
transcriptConsequenceSlice.actions;
export default transcriptConsequenceSlice.reducer;
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

.transcriptId {
color: var(--color-blue);
cursor: pointer;
width: fit-content;
padding-top: 8px;
}

Expand Down
Loading

0 comments on commit 95ad505

Please sign in to comment.