bbovenzi commented on code in PR #71731: URL: https://github.com/apache/airflow/pull/71731#discussion_r3804858823
########## airflow-core/src/airflow/ui/src/components/MatchModeToggle.tsx: ########## @@ -0,0 +1,58 @@ +/*! + * 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 { HStack, Text } from "@chakra-ui/react"; +import { useTranslation } from "react-i18next"; + +import { Switch } from "src/components/ui"; +import type { MatchMode } from "src/hooks/useMatchMode"; + +type Props = { + readonly mode: MatchMode; + readonly onModeChange: (mode: MatchMode) => void; +}; + +export const MatchModeToggle = ({ mode, onModeChange }: Props) => { + const { t: translate } = useTranslation("common"); Review Comment: ```suggestion const { t: translate } = useTranslation(); ``` ########## airflow-core/src/airflow/ui/src/utils/useFiltersHandler.test.tsx: ########## Review Comment: Can we add a test here for the boolean values like `?needs_review=false`? ########## airflow-core/src/airflow/ui/src/components/FilterBar/filters/MultiSelectPill.tsx: ########## @@ -0,0 +1,145 @@ +/*! + * 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, HStack, Text } from "@chakra-ui/react"; +import { CreatableSelect, Select as ReactSelect } from "chakra-react-select"; + +import { MatchModeToggle } from "src/components/MatchModeToggle"; +import { useMatchMode } from "src/hooks/useMatchMode"; + +import { FilterPill } from "../FilterPill"; +import type { FilterPluginProps } from "../types"; + +type SelectOption = { label: string; value: string }; + +type Props = FilterPluginProps & { + readonly noOptionsMessage: string; + readonly onInputChange?: (value: string) => void; + readonly onMenuScrollToBottom?: () => void; + readonly onMenuScrollToTop?: () => void; + readonly options: Array<SelectOption>; +}; + +/** + * Shared shell for every multiselect filter: the pill chrome, the ``chakra-react-select`` + * control, and the optional any/all toggle. Editors that need async options supply their + * own ``options`` plus the search and scroll callbacks. + */ +export const MultiSelectPill = ({ + filter, + noOptionsMessage, + onChange, + onInputChange, + onMenuScrollToBottom, + onMenuScrollToTop, + onRemove, + options, +}: Props) => { + const { mode, setMode } = useMatchMode(filter.config.matchModeKey); + const values = Array.isArray(filter.value) ? filter.value : []; + const SelectComponent = filter.config.isCreatable === true ? CreatableSelect : ReactSelect; + const showMatchMode = filter.config.matchModeKey !== undefined && values.length >= 2; + + return ( + <FilterPill + // Each value is its own node so the collapsed chip stays queryable by value. + displayValue={ + <HStack display="inline-flex" gap={1}> + {mode === "all" && values.length >= 2 ? ( + <Box as="span" color="fg.muted" fontSize="xs"> + {`(${mode})`} + </Box> + ) : undefined} + {values.map((value) => value).join(", ")} + </HStack> + } + filter={filter} + hasValue={values.length > 0} + onRemove={onRemove} + // ``onKeyDown`` is deliberately not forwarded: react-select owns Enter (select the + // highlighted option, or create one) and Escape (close the menu). Letting the pill also + // act on Enter tears the filter down before the value it just created commits. + renderInput={({ onBlur, onFocus, ref }) => ( + <Box + alignItems="center" + bg="bg" + border="0.5px solid" + borderColor="border" + borderRadius="full" + display="flex" + h="full" + onBlur={onBlur} + onFocus={onFocus} + overflow="hidden" + ref={ref} + tabIndex={0} + // Wider than the single-value editors: chips plus the optional match-mode + // toggle need the room, and a narrow control stacks them vertically. + width={showMatchMode ? "620px" : "460px"} Review Comment: Not the biggest fan of magical numbers here. ########## airflow-core/src/airflow/ui/src/components/FilterBar/filters/TagsFilter.tsx: ########## @@ -0,0 +1,57 @@ +/*! + * 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 { useState } from "react"; +import { useTranslation } from "react-i18next"; + +import { useDagTagsInfinite } from "src/queries/useDagTagsInfinite"; + +import type { FilterPluginProps } from "../types"; +import { MultiSelectPill } from "./MultiSelectPill"; + +/** + * Tags multiselect. Attached to its config as an ``EditorComponent`` so the paginated + * tag query only runs while the pill is mounted, rather than on every FilterBar page. + */ +export const TagsFilter = ({ filter, onChange, onRemove }: FilterPluginProps) => { + const { t: translate } = useTranslation("common"); Review Comment: ```suggestion const { t: translate } = useTranslation(); ``` ########## airflow-core/src/airflow/ui/src/components/FilterBar/filters/MultiSelectFilter.tsx: ########## @@ -16,27 +16,27 @@ * specific language governing permissions and limitations * under the License. */ -import { Button } from "@chakra-ui/react"; import { useTranslation } from "react-i18next"; -import { StateBadge } from "src/components/StateBadge"; +import type { FilterPluginProps } from "../types"; +import { MultiSelectPill } from "./MultiSelectPill"; -type Props = { - readonly needsReview: boolean; - readonly onToggle: () => void; -}; +/** Multiselect over a static ``config.options`` list (teams, owners). */ +export const MultiSelectFilter = ({ filter, onChange, onRemove }: FilterPluginProps) => { + const { t: translate } = useTranslation("common"); Review Comment: ```suggestion const { t: translate } = useTranslation(); ``` -- 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]
