From ce4f20ae8474f9eb8348883e11dc402337920d73 Mon Sep 17 00:00:00 2001 From: fnguyen Date: Fri, 3 May 2024 10:45:25 -0400 Subject: [PATCH 1/2] Fix to work with Query: Filter elements are now pipe delimited --- .../MainLayout/Header/ProfileSection/index.js | 10 +-- src/views/clinicalGenomic/widgets/sidebar.js | 74 +++++++++---------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/layout/MainLayout/Header/ProfileSection/index.js b/src/layout/MainLayout/Header/ProfileSection/index.js index 1018b700..45b13bce 100644 --- a/src/layout/MainLayout/Header/ProfileSection/index.js +++ b/src/layout/MainLayout/Header/ProfileSection/index.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { styled } from '@mui/material/styles'; import { useSelector } from 'react-redux'; @@ -157,9 +157,9 @@ function ProfileSection() { const theme = useTheme(); const customization = useSelector((state) => state.customization); - const [selectedIndex] = React.useState(1); + const [selectedIndex] = useState(1); - const [open, setOpen] = React.useState(false); + const [open, setOpen] = useState(false); const anchorRef = React.useRef(null); @@ -175,7 +175,7 @@ function ProfileSection() { }; const prevOpen = React.useRef(open); - React.useEffect(() => { + useEffect(() => { if (prevOpen.current === true && open === false) { anchorRef.current.focus(); } @@ -243,7 +243,7 @@ function ProfileSection() { - Hello! + Hello, ! {/* First Name Last Name */} diff --git a/src/views/clinicalGenomic/widgets/sidebar.js b/src/views/clinicalGenomic/widgets/sidebar.js index 41b6b499..83ec299f 100644 --- a/src/views/clinicalGenomic/widgets/sidebar.js +++ b/src/views/clinicalGenomic/widgets/sidebar.js @@ -131,62 +131,49 @@ function StyledCheckboxList(props) { // Remove duplicates if (Array.isArray(ids)) { ids = Array.from(new Set(ids?.flat(1))); + } else { + ids = [ids]; } + console.log(ids); if (isExclusion ? !isChecked : isChecked) { - if (useAutoComplete) { - // Autcomplete's onChange will have IDs be a list of options that are checked - setChecked((_) => { - const retVal = {}; - ids.forEach((id) => { - retVal[id] = true; - }); - return retVal; + setChecked((_) => { + const retVal = {}; + ids.forEach((id) => { + retVal[id] = true; }); - } else { - // FormControlLabel's onChange will have IDs be a list of IDs that have _changed_ - setChecked((old) => ({ ...old, [ids]: true })); - } + return retVal; + }); onWrite((old) => { const retVal = { donorLists: {}, filter: {}, query: {}, ...old }; - // The following appends ourselves to the write context under 'query': {group: [list]} or 'donorList': {group: [list]} - if (isFilterList) { - // Filter lists operate differently: you _remove_ the option when you check it - retVal.filter[groupName].splice(retVal.filter[groupName].indexOf(ids)); - } else { - retVal.query[groupName] = ids; + // The following appends ourselves to the write context under 'query': {group: [|-delimited-list]} or 'donorList': {group: [|-delimited-list]} + if (ids.length > 0) { + retVal.query[groupName] = ids.join('|'); } return retVal; }); } else { - setChecked((old) => { - // Autocomplete's onChange will return a list - if (useAutoComplete) { - const retVal = {}; - ids.forEach((id) => { - retVal[id] = true; - }); - return retVal; - } - - // FormControlLabel's onChange - const { [ids]: _, ...rest } = old; - return rest; + setChecked((_) => { + const retVal = {}; + ids.forEach((id) => { + retVal[id] = true; + }); + return retVal; }); onWrite((old) => { const retVal = { filter: {}, ...old }; if (isFilterList) { - if (groupName in retVal.filter) { - retVal.filter[groupName].push(ids); - } else { - retVal.filter[groupName] = [ids]; + if (ids.length > 0) { + retVal.filter[groupName] = ids.join('|'); } return retVal; } const newList = Object.fromEntries(Object.entries(old.query).filter(([name, _]) => name !== groupName)); - newList[groupName] = ids; + if (ids.length > 0) { + newList[groupName] = ids.join('|'); + } retVal.query = newList; return retVal; }); @@ -230,7 +217,20 @@ function StyledCheckboxList(props) { HandleChange(option, event.target.checked)} + onChange={(event) => { + const newList = Object.keys(checked).slice(); + if (event.target.checked) { + // Add to list + newList.push(option); + } else { + // Remove from list + const oldPos = newList.indexOf(option); + if (oldPos >= 0) { + newList.splice(oldPos, 1); + } + } + HandleChange(newList, event.target.checked); + }} /> } key={option} From 0b0c1ce05048279cf102f7ea40dfb392fe7db52a Mon Sep 17 00:00:00 2001 From: fnguyen Date: Fri, 3 May 2024 12:28:27 -0400 Subject: [PATCH 2/2] Remove debugging code --- src/layout/MainLayout/Header/ProfileSection/index.js | 2 +- src/views/clinicalGenomic/widgets/sidebar.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/layout/MainLayout/Header/ProfileSection/index.js b/src/layout/MainLayout/Header/ProfileSection/index.js index 45b13bce..737fe9eb 100644 --- a/src/layout/MainLayout/Header/ProfileSection/index.js +++ b/src/layout/MainLayout/Header/ProfileSection/index.js @@ -243,7 +243,7 @@ function ProfileSection() { - Hello, ! + Hello! {/* First Name Last Name */} diff --git a/src/views/clinicalGenomic/widgets/sidebar.js b/src/views/clinicalGenomic/widgets/sidebar.js index 83ec299f..d8b2dfd8 100644 --- a/src/views/clinicalGenomic/widgets/sidebar.js +++ b/src/views/clinicalGenomic/widgets/sidebar.js @@ -134,7 +134,6 @@ function StyledCheckboxList(props) { } else { ids = [ids]; } - console.log(ids); if (isExclusion ? !isChecked : isChecked) { setChecked((_) => {