Skip to content

Commit

Permalink
fix(list-service-logs): filter by container and version first renderi…
Browse files Browse the repository at this point in the history
…ng (#1770)

* fix(list-service-logs): filter by container and version first rendering
  • Loading branch information
RemiBonnet authored Nov 28, 2024
1 parent 7be228f commit ca169dc
Showing 1 changed file with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,23 @@ export function ListServiceLogs({ environment, clusterId, serviceStatus, environ
[columnHelper, hasMultipleContainers]
)

const columnFilters = useMemo(() => {
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>(
searchParams.get('pod_name')
? [
{
id: 'pod_name',
value: searchParams.get('pod_name'),
},
]
: []
)

// Necessary with sidebar-pod-statuses to keep the filter in sync if you navigate from service logs page
useEffect(() => {
const podName = searchParams.get('pod_name')
return podName ? [{ id: 'pod_name', value: podName }] : []
setColumnFilters(podName ? [{ id: 'pod_name', value: podName }] : [])
}, [searchParams])

const setColumnFilters = useCallback(
(filterOrUpdater: ColumnFiltersState | ((prev: ColumnFiltersState) => ColumnFiltersState)) => {
const newFilters = typeof filterOrUpdater === 'function' ? filterOrUpdater(columnFilters) : filterOrUpdater

// Update searchParams based on the new filters
const podNameFilter = newFilters.find((f) => f.id === 'pod_name')
if (podNameFilter) {
searchParams.set('pod_name', podNameFilter.value as string)
} else {
searchParams.delete('pod_name')
}
setSearchParams(searchParams)
},
[searchParams, setSearchParams, columnFilters]
)

const table = useReactTable({
data: logs,
state: { columnFilters },
Expand Down

0 comments on commit ca169dc

Please sign in to comment.