@stolostron/multicluster-sdk
Version:
Provides extensions and APIs that dynamic plugins can use to leverage multicluster capabilities provided by Red Hat Advanced Cluster Management.
72 lines • 2.93 kB
TypeScript
import { Fleet } from '../types/fleet';
import { SearchInput } from '../types/search';
/**
* A React hook that provides fleet-wide search functionality using the ACM search API,
* with optional real-time updates via a GraphQL WebSocket subscription.
*
* When `subscriptionEnabled` is `false` (the default), the hook issues a one-shot
* GraphQL query and returns the results. When `subscriptionEnabled` is `true`, the
* hook additionally opens a WebSocket subscription and patches the locally-held
* results as INSERT, UPDATE, and DELETE events arrive — keeping the data always
* up to date without polling.
*
* Pagination is supported by setting `limit` and `offset` on the `SearchInput`
* object. The caller is responsible for constructing those values.
*
* @param input - The search input object (filters, keywords, limit, offset, etc.).
* Pass `undefined` to skip the query entirely.
* @param subscriptionEnabled - When `true`, a WebSocket subscription is opened
* and the local result set is kept current via incremental event patches.
* Defaults to `false`.
*
* @returns A tuple of:
* - `data` — The current search results mapped through
* {@link convertSearchItemToResource}, or `undefined` before the first
* response arrives.
* - `loaded` — `true` once the initial query has completed (regardless of
* whether the subscription is active).
* - `error` — Any query or subscription error, or `undefined` on success.
* - `refetch` — A stable callback that re-executes the base query and resets
* the local state to the fresh result.
*
* @example
* ```typescript
* // Basic query — no real-time updates
* const [resources, loaded, error, refetch] = useFleetSearch({
* filters: [
* { property: 'kind', values: ['Pod'] },
* { property: 'namespace', values: ['default'] },
* ],
* limit: 100,
* })
*
* // With real-time subscription — results update automatically
* const [resources, loaded, error, refetch] = useFleetSearch(
* {
* filters: [
* { property: 'kind', values: ['Pod'] },
* { property: 'namespace', values: ['default'] },
* ],
* },
* true,
* )
*
* // With subscription enabled and pagination/ordering — page 2 of 20 results sorted by name
* const PAGE_SIZE = 20
* const [page, setPage] = useState(1)
* const [resources, loaded, error, refetch] = useFleetSearch(
* {
* filters: [
* { property: 'kind', values: ['Pod'] },
* { property: 'namespace', values: ['default'] },
* ],
* limit: PAGE_SIZE,
* offset: (page - 1) * PAGE_SIZE,
* orderBy: 'name asc',
* },
* true,
* )
* ```
*/
export declare function useFleetSearch<T extends K8sResourceCommon = K8sResourceCommon>(input: SearchInput | undefined, subscriptionEnabled?: boolean): [Fleet<T>[] | undefined, boolean, Error | undefined, () => void];
//# sourceMappingURL=useFleetSearch.d.ts.map