parkhojeong commented on code in PR #65469:
URL: https://github.com/apache/airflow/pull/65469#discussion_r3247497390


##########
airflow-core/tests/unit/serialization/definitions/test_param.py:
##########


Review Comment:
   Should these test `SerializedParam.resolve()` instead? This file is for 
serialization params, but the new cases currently
     exercise SDK `Param`.



##########
airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDuration.tsx:
##########


Review Comment:
   Should we also update `airflow-core/docs/core-concepts/params.rst` to 
document format="duration" in the supported string formats list?



##########
airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDuration.tsx:
##########
@@ -0,0 +1,70 @@
+/*!
+ * 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 } from "@chakra-ui/react";
+import { parse } from "iso8601-duration";
+import { useTranslation } from "react-i18next";
+
+import { paramPlaceholder, useParamStore } from "src/queries/useParamStore";
+
+import type { FlexibleFormElementProps } from ".";
+
+export const FieldDuration = ({ name, namespace = "default", onUpdate }: 
FlexibleFormElementProps) => {
+  const { t: translate } = useTranslation("components");
+  const { disabled, paramsDict, setParamsDict } = useParamStore(namespace);
+  const param = paramsDict[name] ?? paramPlaceholder;
+  const handleChange = (value: string) => {
+    const isEmpty = value === "";
+    const parsedValue = value.replaceAll(",", ".");
+
+    if (paramsDict[name]) {
+      setParamsDict({
+        ...paramsDict,
+        [name]: {
+          ...paramsDict[name],
+          value: isEmpty ? null : value,
+        },
+      });
+    }
+    if (isEmpty) {
+      onUpdate(value);
+
+      return;
+    }
+    try {
+      parse(parsedValue);
+      onUpdate(parsedValue);
+    } catch {
+      onUpdate(undefined, translate("flexibleForm.validationErrorDuration"));

Review Comment:
   Both `asdfasbasabsa` and `PT15M21312312321` are invalid duration values, but 
they show different errors under the input. Should they use the same validation 
error message?
   
   <img width="853" height="1062" alt="Image" 
src="https://github.com/user-attachments/assets/1ddf995f-3fdf-49ec-b113-6b1ea4edd109";
 />
   
   <img width="851" height="1082" alt="Image" 
src="https://github.com/user-attachments/assets/a9117a65-1472-4ad9-bbdb-5790e9b67bcc";
 />



##########
airflow-core/src/airflow/serialization/definitions/param.py:
##########
@@ -56,11 +56,16 @@ def resolve(self, *, raises: bool = False) -> Any:
             default. They are only raised if this is set to *True* instead.
         """
         import jsonschema
+        from jsonschema import FormatChecker
 
         try:
             if not is_arg_set(value := self.value):
                 raise ValueError("No value passed")
-            jsonschema.validate(value, self.schema, 
format_checker=jsonschema.FormatChecker())
+            jsonschema.validate(
+                value,
+                self.schema,
+                format_checker=FormatChecker(),
+            )

Review Comment:
   Nit: why do we import FormatChecker here? Also, validate still does not seem 
to be imported.



##########
airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDuration.tsx:
##########
@@ -0,0 +1,70 @@
+/*!
+ * 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 } from "@chakra-ui/react";
+import { parse } from "iso8601-duration";
+import { useTranslation } from "react-i18next";
+
+import { paramPlaceholder, useParamStore } from "src/queries/useParamStore";
+
+import type { FlexibleFormElementProps } from ".";
+
+export const FieldDuration = ({ name, namespace = "default", onUpdate }: 
FlexibleFormElementProps) => {
+  const { t: translate } = useTranslation("components");
+  const { disabled, paramsDict, setParamsDict } = useParamStore(namespace);
+  const param = paramsDict[name] ?? paramPlaceholder;
+  const handleChange = (value: string) => {
+    const isEmpty = value === "";
+    const parsedValue = value.replaceAll(",", ".");
+
+    if (paramsDict[name]) {
+      setParamsDict({
+        ...paramsDict,
+        [name]: {
+          ...paramsDict[name],
+          value: isEmpty ? null : value,
+        },
+      });
+    }
+    if (isEmpty) {
+      onUpdate(value);
+
+      return;
+    }
+    try {
+      parse(parsedValue);
+      onUpdate(parsedValue);
+    } catch {
+      onUpdate(undefined, translate("flexibleForm.validationErrorDuration"));
+    }

Review Comment:
   Can we test this branch? Since `parse(parsedValue)` is used only for 
validation, we should cover valid, invalid, and normalized comma input.



##########
airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldSelector.tsx:
##########
@@ -127,6 +131,8 @@ export const FieldSelector = ({ name, namespace = 
"default", onUpdate }: Flexibl
     return <FieldObject name={name} namespace={namespace} onUpdate={onUpdate} 
/>;
   } else if (isFieldNumber(fieldType)) {
     return <FieldNumber name={name} namespace={namespace} onUpdate={onUpdate} 
/>;
+  } else if (isFieldDuration(fieldType, param.schema)) {
+    return <FieldDuration name={name} namespace={namespace} 
onUpdate={onUpdate} />;

Review Comment:
    Nit: should `isFieldDuration` live next to the time checks (`date`, 
`date-time`, `time`) so all time fields are grouped together?



##########
airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDuration.tsx:
##########
@@ -0,0 +1,70 @@
+/*!
+ * 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 } from "@chakra-ui/react";
+import { parse } from "iso8601-duration";
+import { useTranslation } from "react-i18next";
+
+import { paramPlaceholder, useParamStore } from "src/queries/useParamStore";
+
+import type { FlexibleFormElementProps } from ".";
+
+export const FieldDuration = ({ name, namespace = "default", onUpdate }: 
FlexibleFormElementProps) => {
+  const { t: translate } = useTranslation("components");
+  const { disabled, paramsDict, setParamsDict } = useParamStore(namespace);
+  const param = paramsDict[name] ?? paramPlaceholder;
+  const handleChange = (value: string) => {
+    const isEmpty = value === "";
+    const parsedValue = value.replaceAll(",", ".");

Review Comment:
   Do we need comma-to-dot normalization here? If we keep it, can we keep 
stored/displayed and submitted values consistent, with a test for comma decimal 
input?



-- 
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]

Reply via email to