Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions airflow-core/src/airflow/ui/src/components/UIAlertAccordion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*!
* 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 { Accordion } from "@chakra-ui/react";
import ReactMarkdown from "react-markdown";

import type { UIAlert } from "openapi/requests/types.gen";
import { Alert } from "src/components/ui";
import { useConfig } from "src/queries/useConfig";

export const UIAlertAccordion = () => {
const alerts = useConfig("dashboard_alert") as Array<UIAlert>;

if (alerts.length === 0) {
return undefined;
}

return (
<Accordion.Root collapsible defaultValue={["ui_alerts"]}>
<Accordion.Item key="ui_alerts" value="ui_alerts">
{alerts.map((alert: UIAlert, index) =>
index === 0 ? (
<Accordion.ItemTrigger key={alert.text} mb={2}>
<Alert status={alert.category}>
<ReactMarkdown>{alert.text}</ReactMarkdown>
</Alert>
{alerts.length > 1 && <Accordion.ItemIndicator />}
</Accordion.ItemTrigger>
) : (
<Accordion.ItemContent key={alert.text} mb={4} pr={8}>
<Alert status={alert.category}>
<ReactMarkdown>{alert.text}</ReactMarkdown>
</Alert>
</Accordion.ItemContent>
),
)}
</Accordion.Item>
</Accordion.Root>
);
};
2 changes: 2 additions & 0 deletions airflow-core/src/airflow/ui/src/pages/Dag/Dag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useParams } from "react-router-dom";
import { useDagServiceGetDagDetails, useDagsServiceRecentDagRuns } from "openapi/queries";
import type { DAGWithLatestDagRunsResponse } from "openapi/requests/types.gen";
import { TaskIcon } from "src/assets/TaskIcon";
import { UIAlertAccordion } from "src/components/UIAlertAccordion";
import { DetailsLayout } from "src/layouts/Details/DetailsLayout";
import { isStatePending, useAutoRefresh } from "src/utils";

Expand Down Expand Up @@ -80,6 +81,7 @@ export const Dag = () => {

return (
<ReactFlowProvider>
<UIAlertAccordion />
<DetailsLayout
dag={dag}
error={error ?? runsError}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@
*/
import "@testing-library/jest-dom";
import { render, screen, waitFor } from "@testing-library/react";
import { describe, it, expect } from "vitest";
import { describe, it, expect, vi, beforeEach } from "vitest";

import * as configHooks from "src/queries/useConfig";
import { AppWrapper } from "src/utils/AppWrapper";

describe("Dag Filters", () => {
beforeEach(() => {
vi.spyOn(configHooks, "useConfig").mockImplementation((key) => {
if (key === "dashboard_alert") {
return [];
}

return false;
});
});

it("Filter by selected last run state", async () => {
render(<AppWrapper initialEntries={["/dags"]} />);

Expand Down
78 changes: 41 additions & 37 deletions airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { ErrorAlert } from "src/components/ErrorAlert";
import { SearchBar } from "src/components/SearchBar";
import { TogglePause } from "src/components/TogglePause";
import TriggerDAGButton from "src/components/TriggerDag/TriggerDAGButton";
import { UIAlertAccordion } from "src/components/UIAlertAccordion";
import { SearchParamsKeys, type SearchParamsKeysType } from "src/constants/searchParams";
import { DagsLayout } from "src/layouts/DagsLayout";
import { useConfig } from "src/queries/useConfig";
Expand Down Expand Up @@ -231,43 +232,46 @@ export const DagsList = () => {
);

return (
<DagsLayout>
<VStack alignItems="none">
<SearchBar
buttonProps={{ disabled: true }}
defaultValue={dagDisplayNamePattern ?? ""}
onChange={handleSearchChange}
placeHolder="Search Dags"
/>
<DagsFilters />
<HStack justifyContent="space-between">
<HStack>
<Heading py={3} size="md">
{pluralize("Dag", data.total_entries)}
</Heading>
<DAGImportErrors iconOnly />
<>
<UIAlertAccordion />
<DagsLayout>
<VStack alignItems="none">
<SearchBar
buttonProps={{ disabled: true }}
defaultValue={dagDisplayNamePattern ?? ""}
onChange={handleSearchChange}
placeHolder="Search Dags"
/>
<DagsFilters />
<HStack justifyContent="space-between">
<HStack>
<Heading py={3} size="md">
{pluralize("Dag", data.total_entries)}
</Heading>
<DAGImportErrors iconOnly />
</HStack>
{display === "card" ? (
<SortSelect handleSortChange={handleSortChange} orderBy={orderBy} />
) : undefined}
</HStack>
{display === "card" ? (
<SortSelect handleSortChange={handleSortChange} orderBy={orderBy} />
) : undefined}
</HStack>
</VStack>
<ToggleTableDisplay display={display} setDisplay={setDisplay} />
<Box overflow="auto">
<DataTable
cardDef={cardDef}
columns={columns}
data={data.dags}
displayMode={display}
errorMessage={<ErrorAlert error={error} />}
initialState={tableURLState}
isLoading={isLoading}
modelName="Dag"
onStateChange={setTableURLState}
skeletonCount={display === "card" ? 5 : undefined}
total={data.total_entries}
/>
</Box>
</DagsLayout>
</VStack>
<ToggleTableDisplay display={display} setDisplay={setDisplay} />
<Box overflow="auto">
<DataTable
cardDef={cardDef}
columns={columns}
data={data.dags}
displayMode={display}
errorMessage={<ErrorAlert error={error} />}
initialState={tableURLState}
isLoading={isLoading}
modelName="Dag"
onStateChange={setTableURLState}
skeletonCount={display === "card" ? 5 : undefined}
total={data.total_entries}
/>
</Box>
</DagsLayout>
</>
);
};
67 changes: 20 additions & 47 deletions airflow-core/src/airflow/ui/src/pages/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,30 @@
*/
import { Box, Heading, VStack } from "@chakra-ui/react";

import type { UIAlert } from "openapi/requests/types.gen";
import ReactMarkdown from "src/components/ReactMarkdown";
import { Accordion, Alert } from "src/components/ui";
import { useConfig } from "src/queries/useConfig";
import { UIAlertAccordion } from "src/components/UIAlertAccordion";

import { Health } from "./Health";
import { HistoricalMetrics } from "./HistoricalMetrics";
import { PoolSummary } from "./PoolSummary";
import { Stats } from "./Stats";

export const Dashboard = () => {
const alerts = useConfig("dashboard_alert") as Array<UIAlert>;

return (
<Box overflow="auto" px={4}>
<VStack alignItems="start">
{alerts.length > 0 ? (
<Accordion.Root collapsible defaultValue={["ui_alerts"]}>
<Accordion.Item key="ui_alerts" value="ui_alerts">
{alerts.map((alert: UIAlert, index) =>
index === 0 ? (
<Accordion.ItemTrigger key={alert.text} mb={2}>
<Alert status={alert.category}>
<ReactMarkdown>{alert.text}</ReactMarkdown>
</Alert>
</Accordion.ItemTrigger>
) : (
<Accordion.ItemContent key={alert.text} pr={8}>
<Alert status={alert.category}>
<ReactMarkdown>{alert.text}</ReactMarkdown>
</Alert>
</Accordion.ItemContent>
),
)}
</Accordion.Item>
</Accordion.Root>
) : undefined}
<Heading mb={2} size="2xl">
Welcome
</Heading>
</VStack>
<Box>
<Stats />
</Box>
<Box display="flex" gap={8} mt={8}>
<Health />
<PoolSummary />
</Box>
<Box mt={8}>
<HistoricalMetrics />
</Box>
export const Dashboard = () => (
<Box overflow="auto" px={4}>
<VStack alignItems="start">
<UIAlertAccordion />
<Heading mb={2} size="2xl">
Welcome
</Heading>
</VStack>
<Box>
<Stats />
</Box>
<Box display="flex" gap={8} mt={8}>
<Health />
<PoolSummary />
</Box>
<Box mt={8}>
<HistoricalMetrics />
</Box>
);
};
</Box>
);