Skip to content

Commit

Permalink
Scroll to gene in variant transcript consequences panel (#1128)
Browse files Browse the repository at this point in the history
Also:
- Used the TextButton component for the clickable transcript ids that expand and collapse the consequences
   for a given transcript.
  • Loading branch information
azangru authored May 8, 2024
1 parent 0f33671 commit 7703df9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,32 @@
font-weight: var(--font-weight-bold);
}

.transcriptConsqTitle {
margin-left: 20px;
}

.scrollToGeneSection {
display: inline-flex;
align-items: baseline;
column-gap: 10px;
margin-left: 64px;
}

.scrollToLabel {
font-weight: var(--font-weight-light);
font-size: 11px;
}

.geneButtons {
display: flex;
column-gap: 25px;
}

.transcriptLeftColumn {
padding-top: 6px;
}

.transcriptId {
color: var(--color-blue);
width: fit-content;
padding-top: 8px;
}
Expand All @@ -47,10 +67,6 @@
padding-left: 10px;
}

.transcriptConsqTitle {
margin-left: 20px;
}

.geneSection:not(:first-child) {
margin-top: 100px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Panel from 'src/shared/components/panel/Panel';
import TranscriptConsequenceDetails from './transcript-consequence-details/TranscriptConsequenceDetails';
import { TranscriptQualityLabel } from 'src/content/app/entity-viewer/shared/components/default-transcript-label/TranscriptQualityLabel';
import { CircleLoader } from 'src/shared/components/loader';
import TextButton from 'src/shared/components/text-button/TextButton';

import type { GeneInResponse } from '../../state/api/queries/variantTranscriptConsequencesQueries';

Expand Down Expand Up @@ -93,7 +94,9 @@ const TranscriptConsequences = (props: Props) => {
}

const { variant, transcriptConsequences, allele, geneData } = currentData;
const panelHeader = <PanelHeader variant={variant} />;
const panelHeader = (
<PanelHeader variant={variant} genesCount={geneData.length} />
);

if (!transcriptConsequences) {
return (
Expand Down Expand Up @@ -149,8 +152,21 @@ const TranscriptConsequences = (props: Props) => {

const PanelHeader = (props: {
variant: TranscriptConsequencesData['variant'];
genesCount: number;
}) => {
const { variant } = props;
const { variant, genesCount } = props;

const scrollToGene = (geneIndex: number) => {
const geneSections = document.querySelectorAll(`.${styles.geneDetails}`);
const geneSection = geneSections[geneIndex];

if (geneSection) {
// this should always be the case
geneSection.scrollIntoView({
behavior: 'smooth'
});
}
};

return (
<div className={styles.panelHeader}>
Expand All @@ -160,6 +176,19 @@ const PanelHeader = (props: {
<span className={styles.transcriptConsqTitle}>
Transcript consequences
</span>

{genesCount > 1 && (
<div className={styles.scrollToGeneSection}>
<span className={styles.scrollToLabel}>Scroll to</span>
<div className={styles.geneButtons}>
{[...Array(genesCount)].map((_, index) => (
<TextButton key={index} onClick={() => scrollToGene(index)}>
Gene {index + 1}
</TextButton>
))}
</div>
</div>
)}
</div>
);
};
Expand Down Expand Up @@ -419,7 +448,7 @@ const TranscriptConsequencesList = (props: TranscriptConsequencesListProps) => {
</div>
</div>
</div>
<button
<TextButton
className={classNames(styles.right, styles.transcriptId)}
onClick={() =>
handleTranscriptConsequenceClick(
Expand All @@ -428,7 +457,7 @@ const TranscriptConsequencesList = (props: TranscriptConsequencesListProps) => {
}
>
{consequencesForSingleTranscript.stable_id}
</button>
</TextButton>
</div>

{expandedIds.has(consequencesForSingleTranscript.stable_id) ? (
Expand Down

0 comments on commit 7703df9

Please sign in to comment.