Skip to content
This repository was archived by the owner on Nov 2, 2021. It is now read-only.

Commit df8f2fd

Browse files
nayakrahuljeremyphilemon
authored andcommitted
Feat: Highlight currently selected row in table. (#1482)
1 parent ce77474 commit df8f2fd

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

src/App.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,9 +1545,12 @@ table {
15451545
tr {
15461546
cursor: pointer;
15471547

1548-
&:hover {
1548+
&.is-highlighted {
15491549
background: $gray-hover !important;
1550+
}
15501551

1552+
&:hover {
1553+
background: $gray-hover !important;
15511554

15521555
.dropdown {
15531556
background: $gray-hover;

src/components/home.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ function Home(props) {
2929
const [fetched, setFetched] = useState(false);
3030
const [activeStateCode, setActiveStateCode] = useState('TT');
3131
const [regionHighlighted, setRegionHighlighted] = useState(undefined);
32+
const [rowHighlighted, setRowHighlighted] = useState({
33+
statecode: undefined,
34+
isDistrict: false,
35+
districtName: undefined,
36+
});
3237
const [showUpdates, setShowUpdates] = useState(false);
3338
const [anchor, setAnchor] = useState(null);
3439
const [lastViewedLog, setLastViewedLog] = useLocalStorage(
@@ -110,8 +115,20 @@ function Home(props) {
110115
setRegionHighlighted({district, state, index});
111116
};
112117

113-
const onMapHighlightChange = useCallback(({statecode}) => {
114-
setActiveStateCode(statecode);
118+
const onMapHighlightChange = useCallback((region) => {
119+
setActiveStateCode(region.statecode);
120+
if ('districtName' in region)
121+
setRowHighlighted({
122+
statecode: region.statecode,
123+
isDistrict: true,
124+
districtName: region.districtName,
125+
});
126+
else
127+
setRowHighlighted({
128+
statecode: region.statecode,
129+
isDistrict: false,
130+
districtName: undefined,
131+
});
115132
}, []);
116133

117134
return (
@@ -159,6 +176,7 @@ function Home(props) {
159176
states={states}
160177
summary={false}
161178
stateDistrictWiseData={stateDistrictWiseData}
179+
rowHighlighted={rowHighlighted}
162180
onHighlightState={onHighlightState}
163181
onHighlightDistrict={onHighlightDistrict}
164182
/>

src/components/mapexplorer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ function MapExplorer({
123123
setPanelRegion(panelRegion);
124124
currentHoveredRegion.statecode = panelRegion.statecode;
125125
setCurrentHoveredRegion(currentHoveredRegion);
126+
panelRegion.districtName = currentHoveredRegion.name;
126127
if (onMapHighlightChange) onMapHighlightChange(panelRegion);
127128
}
128129
},

src/components/row.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function Row(props) {
9898
<tr
9999
className={`state ${props.total ? 'is-total' : ''} ${
100100
props.index % 2 === 0 ? 'is-odd' : ''
101-
}`}
101+
} ${props.isHighlighted ? 'is-highlighted' : ''}`}
102102
onMouseEnter={() => props.onHighlightState?.(state, props.index)}
103103
onMouseLeave={() => props.onHighlightState?.()}
104104
onClick={!props.total ? handleReveal : null}
@@ -275,7 +275,11 @@ function Row(props) {
275275
return (
276276
<tr
277277
key={index}
278-
className={`district ${index % 2 === 0 ? 'is-odd' : ''}`}
278+
className={`district ${index % 2 === 0 ? 'is-odd' : ''} ${
279+
props.highlightedDistrict === district
280+
? 'is-highlighted'
281+
: ''
282+
}`}
279283
style={{
280284
background: index % 2 === 0 ? '#f8f9fa' : '',
281285
}}

src/components/table.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import Row from './row';
33
import React, {useState, useEffect} from 'react';
44
import {Link} from 'react-router-dom';
55

6-
const isEqual = () => {
7-
return true;
6+
const isEqual = (prevProps, currProps) => {
7+
return (
8+
JSON.stringify(prevProps.rowHighlighted) ===
9+
JSON.stringify(currProps.rowHighlighted)
10+
);
811
};
912

1013
function Table(props) {
@@ -271,6 +274,16 @@ function Table(props) {
271274
? districts[state.state].districtData
272275
: []
273276
}
277+
isHighlighted={
278+
!props.rowHighlighted.isDistrict &&
279+
props.rowHighlighted.statecode === state.statecode
280+
}
281+
highlightedDistrict={
282+
props.rowHighlighted.isDistrict &&
283+
props.rowHighlighted.statecode === state.statecode
284+
? props.rowHighlighted.districtName
285+
: null
286+
}
274287
onHighlightState={props.onHighlightState}
275288
onHighlightDistrict={props.onHighlightDistrict}
276289
handleReveal={handleReveal}

0 commit comments

Comments
 (0)