bbovenzi commented on code in PR #70028: URL: https://github.com/apache/airflow/pull/70028#discussion_r3623281897
########## airflow-core/src/airflow/ui/src/pages/DagsList/DagsFilters/TeamFilter.tsx: ########## @@ -0,0 +1,81 @@ +/*! + * 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, Field } from "@chakra-ui/react"; +import { Select as ReactSelect, type MultiValue } from "chakra-react-select"; +import { useTranslation } from "react-i18next"; + +import { useTeamsServiceListTeams } from "openapi/queries"; + +type Props = { + readonly onChange: (teams: Array<string>) => void; + readonly selectedTeams: Array<string>; +}; + +export const TeamFilter = ({ onChange, selectedTeams }: Props) => { + const { t: translate } = useTranslation("common"); + const { data } = useTeamsServiceListTeams({ orderBy: ["name"] }); + + const options = (data?.teams ?? []).map((team) => ({ + label: team.name, + value: team.name, + })); + + const handleChange = (selected: MultiValue<{ label: string; value: string }>) => { + onChange(selected.map(({ value }) => value)); + }; + + return ( + <Box> + <Field.Root> + <ReactSelect + aria-label={translate("dagDetails.team")} + chakraStyles={{ + clearIndicator: (provided) => ({ + ...provided, + color: "gray.fg", + }), + container: (provided) => ({ + ...provided, + maxWidth: 200, + minWidth: 64, + }), + control: (provided) => ({ + ...provided, + colorPalette: "brand", + }), + menu: (provided) => ({ + ...provided, + zIndex: 2, + }), + }} + isClearable + isMulti + noOptionsMessage={() => translate("table.noTagsFound")} Review Comment: We'll need a new translation here ########## airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx: ########## @@ -135,6 +137,15 @@ export const DagCard = ({ dag, runStateCounts, runStateCountsLoading, stateCount stateCountLimit={stateCountLimit} /> </GridItem> + {multiTeamEnabled ? ( + <GridItem gridColumn={2} gridRow={2}> + <Stat data-testid="team" label={translate("dagDetails.team")}> + {dag.team_name === undefined || dag.team_name === null ? undefined : ( + <RouterLink to={`/dags?teams=${dag.team_name}`}>{dag.team_name}</RouterLink> + )} + </Stat> + </GridItem> + ) : undefined} Review Comment: Could we make this a separate column instead of appearing below "Next Run"? On wide screens there is plenty of space. Then otherwise we should make sure our grid is wrapping on smaller screens. ########## airflow-core/src/airflow/ui/src/pages/DagsList/DagsFilters/TeamFilter.tsx: ########## @@ -0,0 +1,81 @@ +/*! + * 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, Field } from "@chakra-ui/react"; +import { Select as ReactSelect, type MultiValue } from "chakra-react-select"; +import { useTranslation } from "react-i18next"; + +import { useTeamsServiceListTeams } from "openapi/queries"; + +type Props = { + readonly onChange: (teams: Array<string>) => void; + readonly selectedTeams: Array<string>; +}; + +export const TeamFilter = ({ onChange, selectedTeams }: Props) => { + const { t: translate } = useTranslation("common"); + const { data } = useTeamsServiceListTeams({ orderBy: ["name"] }); + + const options = (data?.teams ?? []).map((team) => ({ + label: team.name, + value: team.name, + })); + + const handleChange = (selected: MultiValue<{ label: string; value: string }>) => { + onChange(selected.map(({ value }) => value)); + }; + + return ( + <Box> + <Field.Root> + <ReactSelect + aria-label={translate("dagDetails.team")} + chakraStyles={{ Review Comment: Not this PR. But I think we need shared styles for ReactSelect components. This just came up in https://github.com/apache/airflow/pull/70054 ########## airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx: ########## @@ -135,6 +137,15 @@ export const DagCard = ({ dag, runStateCounts, runStateCountsLoading, stateCount stateCountLimit={stateCountLimit} /> </GridItem> + {multiTeamEnabled ? ( + <GridItem gridColumn={2} gridRow={2}> + <Stat data-testid="team" label={translate("dagDetails.team")}> + {dag.team_name === undefined || dag.team_name === null ? undefined : ( + <RouterLink to={`/dags?teams=${dag.team_name}`}>{dag.team_name}</RouterLink> Review Comment: Let's use `encodeURIComponent(dag.team_name)` for a little more url safety ########## airflow-core/src/airflow/api_fastapi/core_api/routes/ui/dags.py: ########## @@ -77,6 +78,8 @@ from airflow.models.taskinstance import TaskInstance from airflow.utils.state import DagRunState, TaskInstanceState +_multi_team_enabled = conf.getboolean("core", "multi_team") Review Comment: Let's move this inside of `get_dags()` ########## airflow-core/src/airflow/ui/src/pages/DagsList/DagCard.tsx: ########## @@ -135,6 +137,15 @@ export const DagCard = ({ dag, runStateCounts, runStateCountsLoading, stateCount stateCountLimit={stateCountLimit} /> </GridItem> + {multiTeamEnabled ? ( + <GridItem gridColumn={2} gridRow={2}> + <Stat data-testid="team" label={translate("dagDetails.team")}> Review Comment: What's this test-id for? I don't see any tests using it? -- 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]
