pierrejeambrun commented on code in PR #26457: URL: https://github.com/apache/airflow/pull/26457#discussion_r982889425
########## airflow/www/static/js/dag/details/SetDagTaskNotes.tsx: ########## @@ -0,0 +1,134 @@ +/*! + * 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 React, { useState } from 'react'; +import { + Accordion, + AccordionItem, + AccordionButton, + AccordionPanel, + AccordionIcon, + Box, + Button, + Text, + Textarea, +} from '@chakra-ui/react'; +import ResizeTextarea from 'react-textarea-autosize'; +import { getMetaValue } from '../../utils'; +import { useSetDagRunNotes, useSetTaskInstanceNotes } from '../../api'; + +interface Props { + dagId: string; + runId: string; + taskId: string | undefined; + mapIndex: number | undefined; + initialValue: string | undefined | null; +} + +const canEdit = getMetaValue('can_edit') === 'True'; + +const SetDagTaskNotes = ({ + dagId, runId, taskId, mapIndex, initialValue, +}: Props) => { + const [notes, setNotes] = useState(initialValue == null ? '' : initialValue); + const [noteBeforeEdit, setNoteBeforeEdit] = useState(''); + const [editMode, changeEditMode] = useState(false); + const tiStr = (taskId != null ? taskId : ''); + const { + mutateAsync: apiCallToSetDagRunNote, isLoading: dagRunIsLoading, + } = useSetDagRunNotes(dagId, runId, notes); + const { + mutateAsync: apiCallToSetTINote, isLoading: tiIsLoading, + } = useSetTaskInstanceNotes(dagId, runId, tiStr, (mapIndex != null ? mapIndex : -1), notes); + + const objectIdentifier = (taskId == null) ? 'DAG Run' : 'Task Instance'; + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + if (taskId == null) { + await apiCallToSetDagRunNote(); + } else { + await apiCallToSetTINote(); + } + changeEditMode(false); + }; + + return ( + <Accordion defaultIndex={[0]} allowMultiple> + <AccordionItem style={{ border: 0 }}> + <AccordionButton style={{ padding: 0, paddingBottom: '10px', fontSize: 'inherit' }}> + <Box flex="1" textAlign="left"> + <Text as="strong" size="lg"> + {objectIdentifier} + {' '} + Notes: + </Text> + </Box> + <AccordionIcon /> + </AccordionButton> + <AccordionPanel style={{ padding: '0 0 15px 0' }}> + {editMode ? ( + <form onSubmit={handleSubmit}> + <div> + <Textarea + minH="unset" + overflow="hidden" + w="100%" + resize="none" + minRows={3} + maxRows={10} + as={ResizeTextarea} + value={notes} + onChange={(e) => setNotes(e.target.value)} + style={{ width: '100%' }} + /> + </div> + <div style={{ marginTop: '10px' }}> + <Button type="submit" isLoading={dagRunIsLoading || tiIsLoading}> + Update user notes Review Comment: Looks like almost all buttons in UI are in Title Case -> `Update User Notes`. Maybe we should update these new buttons to harmonize with the rest of the UI ? -- 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]
