Skip to content

Commit

Permalink
[UI v2] feat: Refines flow run card in replacement for flow run data …
Browse files Browse the repository at this point in the history
…table
  • Loading branch information
devinvillarosa committed Feb 21, 2025
1 parent 27e85f9 commit 3c32c67
Show file tree
Hide file tree
Showing 40 changed files with 311 additions and 1,303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function useBuildTabOptions(deployment: Deployment) {
),
ViewComponent: () => (
<TabsContent value="Upcoming">
<DeploymentDetailsUpcomingTab deploymentId={deployment.id} />
<DeploymentDetailsUpcomingTab deployment={deployment} />
</TabsContent>
),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { getRouteApi } from "@tanstack/react-router";

import { Deployment } from "@/api/deployments";
import { usePaginateFlowRunswithFlows } from "@/api/flow-runs/use-paginate-flow-runs-with-flows";
import { FlowRunState, SortFilters } from "@/components/flow-runs/data-table";
import {
FlowRunState,
FlowRunsFilters,
FlowRunsList,
FlowRunsPagination,
FlowRunsRowCount,
type PaginationState,
SortFilters,
} from "@/components/flow-runs/flow-runs-list";
import { useCallback, useMemo, useState } from "react";

const routeApi = getRouteApi("/deployments/deployment/$id");

type DeploymentDetailsUpcomingTabProps = {
deploymentId: string;
deployment: Deployment;
};

export const DeploymentDetailsUpcomingTab = ({
deploymentId,
deployment,
}: DeploymentDetailsUpcomingTabProps) => {
const [selectedRows, setSelectedRows] = useState<Set<string>>(new Set());
const [pagination, onChangePagination] = usePagination();
Expand All @@ -30,7 +32,7 @@ export const DeploymentDetailsUpcomingTab = ({
const { data } = usePaginateFlowRunswithFlows({
deployments: {
operator: "and_",
id: { any_: [deploymentId] },
id: { any_: [deployment.id] },
},
flow_runs: {
name: { like_: search || undefined },
Expand All @@ -45,10 +47,15 @@ export const DeploymentDetailsUpcomingTab = ({
sort,
});

const handleResetFilters = () => {
resetFilters();
setSelectedRows(new Set());
};
const dataWithDeployment = useMemo(() => {
if (!data) {
return undefined;
}
return {
...data,
results: data.results.map((flowRun) => ({ ...flowRun, deployment })),
};
}, [data, deployment]);

const addRow = (id: string) =>
setSelectedRows((curr) => new Set(curr).add(id));
Expand All @@ -67,12 +74,19 @@ export const DeploymentDetailsUpcomingTab = ({
}
};

const handleResetFilters = !resetFilters
? undefined
: () => {
resetFilters();
setSelectedRows(new Set());
};

return (
<div className="flex flex-col gap-2">
<div className="flex items-center justify-between">
<FlowRunsRowCount
count={data?.count}
results={data?.results}
count={dataWithDeployment?.count}
results={dataWithDeployment?.results}
selectedRows={selectedRows}
setSelectedRows={setSelectedRows}
/>
Expand All @@ -87,24 +101,26 @@ export const DeploymentDetailsUpcomingTab = ({
</div>

<FlowRunsList
flowRuns={data?.results}
flowRuns={dataWithDeployment?.results}
selectedRows={selectedRows}
onSelect={handleSelectRow}
onClearFilters={handleResetFilters}
/>

{data && data.results.length > 0 && (
{dataWithDeployment && dataWithDeployment.results.length > 0 && (
<FlowRunsPagination
count={dataWithDeployment.count}
pagination={pagination}
onChangePagination={onChangePagination}
pages={data.pages}
pages={dataWithDeployment.pages}
/>
)}
</div>
);
};

function useResetFilters() {
const { upcoming } = routeApi.useSearch();
const navigate = routeApi.useNavigate();
const resetFilters = useCallback(() => {
void navigate({
Expand All @@ -116,7 +132,9 @@ function useResetFilters() {
replace: true,
});
}, [navigate]);
return resetFilters;
const hasFiltersApplied = useMemo(() => Boolean(upcoming), [upcoming]);

return hasFiltersApplied ? resetFilters : undefined;
}

function usePagination() {
Expand Down
116 changes: 0 additions & 116 deletions ui-v2/src/components/flow-runs/data-table/data-table-filters.tsx

This file was deleted.

144 changes: 0 additions & 144 deletions ui-v2/src/components/flow-runs/data-table/data-table.stories.tsx

This file was deleted.

Loading

0 comments on commit 3c32c67

Please sign in to comment.