shubhamraj-git commented on code in PR #43367: URL: https://github.com/apache/airflow/pull/43367#discussion_r1817179751
########## airflow/ui/src/components/DataTable/TriggerDAGForm.tsx: ########## @@ -0,0 +1,188 @@ +/*! + * 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 { + FormControl, + FormLabel, + Input, + VStack, + ModalCloseButton, + Button, + ModalFooter, + Box, + Text, + Spacer, + HStack, + Collapse, +} from "@chakra-ui/react"; +import { autocompletion } from "@codemirror/autocomplete"; +import { json } from "@codemirror/lang-json"; +import { oneDark } from "@codemirror/theme-one-dark"; +import CodeMirror, { lineNumbers } from "@uiw/react-codemirror"; +import React, { useState, useEffect } from "react"; + +type DagParams = { + configJson: string; + dagId: string; + logicalDate: string; + runId?: string; +}; + +type TriggerDAGFormProps = { + dagParams: DagParams; + onClose: () => void; + onTrigger: () => void; + setDagParams: React.Dispatch<React.SetStateAction<DagParams>>; +}; + +const TriggerDAGForm: React.FC<TriggerDAGFormProps> = ({ + dagParams, + onTrigger, + setDagParams, +}) => { + const [showDetails, setShowDetails] = useState(false); + + useEffect(() => { + try { + const prettyJson = JSON.stringify( + JSON.parse(dagParams.configJson), + undefined, + 2, + ); + + setDagParams((prev) => ({ ...prev, configJson: prettyJson })); + } catch { + // Invalid JSON handling + } + }, [dagParams.configJson, setDagParams]); + + const handleChange = ( + ele: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>, + ) => { + const { name, value } = ele.target; + + setDagParams((prev) => ({ ...prev, [name]: value })); + }; + + const handleReset = () => { + setDagParams({ + configJson: "{}", + dagId: dagParams.dagId, + logicalDate: "", + runId: "", + }); + }; + + const handleJsonChange = (value: string) => { + setDagParams((prev) => ({ ...prev, configJson: value })); + }; + + const isValidJson = () => { + try { + JSON.parse(dagParams.configJson); + + return true; + } catch { + return false; + } + }; + + return ( + <> + <ModalCloseButton /> + + <VStack align="stretch" p={5} spacing={2}> + <Button + onClick={() => setShowDetails(!showDetails)} + variant="outline" + width="full" + > + {showDetails ? "Hide Advance Options" : "Show Advance Options"} + </Button> + + <Collapse in={showDetails}> + <VStack align="stretch" spacing={3}> + <FormControl> + <FormLabel size="sm">Logical date</FormLabel> + <Input + name="logicalDate" + onChange={handleChange} + placeholder="yyyy-mm-ddThh:mm" + size="sm" + type="datetime-local" + value={dagParams.logicalDate} + /> + </FormControl> + + <FormControl> + <FormLabel size="sm">Run ID (Optional)</FormLabel> + <Input + name="runId" + onChange={handleChange} + placeholder="Autogenerated if left empty" + size="sm" + value={dagParams.runId} + /> + </FormControl> + + <FormControl> + <FormLabel size="sm">Configuration JSON</FormLabel> + <CodeMirror + extensions={[json(), autocompletion(), lineNumbers()]} + height="200px" + onChange={handleJsonChange} Review Comment: Yes, I edited most of them to codemirror, some functionalities is yet to do. Will add them under extension. -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org