Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 16 additions & 2 deletions airflow-core/src/airflow/ui/src/layouts/Nav/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
import { Box, Flex, VStack, useDisclosure } from "@chakra-ui/react";

/* eslint-disable i18next/no-literal-string */
import { Box, Button, Flex, VStack, useDisclosure } from "@chakra-ui/react";
import { useTranslation } from "react-i18next";
import { FiDatabase, FiHome, FiClock } from "react-icons/fi";
import { Link } from "react-router-dom";
Expand All @@ -29,6 +31,7 @@ import {
import type { ExternalViewResponse } from "openapi/requests/types.gen";
import { AirflowPin } from "src/assets/AirflowPin";
import { DagIcon } from "src/assets/DagIcon";
import { toaster } from "src/components/ui";
import { useTimezone } from "src/context/timezone";
import { getTimezoneOffsetString, getTimezoneTooltipLabel } from "src/utils/datetimeUtils";
import type { NavItemResponse } from "src/utils/types";
Expand All @@ -43,6 +46,16 @@ import { SecurityButton } from "./SecurityButton";
import TimezoneModal from "./TimezoneModal";
import { UserSettingsButton } from "./UserSettingsButton";

const onToasterTestClick = () => {
console.log("Nav onToasterTestClick");
toaster.create({
description: `Toaster from Nav via imported toaster.`,
title: "Test Toaster Imported",
type: "success",
});
console.log("Nav onToasterTestClick DONE");
};

// Define existing button categories to filter out
const existingCategories = ["user", "docs", "admin", "browse"];

Expand Down Expand Up @@ -194,7 +207,8 @@ export const Nav = () => {
<SecurityButton />
<PluginMenus navItems={navItemsWithLegacy} />
</Flex>
<Flex flexDir="column" gap={1}>
<Flex flexDir="column">
<Button onClick={onToasterTestClick}>Toaster</Button>
<DocsButton
externalViews={docsItems}
showAPI={authLinks?.authorized_menu_items.includes("Docs")}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

export * from "./Alert";
export * from "./CloseButton";
export * from "./createToaster";
export * from "./InputGroup";
export * from "./toaster";
export * from "./ScrollToAnchor";
export * from "./Select";
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*!
* 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 { Toaster as ChakraToaster, Portal, Spinner, Stack, Toast, createToaster } from "@chakra-ui/react";
import { useRef } from "react";

export const toaster = createToaster({
pauseOnPageIdle: true,
placement: "bottom-end",
});

export const Toaster = () => {
const portalContainerRef = useRef<HTMLDivElement>(null);
<div ref={portalContainerRef}>{APP}</div> // <-- FAIL where to import APP from?!?
return (
<Portal containerRef={portalContainerRef}>
{/* ^^^Error: Type '{ children: Element; containerRef: RefObject<HTMLDivElement | null>; }' is not assignable to type
'IntrinsicAttributes & PortalProps & { children?: ReactNode; }'.
Property 'containerRef' does not exist on type 'IntrinsicAttributes & PortalProps & { children?: ReactNode; }'.
Did you mean 'container'?ts(2322)
*/}
Comment thread
jscheffl marked this conversation as resolved.
Resolved
<ChakraToaster toaster={toaster} insetInline={{ mdDown: "4" }}>
{(toast) => (
<Toast.Root width={{ md: "sm" }}>
{toast.type === "loading" ? <Spinner size="sm" color="blue.solid" /> : <Toast.Indicator />}
<Stack gap="1" flex="1" maxWidth="100%">
{toast.title && <Toast.Title>{toast.title}</Toast.Title>}
{toast.description && <Toast.Description>{toast.description}</Toast.Description>}
</Stack>
{toast.action && <Toast.ActionTrigger>{toast.action.label}</Toast.ActionTrigger>}
{toast.closable && <Toast.CloseTrigger />}
</Toast.Root>
)}
</ChakraToaster>
</Portal>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { Box, Code, HStack, Link as ChakraLink, List, Table, Text, type SelectValueChangeDetails } from "@chakra-ui/react";
import { Box, Button, Code, HStack, Link as ChakraLink, List, Table, Text, type SelectValueChangeDetails } from "@chakra-ui/react";
import { useState, useCallback } from "react";
import { useUiServiceWorker } from "openapi/queries";
import { Link } from "react-router-dom";
Expand All @@ -27,7 +27,7 @@ import { ErrorAlert } from "src/components/ErrorAlert";
import { SearchBar } from "src/components/SearchBar";
import { WorkerOperations } from "src/components/WorkerOperations";
import { WorkerStateBadge } from "src/components/WorkerStateBadge";
import { ScrollToAnchor, Select } from "src/components/ui";
import { ScrollToAnchor, Select, toaster } from "src/components/ui";
import { workerStateOptions } from "src/constants";
import { autoRefreshInterval } from "src/utils";
import type { EdgeWorkerState } from "openapi/requests/types.gen";
Expand All @@ -51,6 +51,15 @@ export const WorkerPage = () => {
refetchInterval: autoRefreshInterval,
},
);
const onToasterTestClick = () => {
console.log("Nav onToasterTestClick");
toaster.create({
description: `Toaster from Plugin.`,
title: "Test Toaster",
type: "success",
});
console.log("Nav onToasterTestClick DONE");
};

const handleWorkerSearchChange = (value: string) => {
setWorkerNamePattern(value);
Expand Down Expand Up @@ -207,6 +216,7 @@ export const WorkerPage = () => {
</Table.Body>
</Table.Root>
<ScrollToAnchor />
<Button onClick={onToasterTestClick}>Open a Toaster in Plugin</Button>
</>
) : (
<Text as="div" pl={2} pt={1}>
Expand Down
Loading