yuseok89 commented on code in PR #76018:
URL: https://github.com/apache/airflow/pull/76018#discussion_r4424616155


##########
airflow-core/src/airflow/ui/src/components/FlexibleForm/parseArrayElement.ts:
##########
@@ -0,0 +1,62 @@
+/*!
+ * 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.
+ */
+
+export type ArrayElement = boolean | number | string;
+
+/**
+ * Parse one typed-in entry to the element type from `items.type`; `undefined` 
means invalid.
+ * Without an `items.type`, JSON primitives keep their type ("1" stays a 
number) and
+ * everything else is taken as a string.
+ */
+export const parseArrayElement = (raw: string, itemsType: unknown): 
ArrayElement | undefined => {
+  const text = raw.trim();
+
+  if (text === "") {
+    return undefined;
+  }
+  switch (itemsType) {
+    case "boolean":
+      return text === "true" || text === "false" ? text === "true" : undefined;
+    case "integer": {
+      const num = Number(text);
+
+      return Number.isInteger(num) ? num : undefined;
+    }
+    case "number": {
+      const num = Number(text);
+
+      return Number.isFinite(num) ? num : undefined;
+    }
+    case "string":
+      return text;
+    default: {
+      try {
+        const parsed = JSON.parse(text) as unknown;

Review Comment:
   Just a note. Number-like entries in untyped arrays can change unexpectedly 
here, and users might not realize they need quotes to keep an entry as a string.
   
   - `3.10` becomes `3.1`
   - `12345678901234567890` becomes `12345678901234567000`



##########
airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldArray.tsx:
##########
@@ -0,0 +1,138 @@
+/*!
+ * 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 { useState, type ClipboardEvent, type KeyboardEvent } from "react";
+
+import { CreatableSelect, type MultiValue } from "chakra-react-select";
+import { useTranslation } from "react-i18next";
+
+import { paramPlaceholder, useParamStore } from "src/queries/useParamStore";
+
+import type { FlexibleFormElementProps } from ".";
+import { parseArrayElement, type ArrayElement } from "./parseArrayElement";
+
+type ChipOption = { label: string; value: ArrayElement };
+
+const toChip = (value: ArrayElement): ChipOption => ({ label: String(value), 
value });

Review Comment:
   It looks like removing one of two chips with the same value drops both from 
the value, while the screen still shows one of them.



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