dsuhinin commented on code in PR #73123: URL: https://github.com/apache/airflow/pull/73123#discussion_r4073045147
########## airflow-core/src/airflow/ui/src/layouts/Details/Grid/useGridScrollRestore.ts: ########## @@ -0,0 +1,87 @@ +/*! + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { useLayoutEffect } from "react"; + +import type { Virtualizer } from "@tanstack/react-virtual"; + +import { ROW_HEIGHT } from "./constants"; +import type { GridTask } from "./utils"; + +// Last Grid scrollTop per Dag. Module scope so it outlives the Grid remounting. +const gridScrollTops = new Map<string, number>(); + +type Params = { + dagId: string; + flatNodes: Array<GridTask>; + // Height of the sticky header above the rows (also the virtualizer's scrollPaddingStart). + headerPad: number; + rowVirtualizer: Virtualizer<HTMLDivElement, Element>; + selectedGroupId?: string; + selectedTaskId?: string; +}; + +// Opening a task remounts the Grid and resets its scrollTop to the top. We restore the last +// position so an ordinary click never jumps the Grid: across that remount the structure is +// unchanged, so the saved pixel offset still points at the same rows. +// +// If the structure did change since we saved (a new version, or groups expanded/collapsed) the +// saved offset no longer lines up, so we fall back to locating the selected task by id and +// centering it. Rows are a fixed height, so the index alone gives the offset — this stays correct +// without depending on the stored pixels. +export const useGridScrollRestore = ({ Review Comment: changed a bit comment to avoid possible confusion. -- 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]
