This is an automated email from the ASF dual-hosted git repository.
bbovenzi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new c490605280c AIP-38 Add logical date to trigger DagRun form and remove
dataInterval (#46471)
c490605280c is described below
commit c490605280cdf541205b4fbefb48864bb779f0f1
Author: Pierre Jeambrun <[email protected]>
AuthorDate: Tue Feb 11 17:48:37 2025 +0100
AIP-38 Add logical date to trigger DagRun form and remove dataInterval
(#46471)
* AIP-38 Add logical date to trigger DagRun form
* Automatically fill fields based on conditions
* Remove dataIntervalEnd and dataIntervalStart
---
.../src/components/TriggerDag/TriggerDAGForm.tsx | 47 +++-------------------
airflow/ui/src/queries/useTrigger.ts | 42 +++----------------
2 files changed, 11 insertions(+), 78 deletions(-)
diff --git a/airflow/ui/src/components/TriggerDag/TriggerDAGForm.tsx
b/airflow/ui/src/components/TriggerDag/TriggerDAGForm.tsx
index 1fe47e8c0c9..24bd983ebec 100644
--- a/airflow/ui/src/components/TriggerDag/TriggerDAGForm.tsx
+++ b/airflow/ui/src/components/TriggerDag/TriggerDAGForm.tsx
@@ -42,28 +42,21 @@ type TriggerDAGFormProps = {
export type DagRunTriggerParams = {
conf: string;
dagRunId: string;
- dataIntervalEnd: string;
- dataIntervalStart: string;
+ logicalDate: string;
note: string;
};
const TriggerDAGForm = ({ dagId, onClose, open }: TriggerDAGFormProps) => {
const [errors, setErrors] = useState<{ conf?: string; date?: unknown }>({});
const initialParamsDict = useDagParams(dagId, open);
- const {
- dateValidationError,
- error: errorTrigger,
- isPending,
- triggerDagRun,
- } = useTrigger({ dagId, onSuccessConfirm: onClose });
+ const { error: errorTrigger, isPending, triggerDagRun } = useTrigger({
dagId, onSuccessConfirm: onClose });
const { conf, setConf } = useParamStore();
- const { control, handleSubmit, reset, watch } =
useForm<DagRunTriggerParams>({
+ const { control, handleSubmit, reset } = useForm<DagRunTriggerParams>({
defaultValues: {
conf,
dagRunId: "",
- dataIntervalEnd: "",
- dataIntervalStart: "",
+ logicalDate: "",
note: "",
},
});
@@ -75,15 +68,6 @@ const TriggerDAGForm = ({ dagId, onClose, open }:
TriggerDAGFormProps) => {
}
}, [conf, reset]);
- useEffect(() => {
- if (Boolean(dateValidationError)) {
- setErrors((prev) => ({ ...prev, date: dateValidationError }));
- }
- }, [dateValidationError]);
-
- const dataIntervalStart = watch("dataIntervalStart");
- const dataIntervalEnd = watch("dataIntervalEnd");
-
const onSubmit = (data: DagRunTriggerParams) => {
triggerDagRun(data);
};
@@ -136,31 +120,12 @@ const TriggerDAGForm = ({ dagId, onClose, open }:
TriggerDAGFormProps) => {
<Box p={5}>
<Controller
control={control}
- name="dataIntervalStart"
+ name="logicalDate"
render={({ field }) => (
<Field.Root invalid={Boolean(errors.date)}>
- <Field.Label fontSize="md">Data Interval Start
Date</Field.Label>
- <Input
- {...field}
- max={dataIntervalEnd || undefined}
- onBlur={resetDateError}
- placeholder="yyyy-mm-ddThh:mm"
- size="sm"
- type="datetime-local"
- />
- </Field.Root>
- )}
- />
-
- <Controller
- control={control}
- name="dataIntervalEnd"
- render={({ field }) => (
- <Field.Root invalid={Boolean(errors.date)} mt={6}>
- <Field.Label fontSize="md">Data Interval End
Date</Field.Label>
+ <Field.Label fontSize="md">Logical Date</Field.Label>
<Input
{...field}
- min={dataIntervalStart || undefined}
onBlur={resetDateError}
placeholder="yyyy-mm-ddThh:mm"
size="sm"
diff --git a/airflow/ui/src/queries/useTrigger.ts
b/airflow/ui/src/queries/useTrigger.ts
index 3b55be037c6..6d93383ff3c 100644
--- a/airflow/ui/src/queries/useTrigger.ts
+++ b/airflow/ui/src/queries/useTrigger.ts
@@ -33,8 +33,6 @@ export const useTrigger = ({ dagId, onSuccessConfirm }: {
dagId: string; onSucce
const queryClient = useQueryClient();
const [error, setError] = useState<unknown>(undefined);
- const [dateValidationError, setDateValidationError] =
useState<unknown>(undefined);
-
const onSuccess = async () => {
const queryKeys = [
[useDagServiceGetDagsKey],
@@ -65,38 +63,10 @@ export const useTrigger = ({ dagId, onSuccessConfirm }: {
dagId: string; onSucce
const triggerDagRun = (dagRunRequestBody: DagRunTriggerParams) => {
const parsedConfig = JSON.parse(dagRunRequestBody.conf) as Record<string,
unknown>;
- const DataIntervalStart = dagRunRequestBody.dataIntervalStart
- ? new Date(dagRunRequestBody.dataIntervalStart)
- : undefined;
- const DataIntervalEnd = dagRunRequestBody.dataIntervalEnd
- ? new Date(dagRunRequestBody.dataIntervalEnd)
- : undefined;
-
- if (Boolean(DataIntervalStart) !== Boolean(DataIntervalEnd)) {
- setDateValidationError({
- body: {
- detail:
- "Either both Data Interval Start Date and End Date must be
provided, or both must be empty.",
- },
- });
-
- return;
- }
-
- if (DataIntervalStart && DataIntervalEnd) {
- if (DataIntervalStart > DataIntervalEnd) {
- setDateValidationError({
- body: {
- detail: "Data Interval Start Date must be less than or equal to
Data Interval End Date.",
- },
- });
-
- return;
- }
- }
+ const logicalDate = dagRunRequestBody.logicalDate ? new
Date(dagRunRequestBody.logicalDate) : undefined;
- const formattedDataIntervalStart = DataIntervalStart?.toISOString() ??
undefined;
- const formattedDataIntervalEnd = DataIntervalEnd?.toISOString() ??
undefined;
+ // eslint-disable-next-line unicorn/no-null
+ const formattedLogicalDate = logicalDate?.toISOString() ?? null;
const checkDagRunId = dagRunRequestBody.dagRunId === "" ? undefined :
dagRunRequestBody.dagRunId;
const checkNote = dagRunRequestBody.note === "" ? undefined :
dagRunRequestBody.note;
@@ -106,13 +76,11 @@ export const useTrigger = ({ dagId, onSuccessConfirm }: {
dagId: string; onSucce
requestBody: {
conf: parsedConfig,
dag_run_id: checkDagRunId,
- data_interval_end: formattedDataIntervalEnd,
- data_interval_start: formattedDataIntervalStart,
- logical_date: null,
+ logical_date: formattedLogicalDate,
note: checkNote,
},
});
};
- return { dateValidationError, error, isPending, triggerDagRun };
+ return { error, isPending, triggerDagRun };
};