Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*!
* 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 { useMemo } from "react";

import { FilterBar, type FilterValue } from "src/components/FilterBar";
import { SearchParamsKeys } from "src/constants/searchParams";
import { useFiltersHandler, type FilterableSearchParamsKeys } from "src/utils";

export const RunTaskFilters = () => {
// Keep to keys supported by FilterBar & TaskInstances API mapping
const searchParamKeys = useMemo(
(): Array<FilterableSearchParamsKeys> => [
SearchParamsKeys.TASK_ID_PATTERN, // pill label "Task" (text)
SearchParamsKeys.START_DATE, // date from
SearchParamsKeys.END_DATE, // date to
],
[],
);

const { filterConfigs, handleFiltersChange, searchParams } = useFiltersHandler(searchParamKeys);

const initialValues = useMemo(() => {
const values: Record<string, FilterValue> = {};

filterConfigs.forEach((cfg) => {
const raw = searchParams.get(cfg.key);

if (raw !== null && raw !== "") {
if (cfg.type === "number") {
const num = Number(raw);

values[cfg.key] = Number.isNaN(num) ? raw : num;
} else {
values[cfg.key] = raw;
}
}
});

return values;
}, [searchParams, filterConfigs]);

return (
<FilterBar configs={filterConfigs} initialValues={initialValues} onFiltersChange={handleFiltersChange} />
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/

import { Flex, Link } from "@chakra-ui/react";
import type { ColumnDef } from "@tanstack/react-table";
import type { TFunction } from "i18next";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { Link as RouterLink, useParams, useSearchParams } from "react-router-dom";

Expand All @@ -39,7 +39,7 @@ import { getDuration, useAutoRefresh, isStatePending } from "src/utils";
import { getTaskInstanceLink } from "src/utils/links";

import DeleteTaskInstanceButton from "./DeleteTaskInstanceButton";
import { TaskInstancesFilter } from "./TaskInstancesFilter";
import { RunTaskFilters } from "./RunTaskFilters";

type TaskInstanceRow = { row: { original: TaskInstanceResponse } };

Expand All @@ -49,6 +49,7 @@ const {
POOL: POOL_PARAM,
START_DATE: START_DATE_PARAM,
STATE: STATE_PARAM,
TASK_ID_PATTERN: TASK_ID_PATTERN_PARAM,
}: SearchParamsKeysType = SearchParamsKeys;

const taskInstanceColumns = ({
Expand Down Expand Up @@ -76,7 +77,6 @@ const taskInstanceColumns = ({
: [
{
accessorKey: "run_after",
// If we don't show the taskId column, make the dag run a link to the task instance
cell: ({ row: { original } }: TaskInstanceRow) =>
Boolean(taskId) ? (
<Link asChild color="fg.info" fontWeight="bold">
Expand Down Expand Up @@ -201,9 +201,9 @@ export const TaskInstances = () => {
const hasFilteredState = filteredState.length > 0;
const hasFilteredPool = pool.length > 0;

const [taskDisplayNamePattern, setTaskDisplayNamePattern] = useState(
searchParams.get(NAME_PATTERN_PARAM) ?? undefined,
);
// Read the pill value (name_pattern), but accept legacy task_id_pattern too.
const taskNamePattern =
searchParams.get(NAME_PATTERN_PARAM) ?? searchParams.get(TASK_ID_PATTERN_PARAM) ?? undefined;

const refetchInterval = useAutoRefresh({});

Expand All @@ -218,7 +218,7 @@ export const TaskInstances = () => {
pool: hasFilteredPool ? pool : undefined,
startDateGte: startDate ?? undefined,
state: hasFilteredState ? filteredState : undefined,
taskDisplayNamePattern: groupId ?? taskDisplayNamePattern ?? undefined,
taskDisplayNamePattern: groupId ?? taskNamePattern ?? undefined,
taskId: Boolean(groupId) ? undefined : taskId,
},
undefined,
Expand All @@ -230,10 +230,9 @@ export const TaskInstances = () => {

return (
<>
<TaskInstancesFilter
setTaskDisplayNamePattern={setTaskDisplayNamePattern}
taskDisplayNamePattern={taskDisplayNamePattern}
/>
{/* Pill-based FilterBar for Task name + From/To */}
<RunTaskFilters />

<DataTable
columns={taskInstanceColumns({
dagId,
Expand Down
Loading