Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate grid collapse actions to a single full screen toggle #39070

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 60 additions & 83 deletions airflow/www/static/js/dag/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,21 @@ import {
AccordionPanel,
} from "@chakra-ui/react";
import { isEmpty, debounce } from "lodash";
import { MdDoubleArrow } from "react-icons/md";
import { useSearchParams } from "react-router-dom";
import { FaExpandArrowsAlt, FaCompressArrowsAlt } from "react-icons/fa";

import { useGridData } from "src/api";
import { hoverDelay } from "src/utils";

import ShortcutCheatSheet from "src/components/ShortcutCheatSheet";
import { useKeysPress } from "src/utils/useKeysPress";

import Details, { TAB_PARAM } from "./details";
import Details from "./details";
import Grid from "./grid";
import FilterBar from "./nav/FilterBar";
import LegendRow from "./nav/LegendRow";
import useToggleGroups from "./useToggleGroups";
import keyboardShortcutIdentifier from "./keyboardShortcutIdentifier";

const detailsPanelKey = "hideDetailsPanel";
const minPanelWidth = 300;
const collapsedWidth = "32px";

Expand Down Expand Up @@ -82,21 +80,12 @@ const Main = () => {

const [accordionIndexes, setAccordionIndexes] = useState<Array<number>>([0]);
const isFilterCollapsed = !accordionIndexes.length;
const toggleFilterCollapsed = () => {
if (isFilterCollapsed) setAccordionIndexes([0]);
else setAccordionIndexes([]);
};

const [searchParams] = useSearchParams();
const resizeRef = useRef<HTMLDivElement>(null);
const gridRef = useRef<HTMLDivElement>(null);
const gridScrollRef = useRef<HTMLDivElement>(null);
const ganttScrollRef = useRef<HTMLDivElement>(null);

const isPanelOpen =
localStorage.getItem(detailsPanelKey) !== "true" ||
!!searchParams.get(TAB_PARAM);
const { isOpen, onToggle } = useDisclosure({ defaultIsOpen: isPanelOpen });
const [hoveredTaskState, setHoveredTaskState] = useState<
string | null | undefined
>();
Expand All @@ -122,29 +111,23 @@ const Main = () => {

const gridWidth = localStorage.getItem(gridWidthKey) || undefined;

const onPanelToggle = () => {
if (!isOpen) {
localStorage.setItem(detailsPanelKey, "false");
} else {
localStorage.setItem(detailsPanelKey, "true");
if (isGridCollapsed) {
setIsGridCollapsed(!isGridCollapsed);
}
}
onToggle();
};

const onToggleGridCollapse = useCallback(() => {
const gridElement = gridRef.current;
if (gridElement) {
if (isGridCollapsed) {
gridElement.style.width = localStorage.getItem(gridWidthKey) || "";
} else {
gridElement.style.width = collapsedWidth;
}
setIsGridCollapsed(!isGridCollapsed);
}
}, [isGridCollapsed]);
const onToggleGridCollapse = useCallback(
(collapseNext?: boolean) => {
const gridElement = gridRef.current;
const collapse =
collapseNext !== undefined ? collapseNext : !isGridCollapsed;
if (collapse !== undefined)
if (gridElement) {
if (!collapse) {
gridElement.style.width = localStorage.getItem(gridWidthKey) || "";
} else {
gridElement.style.width = collapsedWidth;
}
setIsGridCollapsed(collapse);
}
},
[isGridCollapsed]
);

const resize = useCallback(
(e: MouseEvent) => {
Expand Down Expand Up @@ -195,7 +178,7 @@ const Main = () => {
};
}
return () => {};
}, [resize, isLoading, isOpen]);
}, [resize, isLoading]);

useKeysPress(
keyboardShortcutIdentifier.toggleShortcutCheatSheet,
Expand All @@ -206,10 +189,10 @@ const Main = () => {
const toggleFullScreen = () => {
if (!isFullScreen) {
setAccordionIndexes([]);
setIsGridCollapsed(true);
onToggleGridCollapse(true);
} else {
setAccordionIndexes([0]);
setIsGridCollapsed(false);
onToggleGridCollapse(false);
}
};

Expand All @@ -222,18 +205,6 @@ const Main = () => {
overflow="hidden"
position="relative"
>
<IconButton
position="absolute"
variant="ghost"
color="gray.400"
top={0}
left={0}
onClick={toggleFilterCollapsed}
icon={<MdDoubleArrow />}
aria-label="Toggle filters bar"
transform={isFilterCollapsed ? "rotateZ(90deg)" : "rotateZ(270deg)"}
transition="all 0.2s"
/>
<Accordion allowToggle index={accordionIndexes} borderTopWidth={0}>
<AccordionItem
sx={{
Expand All @@ -259,52 +230,58 @@ const Main = () => {
) : (
<>
<Box
flex={isOpen ? undefined : 1}
minWidth={isGridCollapsed ? collapsedWidth : minPanelWidth}
ref={gridRef}
height="100%"
width={isGridCollapsed ? collapsedWidth : gridWidth}
position="relative"
>
<IconButton
icon={
isFullScreen ? <FaExpandArrowsAlt /> : <FaCompressArrowsAlt />
}
fontSize="xl"
position="absolute"
right={0}
top={0}
variant="ghost"
color="gray.400"
size="sm"
aria-label="Toggle full screen details"
title="Toggle full screen details"
onClick={toggleFullScreen}
/>
<Grid
isPanelOpen={isOpen}
onPanelToggle={onPanelToggle}
hoveredTaskState={hoveredTaskState}
openGroupIds={openGroupIds}
onToggleGroups={onToggleGroups}
isGridCollapsed={isGridCollapsed}
setIsGridCollapsed={onToggleGridCollapse}
gridScrollRef={gridScrollRef}
ganttScrollRef={ganttScrollRef}
/>
</Box>
{isOpen && (
<>
<Box
width={2}
cursor="ew-resize"
bg="gray.200"
ref={resizeRef}
zIndex={1}
/>
<Box
flex={1}
minWidth={minPanelWidth}
zIndex={1}
bg="white"
height="100%"
>
<Details
openGroupIds={openGroupIds}
onToggleGroups={onToggleGroups}
hoveredTaskState={hoveredTaskState}
gridScrollRef={gridScrollRef}
ganttScrollRef={ganttScrollRef}
isFullScreen={isFullScreen}
toggleFullScreen={toggleFullScreen}
/>
</Box>
</>
)}
<Box
width={2}
cursor="ew-resize"
bg="gray.200"
ref={resizeRef}
zIndex={1}
/>
<Box
flex={1}
minWidth={minPanelWidth}
zIndex={1}
bg="white"
height="100%"
>
<Details
openGroupIds={openGroupIds}
onToggleGroups={onToggleGroups}
hoveredTaskState={hoveredTaskState}
gridScrollRef={gridScrollRef}
ganttScrollRef={ganttScrollRef}
/>
</Box>
</>
)}
</Flex>
Expand Down
22 changes: 2 additions & 20 deletions airflow/www/static/js/dag/details/graph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ import ReactFlow, {
Panel,
useOnViewportChange,
Viewport,
ControlButton,
} from "reactflow";
import { BiCollapse, BiExpand } from "react-icons/bi";

import { useDatasets, useGraphData, useGridData } from "src/api";
import useSelection from "src/dag/useSelection";
Expand All @@ -49,19 +47,11 @@ interface Props {
openGroupIds: string[];
onToggleGroups: (groupIds: string[]) => void;
hoveredTaskState?: string | null;
isFullScreen?: boolean;
toggleFullScreen?: () => void;
}

const dagId = getMetaValue("dag_id");

const Graph = ({
openGroupIds,
onToggleGroups,
hoveredTaskState,
isFullScreen,
toggleFullScreen,
}: Props) => {
const Graph = ({ openGroupIds, onToggleGroups, hoveredTaskState }: Props) => {
const graphRef = useRef(null);
const { data } = useGraphData();
const [arrange, setArrange] = useState(data?.arrange || "LR");
Expand Down Expand Up @@ -235,15 +225,7 @@ const Graph = ({
</Box>
</Panel>
<Background />
<Controls showInteractive={false}>
<ControlButton
onClick={toggleFullScreen}
aria-label="Toggle full screen"
title="Toggle full screen"
>
{isFullScreen ? <BiCollapse /> : <BiExpand />}
</ControlButton>
</Controls>
<Controls showInteractive={false} />
<MiniMap
nodeStrokeWidth={15}
nodeStrokeColor={(props) => nodeStrokeColor(props, colors)}
Expand Down
15 changes: 1 addition & 14 deletions airflow/www/static/js/dag/details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ interface Props {
hoveredTaskState?: string | null;
gridScrollRef: React.RefObject<HTMLDivElement>;
ganttScrollRef: React.RefObject<HTMLDivElement>;
isFullScreen?: boolean;
toggleFullScreen?: () => void;
}

const tabToIndex = (tab?: string) => {
Expand Down Expand Up @@ -150,8 +148,6 @@ const Details = ({
hoveredTaskState,
gridScrollRef,
ganttScrollRef,
isFullScreen,
toggleFullScreen,
}: Props) => {
const {
selected: { runId, taskId, mapIndex },
Expand Down Expand Up @@ -241,12 +237,7 @@ const Details = ({

return (
<Flex flexDirection="column" height="100%">
<Flex
alignItems="center"
justifyContent="space-between"
flexWrap="wrap"
ml={6}
>
<Flex alignItems="center" justifyContent="space-between" flexWrap="wrap">
<Header
mapIndex={
mappedTaskInstance?.renderedMapIndex || mappedTaskInstance?.mapIndex
Expand Down Expand Up @@ -418,8 +409,6 @@ const Details = ({
openGroupIds={openGroupIds}
onToggleGroups={onToggleGroups}
hoveredTaskState={hoveredTaskState}
isFullScreen={isFullScreen}
toggleFullScreen={toggleFullScreen}
/>
</TabPanel>
<TabPanel p={0} height="100%">
Expand Down Expand Up @@ -469,8 +458,6 @@ const Details = ({
? undefined
: instance.state
}
isFullScreen={isFullScreen}
toggleFullScreen={toggleFullScreen}
/>
</TabPanel>
)}
Expand Down
19 changes: 0 additions & 19 deletions airflow/www/static/js/dag/details/taskInstance/Logs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ import {
Icon,
Spinner,
Select,
IconButton,
} from "@chakra-ui/react";
import { MdWarning } from "react-icons/md";
import { BiCollapse, BiExpand } from "react-icons/bi";

import { getMetaValue } from "src/utils";
import useTaskLog from "src/api/useTaskLog";
Expand Down Expand Up @@ -96,8 +94,6 @@ interface Props {
executionDate: DagRun["executionDate"];
tryNumber: TaskInstance["tryNumber"];
state?: TaskInstance["state"];
isFullScreen?: boolean;
toggleFullScreen?: () => void;
}

const Logs = ({
Expand All @@ -108,8 +104,6 @@ const Logs = ({
executionDate,
tryNumber,
state,
isFullScreen,
toggleFullScreen,
}: Props) => {
const [internalIndexes, externalIndexes] = getLinkIndexes(tryNumber);
const [selectedTryNumber, setSelectedTryNumber] = useState<
Expand Down Expand Up @@ -297,19 +291,6 @@ const Logs = ({
<LinkButton href={`${logUrl}&${params.toString()}`}>
See More
</LinkButton>
<IconButton
variant="ghost"
aria-label="Toggle full screen"
title="Toggle full screen"
onClick={toggleFullScreen}
icon={
isFullScreen ? (
<BiCollapse height="24px" />
) : (
<BiExpand height="24px" />
)
}
/>
</Flex>
</Flex>
</Box>
Expand Down
Loading