-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Add Trigger DAG UI with advance options #43367
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 all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
4ed4f02
Initial draft
shubhamraj-git fd30080
some modifications
shubhamraj-git 922ec5e
rectifications
shubhamraj-git 63e20cb
initial react hook
shubhamraj-git ba35a53
reset only on form change
shubhamraj-git 7aa4e09
moving to diff componnent
shubhamraj-git db533b3
upgrading chakra ui 3.0 for TriggerDagForm.tsx
shubhamraj-git b363542
upgrading chakra ui 3.0 for TriggerDagModal.tsx
shubhamraj-git 2c999fd
fix lint
shubhamraj-git 91b87da
fix css
shubhamraj-git 144f39b
add close
shubhamraj-git da9e417
dynamic theme for json
shubhamraj-git 9e1e64f
lint fix
shubhamraj-git 4dbefc5
simplify reset
shubhamraj-git 29eb4de
reviews
shubhamraj-git 7f2ada0
json validation
shubhamraj-git 2f5e7d9
remove color schema
shubhamraj-git ce77083
use accordion
shubhamraj-git 396fa5d
Add Accordion component
bbovenzi 92f82b0
Use accordion component in triggeer form
bbovenzi f52b78d
remove dag id from title
shubhamraj-git 9ddcd72
fix response tracking
shubhamraj-git 5107d5e
add blue button
shubhamraj-git e3fd9f1
making diff components for diff buttons
shubhamraj-git a851556
lints
shubhamraj-git b027b75
Merge branch 'main' into trigger-ui
shubhamraj-git c581110
lints fix
shubhamraj-git d64b0ae
variant add
shubhamraj-git a327959
reset the form on close
shubhamraj-git 0b965a7
change type to string
shubhamraj-git 14db6b1
optimise
shubhamraj-git 348b7c6
post input validation and pretiffy for json
shubhamraj-git a5bee54
modal refactor
shubhamraj-git 11eac45
Merge branch 'main' into trigger-ui
shubhamraj-git 20a7617
reviews
shubhamraj-git b982490
Merge branch 'main' into trigger-ui
shubhamraj-git d9d2854
Merge branch 'main' into trigger-ui
shubhamraj-git b0c95cc
add fiplay button
shubhamraj-git a9e32ed
replace logical with data interval
shubhamraj-git e2a217b
add dag pause-upause toggle
shubhamraj-git f97dd4a
Merge branch 'main' into trigger-ui
shubhamraj-git 0c323fd
enable trigger for pause dag
shubhamraj-git dac3727
Merge branch 'main' into trigger-ui
shubhamraj-git 6e13965
refactor
shubhamraj-git 8f337cc
Merge branch 'main' into trigger-ui
shubhamraj-git c8c0119
DAG
shubhamraj-git 47e3672
Merge branch 'main' into trigger-ui
shubhamraj-git 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
Large diffs are not rendered by default.
Oops, something went wrong.
233 changes: 233 additions & 0 deletions
233
airflow/ui/src/components/TriggerDag/TriggerDAGForm.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,233 @@ | ||
| /*! | ||
| * 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 { Input, Button, Box, Text, Spacer, HStack } from "@chakra-ui/react"; | ||
| import { json } from "@codemirror/lang-json"; | ||
| import { githubLight, githubDark } from "@uiw/codemirror-themes-all"; | ||
| import CodeMirror from "@uiw/react-codemirror"; | ||
| import { useEffect, useState } from "react"; | ||
| import { useForm, Controller } from "react-hook-form"; | ||
| import { FiPlay } from "react-icons/fi"; | ||
|
|
||
| import { useColorMode } from "src/context/colorMode"; | ||
|
|
||
| import { Accordion } from "../ui"; | ||
| import type { DagParams } from "./TriggerDag"; | ||
|
|
||
| type TriggerDAGFormProps = { | ||
| dagParams: DagParams; | ||
| onClose: () => void; | ||
| onTrigger: (updatedDagParams: DagParams) => void; | ||
| setDagParams: React.Dispatch<React.SetStateAction<DagParams>>; | ||
| }; | ||
|
|
||
| const TriggerDAGForm: React.FC<TriggerDAGFormProps> = ({ | ||
| dagParams, | ||
| onTrigger, | ||
| setDagParams, | ||
| }) => { | ||
| const [jsonError, setJsonError] = useState<string | undefined>(); | ||
|
|
||
| const { | ||
| control, | ||
| formState: { isDirty }, | ||
| handleSubmit, | ||
| reset, | ||
| setValue, | ||
| watch, | ||
| } = useForm<DagParams>({ | ||
| defaultValues: dagParams, | ||
| }); | ||
|
|
||
| const dataIntervalStart = watch("dataIntervalStart"); | ||
| const dataIntervalEnd = watch("dataIntervalEnd"); | ||
|
|
||
| useEffect(() => { | ||
| reset(dagParams); | ||
| }, [dagParams, reset]); | ||
|
|
||
| const onSubmit = (data: DagParams) => { | ||
| onTrigger(data); | ||
| setDagParams(data); | ||
| setJsonError(undefined); | ||
| }; | ||
|
|
||
| const validateAndPrettifyJson = (value: string) => { | ||
| try { | ||
| const parsedJson = JSON.parse(value) as JSON; | ||
|
|
||
| setJsonError(undefined); | ||
|
|
||
| return JSON.stringify(parsedJson, undefined, 2); | ||
| } catch (error) { | ||
| const errorMessage = | ||
| error instanceof Error ? error.message : "Unknown error occurred."; | ||
|
|
||
| setJsonError(`Invalid JSON format: ${errorMessage}`); | ||
|
|
||
| return value; | ||
| } | ||
| }; | ||
|
|
||
| const validateDates = ( | ||
| fieldName: "dataIntervalEnd" | "dataIntervalStart", | ||
| ) => { | ||
| const startDate = dataIntervalStart | ||
| ? new Date(dataIntervalStart) | ||
| : undefined; | ||
| const endDate = dataIntervalEnd ? new Date(dataIntervalEnd) : undefined; | ||
|
|
||
| if (startDate && endDate) { | ||
| if (fieldName === "dataIntervalStart" && startDate > endDate) { | ||
| setValue("dataIntervalStart", dataIntervalEnd); | ||
| } else if (fieldName === "dataIntervalEnd" && endDate < startDate) { | ||
| setValue("dataIntervalEnd", dataIntervalStart); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| const { colorMode } = useColorMode(); | ||
|
|
||
| return ( | ||
| <> | ||
| <Accordion.Root collapsible size="lg" variant="enclosed"> | ||
| <Accordion.Item key="advancedOptions" value="advancedOptions"> | ||
| <Accordion.ItemTrigger cursor="button"> | ||
| Advanced Options | ||
| </Accordion.ItemTrigger> | ||
| <Accordion.ItemContent> | ||
| <Box p={5}> | ||
| <Text fontSize="md" mb={2}> | ||
| Data Interval Start Date | ||
| </Text> | ||
| <Controller | ||
| control={control} | ||
| name="dataIntervalStart" | ||
| render={({ field }) => ( | ||
| <Input | ||
| {...field} | ||
| max={dataIntervalEnd || undefined} | ||
| onBlur={() => validateDates("dataIntervalStart")} | ||
| placeholder="yyyy-mm-ddThh:mm" | ||
| size="sm" | ||
| type="datetime-local" | ||
| /> | ||
| )} | ||
| /> | ||
|
|
||
| <Text fontSize="md" mb={2} mt={6}> | ||
| Data Interval End Date | ||
| </Text> | ||
| <Controller | ||
| control={control} | ||
| name="dataIntervalEnd" | ||
| render={({ field }) => ( | ||
| <Input | ||
| {...field} | ||
| min={dataIntervalStart || undefined} | ||
| onBlur={() => validateDates("dataIntervalEnd")} | ||
| placeholder="yyyy-mm-ddThh:mm" | ||
| size="sm" | ||
| type="datetime-local" | ||
| /> | ||
| )} | ||
| /> | ||
|
|
||
| <Text fontSize="md" mb={2} mt={6}> | ||
| Run ID | ||
| </Text> | ||
| <Controller | ||
| control={control} | ||
| name="runId" | ||
| render={({ field }) => ( | ||
| <Input | ||
| {...field} | ||
| placeholder="Run id, optional - will be generated if not provided" | ||
| size="sm" | ||
| /> | ||
| )} | ||
| /> | ||
|
|
||
| <Text fontSize="md" mb={2} mt={6}> | ||
| Configuration JSON | ||
| </Text> | ||
| <Controller | ||
| control={control} | ||
| name="configJson" | ||
| render={({ field }) => ( | ||
| <Box mb={4}> | ||
| <CodeMirror | ||
| {...field} | ||
| basicSetup={{ | ||
| autocompletion: true, | ||
| bracketMatching: true, | ||
| foldGutter: true, | ||
| lineNumbers: true, | ||
| }} | ||
| extensions={[json()]} | ||
| height="200px" | ||
| onBlur={() => { | ||
| const prettifiedJson = validateAndPrettifyJson( | ||
| field.value, | ||
| ); | ||
|
|
||
| field.onChange(prettifiedJson); | ||
| }} | ||
| style={{ | ||
| border: "1px solid #CBD5E0", | ||
| borderRadius: "8px", | ||
| outline: "none", | ||
| padding: "2px", | ||
| }} | ||
| theme={colorMode === "dark" ? githubDark : githubLight} | ||
| /> | ||
| {Boolean(jsonError) ? ( | ||
| <Text color="red.500" fontSize="sm" mt={2}> | ||
| {jsonError} | ||
| </Text> | ||
| ) : undefined} | ||
| </Box> | ||
| )} | ||
| /> | ||
| </Box> | ||
| </Accordion.ItemContent> | ||
| </Accordion.Item> | ||
| </Accordion.Root> | ||
|
|
||
| <Box as="footer" display="flex" justifyContent="flex-end" mt={4}> | ||
| <HStack w="full"> | ||
| {isDirty ? ( | ||
| <Button onClick={() => reset()} variant="outline"> | ||
| Reset | ||
| </Button> | ||
| ) : undefined} | ||
| <Spacer /> | ||
| <Button | ||
|
jscheffl marked this conversation as resolved.
|
||
| colorPalette="blue" | ||
| disabled={Boolean(jsonError)} | ||
| onClick={() => void handleSubmit(onSubmit)()} | ||
|
bbovenzi marked this conversation as resolved.
|
||
| > | ||
| <FiPlay /> Trigger | ||
| </Button> | ||
| </HStack> | ||
| </Box> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default TriggerDAGForm; | ||
51 changes: 51 additions & 0 deletions
51
airflow/ui/src/components/TriggerDag/TriggerDAGIconButton.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,51 @@ | ||
| /*! | ||
| * 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, Button } from "@chakra-ui/react"; | ||
| import { useDisclosure } from "@chakra-ui/react"; | ||
| import { FiPlay } from "react-icons/fi"; | ||
|
|
||
| import type { DAGWithLatestDagRunsResponse } from "openapi/requests/types.gen"; | ||
|
|
||
| import TriggerDAGModal from "./TriggerDAGModal"; | ||
|
|
||
| type Props = { | ||
| readonly dag: DAGWithLatestDagRunsResponse; | ||
| }; | ||
|
|
||
| const TriggerDAGIconButton: React.FC<Props> = ({ dag }) => { | ||
| const { onClose, onOpen, open } = useDisclosure(); | ||
|
|
||
| return ( | ||
| <Box> | ||
| <Button onClick={onOpen} variant="ghost"> | ||
| <FiPlay /> | ||
| </Button> | ||
|
|
||
| <TriggerDAGModal | ||
| dagDisplayName={dag.dag_display_name} | ||
| dagId={dag.dag_id} | ||
| isPaused={dag.is_paused} | ||
| onClose={onClose} | ||
| open={open} | ||
| /> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| export default TriggerDAGIconButton; |
Oops, something went wrong.
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.