mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
## Context For Database Connections - the PIDs on the overview cards are selectable such that clicking on them should scroll the browser down to where the row is. However, if the selected PID isn't rendered due to the applied filters, clicking on it will seemingly do nothing. Changes here hence opt to remove all filters then scroll to the selected PID into view, so that users can always quickly find which PID the overview card is referencing. Also chucked in some refactors to centralize the management of filters, and functionality of selecting a PID into their own hooks <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added shared filtering for database activity by state, role, application, search text, and view. * Activity filters are now preserved in the URL for easier navigation and sharing. * Selecting activity metrics or process IDs now automatically reveals the relevant activity row. * Blocker view highlights root activities that are blocking other queries. * **Bug Fixes** * Improved selection behavior when the chosen activity is hidden by active filters. * **Tests** * Added coverage for individual, combined, case-insensitive, and blocker-specific filtering scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
import { parseAsInteger, useQueryState } from 'nuqs'
|
|
|
|
import { filterActivities } from './DatabaseConnections.utils'
|
|
import { EMPTY_ACTIVITY_FILTERS, useActivityFilters } from './useActivityFilters'
|
|
import { useDatabaseActivityQuery } from '@/data/database/activity-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
|
|
// Selecting a pid should always bring it into view. If the current filters would hide it (e.g.
|
|
// its role isn't in the default roles filter), clear all filters so it's guaranteed to render.
|
|
export const useSelectActivityPid = () => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const { data } = useDatabaseActivityQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
const { filters, setFilters } = useActivityFilters()
|
|
const [selectedPid, setSelectedPid] = useQueryState('pid', parseAsInteger)
|
|
|
|
const selectPid = (pid: number) => {
|
|
const isVisible = filterActivities(data ?? [], filters).some((x) => x.pid === pid)
|
|
if (!isVisible) setFilters(EMPTY_ACTIVITY_FILTERS)
|
|
setSelectedPid(pid)
|
|
}
|
|
|
|
return { selectedPid, selectPid }
|
|
}
|