bbovenzi commented on code in PR #77211:
URL: https://github.com/apache/airflow/pull/77211#discussion_r4616889616


##########
airflow-core/src/airflow/ui/src/pages/Asset/AssetPartitions/AssetPartitions.tsx:
##########
@@ -0,0 +1,200 @@
+/*!
+ * 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 { Box, Button, HStack, Text } from "@chakra-ui/react";
+import type { ColumnDef } from "@tanstack/react-table";
+import { useTranslation } from "react-i18next";
+import { useParams, useSearchParams } from "react-router-dom";
+
+import { useAssetServiceGetAssetPartitions } from "openapi/queries";
+import type { AssetPartitionResponse } from "openapi/requests/types.gen";
+
+import { RouterLink, Tooltip } from "src/system-components";
+
+import { DataTable } from "src/components/DataTable";
+import type { DataTableFeatures } from "src/components/DataTable/features";
+import { useTableURLState } from "src/components/DataTable/useTableUrlState";
+import { ErrorAlert } from "src/components/ErrorAlert";
+import { FilterBar } from "src/components/FilterBar";
+import { StateBadge } from "src/components/StateBadge";
+import Time from "src/components/Time";
+
+import { SearchParamsKeys } from "src/constants/searchParams";
+import { formatNumber } from "src/utils";
+import { useFiltersHandler, type FilterableSearchParamsKeys } from 
"src/utils/useFiltersHandler";
+
+import { PartitionDayGrid } from "./PartitionDayGrid";
+import {
+  groupByMonth,
+  PARTITION_STATUSES,
+  type PartitionStatus,
+  RUN_STATE_BY_STATUS,
+  STATUS_LABEL_KEY,
+} from "./partitionStatus";
+
+const FILTER_KEYS: Array<FilterableSearchParamsKeys> = 
[SearchParamsKeys.PARTITION_KEY];
+
+const isPartitionStatus = (value: string): value is PartitionStatus =>
+  (PARTITION_STATUSES as Array<string>).includes(value);
+
+const getColumns = (
+  translate: (key: string) => string,
+  language: string,
+): Array<ColumnDef<DataTableFeatures, AssetPartitionResponse>> => [
+  {
+    accessorKey: "partition_key",
+    enableSorting: false,
+    header: translate("common:dagRun.partitionKey"),
+  },
+  {
+    accessorKey: "status",
+    cell: ({ row: { original } }) => (
+      <StateBadge state={RUN_STATE_BY_STATUS[original.status]}>
+        {translate(STATUS_LABEL_KEY[original.status])}
+      </StateBadge>
+    ),
+    enableSorting: false,
+    header: translate("common:state"),
+  },
+  {
+    accessorKey: "last_producer_run",
+    cell: ({ row: { original } }) => {
+      const run = original.last_producer_run;
+
+      return run === null ? (
+        <Text color="fg.muted">—</Text>
+      ) : (
+        <HStack gap={2}>
+          <StateBadge state={run.state} />
+          <RouterLink
+            overflowWrap="anywhere"
+            to={`/dags/${run.dag_id}/runs/${encodeURIComponent(run.run_id)}`}
+          >
+            {run.dag_id}
+          </RouterLink>
+        </HStack>
+      );
+    },
+    enableSorting: false,
+    header: translate("assets:partitions.lastProducerRun"),
+  },
+  {
+    accessorKey: "last_event_timestamp",
+    cell: ({ row: { original } }) =>
+      original.last_event_timestamp === null ? (
+        <Text color="fg.muted">—</Text>
+      ) : (
+        <Time datetime={original.last_event_timestamp} whiteSpace="nowrap" />
+      ),
+    enableSorting: false,
+    header: translate("assets:lastAssetEvent"),
+  },
+  {
+    accessorKey: "consumer_run_count",
+    cell: ({ row: { original } }) => formatNumber(original.consumer_run_count 
?? 0, language),
+    enableSorting: false,
+    header: () => (
+      <Tooltip content={translate("assets:partitions.consumerRunsHelp")}>
+        <span>{translate("assets:partitions.consumerRuns")}</span>
+      </Tooltip>
+    ),
+  },
+];
+
+export const AssetPartitions = () => {
+  const { i18n, t: translate } = useTranslation(["assets", "common"]);
+  const { assetId: rawAssetId } = useParams();
+  const assetId = rawAssetId === undefined ? 0 : parseInt(rawAssetId, 10);
+  const { setTableURLState, tableURLState } = useTableURLState();
+  const { pagination } = tableURLState;
+  const [searchParams, setSearchParams] = useSearchParams();
+  const { filterConfigs, handleFiltersChange, initialValues } = 
useFiltersHandler(FILTER_KEYS);
+
+  const selectedStatuses = 
searchParams.getAll(SearchParamsKeys.STATE).filter(isPartitionStatus);
+
+  const { data, error, isLoading } = useAssetServiceGetAssetPartitions(
+    {
+      assetId,
+      limit: pagination.pageSize,
+      offset: pagination.pageIndex * pagination.pageSize,
+      partitionKeyPattern: searchParams.get(SearchParamsKeys.PARTITION_KEY) ?? 
undefined,
+      status: selectedStatuses.length === 0 ? undefined : selectedStatuses,
+    },
+    undefined,
+    { enabled: assetId !== 0 },
+  );
+
+  const toggleStatus = (status: PartitionStatus) => {
+    const next = new URLSearchParams(searchParams);
+    const remaining = selectedStatuses.filter((selected) => selected !== 
status);
+
+    next.delete(SearchParamsKeys.STATE);
+    (remaining.length === selectedStatuses.length ? [...selectedStatuses, 
status] : remaining).forEach(
+      (selected) => next.append(SearchParamsKeys.STATE, selected),
+    );
+    // The filtered list is shorter, so the current page may not exist in it.
+    next.delete(SearchParamsKeys.OFFSET);
+    setSearchParams(next);
+  };
+
+  const partitions = data?.partitions ?? [];
+  const months = groupByMonth(partitions);
+
+  return (
+    <Box display="flex" flex={1} flexDirection="column" gap={3} minH={0} 
overflow="auto" px={4} py={2}>
+      <ErrorAlert error={error} />
+      <HStack flexWrap="wrap" gap={1} ms={-2}>
+        {PARTITION_STATUSES.map((status) => (
+          <Button
+            aria-pressed={selectedStatuses.includes(status)}
+            data-testid={`partition-status-${status}`}
+            key={status}
+            onClick={() => toggleStatus(status)}
+            px={2}
+            size="sm"
+            variant={selectedStatuses.includes(status) ? "subtle" : "ghost"}
+          >
+            <StateBadge fontSize="md" state={RUN_STATE_BY_STATUS[status]}>
+              {data === undefined ? " " : 
formatNumber(data.status_counts[status] ?? 0, i18n.language)}
+            </StateBadge>
+            {translate(STATUS_LABEL_KEY[status])}
+          </Button>
+        ))}
+      </HStack>
+      {months === undefined ? undefined : <PartitionDayGrid months={months} />}
+      <DataTable
+        columns={getColumns(translate, i18n.language)}

Review Comment:
   Let's not call this function inline. Please do `const columns =` above line 
158



##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/assets.py:
##########
@@ -59,3 +63,42 @@ class NextRunAssetsResponse(BaseModel):
     caller's permissions; this count does not. It reveals nothing new — the 
redacted
     ``asset_expression`` already carries one slot per asset."""
     pending_partition_count: int | None = None
+
+
+class AssetPartitionProducerRunResponse(BaseModel):
+    """The latest run of a producing Dag for one partition key."""
+
+    dag_id: str
+    run_id: str
+    state: DagRunState
+    start_date: datetime | None
+    end_date: datetime | None
+
+
+class AssetPartitionResponse(BaseModel):
+    """Status of one partition key of an asset."""
+
+    partition_key: str
+    status: AssetPartitionStatus
+    last_event_id: int | None
+    last_event_timestamp: datetime | None
+    last_producer_run: AssetPartitionProducerRunResponse | None
+    consumer_run_count: int = 0

Review Comment:
   ```suggestion
       consumer_run_count: int
   ```
   
   Dropping the default makes this required so we don't need `?? 0` elsewhere. 
We already set it to 0 anyway



##########
airflow-core/src/airflow/ui/src/pages/Asset/AssetPartitions/AssetPartitions.tsx:
##########
@@ -0,0 +1,200 @@
+/*!
+ * 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 { Box, Button, HStack, Text } from "@chakra-ui/react";
+import type { ColumnDef } from "@tanstack/react-table";
+import { useTranslation } from "react-i18next";
+import { useParams, useSearchParams } from "react-router-dom";
+
+import { useAssetServiceGetAssetPartitions } from "openapi/queries";
+import type { AssetPartitionResponse } from "openapi/requests/types.gen";
+
+import { RouterLink, Tooltip } from "src/system-components";
+
+import { DataTable } from "src/components/DataTable";
+import type { DataTableFeatures } from "src/components/DataTable/features";
+import { useTableURLState } from "src/components/DataTable/useTableUrlState";
+import { ErrorAlert } from "src/components/ErrorAlert";
+import { FilterBar } from "src/components/FilterBar";
+import { StateBadge } from "src/components/StateBadge";
+import Time from "src/components/Time";
+
+import { SearchParamsKeys } from "src/constants/searchParams";
+import { formatNumber } from "src/utils";
+import { useFiltersHandler, type FilterableSearchParamsKeys } from 
"src/utils/useFiltersHandler";
+
+import { PartitionDayGrid } from "./PartitionDayGrid";
+import {
+  groupByMonth,
+  PARTITION_STATUSES,
+  type PartitionStatus,
+  RUN_STATE_BY_STATUS,
+  STATUS_LABEL_KEY,
+} from "./partitionStatus";
+
+const FILTER_KEYS: Array<FilterableSearchParamsKeys> = 
[SearchParamsKeys.PARTITION_KEY];
+
+const isPartitionStatus = (value: string): value is PartitionStatus =>
+  (PARTITION_STATUSES as Array<string>).includes(value);
+
+const getColumns = (
+  translate: (key: string) => string,
+  language: string,
+): Array<ColumnDef<DataTableFeatures, AssetPartitionResponse>> => [
+  {
+    accessorKey: "partition_key",
+    enableSorting: false,
+    header: translate("common:dagRun.partitionKey"),
+  },
+  {
+    accessorKey: "status",
+    cell: ({ row: { original } }) => (
+      <StateBadge state={RUN_STATE_BY_STATUS[original.status]}>
+        {translate(STATUS_LABEL_KEY[original.status])}
+      </StateBadge>
+    ),
+    enableSorting: false,
+    header: translate("common:state"),
+  },
+  {
+    accessorKey: "last_producer_run",
+    cell: ({ row: { original } }) => {
+      const run = original.last_producer_run;
+
+      return run === null ? (
+        <Text color="fg.muted">—</Text>

Review Comment:
   This can also be left blank



##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/assets.py:
##########
@@ -390,3 +402,219 @@ def next_run_assets(
         "pending_partition_count": pending_partition_count,
     }
     return NextRunAssetsResponse.model_validate(model_data)
+
+
+def _build_asset_partition_status_subquery(asset_id: int, readable_dag_ids: 
set[str] | None) -> Subquery:
+    """
+    Classify every partition key of an asset.
+
+    A producer run belongs to its own ``partition_key``, which is the key its 
asset
+    events get unless the task overrides it. A run that emitted this asset, 
but never
+    under its own key, is known to have overridden the key and is left out. 
For each
+    key, ``E`` is the newest event and ``R`` the newest attempt among the runs 
of the
+    Dags that declare the asset as an outlet:
+
+    - ``R`` queued or running, and no ``E`` since the attempt began: 
``in_progress``
+    - ``R`` failed, and no ``E`` since the attempt began: ``failed``
+    - otherwise, ``E`` exists: ``materialized``
+    - otherwise the key is left out
+
+    An attempt begins at ``queued_at``, which is also reset when a task of the 
run is
+    cleared, whether or not the run has finished. A cleared run is therefore 
the newest
+    attempt and counts as not having produced an event yet.
+
+    Runs and events of Dags the caller may not read are left out before 
anything is
+    aggregated, so neither the rows nor the counts reveal them.
+    """
+    event_filters = [AssetEvent.asset_id == asset_id, 
AssetEvent.partition_key.is_not(None)]
+    run_filters = [
+        DagRun.dag_id.in_(
+            
select(TaskOutletAssetReference.dag_id).where(TaskOutletAssetReference.asset_id 
== asset_id)
+        ),
+        DagRun.partition_key.is_not(None),
+    ]
+    if readable_dag_ids is not None:
+        # Events created through the API or by a watcher have no source Dag to 
authorize on.
+        event_filters.append(
+            or_(AssetEvent.source_dag_id.in_(readable_dag_ids), 
AssetEvent.source_dag_id.is_(None))
+        )
+        run_filters.append(DagRun.dag_id.in_(readable_dag_ids))
+
+    ranked_events = (
+        select(
+            AssetEvent.partition_key.label("partition_key"),
+            AssetEvent.id.label("event_id"),
+            AssetEvent.timestamp.label("event_timestamp"),
+            func.row_number()
+            .over(
+                partition_by=AssetEvent.partition_key,
+                order_by=(AssetEvent.timestamp.desc(), AssetEvent.id.desc()),
+            )
+            .label("position"),
+        )
+        .where(*event_filters)
+        .subquery("ranked_events")
+    )
+    last_events = select(ranked_events).where(ranked_events.c.position == 
1).cte("last_events")
+
+    # One pass over the asset's events, rather than a lookup per run.
+    source_run = aliased(DagRun)
+    emitted_under_own_key = func.sum(case((AssetEvent.partition_key == 
source_run.partition_key, 1), else_=0))
+    key_overriding_runs = (
+        select(AssetEvent.source_dag_id.label("dag_id"), 
AssetEvent.source_run_id.label("run_id"))
+        .join(
+            source_run,
+            and_(
+                source_run.dag_id == AssetEvent.source_dag_id,
+                source_run.run_id == AssetEvent.source_run_id,
+            ),
+        )
+        .where(AssetEvent.asset_id == asset_id, 
AssetEvent.partition_key.is_not(None))
+        .group_by(AssetEvent.source_dag_id, AssetEvent.source_run_id)
+        .having(emitted_under_own_key == 0)
+        .cte("key_overriding_runs")
+    )
+    attempt_began_at = func.coalesce(DagRun.queued_at, DagRun.start_date, 
DagRun.run_after)
+    ranked_runs = (
+        select(
+            DagRun.partition_key.label("partition_key"),
+            DagRun.dag_id.label("run_dag_id"),
+            DagRun.run_id.label("run_id"),
+            DagRun.state.label("run_state"),
+            DagRun.start_date.label("run_start_date"),
+            DagRun.end_date.label("run_end_date"),
+            attempt_began_at.label("attempt_began_at"),
+            func.row_number()
+            .over(
+                partition_by=DagRun.partition_key,
+                order_by=(attempt_began_at.desc(), DagRun.id.desc()),
+            )
+            .label("position"),
+        )
+        .outerjoin(
+            key_overriding_runs,
+            and_(
+                key_overriding_runs.c.dag_id == DagRun.dag_id,
+                key_overriding_runs.c.run_id == DagRun.run_id,
+            ),
+        )
+        .where(*run_filters, key_overriding_runs.c.run_id.is_(None))
+        .subquery("ranked_runs")
+    )
+    last_runs = select(ranked_runs).where(ranked_runs.c.position == 
1).cte("last_runs")
+    keys = union(select(last_events.c.partition_key), 
select(last_runs.c.partition_key)).cte("partition_keys")
+
+    no_event_since_attempt_began = or_(
+        last_events.c.event_id.is_(None),
+        last_events.c.event_timestamp < last_runs.c.attempt_began_at,
+    )
+    partition_status = case(
+        (
+            and_(
+                last_runs.c.run_state.in_([DagRunState.QUEUED, 
DagRunState.RUNNING]),
+                no_event_since_attempt_began,
+            ),
+            "in_progress",
+        ),
+        (and_(last_runs.c.run_state == DagRunState.FAILED, 
no_event_since_attempt_began), "failed"),
+        (last_events.c.event_id.is_not(None), "materialized"),
+        else_=None,
+    )
+    return (
+        select(
+            keys.c.partition_key,
+            partition_status.label("status"),
+            last_events.c.event_id.label("last_event_id"),
+            last_events.c.event_timestamp.label("last_event_timestamp"),
+            last_runs.c.run_dag_id,
+            last_runs.c.run_id,
+            last_runs.c.run_state,
+            last_runs.c.run_start_date,
+            last_runs.c.run_end_date,
+        )
+        .select_from(keys)
+        .outerjoin(last_events, last_events.c.partition_key == 
keys.c.partition_key)
+        .outerjoin(last_runs, last_runs.c.partition_key == 
keys.c.partition_key)
+        .subquery("asset_partitions")
+    )
+
+
+@assets_router.get(
+    "/assets/{asset_id}/partitions",
+    responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),
+    dependencies=[Depends(requires_access_asset(method="GET"))],
+)
+def get_asset_partitions(
+    asset_id: int,
+    limit: QueryLimit,
+    offset: QueryOffset,
+    readable_dags_filter: ReadableDagsFilterDep,
+    session: SessionDep,
+    partition_status: Annotated[list[AssetPartitionStatus] | None, 
Query(alias="status")] = None,
+    partition_key_pattern: str | None = None,
+) -> AssetPartitionCollectionResponse:
+    """Return the partition keys of an asset with the status of each."""
+    if session.scalar(select(AssetModel.id).where(AssetModel.id == asset_id)) 
is None:
+        raise HTTPException(status.HTTP_404_NOT_FOUND, f"The Asset with ID: 
`{asset_id}` was not found")
+
+    readable_dag_ids = readable_dags_filter.value
+    partitions = _build_asset_partition_status_subquery(asset_id, 
readable_dag_ids)
+    filters: list[ColumnElement[bool]] = [partitions.c.status.is_not(None)]
+    if partition_key_pattern:
+        
filters.append(partitions.c.partition_key.icontains(partition_key_pattern, 
autoescape=True))
+
+    status_counts = AssetPartitionStatusCounts.model_validate(
+        {
+            name: count
+            for name, count in session.execute(
+                select(partitions.c.status, 
func.count()).where(*filters).group_by(partitions.c.status)
+            )
+        }
+    )
+    selected = set(partition_status or get_args(AssetPartitionStatus))
+    total_entries = sum(getattr(status_counts, name) for name in selected)
+
+    page_select = (
+        select(partitions)
+        .where(*filters, partitions.c.status.in_(selected))
+        .order_by(partitions.c.partition_key.desc())
+    )
+    rows = session.execute(apply_filters_to_select(statement=page_select, 
filters=[offset, limit])).all()

Review Comment:
   We are running session.execute for the status twice. Can we try to 
consolidate?



##########
airflow-core/src/airflow/ui/src/pages/Asset/AssetPartitions/AssetPartitions.tsx:
##########
@@ -0,0 +1,200 @@
+/*!
+ * 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 { Box, Button, HStack, Text } from "@chakra-ui/react";
+import type { ColumnDef } from "@tanstack/react-table";
+import { useTranslation } from "react-i18next";
+import { useParams, useSearchParams } from "react-router-dom";
+
+import { useAssetServiceGetAssetPartitions } from "openapi/queries";
+import type { AssetPartitionResponse } from "openapi/requests/types.gen";
+
+import { RouterLink, Tooltip } from "src/system-components";
+
+import { DataTable } from "src/components/DataTable";
+import type { DataTableFeatures } from "src/components/DataTable/features";
+import { useTableURLState } from "src/components/DataTable/useTableUrlState";
+import { ErrorAlert } from "src/components/ErrorAlert";
+import { FilterBar } from "src/components/FilterBar";
+import { StateBadge } from "src/components/StateBadge";
+import Time from "src/components/Time";
+
+import { SearchParamsKeys } from "src/constants/searchParams";
+import { formatNumber } from "src/utils";
+import { useFiltersHandler, type FilterableSearchParamsKeys } from 
"src/utils/useFiltersHandler";
+
+import { PartitionDayGrid } from "./PartitionDayGrid";
+import {
+  groupByMonth,
+  PARTITION_STATUSES,
+  type PartitionStatus,
+  RUN_STATE_BY_STATUS,
+  STATUS_LABEL_KEY,
+} from "./partitionStatus";
+
+const FILTER_KEYS: Array<FilterableSearchParamsKeys> = 
[SearchParamsKeys.PARTITION_KEY];
+
+const isPartitionStatus = (value: string): value is PartitionStatus =>
+  (PARTITION_STATUSES as Array<string>).includes(value);
+
+const getColumns = (
+  translate: (key: string) => string,
+  language: string,
+): Array<ColumnDef<DataTableFeatures, AssetPartitionResponse>> => [
+  {
+    accessorKey: "partition_key",
+    enableSorting: false,
+    header: translate("common:dagRun.partitionKey"),
+  },
+  {
+    accessorKey: "status",
+    cell: ({ row: { original } }) => (
+      <StateBadge state={RUN_STATE_BY_STATUS[original.status]}>
+        {translate(STATUS_LABEL_KEY[original.status])}
+      </StateBadge>
+    ),
+    enableSorting: false,
+    header: translate("common:state"),
+  },
+  {
+    accessorKey: "last_producer_run",
+    cell: ({ row: { original } }) => {
+      const run = original.last_producer_run;
+
+      return run === null ? (
+        <Text color="fg.muted">—</Text>
+      ) : (
+        <HStack gap={2}>
+          <StateBadge state={run.state} />
+          <RouterLink
+            overflowWrap="anywhere"
+            to={`/dags/${run.dag_id}/runs/${encodeURIComponent(run.run_id)}`}
+          >
+            {run.dag_id}
+          </RouterLink>
+        </HStack>
+      );
+    },
+    enableSorting: false,
+    header: translate("assets:partitions.lastProducerRun"),
+  },
+  {
+    accessorKey: "last_event_timestamp",
+    cell: ({ row: { original } }) =>
+      original.last_event_timestamp === null ? (
+        <Text color="fg.muted">—</Text>

Review Comment:
   We can just leave this blank



##########
airflow-core/src/airflow/ui/src/pages/Asset/AssetPartitions/AssetPartitions.tsx:
##########
@@ -0,0 +1,200 @@
+/*!
+ * 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 { Box, Button, HStack, Text } from "@chakra-ui/react";
+import type { ColumnDef } from "@tanstack/react-table";
+import { useTranslation } from "react-i18next";
+import { useParams, useSearchParams } from "react-router-dom";
+
+import { useAssetServiceGetAssetPartitions } from "openapi/queries";
+import type { AssetPartitionResponse } from "openapi/requests/types.gen";
+
+import { RouterLink, Tooltip } from "src/system-components";
+
+import { DataTable } from "src/components/DataTable";
+import type { DataTableFeatures } from "src/components/DataTable/features";
+import { useTableURLState } from "src/components/DataTable/useTableUrlState";
+import { ErrorAlert } from "src/components/ErrorAlert";
+import { FilterBar } from "src/components/FilterBar";
+import { StateBadge } from "src/components/StateBadge";
+import Time from "src/components/Time";
+
+import { SearchParamsKeys } from "src/constants/searchParams";
+import { formatNumber } from "src/utils";
+import { useFiltersHandler, type FilterableSearchParamsKeys } from 
"src/utils/useFiltersHandler";
+
+import { PartitionDayGrid } from "./PartitionDayGrid";
+import {
+  groupByMonth,
+  PARTITION_STATUSES,
+  type PartitionStatus,
+  RUN_STATE_BY_STATUS,
+  STATUS_LABEL_KEY,
+} from "./partitionStatus";
+
+const FILTER_KEYS: Array<FilterableSearchParamsKeys> = 
[SearchParamsKeys.PARTITION_KEY];
+
+const isPartitionStatus = (value: string): value is PartitionStatus =>
+  (PARTITION_STATUSES as Array<string>).includes(value);
+
+const getColumns = (
+  translate: (key: string) => string,
+  language: string,
+): Array<ColumnDef<DataTableFeatures, AssetPartitionResponse>> => [
+  {
+    accessorKey: "partition_key",
+    enableSorting: false,
+    header: translate("common:dagRun.partitionKey"),
+  },
+  {
+    accessorKey: "status",
+    cell: ({ row: { original } }) => (
+      <StateBadge state={RUN_STATE_BY_STATUS[original.status]}>
+        {translate(STATUS_LABEL_KEY[original.status])}
+      </StateBadge>
+    ),
+    enableSorting: false,

Review Comment:
   Let's make this sortable



##########
airflow-core/src/airflow/ui/src/pages/Asset/AssetLayout.tsx:
##########
@@ -66,6 +66,7 @@ export const AssetLayout = () => {
 
   const tabs = [
     { icon: <MdTimeline />, label: translate("assets:events"), value: "" },
+    { icon: <MdOutlineViewModule />, label: 
translate("common:partition_other"), value: "partitions" },

Review Comment:
   Can we detect if an asset will have partitions? For many assets this page 
will always be blank



##########
airflow-core/src/airflow/ui/src/pages/Asset/AssetPartitions/AssetPartitions.tsx:
##########
@@ -0,0 +1,200 @@
+/*!
+ * 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 { Box, Button, HStack, Text } from "@chakra-ui/react";
+import type { ColumnDef } from "@tanstack/react-table";
+import { useTranslation } from "react-i18next";
+import { useParams, useSearchParams } from "react-router-dom";
+
+import { useAssetServiceGetAssetPartitions } from "openapi/queries";
+import type { AssetPartitionResponse } from "openapi/requests/types.gen";
+
+import { RouterLink, Tooltip } from "src/system-components";
+
+import { DataTable } from "src/components/DataTable";
+import type { DataTableFeatures } from "src/components/DataTable/features";
+import { useTableURLState } from "src/components/DataTable/useTableUrlState";
+import { ErrorAlert } from "src/components/ErrorAlert";
+import { FilterBar } from "src/components/FilterBar";
+import { StateBadge } from "src/components/StateBadge";
+import Time from "src/components/Time";
+
+import { SearchParamsKeys } from "src/constants/searchParams";
+import { formatNumber } from "src/utils";
+import { useFiltersHandler, type FilterableSearchParamsKeys } from 
"src/utils/useFiltersHandler";
+
+import { PartitionDayGrid } from "./PartitionDayGrid";
+import {
+  groupByMonth,
+  PARTITION_STATUSES,
+  type PartitionStatus,
+  RUN_STATE_BY_STATUS,
+  STATUS_LABEL_KEY,
+} from "./partitionStatus";
+
+const FILTER_KEYS: Array<FilterableSearchParamsKeys> = 
[SearchParamsKeys.PARTITION_KEY];
+
+const isPartitionStatus = (value: string): value is PartitionStatus =>
+  (PARTITION_STATUSES as Array<string>).includes(value);
+
+const getColumns = (
+  translate: (key: string) => string,
+  language: string,
+): Array<ColumnDef<DataTableFeatures, AssetPartitionResponse>> => [
+  {
+    accessorKey: "partition_key",
+    enableSorting: false,
+    header: translate("common:dagRun.partitionKey"),
+  },
+  {
+    accessorKey: "status",
+    cell: ({ row: { original } }) => (
+      <StateBadge state={RUN_STATE_BY_STATUS[original.status]}>
+        {translate(STATUS_LABEL_KEY[original.status])}
+      </StateBadge>
+    ),
+    enableSorting: false,
+    header: translate("common:state"),
+  },
+  {
+    accessorKey: "last_producer_run",
+    cell: ({ row: { original } }) => {
+      const run = original.last_producer_run;
+
+      return run === null ? (
+        <Text color="fg.muted">—</Text>
+      ) : (
+        <HStack gap={2}>
+          <StateBadge state={run.state} />
+          <RouterLink
+            overflowWrap="anywhere"
+            to={`/dags/${run.dag_id}/runs/${encodeURIComponent(run.run_id)}`}
+          >
+            {run.dag_id}
+          </RouterLink>
+        </HStack>
+      );
+    },
+    enableSorting: false,
+    header: translate("assets:partitions.lastProducerRun"),
+  },
+  {
+    accessorKey: "last_event_timestamp",
+    cell: ({ row: { original } }) =>
+      original.last_event_timestamp === null ? (
+        <Text color="fg.muted">—</Text>
+      ) : (
+        <Time datetime={original.last_event_timestamp} whiteSpace="nowrap" />
+      ),
+    enableSorting: false,

Review Comment:
   Let's make this sortable



##########
airflow-core/src/airflow/ui/src/pages/Asset/AssetPartitions/AssetPartitions.tsx:
##########
@@ -0,0 +1,200 @@
+/*!
+ * 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 { Box, Button, HStack, Text } from "@chakra-ui/react";
+import type { ColumnDef } from "@tanstack/react-table";
+import { useTranslation } from "react-i18next";
+import { useParams, useSearchParams } from "react-router-dom";
+
+import { useAssetServiceGetAssetPartitions } from "openapi/queries";
+import type { AssetPartitionResponse } from "openapi/requests/types.gen";
+
+import { RouterLink, Tooltip } from "src/system-components";
+
+import { DataTable } from "src/components/DataTable";
+import type { DataTableFeatures } from "src/components/DataTable/features";
+import { useTableURLState } from "src/components/DataTable/useTableUrlState";
+import { ErrorAlert } from "src/components/ErrorAlert";
+import { FilterBar } from "src/components/FilterBar";
+import { StateBadge } from "src/components/StateBadge";
+import Time from "src/components/Time";
+
+import { SearchParamsKeys } from "src/constants/searchParams";
+import { formatNumber } from "src/utils";
+import { useFiltersHandler, type FilterableSearchParamsKeys } from 
"src/utils/useFiltersHandler";
+
+import { PartitionDayGrid } from "./PartitionDayGrid";
+import {
+  groupByMonth,
+  PARTITION_STATUSES,
+  type PartitionStatus,
+  RUN_STATE_BY_STATUS,
+  STATUS_LABEL_KEY,
+} from "./partitionStatus";
+
+const FILTER_KEYS: Array<FilterableSearchParamsKeys> = 
[SearchParamsKeys.PARTITION_KEY];
+
+const isPartitionStatus = (value: string): value is PartitionStatus =>
+  (PARTITION_STATUSES as Array<string>).includes(value);
+
+const getColumns = (
+  translate: (key: string) => string,
+  language: string,
+): Array<ColumnDef<DataTableFeatures, AssetPartitionResponse>> => [
+  {
+    accessorKey: "partition_key",
+    enableSorting: false,
+    header: translate("common:dagRun.partitionKey"),
+  },
+  {
+    accessorKey: "status",
+    cell: ({ row: { original } }) => (
+      <StateBadge state={RUN_STATE_BY_STATUS[original.status]}>
+        {translate(STATUS_LABEL_KEY[original.status])}
+      </StateBadge>
+    ),
+    enableSorting: false,
+    header: translate("common:state"),
+  },
+  {
+    accessorKey: "last_producer_run",
+    cell: ({ row: { original } }) => {
+      const run = original.last_producer_run;
+
+      return run === null ? (
+        <Text color="fg.muted">—</Text>
+      ) : (
+        <HStack gap={2}>
+          <StateBadge state={run.state} />
+          <RouterLink
+            overflowWrap="anywhere"
+            to={`/dags/${run.dag_id}/runs/${encodeURIComponent(run.run_id)}`}
+          >
+            {run.dag_id}
+          </RouterLink>
+        </HStack>
+      );
+    },
+    enableSorting: false,

Review Comment:
   Let's make this sortable



##########
airflow-core/src/airflow/ui/src/pages/Asset/AssetPartitions/AssetPartitions.tsx:
##########
@@ -0,0 +1,200 @@
+/*!
+ * 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 { Box, Button, HStack, Text } from "@chakra-ui/react";
+import type { ColumnDef } from "@tanstack/react-table";
+import { useTranslation } from "react-i18next";
+import { useParams, useSearchParams } from "react-router-dom";
+
+import { useAssetServiceGetAssetPartitions } from "openapi/queries";
+import type { AssetPartitionResponse } from "openapi/requests/types.gen";
+
+import { RouterLink, Tooltip } from "src/system-components";
+
+import { DataTable } from "src/components/DataTable";
+import type { DataTableFeatures } from "src/components/DataTable/features";
+import { useTableURLState } from "src/components/DataTable/useTableUrlState";
+import { ErrorAlert } from "src/components/ErrorAlert";
+import { FilterBar } from "src/components/FilterBar";
+import { StateBadge } from "src/components/StateBadge";
+import Time from "src/components/Time";
+
+import { SearchParamsKeys } from "src/constants/searchParams";
+import { formatNumber } from "src/utils";
+import { useFiltersHandler, type FilterableSearchParamsKeys } from 
"src/utils/useFiltersHandler";
+
+import { PartitionDayGrid } from "./PartitionDayGrid";
+import {
+  groupByMonth,
+  PARTITION_STATUSES,
+  type PartitionStatus,
+  RUN_STATE_BY_STATUS,
+  STATUS_LABEL_KEY,
+} from "./partitionStatus";
+
+const FILTER_KEYS: Array<FilterableSearchParamsKeys> = 
[SearchParamsKeys.PARTITION_KEY];
+
+const isPartitionStatus = (value: string): value is PartitionStatus =>
+  (PARTITION_STATUSES as Array<string>).includes(value);
+
+const getColumns = (
+  translate: (key: string) => string,
+  language: string,
+): Array<ColumnDef<DataTableFeatures, AssetPartitionResponse>> => [
+  {
+    accessorKey: "partition_key",
+    enableSorting: false,
+    header: translate("common:dagRun.partitionKey"),
+  },
+  {
+    accessorKey: "status",
+    cell: ({ row: { original } }) => (
+      <StateBadge state={RUN_STATE_BY_STATUS[original.status]}>
+        {translate(STATUS_LABEL_KEY[original.status])}
+      </StateBadge>
+    ),
+    enableSorting: false,
+    header: translate("common:state"),
+  },
+  {
+    accessorKey: "last_producer_run",
+    cell: ({ row: { original } }) => {
+      const run = original.last_producer_run;
+
+      return run === null ? (
+        <Text color="fg.muted">—</Text>
+      ) : (
+        <HStack gap={2}>
+          <StateBadge state={run.state} />
+          <RouterLink
+            overflowWrap="anywhere"
+            to={`/dags/${run.dag_id}/runs/${encodeURIComponent(run.run_id)}`}
+          >
+            {run.dag_id}
+          </RouterLink>
+        </HStack>
+      );
+    },
+    enableSorting: false,
+    header: translate("assets:partitions.lastProducerRun"),
+  },
+  {
+    accessorKey: "last_event_timestamp",
+    cell: ({ row: { original } }) =>
+      original.last_event_timestamp === null ? (
+        <Text color="fg.muted">—</Text>
+      ) : (
+        <Time datetime={original.last_event_timestamp} whiteSpace="nowrap" />
+      ),
+    enableSorting: false,
+    header: translate("assets:lastAssetEvent"),
+  },
+  {
+    accessorKey: "consumer_run_count",
+    cell: ({ row: { original } }) => formatNumber(original.consumer_run_count 
?? 0, language),
+    enableSorting: false,
+    header: () => (
+      <Tooltip content={translate("assets:partitions.consumerRunsHelp")}>
+        <span>{translate("assets:partitions.consumerRuns")}</span>
+      </Tooltip>
+    ),
+  },
+];
+
+export const AssetPartitions = () => {
+  const { i18n, t: translate } = useTranslation(["assets", "common"]);
+  const { assetId: rawAssetId } = useParams();
+  const assetId = rawAssetId === undefined ? 0 : parseInt(rawAssetId, 10);
+  const { setTableURLState, tableURLState } = useTableURLState();
+  const { pagination } = tableURLState;
+  const [searchParams, setSearchParams] = useSearchParams();
+  const { filterConfigs, handleFiltersChange, initialValues } = 
useFiltersHandler(FILTER_KEYS);
+
+  const selectedStatuses = 
searchParams.getAll(SearchParamsKeys.STATE).filter(isPartitionStatus);
+
+  const { data, error, isLoading } = useAssetServiceGetAssetPartitions(
+    {
+      assetId,
+      limit: pagination.pageSize,
+      offset: pagination.pageIndex * pagination.pageSize,
+      partitionKeyPattern: searchParams.get(SearchParamsKeys.PARTITION_KEY) ?? 
undefined,
+      status: selectedStatuses.length === 0 ? undefined : selectedStatuses,
+    },
+    undefined,
+    { enabled: assetId !== 0 },

Review Comment:
   Let's add auto refresh here, but only when we have pending partitions



##########
airflow-core/src/airflow/ui/src/pages/Asset/AssetPartitions/AssetPartitions.tsx:
##########
@@ -0,0 +1,200 @@
+/*!
+ * 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 { Box, Button, HStack, Text } from "@chakra-ui/react";
+import type { ColumnDef } from "@tanstack/react-table";
+import { useTranslation } from "react-i18next";
+import { useParams, useSearchParams } from "react-router-dom";
+
+import { useAssetServiceGetAssetPartitions } from "openapi/queries";
+import type { AssetPartitionResponse } from "openapi/requests/types.gen";
+
+import { RouterLink, Tooltip } from "src/system-components";
+
+import { DataTable } from "src/components/DataTable";
+import type { DataTableFeatures } from "src/components/DataTable/features";
+import { useTableURLState } from "src/components/DataTable/useTableUrlState";
+import { ErrorAlert } from "src/components/ErrorAlert";
+import { FilterBar } from "src/components/FilterBar";
+import { StateBadge } from "src/components/StateBadge";
+import Time from "src/components/Time";
+
+import { SearchParamsKeys } from "src/constants/searchParams";
+import { formatNumber } from "src/utils";
+import { useFiltersHandler, type FilterableSearchParamsKeys } from 
"src/utils/useFiltersHandler";
+
+import { PartitionDayGrid } from "./PartitionDayGrid";
+import {
+  groupByMonth,
+  PARTITION_STATUSES,
+  type PartitionStatus,
+  RUN_STATE_BY_STATUS,
+  STATUS_LABEL_KEY,
+} from "./partitionStatus";
+
+const FILTER_KEYS: Array<FilterableSearchParamsKeys> = 
[SearchParamsKeys.PARTITION_KEY];
+
+const isPartitionStatus = (value: string): value is PartitionStatus =>
+  (PARTITION_STATUSES as Array<string>).includes(value);
+
+const getColumns = (
+  translate: (key: string) => string,
+  language: string,
+): Array<ColumnDef<DataTableFeatures, AssetPartitionResponse>> => [
+  {
+    accessorKey: "partition_key",
+    enableSorting: false,
+    header: translate("common:dagRun.partitionKey"),
+  },
+  {
+    accessorKey: "status",
+    cell: ({ row: { original } }) => (
+      <StateBadge state={RUN_STATE_BY_STATUS[original.status]}>
+        {translate(STATUS_LABEL_KEY[original.status])}
+      </StateBadge>
+    ),
+    enableSorting: false,
+    header: translate("common:state"),
+  },
+  {
+    accessorKey: "last_producer_run",
+    cell: ({ row: { original } }) => {
+      const run = original.last_producer_run;
+
+      return run === null ? (
+        <Text color="fg.muted">—</Text>
+      ) : (
+        <HStack gap={2}>
+          <StateBadge state={run.state} />
+          <RouterLink
+            overflowWrap="anywhere"
+            to={`/dags/${run.dag_id}/runs/${encodeURIComponent(run.run_id)}`}
+          >
+            {run.dag_id}
+          </RouterLink>
+        </HStack>
+      );
+    },
+    enableSorting: false,
+    header: translate("assets:partitions.lastProducerRun"),
+  },
+  {
+    accessorKey: "last_event_timestamp",
+    cell: ({ row: { original } }) =>
+      original.last_event_timestamp === null ? (
+        <Text color="fg.muted">—</Text>
+      ) : (
+        <Time datetime={original.last_event_timestamp} whiteSpace="nowrap" />
+      ),
+    enableSorting: false,
+    header: translate("assets:lastAssetEvent"),
+  },
+  {
+    accessorKey: "consumer_run_count",
+    cell: ({ row: { original } }) => formatNumber(original.consumer_run_count 
?? 0, language),
+    enableSorting: false,
+    header: () => (
+      <Tooltip content={translate("assets:partitions.consumerRunsHelp")}>
+        <span>{translate("assets:partitions.consumerRuns")}</span>
+      </Tooltip>

Review Comment:
   This is only a count. Is it possible to make this a popover with a link to 
each run like we do for asset events ?



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