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


##########
airflow-core/src/airflow/ui/src/i18n/locales/de/common.json:
##########
@@ -63,6 +63,11 @@
   },
   "duration": "Laufzeit",
   "endDate": "Enddatum",
+  "expand": {
+    "collapse": "Einklappen",
+    "expand": "Erweitern",
+    "tooltip": "Drücken Sie {{hotkey}}, um zu erweitern"
+  },

Review Comment:
   Just fill the english translations (because those are the one we can 
approve) and let the other translation owners update their respective files in 
follow up PRs.



##########
airflow-core/src/airflow/ui/src/queries/useLogs.tsx:
##########
@@ -95,40 +94,72 @@ const parseLogs = ({
     return { data, warning };
   }
 
-  // TODO: Add support for nested groups
-
-  parsedLines = parsedLines.map((line) => {
-    const text = innerText(line);
-
-    if (text.includes("::group::") && !startGroup) {
-      startGroup = true;
-      groupName = text.split("::group::")[1] as string;
-    } else if (text.includes("::endgroup::")) {
-      startGroup = false;
-      const group = (
-        <details key={groupName} open={open} style={{ width: "100%" }}>
-          <summary data-testid={`summary-${groupName}`}>
-            <chakra.span color="fg.info" cursor="pointer">
-              {groupName}
-            </chakra.span>
-          </summary>
-          {groupLines}
-        </details>
-      );
-
-      groupLines = [];
-
-      return group;
-    }
+  parsedLines = (() => {
+    type Group = { level: number; lines: Array<JSX.Element | "">; name: string 
};
+    const groupStack: Array<Group> = [];
+    const result: Array<JSX.Element | ""> = [];
+
+    parsedLines.forEach((line) => {
+      const text = innerText(line);
+
+      if (text.includes("::group::")) {
+        const groupName = text.split("::group::")[1] as string;
+
+        groupStack.push({ level: groupStack.length, lines: [], name: groupName 
});
+
+        return;
+      }
 
-    if (startGroup) {
-      groupLines.push(line);
+      if (text.includes("::endgroup::")) {
+        const finishedGroup = groupStack.pop();
+
+        if (finishedGroup) {
+          const groupElement = (
+            <Box key={finishedGroup.name + Math.random()} mb={2} 
pl={finishedGroup.level * 2}>
+              <details open={open} style={{ width: "100%" }}>
+                <summary data-testid={`summary-${finishedGroup.name}`}>
+                  <chakra.span color="fg.info" cursor="pointer">
+                    {finishedGroup.name}
+                  </chakra.span>
+                </summary>
+                {finishedGroup.lines}
+              </details>
+            </Box>
+          );
+
+          const lastGroup = groupStack[groupStack.length - 1];
+
+          if (groupStack.length > 0 && lastGroup) {
+            lastGroup.lines.push(groupElement);
+          } else {
+            result.push(groupElement);
+          }
+        }
 
-      return undefined;
-    } else {
-      return line;
+        return;
+      }
+
+      if (groupStack.length > 0 && groupStack[groupStack.length - 1]) {
+        groupStack[groupStack.length - 1]?.lines.push(line);
+      } else {
+        result.push(line);
+      }
+    });
+
+    while (groupStack.length > 0) {
+      const unfinished = groupStack.pop();
+
+      if (unfinished) {
+        result.push(
+          <Box key={unfinished.name + Math.random()} mb={2} 
pl={unfinished.level * 2}>

Review Comment:
   Same



##########
airflow-core/src/airflow/ui/src/queries/useLogs.tsx:
##########
@@ -95,40 +94,72 @@ const parseLogs = ({
     return { data, warning };
   }
 
-  // TODO: Add support for nested groups
-
-  parsedLines = parsedLines.map((line) => {
-    const text = innerText(line);
-
-    if (text.includes("::group::") && !startGroup) {
-      startGroup = true;
-      groupName = text.split("::group::")[1] as string;
-    } else if (text.includes("::endgroup::")) {
-      startGroup = false;
-      const group = (
-        <details key={groupName} open={open} style={{ width: "100%" }}>
-          <summary data-testid={`summary-${groupName}`}>
-            <chakra.span color="fg.info" cursor="pointer">
-              {groupName}
-            </chakra.span>
-          </summary>
-          {groupLines}
-        </details>
-      );
-
-      groupLines = [];
-
-      return group;
-    }
+  parsedLines = (() => {
+    type Group = { level: number; lines: Array<JSX.Element | "">; name: string 
};
+    const groupStack: Array<Group> = [];
+    const result: Array<JSX.Element | ""> = [];
+
+    parsedLines.forEach((line) => {
+      const text = innerText(line);
+
+      if (text.includes("::group::")) {
+        const groupName = text.split("::group::")[1] as string;
+
+        groupStack.push({ level: groupStack.length, lines: [], name: groupName 
});
+
+        return;
+      }
 
-    if (startGroup) {
-      groupLines.push(line);
+      if (text.includes("::endgroup::")) {
+        const finishedGroup = groupStack.pop();
+
+        if (finishedGroup) {
+          const groupElement = (
+            <Box key={finishedGroup.name + Math.random()} mb={2} 
pl={finishedGroup.level * 2}>

Review Comment:
   Don't push a random number on the key, that defeats the purpose keys and 
react diffing between renders.



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