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


##########
airflow/ui/src/pages/Provider.tsx:
##########
@@ -0,0 +1,107 @@
+/*!
+ * 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 { Box, Heading, Link, Table } from "@chakra-ui/react";
+
+import { useProviderServiceGetProviders } from "openapi/queries";
+
+const embedLinks = (text: string) => {
+  const regexUrl = /https?:\/\/[^\s)]+/gu;
+  const regexSourceAndUrl = 
/(?<source>(?:\(*[A-Z][\w.]*\)*\s+)+)(?<url>https?:\/\/[^\s)]+)/gu;
+  const hasManySources = text.includes("including") || text.includes("and") || 
text.includes("the");
+  const matches = hasManySources ? text.match(regexSourceAndUrl) : 
text.match(regexUrl);
+
+  if (!matches) {
+    return text;
+  }
+
+  if (hasManySources) {
+    const flatMatches = matches.flatMap((item) => {
+      const url = item.match(regexUrl)?.[0] ?? "";
+      const source = item.replace(url, "");
+
+      return [source, url];
+    });
+    const splitText = text.split(regexSourceAndUrl);
+
+    const renderText = [];
+    let matchIndex = 0;
+
+    for (let curIndex = 0; curIndex < splitText.length; curIndex += 1) {
+      if (flatMatches[matchIndex] !== undefined && flatMatches[matchIndex] === 
splitText[curIndex]) {
+        const source = flatMatches[matchIndex];
+        const url = flatMatches[matchIndex + 1];
+
+        renderText.push(
+          <Link color="fg.info" href={url} rel="noopener noreferrer" 
target="_blank">
+            {source}
+          </Link>,
+        );
+        matchIndex += 2;
+        curIndex += 2;
+      }
+      renderText.push(splitText[curIndex]);
+    }
+
+    return renderText;
+  }
+
+  return (
+    <Link color="fg.info" href={matches[0]} rel="noopener noreferrer" 
target="_blank">
+      {text.replace(matches[0], "").trim()}
+    </Link>
+  );
+};
+
+export const Provider = () => {
+  const { data } = useProviderServiceGetProviders();
+
+  return (
+    <Box p={2}>
+      <Heading>Providers</Heading>
+      <Table.Root striped>
+        <Table.Header>
+          <Table.Row>
+            <Table.ColumnHeader>Package Name</Table.ColumnHeader>
+            <Table.ColumnHeader>Version</Table.ColumnHeader>
+            <Table.ColumnHeader>Description</Table.ColumnHeader>
+          </Table.Row>
+        </Table.Header>
+        <Table.Body>
+          {data?.providers.map((provider) => (
+            <Table.Row key={provider.package_name}>
+              <Table.Cell>
+                <Link
+                  aria-label={provider.package_name}
+                  color="fg.info"
+                  
href={`https://airflow.apache.org/docs/${provider.package_name}/${provider.version}/`}
+                  rel="noopener noreferrer"
+                  target="_blank"
+                >
+                  {provider.package_name}
+                </Link>
+              </Table.Cell>
+              <Table.Cell>{provider.version}</Table.Cell>
+              <Table.Cell>{embedLinks(provider.description)}</Table.Cell>

Review Comment:
   Or maybe just replace the url by a clickable link, without merging the 'url' 
into the source. I think it makes it overly complicated. But it looks nice and 
we can keep it like this.



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