-
Notifications
You must be signed in to change notification settings - Fork 15.9k
Add resize function for Dag Documentation #56344
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6f2b6f5
feat: Add dialog resize function
RoyLee1224 381b515
Merge branch 'main' into doc-resize
RoyLee1224 32c9d54
feat: Memorize resize state
RoyLee1224 948a645
refactor: replace inline style and use useLocalStorage
RoyLee1224 47dcc9f
fix: remove redundent style
RoyLee1224 e85f4cb
refactor: optimize state management
RoyLee1224 ea94f96
Merge branch 'main' into doc-resize
RoyLee1224 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
airflow-core/src/airflow/ui/src/components/ui/ResizableWrapper.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /*! | ||
| * 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 { Box } from "@chakra-ui/react"; | ||
| import { forwardRef } from "react"; | ||
| import type { ReactNode } from "react"; | ||
| import { ResizableBox } from "react-resizable"; | ||
| import "react-resizable/css/styles.css"; | ||
|
|
||
| import { usePersistentResizableState } from "src/utils/usePersistentResizableState"; | ||
|
|
||
| const ResizeHandle = forwardRef<HTMLDivElement>((props, ref) => ( | ||
| <Box | ||
| _before={{ | ||
| background: | ||
| "linear-gradient(-45deg, transparent 6px, #ccc 6px, #ccc 8px, transparent 8px, transparent 12px, #ccc 12px, #ccc 14px, transparent 14px)", | ||
| bottom: 0, | ||
| content: '""', | ||
| height: "100%", | ||
| position: "absolute", | ||
| right: 0, | ||
| width: "100%", | ||
| }} | ||
| bottom={0} | ||
| cursor="se-resize" | ||
| height="20px" | ||
| position="absolute" | ||
| ref={ref} | ||
| right={0} | ||
| width="20px" | ||
| {...props} | ||
| /> | ||
RoyLee1224 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| )); | ||
|
|
||
| type ResizableWrapperProps = { | ||
| readonly children: ReactNode; | ||
| readonly defaultSize?: { height: number; width: number }; | ||
| readonly maxConstraints?: [number, number]; | ||
| readonly storageKey: string; | ||
| }; | ||
|
|
||
| const DEFAULT_SIZE = { height: 400, width: 500 }; | ||
| const DEFAULT_MAX: [number, number] = [1200, 800]; | ||
RoyLee1224 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| export const ResizableWrapper = ({ | ||
| children, | ||
| defaultSize = DEFAULT_SIZE, | ||
| maxConstraints = DEFAULT_MAX, | ||
| storageKey, | ||
| }: ResizableWrapperProps) => { | ||
| const { handleResize, handleResizeStop, size } = usePersistentResizableState(storageKey, defaultSize); | ||
|
|
||
| return ( | ||
| <ResizableBox | ||
| handle={<ResizeHandle />} | ||
| height={size.height} | ||
| maxConstraints={maxConstraints} | ||
| minConstraints={[DEFAULT_SIZE.width, DEFAULT_SIZE.height]} | ||
| onResize={handleResize} | ||
| onResizeStop={handleResizeStop} | ||
| resizeHandles={["se"]} | ||
| style={{ | ||
| backgroundColor: "inherit", | ||
| borderRadius: "inherit", | ||
| overflow: "hidden", | ||
| position: "relative", | ||
| }} | ||
| width={size.width} | ||
| > | ||
| {children} | ||
| </ResizableBox> | ||
| ); | ||
| }; | ||
69 changes: 69 additions & 0 deletions
69
airflow-core/src/airflow/ui/src/utils/usePersistentResizableState.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /*! | ||
| * 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 { useCallback, useState } from "react"; | ||
|
|
||
| type Size = { height: number; width: number }; | ||
|
|
||
| const getInitialSize = (key: string, defaultSize: Size): Size => { | ||
| try { | ||
| const item = localStorage.getItem(key); | ||
|
|
||
| if (item === null) { | ||
| return defaultSize; | ||
| } | ||
|
|
||
| const parsed: unknown = JSON.parse(item); | ||
|
|
||
| if ( | ||
| typeof parsed === "object" && | ||
| parsed !== null && | ||
| "width" in parsed && | ||
| "height" in parsed && | ||
| typeof parsed.width === "number" && | ||
| typeof parsed.height === "number" | ||
| ) { | ||
| return { height: parsed.height, width: parsed.width }; | ||
| } | ||
| } catch { | ||
| // Ignore parsing errors | ||
| } | ||
RoyLee1224 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return defaultSize; | ||
| }; | ||
|
|
||
| export const usePersistentResizableState = (storageKey: string, defaultSize: Size) => { | ||
| const [size, setSize] = useState(() => getInitialSize(storageKey, defaultSize)); | ||
|
|
||
| const handleResize = useCallback((_event: React.SyntheticEvent, { size: newSize }: { size: Size }) => { | ||
| setSize(newSize); | ||
| }, []); | ||
|
|
||
| const handleResizeStop = useCallback( | ||
| (_event: React.SyntheticEvent, { size: finalSize }: { size: Size }) => { | ||
| try { | ||
| localStorage.setItem(storageKey, JSON.stringify(finalSize)); | ||
| } catch { | ||
| // Ignore storage errors | ||
| } | ||
| }, | ||
RoyLee1224 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [storageKey], | ||
| ); | ||
|
|
||
| return { handleResize, handleResizeStop, size }; | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.