Skip to content

Commit cc98ac0

Browse files
[Orchestrator] Use instance totalCount for All runs tab count
Read totalCount from the instances API for the runs tab title and pagination instead of showing only the current page size. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e2df0a3 commit cc98ac0

2 files changed

Lines changed: 41 additions & 17 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-orchestrator': patch
3+
---
4+
5+
Use instance `totalCount` from the API for the All runs tab title and pagination instead of the current page size.

workspaces/orchestrator/plugins/orchestrator/src/components/OrchestratorPage/WorkflowRunsTabContent.tsx

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ import { VariablesDialog } from '../WorkflowInstancePage/VariablesDialog';
8989
import { mapProcessInstanceToDetails } from '../WorkflowInstancePage/WorkflowInstancePageContent';
9090
import { WorkflowLogsDialog } from '../WorkflowInstancePage/WorkflowLogsDialog';
9191

92+
type WorkflowRunsFetchResult = {
93+
items: WorkflowRunDetail[];
94+
totalCount?: number;
95+
};
96+
9297
const EntityRefTableCell = ({
9398
entityRef,
9499
defaultKind,
@@ -450,11 +455,14 @@ export const WorkflowRunsTabContent = ({
450455
filter,
451456
);
452457

453-
const clonedData: WorkflowRunDetail[] =
458+
const items: WorkflowRunDetail[] =
454459
instances.data.items?.map(instance =>
455460
mapProcessInstanceToDetails(instance, t),
456461
) || [];
457-
return clonedData;
462+
return {
463+
items,
464+
totalCount: instances.data.totalCount,
465+
};
458466
}, [
459467
orchestratorApi,
460468
page,
@@ -491,9 +499,14 @@ export const WorkflowRunsTabContent = ({
491499
],
492500
);
493501

494-
const { loading, error, value } = usePolling(fetchInstances, {
495-
cacheKey: pollingCacheKey,
496-
});
502+
const { loading, error, value } = usePolling<WorkflowRunsFetchResult>(
503+
fetchInstances,
504+
{
505+
cacheKey: pollingCacheKey,
506+
},
507+
);
508+
509+
const runItems = value?.items;
497510

498511
const filterForRunByOptions = useMemo(
499512
() => getFilter({ includeRunByFilter: false }),
@@ -502,10 +515,10 @@ export const WorkflowRunsTabContent = ({
502515

503516
const additionalInitiators = useMemo(
504517
() =>
505-
(value ?? [])
518+
(runItems ?? [])
506519
.map(run => run.initiatorEntity)
507520
.filter((initiator): initiator is string => Boolean(initiator)),
508-
[value],
521+
[runItems],
509522
);
510523

511524
const { items: runByFilterItems } = useRunByFilterItems({
@@ -541,16 +554,16 @@ export const WorkflowRunsTabContent = ({
541554
// Should be resolved when upgrading backstage and all plugins to material6
542555
// The workaround is to configure the FE sorting material-table applies to be according to order received from backend
543556
// TODO: resolve when upgrading to material 6
544-
if (!value) {
557+
if (!runItems) {
545558
return 0;
546559
}
547-
const item1Index = value?.findIndex(curItem => curItem.id === item1.id);
548-
const item2Index = value?.findIndex(curItem => curItem.id === item2.id);
560+
const item1Index = runItems.findIndex(curItem => curItem.id === item1.id);
561+
const item2Index = runItems.findIndex(curItem => curItem.id === item2.id);
549562
return orderDirection === 'asc'
550563
? item1Index - item2Index
551564
: item2Index - item1Index;
552565
},
553-
[value, orderDirection],
566+
[runItems, orderDirection],
554567
);
555568

556569
const columns = useMemo(
@@ -686,13 +699,13 @@ export const WorkflowRunsTabContent = ({
686699
}, [canViewRunVariables, handleViewRunVariables, t]);
687700

688701
const data = useMemo(() => {
689-
const items = value || [];
702+
const items = runItems ?? [];
690703
if (items.length === pageSize + 1) {
691704
return items.slice(0, -1);
692705
}
693706
return items;
694-
}, [value, pageSize]);
695-
const hasNextPage = (value?.length ?? 0) === pageSize + 1;
707+
}, [runItems, pageSize]);
708+
const hasNextPage = (runItems?.length ?? 0) === pageSize + 1;
696709
const filteredData = useMemo(() => {
697710
const query = search.trim().toLowerCase();
698711
if (!query) {
@@ -710,6 +723,12 @@ export const WorkflowRunsTabContent = ({
710723
row.start.toLowerCase().includes(query),
711724
);
712725
}, [data, search]);
726+
const displayedRunCount = useMemo(() => {
727+
if (search.trim()) {
728+
return filteredData.length;
729+
}
730+
return value?.totalCount ?? data.length;
731+
}, [search, filteredData.length, value?.totalCount, data.length]);
713732
const enablePaging = page > 0 || hasNextPage;
714733
const isDefaultFilters =
715734
statusSelectorValue === Selector.AllItems &&
@@ -863,12 +882,12 @@ export const WorkflowRunsTabContent = ({
863882
workflowId ? (
864883
<Trans
865884
message="table.title.allWorkflowRuns"
866-
params={{ count: filteredData.length }}
885+
params={{ count: displayedRunCount }}
867886
/>
868887
) : (
869888
<Trans
870889
message="table.title.allRuns"
871-
params={{ count: filteredData.length }}
890+
params={{ count: displayedRunCount }}
872891
/>
873892
)
874893
}
@@ -903,7 +922,7 @@ export const WorkflowRunsTabContent = ({
903922
{enablePaging && (
904923
<TablePagination
905924
component="div"
906-
count={-1}
925+
count={value?.totalCount ?? -1}
907926
page={page}
908927
onPageChange={(_, page_) => setPage(page_)}
909928
onRowsPerPageChange={e => {

0 commit comments

Comments
 (0)