Skip to content

Commit

Permalink
refactor: Extract feature click handler into reusable function
Browse files Browse the repository at this point in the history
  • Loading branch information
theosanderson committed Dec 12, 2024
1 parent 008c99b commit 9d292d6
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions gensplore-component/src/components/SingleRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ const SingleRow = ({

const codonZoomThreshold = -2;

const handleFeatureClick = (feature) => {
const minLoc = feature.locations.map((loc) => Math.min(loc.start, loc.end)).reduce((a, b) => Math.min(a, b));
const maxLoc = feature.locations.map((loc) => Math.max(loc.start, loc.end)).reduce((a, b) => Math.max(a, b));
setWhereMouseWentDown(minLoc);
setWhereMouseWentUp(maxLoc+1);
if (feature.locations.length > 1) {
toast.info(
`This feature has multiple locations. The selection will be from the start of the first location to the end of the last location.`
);
}
console.log(feature);
};

const featureBlocksSVG = featureBlocks.map((feature, i) => {
const x = feature.start * sep;

Expand Down Expand Up @@ -322,21 +335,7 @@ const SingleRow = ({
width={(block.end - block.start) * sep + extraFeat * 2}
height={10}
fill={getColor(feature, product)}
onClick={() => {


const minLoc = feature.locations.map((loc) => Math.min(loc.start, loc.end)).reduce((a, b) => Math.min(a, b));
const maxLoc = feature.locations.map((loc) => Math.max(loc.start, loc.end)).reduce((a, b) => Math.max(a, b));
setWhereMouseWentDown(minLoc);
setWhereMouseWentUp(maxLoc+1);
if (feature.locations.length > 1) {
toast.info(
`This feature has multiple locations. The selection will be from the start of the first location to the end of the last location.`
);
}

console.log(feature);
}}
onClick={() => handleFeatureClick(feature)}
onMouseEnter={() => {
if (zoomLevel < codonZoomThreshold)
setHoveredInfo({
Expand Down Expand Up @@ -368,6 +367,7 @@ const SingleRow = ({
y={y + 9}
textAnchor="middle"
fontSize="10"
onClick={() => handleFeatureClick(feature)}
onMouseOver={() =>
setHoveredInfo({
label: `${betterName}: ${codon.aminoAcid}${
Expand Down

0 comments on commit 9d292d6

Please sign in to comment.