Skip to content

Commit

Permalink
Add sidebar button selection based on URL path
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtitherington committed Nov 10, 2023
1 parent 60862aa commit 885f19b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion frontend/src/components/sidebarMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { TextButton } from 'components/buttons';
import { useNavigate } from 'react-router';
import { isHasData } from 'api/utils';
import { usePopper } from 'react-popper';
import { useLocation } from 'react-router-dom';

interface ProjectEntry {
id: number;
Expand All @@ -37,6 +38,7 @@ const SidebarMenu = ({ projects }: SidebarMenuProps) => {
const [isOpen, setIsOpen] = useState(false);
const { selectedProject, setSelectedProject } = useProjectsStore();
const isLoadingState = ['initial', 'loading', 'hasError'].includes(selectedProject.state);
const location = useLocation();
const navigate = useNavigate();

const [referenceElement, setReferenceElement] = useState<HTMLButtonElement | null>(null);
Expand All @@ -53,10 +55,15 @@ const SidebarMenu = ({ projects }: SidebarMenuProps) => {
setIsOpen(true);
}

const isActive = (path: string) => {
return location.pathname === path;
};

// icon property is a function to allow for styling
const ButtonList = [
{
label: 'Flows',
path: '/flows',
icon: () => <Flow style={{ height: '16px', width: '16px' }} />,
onClick: () => {
navigate("/flows");
Expand All @@ -65,6 +72,7 @@ const SidebarMenu = ({ projects }: SidebarMenuProps) => {
},
{
label: 'People',
path: '/people',
icon: () => <MdOutlineBadge />,
onClick: () => {
navigate("/people");
Expand Down Expand Up @@ -97,7 +105,7 @@ const SidebarMenu = ({ projects }: SidebarMenuProps) => {
label={button.label}
onClick={button.onClick}
widthFill={true}
selected={button.selected}
selected={isActive(button.path)}
/>
))}
</div>
Expand Down

0 comments on commit 885f19b

Please sign in to comment.