Copilot commented on code in PR #55348: URL: https://github.com/apache/airflow/pull/55348#discussion_r2328842567
########## providers/edge3/src/airflow/providers/edge3/plugins/www/src/components/MaintenanceEnterButton.tsx: ########## @@ -0,0 +1,97 @@ +/*! + * 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 { Portal } from "@chakra-ui/react"; +import { Button, CloseButton, Dialog, IconButton, Textarea, useDisclosure } from "@chakra-ui/react"; +import { useUiServiceRequestWorkerMaintenance } from "openapi/queries"; +import { useState } from "react"; +import { HiOutlineWrenchScrewdriver } from "react-icons/hi2"; + +interface MaintenanceEnterButtonProps { + onEnterMaintenance: () => void; + workerName: string; +} + +export const MaintenanceEnterButton = ({ onEnterMaintenance, workerName }: MaintenanceEnterButtonProps) => { + const { onClose, onOpen, open } = useDisclosure(); + const [comment, setComment] = useState(""); Review Comment: The comment state should be reset when the dialog closes to prevent showing previous comments when reopening. Add a useEffect hook to reset comment when the dialog closes: `useEffect(() => { if (!open) setComment(''); }, [open]);` ########## providers/edge3/src/airflow/providers/edge3/plugins/www/src/components/MaintenanceEnterButton.tsx: ########## @@ -0,0 +1,97 @@ +/*! + * 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 { Portal } from "@chakra-ui/react"; +import { Button, CloseButton, Dialog, IconButton, Textarea, useDisclosure } from "@chakra-ui/react"; +import { useUiServiceRequestWorkerMaintenance } from "openapi/queries"; +import { useState } from "react"; +import { HiOutlineWrenchScrewdriver } from "react-icons/hi2"; + +interface MaintenanceEnterButtonProps { + onEnterMaintenance: () => void; + workerName: string; +} + +export const MaintenanceEnterButton = ({ onEnterMaintenance, workerName }: MaintenanceEnterButtonProps) => { + const { onClose, onOpen, open } = useDisclosure(); + const [comment, setComment] = useState(""); + + const enterMaintenanceMutation = useUiServiceRequestWorkerMaintenance({ + onError: (error) => { + console.error("Error entering maintenance:", error); + alert(`Error entering maintenance: ${error}`); + }, + onSuccess: () => { + console.log("Enter maintenance successful"); + onEnterMaintenance(); Review Comment: The dialog should be closed after successful maintenance entry. Add `onClose()` after `onEnterMaintenance()` to properly close the dialog and reset the comment state. ```suggestion onEnterMaintenance(); onClose(); setComment(""); ``` ########## providers/edge3/src/airflow/providers/edge3/plugins/www/src/components/MaintenanceEnterButton.tsx: ########## @@ -0,0 +1,97 @@ +/*! + * 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 { Portal } from "@chakra-ui/react"; +import { Button, CloseButton, Dialog, IconButton, Textarea, useDisclosure } from "@chakra-ui/react"; +import { useUiServiceRequestWorkerMaintenance } from "openapi/queries"; +import { useState } from "react"; +import { HiOutlineWrenchScrewdriver } from "react-icons/hi2"; + +interface MaintenanceEnterButtonProps { + onEnterMaintenance: () => void; + workerName: string; +} + +export const MaintenanceEnterButton = ({ onEnterMaintenance, workerName }: MaintenanceEnterButtonProps) => { + const { onClose, onOpen, open } = useDisclosure(); + const [comment, setComment] = useState(""); + + const enterMaintenanceMutation = useUiServiceRequestWorkerMaintenance({ + onError: (error) => { + console.error("Error entering maintenance:", error); + alert(`Error entering maintenance: ${error}`); + }, + onSuccess: () => { + console.log("Enter maintenance successful"); + onEnterMaintenance(); + }, + }); + + const enterMaintenance = () => { + console.log(`Entering maintenance for worker: ${workerName}`); + enterMaintenanceMutation.mutate({ requestBody: { maintenance_comment: comment }, workerName }); + }; + + return ( + <> + <IconButton + size="sm" + variant="ghost" + aria-label="Enter Maintenance" + title="Enter Maintenance" + onClick={onOpen} + > + <HiOutlineWrenchScrewdriver /> + </IconButton> + + <Dialog.Root onOpenChange={onClose} open={open} size="md"> Review Comment: The onOpenChange prop should handle both open and close events. Currently it only calls onClose, which means the dialog cannot be opened programmatically or handle external state changes properly. Use a proper state handler: `onOpenChange={(details) => details.open ? onOpen() : onClose()}` ```suggestion <Dialog.Root onOpenChange={(details) => details.open ? onOpen() : onClose()} open={open} size="md"> ``` -- 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]
