pierrejeambrun commented on code in PR #46939: URL: https://github.com/apache/airflow/pull/46939#discussion_r1968105220
########## airflow/ui/src/components/HeaderCard.tsx: ########## @@ -0,0 +1,94 @@ +/*! + * 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, Flex, GridItem, Heading, HStack, SimpleGrid, Spinner } from "@chakra-ui/react"; +import { type ReactNode, useRef } from "react"; +import { FiMessageSquare } from "react-icons/fi"; + +import type { TaskInstanceState } from "openapi/requests/types.gen"; +import DisplayMarkdownButton from "src/components/DisplayMarkdownButton"; +import { Stat } from "src/components/Stat"; +import { StateBadge } from "src/components/StateBadge"; +import { useContainerWidth } from "src/utils"; + +const getColumnCount = (width: number) => { + if (width < 400) { + return 2; + } + if (width < 800) { + return 4; + } + if (width < 1000) { + return 6; + } + + return 8; +}; + +type Props = { + readonly actions?: ReactNode; + readonly icon: ReactNode; + readonly isRefreshing?: boolean; + readonly note?: string | null; + readonly state?: TaskInstanceState | null; + readonly stats: Array<{ label: string; value: ReactNode | string }>; + readonly subTitle?: ReactNode | string; + readonly title: ReactNode | string; +}; + +export const HeaderCard = ({ actions, icon, isRefreshing, note, state, stats, subTitle, title }: Props) => { + const containerRef = useRef<HTMLDivElement>(); + const containerWidth = useContainerWidth(containerRef); + + return ( + <Box borderColor="border" borderRadius={8} borderWidth={1} m={2} p={2} ref={containerRef}> + <Flex alignItems="center" flexWrap="wrap" justifyContent="space-between" mb={2}> + <Flex alignItems="center" flexWrap="wrap" gap={2}> + <Heading size="xl">{icon}</Heading> + <Heading size="lg">{title}</Heading> + <Heading size="lg">{subTitle}</Heading> + {state === undefined ? undefined : <StateBadge state={state}>{state}</StateBadge>} + {isRefreshing ? <Spinner /> : <div />} + </Flex> + <HStack gap={1}> + {note === null || note === undefined || note.length === 0 ? undefined : ( + <DisplayMarkdownButton + header="Task Instance Note" + icon={<FiMessageSquare color="black" />} + mdContent={note} + text="Note" + /> + )} + {actions} Review Comment: This breaks the dag documentation I think. (That's a Dag Documentation, not a Task Note, and the markdown rendering seems off)  ########## airflow/ui/src/layouts/Details/NavTabs.tsx: ########## @@ -17,50 +17,52 @@ * under the License. */ import { Center, Flex } from "@chakra-ui/react"; -import type { ReactNode } from "react"; +import { useRef, type ReactNode } from "react"; import { NavLink, useSearchParams } from "react-router-dom"; +import { useContainerWidth } from "src/utils"; + type Props = { readonly keepSearch?: boolean; - readonly rightButtons?: ReactNode; - readonly tabs: Array<{ label: string; value: string }>; + readonly tabs: Array<{ icon?: ReactNode; label: string; value: string }>; }; -export const NavTabs = ({ keepSearch, rightButtons, tabs }: Props) => { +export const NavTabs = ({ keepSearch, tabs }: Props) => { const [searchParams] = useSearchParams(); + const containerRef = useRef<HTMLDivElement>(null); + const containerWidth = useContainerWidth(containerRef); + return ( - <Flex alignItems="center" borderBottomWidth={1} justifyContent="space-between" mb={2}> - <Flex> - {tabs.map(({ label, value }) => ( - <NavLink - end - key={value} - to={{ - pathname: value, - // Preserve search params when navigating - search: keepSearch ? searchParams.toString() : undefined, - }} - > - {({ isActive }) => ( - <Center - borderBottomColor="border.info" - borderBottomWidth={isActive ? 3 : 0} - color={isActive ? "fg" : "fg.muted"} - fontWeight="bold" - height="40px" - mb="-2px" // Show the border on top of its parent's border - pb={isActive ? 0 : "3px"} - px={4} - transition="all 0.2s ease" - > - {label} - </Center> - )} - </NavLink> - ))} - </Flex> - <Flex alignSelf="flex-end">{rightButtons}</Flex> + <Flex alignItems="center" borderBottomWidth={1} mb={2} ref={containerRef}> + {tabs.map(({ icon, label, value }) => ( + <NavLink + end + key={value} + title={label} + to={{ + pathname: value, + // Preserve search params when navigating + search: keepSearch ? searchParams.toString() : undefined, + }} + > + {({ isActive }) => ( + <Center + borderBottomColor="border.info" + borderBottomWidth={isActive ? 3 : 0} + color={isActive ? "fg" : "fg.muted"} + fontWeight="bold" + height="40px" + mb="-2px" // Show the border on top of its parent's border + pb={isActive ? 0 : "3px"} + px={4} + transition="all 0.2s ease" + > + {containerWidth > 600 || !Boolean(icon) ? label : icon} Review Comment: Nice ! ########## airflow/ui/src/pages/Run/Header.tsx: ########## @@ -36,44 +34,39 @@ export const Header = ({ readonly dagRun: DAGRunResponse; readonly isRefreshing?: boolean; }) => ( - <Box borderColor="border" borderRadius={8} borderWidth={1} p={2}> - <Flex alignItems="center" justifyContent="space-between" mb={2}> - <HStack alignItems="center" gap={2}> - <FiBarChart size="1.75rem" /> - <Heading size="lg"> - <strong>Run: </strong> - {dagRun.dag_run_id} - </Heading> - <StateBadge state={dagRun.state}>{dagRun.state}</StateBadge> - {isRefreshing ? <Spinner /> : <div />} - </HStack> - <HStack> - {dagRun.note === null || dagRun.note.length === 0 ? undefined : ( - <DisplayMarkdownButton - header="Dag Run Note" - icon={<FiMessageSquare color="black" />} - mdContent={dagRun.note} - text="Note" - /> - )} + <HeaderCard + actions={ + <> <ClearRunButton dagRun={dagRun} /> <MarkRunAsButton dagRun={dagRun} /> - </HStack> - </Flex> - <SimpleGrid columns={4} gap={4}> - <Stat label="Run Type"> - <HStack> - <RunTypeIcon runType={dagRun.run_type} /> - <Text>{dagRun.run_type}</Text> - </HStack> - </Stat> - <Stat label="Start"> - <Time datetime={dagRun.start_date} /> - </Stat> - <Stat label="End"> - <Time datetime={dagRun.end_date} /> - </Stat> - <Stat label="Duration">{getDuration(dagRun.start_date, dagRun.end_date)}s</Stat> - </SimpleGrid> - </Box> + </> + } + icon={<FiBarChart />} + isRefreshing={isRefreshing} + note={dagRun.note} + state={dagRun.state} + stats={[ + ...(dagRun.logical_date === null + ? [] + : [ + { + label: "Logical Date", + value: <Time datetime={dagRun.logical_date} />, + }, + ]), + { + label: "Run Type", + value: ( + <HStack> + <RunTypeIcon runType={dagRun.run_type} /> + <Text>{dagRun.run_type}</Text> + </HStack> + ), + }, + { label: "Start", value: <Time datetime={dagRun.start_date} /> }, + { label: "End", value: <Time datetime={dagRun.end_date} /> }, + { label: "Duration", value: `${getDuration(dagRun.start_date, dagRun.end_date)}s` }, Review Comment: I don't think date should wrap like this when we have space to inline them.  -- 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]
