Merge branch '21448-menu-reorder' into 21224-project-details
[arvados.git] / services / workbench2 / src / components / multiselect-toolbar / ms-toolbar-overflow-wrapper.tsx
index 47b019e0ff2200fa2865928a0a3657d726d44c2e..5c1c433712a718230b2476604e90bd31be49ff5e 100644 (file)
@@ -38,7 +38,6 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
 type WrapperProps = {
     children: OverflowChild[];
     menuLength: number;
-    isTransitioning: boolean;
 };
 
 export const IntersectionObserverWrapper = withStyles(styles)((props: WrapperProps & WithStyles<CssRules>) => {
@@ -47,13 +46,13 @@ export const IntersectionObserverWrapper = withStyles(styles)((props: WrapperPro
     const navRef = useRef<any>(null);
     const [visibilityMap, setVisibilityMap] = useState<Record<string, boolean>>({});
     const [numHidden, setNumHidden] = useState(() => findNumHidden(visibilityMap));
-
     const prevNumHidden = useRef(numHidden);
-
+    
     const handleIntersection = (entries) => {
         const updatedEntries: Record<string, boolean> = {};
         entries.forEach((entry) => {
             const targetid = entry.target.dataset.targetid as string;
+            //if true, the element is visible
             if (entry.isIntersecting) {
                 updatedEntries[targetid] = true;
             } else {
@@ -64,12 +63,13 @@ export const IntersectionObserverWrapper = withStyles(styles)((props: WrapperPro
         setVisibilityMap((prev) => ({
             ...prev,
             ...updatedEntries,
-            [lastEntryId]: !props.isTransitioning && Object.keys(updatedEntries)[0] === lastEntryId,
+            [lastEntryId]: Object.keys(updatedEntries)[0] === lastEntryId,
         }));
     };
 
+    //ensures that the last element is always visible if the second to last is visible
     useEffect(() => {
-        if ((prevNumHidden.current === 2 || prevNumHidden.current === 0) && numHidden === 1) {
+        if ((prevNumHidden.current > 1 || prevNumHidden.current === 0) && numHidden === 1) {
             setVisibilityMap((prev) => ({
                 ...prev,
                 [lastEntryId]: true,
@@ -126,7 +126,7 @@ export const IntersectionObserverWrapper = withStyles(styles)((props: WrapperPro
                     visibilityMap={visibilityMap}
                     className={classes.overflowStyle}
                 >
-                    {children}
+                    {children.filter((child) => !child.props['data-targetid'].includes("Divider"))}
                 </OverflowMenu>
             )}
         </div>