fix(swarm/service): list task when filtering service [BE-11029] (#12146)

pull/12152/head
Oscar Zhou 2024-08-28 18:28:38 +12:00 committed by GitHub
parent e8ec648886
commit f59dd34154
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 14 deletions

View File

@ -1,5 +1,6 @@
import { Shuffle } from 'lucide-react'; import { Shuffle } from 'lucide-react';
import { Row } from '@tanstack/react-table'; import { Row } from '@tanstack/react-table';
import { useRef } from 'react';
import { ServiceViewModel } from '@/docker/models/service'; import { ServiceViewModel } from '@/docker/models/service';
import { useApiVersion } from '@/react/docker/proxy/queries/useVersion'; import { useApiVersion } from '@/react/docker/proxy/queries/useVersion';
@ -55,6 +56,8 @@ export function ServicesDatatable({
isStackColumnVisible?: boolean; isStackColumnVisible?: boolean;
onRefresh?(): void; onRefresh?(): void;
}) { }) {
// useRef so that updating the parent filter doesn't cause a re-render
const parentFilteredStatusRef = useRef<Map<string, boolean>>(new Map());
const environmentId = useEnvironmentId(); const environmentId = useEnvironmentId();
const apiVersion = useApiVersion(environmentId); const apiVersion = useApiVersion(environmentId);
const tableState = useTableState(store, tableKey); const tableState = useTableState(store, tableKey);
@ -76,7 +79,11 @@ export function ServicesDatatable({
<td colSpan={Number.MAX_SAFE_INTEGER}> <td colSpan={Number.MAX_SAFE_INTEGER}>
<TasksDatatable <TasksDatatable
dataset={item.Tasks as Array<DecoratedTask>} dataset={item.Tasks as Array<DecoratedTask>}
search={tableState.search} search={
parentFilteredStatusRef.current.get(item.Id)
? ''
: tableState.search
}
/> />
</td> </td>
</tr> </tr>
@ -111,19 +118,24 @@ export function ServicesDatatable({
data-cy="services-datatable" data-cy="services-datatable"
/> />
); );
}
function filter( function filter(
row: Row<ServiceViewModel>, row: Row<ServiceViewModel>,
columnId: string, columnId: string,
filterValue: null | { search: string } filterValue: null | { search: string }
) { ) {
return ( parentFilteredStatusRef.current = parentFilteredStatusRef.current.set(
defaultGlobalFilterFn(row, columnId, filterValue) || row.id,
row.original.Tasks.some((task) => defaultGlobalFilterFn(row, columnId, filterValue)
Object.values(task).some( );
(value) => value && value.toString().includes(filterValue?.search || '') return (
parentFilteredStatusRef.current.get(row.id) ||
row.original.Tasks.some((task) =>
Object.values(task).some(
(value) =>
value && value.toString().includes(filterValue?.search || '')
)
) )
) );
); }
} }

View File

@ -38,6 +38,7 @@ function Cell({
.filter((port) => port.PublishedPort) .filter((port) => port.PublishedPort)
.map((port) => ( .map((port) => (
<PublishedPortLink <PublishedPortLink
key={port.PublishedPort}
hostPort={port.PublishedPort} hostPort={port.PublishedPort}
containerPort={port.TargetPort} containerPort={port.TargetPort}
hostURL={environmentQuery.data.PublicURL} hostURL={environmentQuery.data.PublicURL}