Skip to content

Commit

Permalink
refactor: resolve hook warning
Browse files Browse the repository at this point in the history
  • Loading branch information
aarohinadkarni committed May 6, 2024
1 parent 4b5d9e2 commit 818e1d6
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions src/pages/signing_official_console/ManageResearcherDAAsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,21 @@ export default function ManageResearcherDAAsTable(props) {
const [filteredResearchers, setFilteredResearchers] = useState([]);
const [visibleResearchers, setVisibleResearchers] = useState([]);
const searchRef = useRef('');
const [columnHeaderData, setColumnHeaderData] = useState([columnHeaderFormat.name]);
const { signingOfficial, isLoading, dacs, daas } = props;

const headers = (dacs) => {
const dacColumnWidth = dacs.length > 0 ? 60 / dacs.length : 0;
columnHeaderFormat = {
...columnHeaderFormat,
...dacs.reduce((acc, dac) => {
acc[dac.name] = { label: dac.name, cellStyle: { width: `${dacColumnWidth}%` }};
return acc;
}, {}),
};
const dacColumns = dacs.map((dac) => dac.name);
return [columnHeaderFormat.name, ...dacColumns.map((column) => columnHeaderFormat[column])];
};

//Search function for SearchBar component, function defined in utils
const handleSearchChange = useCallback((searchTerms) => {
searchOnFilteredList(
Expand All @@ -160,30 +172,6 @@ export default function ManageResearcherDAAsTable(props) {
init();
}, [props.researchers]);

useEffect(() => {
const generateColumnData = () => {
const dacColumnWidth = dacs.length > 0 ? 60 / dacs.length : 0;

columnHeaderFormat = {
...columnHeaderFormat,
...dacs.reduce((acc, dac) => {
acc[dac.name] = { label: dac.name, cellStyle: { width: `${dacColumnWidth}%` }};
return acc;
}, {}),
};

const dacColumns = dacs.map((dac) => dac.name);

const newColumnHeaderData = [
...columnHeaderData,
...dacColumns.map((column) => columnHeaderFormat[column]),
];

setColumnHeaderData(newColumnHeaderData);
};
generateColumnData();
}, [dacs]);

useEffect(() => {
searchOnFilteredList(
searchRef.current.value, researchers,
Expand Down Expand Up @@ -265,7 +253,7 @@ export default function ManageResearcherDAAsTable(props) {
<SimpleTable
isLoading={isLoading}
rowData={processResearcherRowData(visibleResearchers)}
columnHeaders={columnHeaderData}
columnHeaders={headers(dacs)}
styles={styles}
tableSize={tableSize}
paginationBar={paginationBar}
Expand Down

0 comments on commit 818e1d6

Please sign in to comment.