vincbeck commented on code in PR #60237: URL: https://github.com/apache/airflow/pull/60237#discussion_r2673862900
########## airflow-core/src/airflow/ui/src/components/TeamSelector.tsx: ########## @@ -0,0 +1,76 @@ +/*! + * 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 { Field, Stack, Spinner } from "@chakra-ui/react"; +import { Select } from "chakra-react-select"; +import { useMemo } from "react"; +import { type Control, Controller, type FieldValues, type Path } from "react-hook-form"; +import { useTranslation } from "react-i18next"; + +import { useTeamsServiceListTeams } from "openapi/queries"; + +type Props<T extends FieldValues = FieldValues> = { + readonly control: Control<T>; +}; + +export const TeamSelector = <T extends FieldValues = FieldValues>({ control }: Props<T>) => { + const { data, isLoading } = useTeamsServiceListTeams({ orderBy: ["name"] }); + const options = useMemo( + () => + (data?.teams ?? []).map((team: { name: string }) => ({ + label: team.name, + value: team.name, + })), + [data], + ); + + const { t: translate } = useTranslation("components"); + + return ( + <Controller + control={control} + name={"team_name" as Path<T>} Review Comment: ``` src/components/TeamSelector.tsx:47:7 - error TS2322: Type 'string' is not assignable to type 'Path<T>'. 47 name="team_name" ``` ########## airflow-core/src/airflow/ui/src/pages/Connections/ConnectionForm.tsx: ########## @@ -74,23 +76,21 @@ const ConnectionForm = ({ const paramsDic = { paramsDict: connectionTypeMeta[selectedConnType]?.extra_fields ?? ({} as ParamsSpec) }; const [formErrors, setFormErrors] = useState(false); + const multiTeamEnabled = Boolean(useConfig("multi_team")); useEffect(() => { - reset((prevValues) => ({ - ...initialConnection, - conn_type: selectedConnType, - connection_id: prevValues.connection_id, - })); + setValue("conn_type", selectedConnType, { + shouldDirty: true, + }); setConf(JSON.stringify(JSON.parse(initialConnection.extra), undefined, 2)); - }, [selectedConnType, reset, initialConnection, setConf]); + }, [selectedConnType, initialConnection, setConf, setValue]); // Automatically reset form when conf is fetched useEffect(() => { - reset((prevValues) => ({ - ...prevValues, // Retain existing form values - extra, - })); - }, [extra, reset, setConf]); + setValue("extra", extra, { + shouldDirty: true, + }); + }, [extra, setValue]); Review Comment: Using `reset` was making the form acting weird. More precisely, the form was considered as non dirty (and therefore the save button was disabled because of that) if no team was selected, even if the other fields (`conn_id` and `conn_type`) were populated. That's why I chose to use `setValue` instead. But if you think there is a better way, I am all for 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]
