Skip to content

Commit c81859a

Browse files
committed
frontend: Minimize activities blocking the main content when needed
When the user clicks a resource and sees its details views, the details opens by default in a side panel. This panel still lets the user view most of the content, so changing to other routes is fine. However, then the user has a panel that maximized or snapped to the left, it will block the main contents in that page; this leads to a situation where we can have e.g the logs view showing and change to a different list view without realizing that the view has not shown up because it's rendered behind the logs panel. This PR solves that by minimizing the activity when a route changes.
1 parent b3b39c5 commit c81859a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

frontend/src/components/activity/Activity.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import React, {
4040
import { createPortal } from 'react-dom';
4141
import { useHotkeys } from 'react-hotkeys-hook';
4242
import { Trans, useTranslation } from 'react-i18next';
43+
import { useLocation } from 'react-router-dom';
4344
import { useTypedSelector } from '../../redux/hooks';
4445
import store from '../../redux/stores/store';
4546
import { activitySlice } from './activitySlice';
@@ -731,6 +732,28 @@ export const ActivitiesRenderer = React.memo(function ActivitiesRenderer() {
731732
const history = useTypedSelector(state => state.activity.history) as string[];
732733
const lastElement = history.at(-1);
733734
const [isOverview, setIsOverview] = useState(false);
735+
const location = useLocation();
736+
const locationRef = useRef(location.pathname);
737+
738+
// Minimize activities that block the main content on route change.
739+
// Activities in 'split-right' location are kept visible since they
740+
// allow the user to see most of the main content.
741+
useEffect(() => {
742+
activities.forEach(activity => {
743+
// If we were triggered just because of the activities changing but the
744+
// location hasn't changed, we have nothing to do.
745+
if (locationRef.current === location.pathname) {
746+
return;
747+
}
748+
749+
if (activity.location !== 'split-right' && !activity.minimized) {
750+
Activity.update(activity.id, { minimized: true });
751+
}
752+
});
753+
754+
locationRef.current = location.pathname;
755+
}, [location.pathname, activities]);
756+
734757
useEffect(() => {
735758
if (activities.length === 0 && isOverview) {
736759
setIsOverview(false);

0 commit comments

Comments
 (0)