bbovenzi commented on code in PR #43058: URL: https://github.com/apache/airflow/pull/43058#discussion_r1803181044
########## airflow/ui/src/components/TriggerDag.tsx: ########## @@ -0,0 +1,206 @@ +/*! + * 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, + useDisclosure, + Text, + Accordion, + AccordionItem, + AccordionButton, + AccordionIcon, + AccordionPanel, + FormControl, + FormLabel, + Input, + FormErrorMessage, + Tr, + Td, + Table, +} from "@chakra-ui/react"; +import { json, jsonParseLinter } from "@codemirror/lang-json"; +import { linter, lintGutter } from "@codemirror/lint"; +import { indentationMarkers } from "@replit/codemirror-indentation-markers"; +import CodeMirror, { + lineNumbers, + type ViewUpdate, +} from "@uiw/react-codemirror"; +import { useForm, SubmitHandler, Controller } from "react-hook-form"; +import { FiPlay } from "react-icons/fi"; + +import ActionModal from "./ActionModal"; + +type Props = { + readonly dagDisplayName: string; + readonly dagId: string; +}; + +type TriggerDagModalProps = { + readonly isOpen: boolean; + readonly onClose: () => void; +} & Props; + +const TriggerDagModal = ({ + dagDisplayName, + dagId, + isOpen, + onClose, +}: TriggerDagModalProps) => { + const onTrigger = (values: any) => + new Promise<void>((resolve) => { + setTimeout(() => { + alert(JSON.stringify(values, null, 2)); Review Comment: We shouldn't use `alert()` once this PR is ready for review ########## airflow/ui/src/components/TriggerDag.tsx: ########## @@ -0,0 +1,206 @@ +/*! + * 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, + useDisclosure, + Text, + Accordion, + AccordionItem, + AccordionButton, + AccordionIcon, + AccordionPanel, + FormControl, + FormLabel, + Input, + FormErrorMessage, + Tr, + Td, + Table, +} from "@chakra-ui/react"; +import { json, jsonParseLinter } from "@codemirror/lang-json"; +import { linter, lintGutter } from "@codemirror/lint"; +import { indentationMarkers } from "@replit/codemirror-indentation-markers"; +import CodeMirror, { + lineNumbers, + type ViewUpdate, +} from "@uiw/react-codemirror"; +import { useForm, SubmitHandler, Controller } from "react-hook-form"; +import { FiPlay } from "react-icons/fi"; + +import ActionModal from "./ActionModal"; + +type Props = { + readonly dagDisplayName: string; + readonly dagId: string; +}; + +type TriggerDagModalProps = { + readonly isOpen: boolean; + readonly onClose: () => void; +} & Props; + +const TriggerDagModal = ({ + dagDisplayName, + dagId, + isOpen, + onClose, +}: TriggerDagModalProps) => { + const onTrigger = (values: any) => + new Promise<void>((resolve) => { + setTimeout(() => { + alert(JSON.stringify(values, null, 2)); + resolve(); + // Trigger here TODO + onClose(); + }, 3000); + }); + + const { + control, + formState: { errors, isSubmitting }, + handleSubmit, + register, + } = useForm(); + + return ( + <ActionModal + header={`Trigger DAG ${dagDisplayName}`} + isOpen={isOpen} + onClose={onClose} + submitButton={ + <Button isLoading={isSubmitting} onClick={handleSubmit(onTrigger)}> Review Comment: ```suggestion <Button isLoading={isSubmitting} onClick={() => handleSubmit(onTrigger)}> ``` We need to pass the function not the return value of a called function. ########## airflow/ui/src/components/TriggerDag.tsx: ########## @@ -0,0 +1,206 @@ +/*! + * 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, + useDisclosure, + Text, + Accordion, + AccordionItem, + AccordionButton, + AccordionIcon, + AccordionPanel, + FormControl, + FormLabel, + Input, + FormErrorMessage, + Tr, + Td, + Table, +} from "@chakra-ui/react"; +import { json, jsonParseLinter } from "@codemirror/lang-json"; +import { linter, lintGutter } from "@codemirror/lint"; +import { indentationMarkers } from "@replit/codemirror-indentation-markers"; +import CodeMirror, { + lineNumbers, + type ViewUpdate, +} from "@uiw/react-codemirror"; +import { useForm, SubmitHandler, Controller } from "react-hook-form"; +import { FiPlay } from "react-icons/fi"; + +import ActionModal from "./ActionModal"; + +type Props = { + readonly dagDisplayName: string; + readonly dagId: string; +}; + +type TriggerDagModalProps = { + readonly isOpen: boolean; + readonly onClose: () => void; +} & Props; + +const TriggerDagModal = ({ + dagDisplayName, + dagId, + isOpen, + onClose, +}: TriggerDagModalProps) => { + const onTrigger = (values: any) => + new Promise<void>((resolve) => { + setTimeout(() => { + alert(JSON.stringify(values, null, 2)); + resolve(); + // Trigger here TODO + onClose(); + }, 3000); + }); + + const { + control, + formState: { errors, isSubmitting }, + handleSubmit, + register, + } = useForm(); + + return ( + <ActionModal + header={`Trigger DAG ${dagDisplayName}`} + isOpen={isOpen} + onClose={onClose} + submitButton={ + <Button isLoading={isSubmitting} onClick={handleSubmit(onTrigger)}> + Trigger + </Button> + } + > + <Box> + <Accordion allowToggle> + <AccordionItem> + <AccordionButton> + <Box flex="1" textAlign="left"> + <Text as="strong" size="lg"> + DAG Run Options + </Text> + </Box> + <AccordionIcon /> + </AccordionButton> + <AccordionPanel> + <form onSubmit={handleSubmit(onTrigger)}> Review Comment: ```suggestion <form onSubmit={() => handleSubmit(onTrigger)}> ``` ########## airflow/ui/src/components/TriggerDag.tsx: ########## @@ -0,0 +1,206 @@ +/*! + * 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, + useDisclosure, + Text, + Accordion, + AccordionItem, + AccordionButton, + AccordionIcon, + AccordionPanel, + FormControl, + FormLabel, + Input, + FormErrorMessage, + Tr, + Td, + Table, +} from "@chakra-ui/react"; +import { json, jsonParseLinter } from "@codemirror/lang-json"; +import { linter, lintGutter } from "@codemirror/lint"; +import { indentationMarkers } from "@replit/codemirror-indentation-markers"; +import CodeMirror, { + lineNumbers, + type ViewUpdate, +} from "@uiw/react-codemirror"; +import { useForm, SubmitHandler, Controller } from "react-hook-form"; +import { FiPlay } from "react-icons/fi"; + +import ActionModal from "./ActionModal"; + +type Props = { + readonly dagDisplayName: string; + readonly dagId: string; +}; + +type TriggerDagModalProps = { + readonly isOpen: boolean; + readonly onClose: () => void; +} & Props; + +const TriggerDagModal = ({ Review Comment: Let's move the modal to its own file. It might be worth splitting into subcomponents but for now we can put an eslintignore on max-depth. Which I should make a warning instead of an error. ########## airflow/ui/src/components/TriggerDag.tsx: ########## @@ -0,0 +1,206 @@ +/*! + * 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, + useDisclosure, + Text, + Accordion, + AccordionItem, + AccordionButton, + AccordionIcon, + AccordionPanel, + FormControl, + FormLabel, + Input, + FormErrorMessage, + Tr, + Td, + Table, +} from "@chakra-ui/react"; +import { json, jsonParseLinter } from "@codemirror/lang-json"; +import { linter, lintGutter } from "@codemirror/lint"; +import { indentationMarkers } from "@replit/codemirror-indentation-markers"; +import CodeMirror, { + lineNumbers, + type ViewUpdate, +} from "@uiw/react-codemirror"; +import { useForm, SubmitHandler, Controller } from "react-hook-form"; +import { FiPlay } from "react-icons/fi"; + +import ActionModal from "./ActionModal"; + +type Props = { + readonly dagDisplayName: string; + readonly dagId: string; +}; + +type TriggerDagModalProps = { + readonly isOpen: boolean; + readonly onClose: () => void; +} & Props; + +const TriggerDagModal = ({ + dagDisplayName, + dagId, + isOpen, + onClose, +}: TriggerDagModalProps) => { + const onTrigger = (values: any) => + new Promise<void>((resolve) => { + setTimeout(() => { + alert(JSON.stringify(values, null, 2)); + resolve(); + // Trigger here TODO + onClose(); + }, 3000); + }); + + const { + control, + formState: { errors, isSubmitting }, + handleSubmit, + register, + } = useForm(); Review Comment: Let's create a FormValue type and pass it here so we can render errors correctly ```suggestion } = useForm<FormValues>(); ``` https://react-hook-form.com/ts ########## airflow/ui/src/components/TriggerDag.tsx: ########## @@ -0,0 +1,206 @@ +/*! + * 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, + useDisclosure, + Text, + Accordion, + AccordionItem, + AccordionButton, + AccordionIcon, + AccordionPanel, + FormControl, + FormLabel, + Input, + FormErrorMessage, + Tr, + Td, + Table, +} from "@chakra-ui/react"; +import { json, jsonParseLinter } from "@codemirror/lang-json"; +import { linter, lintGutter } from "@codemirror/lint"; +import { indentationMarkers } from "@replit/codemirror-indentation-markers"; +import CodeMirror, { + lineNumbers, + type ViewUpdate, +} from "@uiw/react-codemirror"; +import { useForm, SubmitHandler, Controller } from "react-hook-form"; +import { FiPlay } from "react-icons/fi"; + +import ActionModal from "./ActionModal"; + +type Props = { + readonly dagDisplayName: string; + readonly dagId: string; +}; + +type TriggerDagModalProps = { + readonly isOpen: boolean; + readonly onClose: () => void; +} & Props; + +const TriggerDagModal = ({ + dagDisplayName, + dagId, + isOpen, + onClose, +}: TriggerDagModalProps) => { + const onTrigger = (values: any) => + new Promise<void>((resolve) => { + setTimeout(() => { + alert(JSON.stringify(values, null, 2)); + resolve(); + // Trigger here TODO + onClose(); + }, 3000); + }); + + const { + control, + formState: { errors, isSubmitting }, + handleSubmit, + register, + } = useForm(); + + return ( + <ActionModal + header={`Trigger DAG ${dagDisplayName}`} + isOpen={isOpen} + onClose={onClose} + submitButton={ + <Button isLoading={isSubmitting} onClick={handleSubmit(onTrigger)}> + Trigger + </Button> + } + > + <Box> + <Accordion allowToggle> + <AccordionItem> + <AccordionButton> + <Box flex="1" textAlign="left"> + <Text as="strong" size="lg"> + DAG Run Options + </Text> + </Box> + <AccordionIcon /> + </AccordionButton> + <AccordionPanel> + <form onSubmit={handleSubmit(onTrigger)}> + <FormControl isInvalid={errors.name}> Review Comment: ```suggestion <FormControl isInvalid={Boolean(errors.name)}> ``` -- 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]
