Brijesh619 commented on code in PR #688:
URL: https://github.com/apache/atlas/pull/688#discussion_r3782756342


##########
dashboard/src/views/SideBar/SideBarBody.tsx:
##########
@@ -101,61 +101,101 @@ const DrawerHeader = styled("div")(({ theme }) => ({
   marginBottom: "1rem",
 }));
 
+
 const SideBarBody = (props: {
-  loading: boolean;
-  handleOpenModal: any;
-  handleOpenAboutModal: any;
+  handleOpenModal: () => void;
+  handleOpenAboutModal: () => void;
 }) => {
   const location = useLocation();
   const routes = useRoutes(AppRoutes as RouteObject[]);
   const history = useHistory();
   const dispatch = useAppDispatch();
-  const { loading: loader, handleOpenModal, handleOpenAboutModal } = props;
+  const { handleOpenModal, handleOpenAboutModal } = props;
   const navigate = useNavigate();
-  const { loading } = useSelector((state: TypeHeaderState) => 
state.typeHeader);
   const { relationshipSearch = {} } = globalSessionData || {};
   const [open, setOpen] = useState(true);
   const [searchTerm, setSearchTerm] = useState<string>("");
+  const { data: versionData } = useAppSelector((state) => 
state.session?.versionData || {});
+  const searchParams = new URLSearchParams(location.search);
+
+  const isCustomFilterActive = searchParams.get("isCF") === "true";
+  const isGlossaryActive = !isCustomFilterActive && 
(location.pathname.includes("/glossary") || !!searchParams.get("gtype") || 
!!searchParams.get("term") || !!searchParams.get("category"));
+  const isBusinessMetadataActive = !isCustomFilterActive && 
location.pathname.includes("/administrator/businessMetadata");
+  const isClassificationActive = !isCustomFilterActive && 
(!!searchParams.get("tag") || location.pathname.includes("/tag/tagAttribute"));
+  const isRelationshipActive = !isCustomFilterActive && 
(!!searchParams.get("relationshipName") || 
location.pathname.includes("/relationshipDetailPage"));
+
+  const isEntitiesActive = !isCustomFilterActive && 
(!!searchParams.get("type") || location.pathname.includes("/detailPage"));
+
+  const modules = [
+    { id: "entities", title: "Entities", isActive: isEntitiesActive, iconUrl: 
"/img/sidebar-icons/icon-entities.svg", Component: EntitiesTree, isVisible: 
true },
+    { id: "classification", title: "Classifications", isActive: 
isClassificationActive, iconUrl: "/img/sidebar-icons/icon-classifications.svg", 
Component: ClassificationTree, isVisible: true },
+    { id: "glossary", title: "Glossary", isActive: isGlossaryActive, iconUrl: 
"/img/sidebar-icons/icon-glossary.svg", Component: GlossaryTree, isVisible: 
true },
+    { id: "businessMetadata", title: "Business Metadata", isActive: 
isBusinessMetadataActive, iconUrl: 
"/img/sidebar-icons/icon-business-metadata.svg", Component: 
BusinessMetadataTree, isVisible: true },
+    { id: "relationships", title: "Relationships", isActive: 
isRelationshipActive, iconUrl: "/img/sidebar-icons/icon-relationships.svg", 
Component: RelationshipsTree, isVisible: !!relationshipSearch },
+    { id: "customFilters", title: "Custom Filters", isActive: 
isCustomFilterActive, iconUrl: "/img/sidebar-icons/icon-custom-filters.svg", 
Component: CustomFiltersTree, isVisible: true }
+  ];
 
   const handleDrawerOpen = () => {

Review Comment:
   Resolved. Updated handleDrawerOpen and the search icon's onClick to call 
handlePopoverClose() so the popover state clears whenever the drawer expands.



##########
dashboard/src/views/SideBar/SideBarBody.tsx:
##########
@@ -101,61 +101,101 @@ const DrawerHeader = styled("div")(({ theme }) => ({
   marginBottom: "1rem",
 }));
 
+
 const SideBarBody = (props: {
-  loading: boolean;
-  handleOpenModal: any;
-  handleOpenAboutModal: any;
+  handleOpenModal: () => void;
+  handleOpenAboutModal: () => void;
 }) => {
   const location = useLocation();
   const routes = useRoutes(AppRoutes as RouteObject[]);
   const history = useHistory();
   const dispatch = useAppDispatch();
-  const { loading: loader, handleOpenModal, handleOpenAboutModal } = props;
+  const { handleOpenModal, handleOpenAboutModal } = props;
   const navigate = useNavigate();
-  const { loading } = useSelector((state: TypeHeaderState) => 
state.typeHeader);
   const { relationshipSearch = {} } = globalSessionData || {};
   const [open, setOpen] = useState(true);
   const [searchTerm, setSearchTerm] = useState<string>("");
+  const { data: versionData } = useAppSelector((state) => 
state.session?.versionData || {});
+  const searchParams = new URLSearchParams(location.search);
+
+  const isCustomFilterActive = searchParams.get("isCF") === "true";
+  const isGlossaryActive = !isCustomFilterActive && 
(location.pathname.includes("/glossary") || !!searchParams.get("gtype") || 
!!searchParams.get("term") || !!searchParams.get("category"));
+  const isBusinessMetadataActive = !isCustomFilterActive && 
location.pathname.includes("/administrator/businessMetadata");
+  const isClassificationActive = !isCustomFilterActive && 
(!!searchParams.get("tag") || location.pathname.includes("/tag/tagAttribute"));
+  const isRelationshipActive = !isCustomFilterActive && 
(!!searchParams.get("relationshipName") || 
location.pathname.includes("/relationshipDetailPage"));
+
+  const isEntitiesActive = !isCustomFilterActive && 
(!!searchParams.get("type") || location.pathname.includes("/detailPage"));
+
+  const modules = [
+    { id: "entities", title: "Entities", isActive: isEntitiesActive, iconUrl: 
"/img/sidebar-icons/icon-entities.svg", Component: EntitiesTree, isVisible: 
true },
+    { id: "classification", title: "Classifications", isActive: 
isClassificationActive, iconUrl: "/img/sidebar-icons/icon-classifications.svg", 
Component: ClassificationTree, isVisible: true },
+    { id: "glossary", title: "Glossary", isActive: isGlossaryActive, iconUrl: 
"/img/sidebar-icons/icon-glossary.svg", Component: GlossaryTree, isVisible: 
true },
+    { id: "businessMetadata", title: "Business Metadata", isActive: 
isBusinessMetadataActive, iconUrl: 
"/img/sidebar-icons/icon-business-metadata.svg", Component: 
BusinessMetadataTree, isVisible: true },
+    { id: "relationships", title: "Relationships", isActive: 
isRelationshipActive, iconUrl: "/img/sidebar-icons/icon-relationships.svg", 
Component: RelationshipsTree, isVisible: !!relationshipSearch },
+    { id: "customFilters", title: "Custom Filters", isActive: 
isCustomFilterActive, iconUrl: "/img/sidebar-icons/icon-custom-filters.svg", 
Component: CustomFiltersTree, isVisible: true }
+  ];
 
   const handleDrawerOpen = () => {
     setOpen(!open);
   };
 
-  const [position, setPosition] = useState<string | 
number>(defaultDrawerWidth);
-  const draggerRef = useRef<HTMLDivElement>(null);
-  const headerRef = useRef<HTMLDivElement>(null);
-  const windowWidth = window.innerWidth;
-  const minPosition = 300;
-  const maxPosition = windowWidth * 0.6;
-
-  const handleMouseMove = (e: MouseEvent) => {
-    let newPosition = e.clientX;
+  const [popoverAnchor, setPopoverAnchor] = useState<HTMLButtonElement | 
null>(null);
+  const [activePopover, setActivePopover] = useState<string | null>(null);
+  const [popoverMaxHeight, setPopoverMaxHeight] = useState<string>('calc(100vh 
- 100px)');
+  const [isBottomHalf, setIsBottomHalf] = useState<boolean>(false);
+
+  const handlePopoverOpen = (event: React.MouseEvent<HTMLButtonElement>, id: 
string) => {
+    const target = event.currentTarget;
+
+    const openNewPopover = () => {
+      setPopoverAnchor(target);
+      setActivePopover(id);
+
+      // Calculate remaining screen height from the anchor to the bottom
+      const rect = target.getBoundingClientRect();
+      const spaceBelow = window.innerHeight - rect.top - 24;
+      const isBottom = spaceBelow < 350;
+      setIsBottomHalf(isBottom);
+
+      if (isBottom) {
+        const spaceAbove = rect.bottom - 24;
+        setPopoverMaxHeight(`${Math.max(250, spaceAbove)}px`);
+      } else {
+        setPopoverMaxHeight(`${Math.max(250, spaceBelow)}px`);
+      }
+    };
 
-    if (newPosition < minPosition) {
-      newPosition = minPosition;
-    } else if (newPosition > maxPosition) {
-      newPosition = maxPosition;
+    // If a different popover is already open, close it first to ensure clean 
unmount
+    if (activePopover && activePopover !== id) {
+      handlePopoverClose();
+      setTimeout(openNewPopover, 0);

Review Comment:
   Resolved. I've added a useRef (popoverTimeoutRef) to track the setTimeout.
   
   Now, when switching popovers rapidly, any pending timeouts are immediately 
cleared to prevent race conditions that could leave the wrong popover open. I 
also added a cleanup function in a useEffect to clear the timeout if the 
component unmounts before it fires.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to