shubhamraj-git commented on code in PR #44850:
URL: https://github.com/apache/airflow/pull/44850#discussion_r1883289097
##########
airflow/ui/src/components/TriggerDag/TriggerDAGModal.tsx:
##########
@@ -41,33 +57,102 @@ const TriggerDAGModal: React.FC<TriggerDAGModalProps> = ({
onClose,
open,
}) => {
- const initialDagParams = useMemo(
- () => ({
- configJson: "{}",
- dagId,
- dataIntervalEnd: "",
- dataIntervalStart: "",
- notes: "",
- runId: "",
- }),
- [dagId],
- );
+ const { data, error } = useDagServiceGetDagDetails({ dagId });
- const [dagParams, setDagParams] = useState<DagParams>(initialDagParams);
+ const transformedParams = data?.params
+ ? Object.fromEntries(
+ Object.entries(data.params).map(([key, param]) => [
+ key,
+ (param as { value: unknown }).value,
+ ]),
+ )
+ : {};
+
+ const initialConf = JSON.stringify(transformedParams, undefined, 2);
+
+ const [dagParams, setDagParams] = useState<DagParams>({
+ configJson: initialConf,
+ dagId,
+ dataIntervalEnd: "",
+ dataIntervalStart: "",
+ notes: "",
+ runId: "",
+ });
+
+ useEffect(() => {
+ const newConfigJson = Boolean(error) ? "{}" : initialConf; // Fallback to
"{}" if there's an error
- const handleTrigger = useCallback(
+ setDagParams((prevParams) => ({
+ ...prevParams,
+ configJson: newConfigJson,
+ }));
+ }, [initialConf, error]);
+
+ const queryClient = useQueryClient();
+ const onSuccess = async () => {
+ await queryClient.invalidateQueries({
+ queryKey: [useDagServiceGetDagsKey],
+ });
+
+ await queryClient.invalidateQueries({
+ queryKey: [useDagsServiceRecentDagRunsKey],
+ });
+
+ await queryClient.invalidateQueries({
+ queryKey: [useDagRunServiceGetDagRunsKey],
+ });
+ };
+ const { mutate } = useDagRunServiceTriggerDagRun({
+ onSuccess,
+ });
+
+ const onTrigger = useCallback(
Review Comment:
Actual yes, we should make this component light.
--
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]