pierrejeambrun commented on code in PR #53657:
URL: https://github.com/apache/airflow/pull/53657#discussion_r2248385782


##########
airflow-core/src/airflow/ui/src/utils/detectLanguage.ts:
##########
@@ -0,0 +1,90 @@
+/*!
+ * 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 { Parser } from "node-sql-parser";
+import { parse as parseYaml } from "yaml";
+
+export const detectLanguage = (value: string): string => {
+  const trimmed = value.trim();
+
+  // Try to detect JSON
+  if (
+    (trimmed.startsWith("{") && trimmed.endsWith("}")) ||
+    (trimmed.startsWith("[") && trimmed.endsWith("]"))
+  ) {

Review Comment:
   I would remove that check, Just try parsing it if it's not valid, then it's 
not json



##########
airflow-core/src/airflow/ui/src/pages/TaskInstance/RenderedTemplates.tsx:
##########
@@ -32,20 +46,42 @@ export const RenderedTemplates = () => {
     taskId,
   });
 
+  const style = colorMode === "dark" ? oneDark : oneLight;
+
   return (
     <Box p={2}>
       <Table.Root striped>
         <Table.Body>
           {Object.entries(taskInstance?.rendered_fields ?? {}).map(([key, 
value]) => {
             if (value !== null && value !== undefined) {
-              const renderedValue = JSON.stringify(value);
+              const renderedValue = typeof value === "string" ? value : 
JSON.stringify(value);
+              const language = detectLanguage(renderedValue);
 
               return (
                 <Table.Row key={key}>
                   <Table.Cell>{key}</Table.Cell>
                   <Table.Cell>
-                    <HStack>
-                      <Code>{renderedValue}</Code>
+                    <HStack alignItems="flex-start">
+                      <Box
+                        css={{
+                          "& pre": {
+                            borderRadius: "4px",
+                            fontSize: "14px",
+                            margin: 0,
+                            padding: "8px",
+                          },
+                        }}
+                        flex="1"

Review Comment:
   Can we not use such inline css, and style the appropriate component. Also 
chakraUI provide some default value for padding marging etc, that are 1,2,3,4,5 
and translate to fix values in pixels for consitency accross the UI.



##########
airflow-core/src/airflow/ui/src/utils/detectLanguage.ts:
##########
@@ -0,0 +1,90 @@
+/*!
+ * 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 { Parser } from "node-sql-parser";
+import { parse as parseYaml } from "yaml";
+
+export const detectLanguage = (value: string): string => {
+  const trimmed = value.trim();
+
+  // Try to detect JSON
+  if (
+    (trimmed.startsWith("{") && trimmed.endsWith("}")) ||
+    (trimmed.startsWith("[") && trimmed.endsWith("]"))
+  ) {
+    try {
+      JSON.parse(trimmed);
+
+      return "json";
+    } catch {
+      // Not valid JSON, continue
+    }
+  }
+
+  // Try to detect YAML by parsing
+  try {
+    // Basic heuristics first - must contain colons or dashes for key-value 
pairs or lists
+    if (trimmed.includes(":") || trimmed.includes("- ")) {
+      parseYaml(trimmed);
+
+      // If parsing succeeds and it's not just a simple string, it's likely 
YAML
+      return "yaml";
+    }
+  } catch {
+    // Not valid YAML, continue to other checks
+  }

Review Comment:
   Same here



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

Reply via email to