pierrejeambrun commented on code in PR #70413:
URL: https://github.com/apache/airflow/pull/70413#discussion_r3829947101


##########
airflow-core/src/airflow/ui/src/components/TriggerDag/RecentConfigSelect.tsx:
##########
@@ -0,0 +1,117 @@
+/*!
+ * 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 { createListCollection, Flex, Select, type SelectValueChangeDetails, 
Text } from "@chakra-ui/react";
+import { useMemo, useState } from "react";
+import { useTranslation } from "react-i18next";
+
+import { useDagRunServiceGetDagRuns } from "openapi/queries";
+import type { DAGRunResponse } from "openapi/requests/types.gen";
+
+import Time from "../Time";
+
+type RecentConfigOption = {
+  run: DAGRunResponse;
+  value: string;
+};
+
+type RecentConfigSelectProps = {
+  readonly dagId: string;
+  readonly onSelectConf: (conf: Record<string, unknown>) => void;
+  readonly open: boolean;
+};
+
+const RecentConfigSelect = ({ dagId, onSelectConf, open }: 
RecentConfigSelectProps) => {
+  const { t: translate } = useTranslation("components");
+  const [selectedValue, setSelectedValue] = useState<Array<string>>([]);
+  const { data, isLoading } = useDagRunServiceGetDagRuns(
+    { dagId, limit: 25, orderBy: ["-run_after"] },
+    undefined,
+    { enabled: open },
+  );
+
+  const options = useMemo(() => {
+    const seenConfs = new Set<string>();
+
+    return (data?.dag_runs ?? []).reduce<Array<RecentConfigOption>>((items, 
run) => {
+      const hasConf = run.conf !== null && Object.keys(run.conf).length > 0;
+      const confKey = hasConf ? JSON.stringify(run.conf) : undefined;
+      const isNewConf = confKey !== undefined && !seenConfs.has(confKey);
+
+      if (isNewConf) {
+        seenConfs.add(confKey);
+        items.push({ run, value: run.dag_run_id });
+      }
+
+      return items;
+    }, []);
+  }, [data?.dag_runs]);
+
+  const recentConfigOptions = createListCollection({
+    items: options,
+    itemToString: (item: RecentConfigOption) => item.run.dag_run_id,
+  });
+
+  const handleValueChange = ({ items, value }: 
SelectValueChangeDetails<RecentConfigOption>) => {
+    const [selected] = items;
+
+    setSelectedValue(value);
+    if (selected?.run.conf) {
+      onSelectConf(selected.run.conf);

Review Comment:
   This will reset user defined logicalDate, runId, and note to defaults.
   But here it fires interactively: a user who sets a logical date / custom run 
ID / manual data interval / note and then picks a recent config to reuse its 
params loses all of those to defaults. The dropdown is meant to apply a past 
run's conf, not reset the run's scheduling fields.
   
   Either fix that or move this config selector at the top of the form, so we 
know that all fields are affected and will be reset to
   



##########
airflow-core/src/airflow/ui/src/components/TriggerDag/RecentConfigSelect.tsx:
##########
@@ -0,0 +1,117 @@
+/*!
+ * 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 { createListCollection, Flex, Select, type SelectValueChangeDetails, 
Text } from "@chakra-ui/react";
+import { useMemo, useState } from "react";
+import { useTranslation } from "react-i18next";
+
+import { useDagRunServiceGetDagRuns } from "openapi/queries";
+import type { DAGRunResponse } from "openapi/requests/types.gen";
+
+import Time from "../Time";
+
+type RecentConfigOption = {
+  run: DAGRunResponse;
+  value: string;
+};
+
+type RecentConfigSelectProps = {
+  readonly dagId: string;
+  readonly onSelectConf: (conf: Record<string, unknown>) => void;
+  readonly open: boolean;
+};
+
+const RecentConfigSelect = ({ dagId, onSelectConf, open }: 
RecentConfigSelectProps) => {
+  const { t: translate } = useTranslation("components");
+  const [selectedValue, setSelectedValue] = useState<Array<string>>([]);
+  const { data, isLoading } = useDagRunServiceGetDagRuns(
+    { dagId, limit: 25, orderBy: ["-run_after"] },
+    undefined,
+    { enabled: open },
+  );
+
+  const options = useMemo(() => {
+    const seenConfs = new Set<string>();
+
+    return (data?.dag_runs ?? []).reduce<Array<RecentConfigOption>>((items, 
run) => {
+      const hasConf = run.conf !== null && Object.keys(run.conf).length > 0;
+      const confKey = hasConf ? JSON.stringify(run.conf) : undefined;
+      const isNewConf = confKey !== undefined && !seenConfs.has(confKey);
+
+      if (isNewConf) {
+        seenConfs.add(confKey);
+        items.push({ run, value: run.dag_run_id });
+      }
+
+      return items;
+    }, []);
+  }, [data?.dag_runs]);
+
+  const recentConfigOptions = createListCollection({
+    items: options,
+    itemToString: (item: RecentConfigOption) => item.run.dag_run_id,
+  });
+
+  const handleValueChange = ({ items, value }: 
SelectValueChangeDetails<RecentConfigOption>) => {
+    const [selected] = items;
+
+    setSelectedValue(value);
+    if (selected?.run.conf) {
+      onSelectConf(selected.run.conf);
+    }
+  };
+
+  if (!isLoading && options.length === 0) {
+    return undefined;
+  }
+
+  return (
+    <Select.Root
+      collection={recentConfigOptions}
+      data-testid="recent-config-select"
+      disabled={isLoading || options.length === 0}
+      onValueChange={handleValueChange}
+      size="sm"
+      value={selectedValue}
+    >
+      <Select.Label 
fontSize="xs">{translate("triggerDag.recentConfig")}</Select.Label>
+      <Select.Control>
+        <Select.Trigger>
+          <Select.ValueText 
placeholder={translate("triggerDag.recentConfigPlaceholder")} />
+        </Select.Trigger>

Review Comment:
   When we run through 'trigger again with this conf button', this drop down 
probably shouldn't be there at all. 
   
   It's confusing to have it (with nothing selected), but actually a conf is 
passed down. And if it's to change the run conf to another run, there's no 
point running through that 'trigger again with this conf' button.



-- 
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]

Reply via email to