From 4ed4f027ea30f3dada65dca150236d588f308060 Mon Sep 17 00:00:00 2001 From: shubhamraj-git Date: Thu, 24 Oct 2024 02:45:00 +0530 Subject: [PATCH 01/39] Initial draft --- .../ui/src/components/DataTable/TriggerDAG.ts | 30 ++++ .../components/DataTable/TriggerDAGForm.tsx | 170 ++++++++++++++++++ .../components/DataTable/TriggerDAGModal.tsx | 107 +++++++++++ airflow/ui/src/pages/DagsList/DagCard.tsx | 5 + airflow/ui/src/pages/DagsList/DagsList.tsx | 12 ++ 5 files changed, 324 insertions(+) create mode 100644 airflow/ui/src/components/DataTable/TriggerDAG.ts create mode 100644 airflow/ui/src/components/DataTable/TriggerDAGForm.tsx create mode 100644 airflow/ui/src/components/DataTable/TriggerDAGModal.tsx diff --git a/airflow/ui/src/components/DataTable/TriggerDAG.ts b/airflow/ui/src/components/DataTable/TriggerDAG.ts new file mode 100644 index 0000000000000..1147ededb6438 --- /dev/null +++ b/airflow/ui/src/components/DataTable/TriggerDAG.ts @@ -0,0 +1,30 @@ +/*! + * 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. + */ + +type DagParams = { + configJson: string; + dagId: string; + logicalDate: string; + runId?: string; +}; + +export const TriggerDAG = (dagParams: DagParams) => { + // TODO triggering logic + console.log("Triggering DAG with parameters:", dagParams); +}; diff --git a/airflow/ui/src/components/DataTable/TriggerDAGForm.tsx b/airflow/ui/src/components/DataTable/TriggerDAGForm.tsx new file mode 100644 index 0000000000000..e9b7f3573132e --- /dev/null +++ b/airflow/ui/src/components/DataTable/TriggerDAGForm.tsx @@ -0,0 +1,170 @@ +/*! + * 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, + Textarea, + VStack, + ModalCloseButton, + Button, + ModalFooter, + Checkbox, + Box, + Text, + Spacer, + HStack, +} from "@chakra-ui/react"; +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>; +}; + +const TriggerDAGForm: React.FC = ({ + dagParams, + onClose, + onTrigger, + setDagParams, +}) => { + const [validateJson, setValidateJson] = useState(false); // State to track checkbox + + // Format the JSON in a pretty way whenever the configJson changes + useEffect(() => { + if (validateJson && dagParams.configJson) { + try { + const prettyJson = JSON.stringify( + JSON.parse(dagParams.configJson), + null, + 2, + ); // Pretty JSON formatting + + setDagParams((prev) => ({ ...prev, configJson: prettyJson })); + } catch { + // Do nothing if it's invalid; handle validation separately + } + } + }, [dagParams.configJson, validateJson, setDagParams]); + + const handleChange = ( + ele: React.ChangeEvent, + ) => { + const { name, value } = ele.target; + + setDagParams((prev) => ({ ...prev, [name]: value })); + }; + + const handleCheckboxChange = (ele: React.ChangeEvent) => { + setValidateJson(ele.target.checked); + }; + + const isValidJson = () => { + try { + JSON.parse(dagParams.configJson); + + return true; + } catch { + return false; + } + }; + + return ( + <> + + + + + Logical date + + + + + Run ID (Optional) + + + + + Configuration JSON +