You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/09/28 06:22:41 UTC

[GitHub] [airflow] Jorricks commented on a diff in pull request #26457: Add user comment to task instance and dag run

Jorricks commented on code in PR #26457:
URL: https://github.com/apache/airflow/pull/26457#discussion_r981537340


##########
airflow/api_connexion/openapi/v1.yaml:
##########
@@ -585,6 +585,41 @@ paths:
         '404':
           $ref: '#/components/responses/NotFound'
 
+  /dags/{dag_id}/setTaskInstanceNote:

Review Comment:
   I changed this. Marking this as resolved



##########
airflow/www/static/js/dag/details/taskInstance/index.tsx:
##########
@@ -90,6 +92,8 @@ const TaskInstance = ({
 
   if (!group || !run || !instance) return null;
 
+  const updateTaskInstanceNotesCallable = (newNotes: string) => { instance.notes = newNotes; };

Review Comment:
   I updated it. Took me ages to get it right.
   Let me know what you think.
   IMO it's much much better then what I originally had, so thanks a lot for raising this :)



##########
airflow/www/static/js/dag/details/SetDagTaskNotes.jsx:
##########
@@ -0,0 +1,120 @@
+/*!
+ * 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,
+} from '@chakra-ui/react';
+import TextareaAutosize from 'react-textarea-autosize';
+import { getMetaValue } from '../../utils';
+import { useSetDagRunNotes, useSetTaskInstanceNotes } from '../../api';
+
+const canEdit = getMetaValue('can_edit') === 'True';
+
+const SetDagTaskNotes = ({
+  dagId, runId, taskId, initialValue, updateApiDataFunction,
+}) => {
+  const [notes, setNotes] = useState(initialValue == null ? '' : initialValue);
+  const [noteBeforeEdit, setNoteBeforeEdit] = useState('');
+  const [editMode, changeEditMode] = useState(false);
+  const {
+    mutateAsync: apiCallToSetDagRunNote, dagRunIsLoading,
+  } = useSetDagRunNotes(dagId, runId, notes);
+  const {
+    mutateAsync: apiCallToSetTINote, tiIsLoading,
+  } = useSetTaskInstanceNotes(dagId, runId, taskId, notes);
+
+  const objectIdentifier = (taskId == null) ? 'DAG Run' : 'Task Instance';
+
+  const handleSubmit = async (e) => {
+    e.preventDefault();
+    if (taskId == null) {
+      await apiCallToSetDagRunNote();
+    } else {
+      await apiCallToSetTINote();
+    }
+    updateApiDataFunction(notes);
+    changeEditMode(false);
+  };
+
+  return (
+    <Accordion defaultIndex={[0]} allowMultiple>
+      <AccordionItem style={{ border: 0 }}>
+        <AccordionButton style={{ padding: 0, paddingBottom: '10px', fontSize: 'inherit' }}>
+          <Box flex="1" textAlign="left">

Review Comment:
   Moved it onto a `.tsx`. This forced me to restructure some parts and highlighted some typing improvements. Thanks for the suggestion @pierrejeambrun! Let me know if I can improve anything else :)



##########
airflow/www/static/js/dag/details/SetDagTaskNotes.jsx:
##########
@@ -0,0 +1,120 @@
+/*!
+ * 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,
+} from '@chakra-ui/react';
+import TextareaAutosize from 'react-textarea-autosize';
+import { getMetaValue } from '../../utils';
+import { useSetDagRunNotes, useSetTaskInstanceNotes } from '../../api';
+
+const canEdit = getMetaValue('can_edit') === 'True';
+
+const SetDagTaskNotes = ({
+  dagId, runId, taskId, initialValue, updateApiDataFunction,
+}) => {
+  const [notes, setNotes] = useState(initialValue == null ? '' : initialValue);
+  const [noteBeforeEdit, setNoteBeforeEdit] = useState('');
+  const [editMode, changeEditMode] = useState(false);
+  const {
+    mutateAsync: apiCallToSetDagRunNote, dagRunIsLoading,
+  } = useSetDagRunNotes(dagId, runId, notes);
+  const {
+    mutateAsync: apiCallToSetTINote, tiIsLoading,
+  } = useSetTaskInstanceNotes(dagId, runId, taskId, notes);
+
+  const objectIdentifier = (taskId == null) ? 'DAG Run' : 'Task Instance';
+
+  const handleSubmit = async (e) => {
+    e.preventDefault();
+    if (taskId == null) {
+      await apiCallToSetDagRunNote();
+    } else {
+      await apiCallToSetTINote();
+    }
+    updateApiDataFunction(notes);
+    changeEditMode(false);
+  };
+
+  return (
+    <Accordion defaultIndex={[0]} allowMultiple>
+      <AccordionItem style={{ border: 0 }}>
+        <AccordionButton style={{ padding: 0, paddingBottom: '10px', fontSize: 'inherit' }}>
+          <Box flex="1" textAlign="left">

Review Comment:
   I don't mind changing it to the Chakra component with the autoresize. Just note that that autoresize behaviour is also based on the same library.
   
   Regarding `.jsx`, I am completely new to the `node.js` ecosystem. I created a `.jsx` because the most similar item also was `.jsx`. Should I try to make it a `.tsx`?



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org