This is an automated email from the ASF dual-hosted git repository.

bbovenzi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new fb2fd0ff1f7 Display plugin import errors in the UI (#49643)
fb2fd0ff1f7 is described below

commit fb2fd0ff1f7c9ab8bdce7b0df32e33b29402e913
Author: Pierre Jeambrun <[email protected]>
AuthorDate: Thu Apr 24 15:26:09 2025 +0200

    Display plugin import errors in the UI (#49643)
    
    * Display plugin import errors in the UI
    
    * Update following code review
    
    * Handle user without plugin access
---
 .../src/airflow/ui/src/components/ErrorAlert.tsx   |   2 +-
 .../pages/Dashboard/Stats/PluginImportErrors.tsx   |  86 +++++++++++++++
 .../Dashboard/Stats/PluginImportErrorsModal.tsx    | 115 +++++++++++++++++++++
 .../airflow/ui/src/pages/Dashboard/Stats/Stats.tsx |   3 +
 airflow-core/src/airflow/ui/src/pages/Plugins.tsx  |   9 +-
 5 files changed, 212 insertions(+), 3 deletions(-)

diff --git a/airflow-core/src/airflow/ui/src/components/ErrorAlert.tsx 
b/airflow-core/src/airflow/ui/src/components/ErrorAlert.tsx
index 06841c95453..475fb70315e 100644
--- a/airflow-core/src/airflow/ui/src/components/ErrorAlert.tsx
+++ b/airflow-core/src/airflow/ui/src/components/ErrorAlert.tsx
@@ -22,7 +22,7 @@ import type { HTTPExceptionResponse, HTTPValidationError } 
from "openapi-gen/req
 
 import { Alert } from "./ui";
 
-type ExpandedApiError = {
+export type ExpandedApiError = {
   body: HTTPExceptionResponse | HTTPValidationError | undefined;
 } & ApiError;
 
diff --git 
a/airflow-core/src/airflow/ui/src/pages/Dashboard/Stats/PluginImportErrors.tsx 
b/airflow-core/src/airflow/ui/src/pages/Dashboard/Stats/PluginImportErrors.tsx
new file mode 100644
index 00000000000..91596b8bba0
--- /dev/null
+++ 
b/airflow-core/src/airflow/ui/src/pages/Dashboard/Stats/PluginImportErrors.tsx
@@ -0,0 +1,86 @@
+/*!
+ * 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, Text, Button, useDisclosure, Skeleton } from "@chakra-ui/react";
+import { FiChevronRight } from "react-icons/fi";
+import { LuPlug } from "react-icons/lu";
+
+import { usePluginServiceImportErrors } from "openapi/queries";
+import { ErrorAlert, type ExpandedApiError } from "src/components/ErrorAlert";
+import { StateBadge } from "src/components/StateBadge";
+import { pluralize } from "src/utils";
+
+import { PluginImportErrorsModal } from "./PluginImportErrorsModal";
+
+export const PluginImportErrors = ({ iconOnly = false }: { readonly iconOnly?: 
boolean }) => {
+  const { onClose, onOpen, open } = useDisclosure();
+
+  const { data, error, isLoading } = usePluginServiceImportErrors();
+
+  const importErrorsCount = data?.total_entries ?? 0;
+  const importErrors = data?.import_errors ?? [];
+
+  if (isLoading) {
+    return <Skeleton height="9" width="225px" />;
+  }
+
+  if ((error as ExpandedApiError).status === 403) {
+    return undefined;
+  }
+
+  return (
+    <Box alignItems="center" display="flex" maxH="10px">
+      <ErrorAlert error={error} />
+      {importErrorsCount > 0 && (
+        <>
+          {iconOnly ? (
+            <StateBadge
+              as={Button}
+              colorPalette="failed"
+              height={7}
+              onClick={onOpen}
+              title={pluralize("Plugin Import Error", importErrorsCount)}
+            >
+              <LuPlug size="0.5rem" />
+              {importErrorsCount}
+            </StateBadge>
+          ) : (
+            <Button
+              alignItems="center"
+              borderRadius="md"
+              display="flex"
+              gap={2}
+              onClick={onOpen}
+              variant="outline"
+            >
+              <StateBadge colorPalette="failed">
+                <LuPlug />
+                {importErrorsCount}
+              </StateBadge>
+              <Box alignItems="center" display="flex" gap={1}>
+                <Text fontWeight="bold">Plugin Import Errors</Text>
+                <FiChevronRight />
+              </Box>
+            </Button>
+          )}
+          <PluginImportErrorsModal importErrors={importErrors} 
onClose={onClose} open={open} />
+        </>
+      )}
+    </Box>
+  );
+};
diff --git 
a/airflow-core/src/airflow/ui/src/pages/Dashboard/Stats/PluginImportErrorsModal.tsx
 
b/airflow-core/src/airflow/ui/src/pages/Dashboard/Stats/PluginImportErrorsModal.tsx
new file mode 100644
index 00000000000..0fc8b534438
--- /dev/null
+++ 
b/airflow-core/src/airflow/ui/src/pages/Dashboard/Stats/PluginImportErrorsModal.tsx
@@ -0,0 +1,115 @@
+/*!
+ * 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 { Heading, Text, HStack, Input } from "@chakra-ui/react";
+import { useEffect, useState } from "react";
+import { LuFileWarning } from "react-icons/lu";
+import { PiFilePy } from "react-icons/pi";
+
+import type { PluginImportErrorResponse } from "openapi/requests/types.gen";
+import { Accordion, Dialog } from "src/components/ui";
+import { Pagination } from "src/components/ui/Pagination";
+
+type PluginImportErrorsModalProps = {
+  importErrors: Array<PluginImportErrorResponse>;
+  onClose: () => void;
+  open: boolean;
+};
+
+const PAGE_LIMIT = 15;
+
+export const PluginImportErrorsModal: React.FC<PluginImportErrorsModalProps> = 
({
+  importErrors,
+  onClose,
+  open,
+}) => {
+  const [page, setPage] = useState(1);
+  const [searchQuery, setSearchQuery] = useState("");
+  const [filteredErrors, setFilteredErrors] = useState(importErrors);
+
+  const startRange = (page - 1) * PAGE_LIMIT;
+  const endRange = startRange + PAGE_LIMIT;
+  const visibleItems = filteredErrors.slice(startRange, endRange);
+
+  const onOpenChange = () => {
+    setSearchQuery("");
+    setPage(1);
+    onClose();
+  };
+
+  useEffect(() => {
+    const query = searchQuery.toLowerCase();
+    const filtered = importErrors.filter((error) => 
error.source.toLowerCase().includes(query));
+
+    setFilteredErrors(filtered);
+    setPage(1);
+  }, [searchQuery, importErrors]);
+
+  return (
+    <Dialog.Root onOpenChange={onOpenChange} open={open} 
scrollBehavior="inside" size="xl">
+      <Dialog.Content backdrop>
+        <Dialog.Header>
+          <HStack fontSize="xl">
+            <LuFileWarning />
+            <Heading>Plugin Import Errors</Heading>
+          </HStack>
+          <Input
+            mt={4}
+            onChange={(event) => setSearchQuery(event.target.value)}
+            placeholder="Search by file"
+            value={searchQuery}
+          />
+        </Dialog.Header>
+
+        <Dialog.CloseTrigger />
+
+        <Dialog.Body>
+          <Accordion.Root collapsible multiple size="md" variant="enclosed">
+            {visibleItems.map((importError) => (
+              <Accordion.Item key={importError.error} 
value={importError.source}>
+                <Accordion.ItemTrigger cursor="pointer">
+                  <PiFilePy />
+                  {importError.source}
+                </Accordion.ItemTrigger>
+                <Accordion.ItemContent>
+                  <Text color="fg.error" fontSize="sm" whiteSpace="pre-wrap">
+                    <code>{importError.error}</code>
+                  </Text>
+                </Accordion.ItemContent>
+              </Accordion.Item>
+            ))}
+          </Accordion.Root>
+        </Dialog.Body>
+
+        <Pagination.Root
+          count={filteredErrors.length}
+          onPageChange={(event) => setPage(event.page)}
+          p={4}
+          page={page}
+          pageSize={PAGE_LIMIT}
+        >
+          <HStack>
+            <Pagination.PrevTrigger />
+            <Pagination.Items />
+            <Pagination.NextTrigger />
+          </HStack>
+        </Pagination.Root>
+      </Dialog.Content>
+    </Dialog.Root>
+  );
+};
diff --git a/airflow-core/src/airflow/ui/src/pages/Dashboard/Stats/Stats.tsx 
b/airflow-core/src/airflow/ui/src/pages/Dashboard/Stats/Stats.tsx
index 085a348fa7a..fc7ae1b7ec8 100644
--- a/airflow-core/src/airflow/ui/src/pages/Dashboard/Stats/Stats.tsx
+++ b/airflow-core/src/airflow/ui/src/pages/Dashboard/Stats/Stats.tsx
@@ -22,6 +22,7 @@ import { FiClipboard, FiZap } from "react-icons/fi";
 import { useDagServiceGetDags } from "openapi/queries";
 
 import { DAGImportErrors } from "./DAGImportErrors";
+import { PluginImportErrors } from "./PluginImportErrors";
 import { StatsCard } from "./StatsCard";
 
 export const Stats = () => {
@@ -67,6 +68,8 @@ export const Stats = () => {
 
         <DAGImportErrors />
 
+        <PluginImportErrors />
+
         {queuedDagsCount > 0 ? (
           <StatsCard
             colorScheme="queued"
diff --git a/airflow-core/src/airflow/ui/src/pages/Plugins.tsx 
b/airflow-core/src/airflow/ui/src/pages/Plugins.tsx
index f378d5bf930..a97c1e9fb82 100644
--- a/airflow-core/src/airflow/ui/src/pages/Plugins.tsx
+++ b/airflow-core/src/airflow/ui/src/pages/Plugins.tsx
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import { Box, Heading } from "@chakra-ui/react";
+import { Box, Heading, HStack } from "@chakra-ui/react";
 import type { ColumnDef } from "@tanstack/react-table";
 
 import { usePluginServiceGetPlugins } from "openapi/queries";
@@ -24,6 +24,8 @@ import type { PluginResponse } from 
"openapi/requests/types.gen";
 import { DataTable } from "src/components/DataTable";
 import { ErrorAlert } from "src/components/ErrorAlert";
 
+import { PluginImportErrors } from "./Dashboard/Stats/PluginImportErrors";
+
 const columns: Array<ColumnDef<PluginResponse>> = [
   {
     accessorKey: "name",
@@ -42,7 +44,10 @@ export const Plugins = () => {
 
   return (
     <Box p={2}>
-      <Heading>Plugins</Heading>
+      <HStack>
+        <Heading>Plugins</Heading>
+        <PluginImportErrors iconOnly />
+      </HStack>
       <DataTable
         columns={columns}
         data={data?.plugins ?? []}

Reply via email to