feat(search): add useFleetSearchSubscription and useFleetSearch hooks to multicluster-sdk#1
Open
zlayne wants to merge 16 commits into
Open
feat(search): add useFleetSearchSubscription and useFleetSearch hooks to multicluster-sdk#1zlayne wants to merge 16 commits into
zlayne wants to merge 16 commits into
Conversation
… to multicluster-sdk ACM-32322 — Add GraphQL subscription support to the multicluster-sdk. - useFleetSearchSubscription: wraps the generated useSearchSubscription Apollo hook; returns [latestEvent, loading, error]; skips the WebSocket connection when input is undefined. - useFleetSearch: one-shot query hook with optional real-time patching via useFleetSearchSubscription; handles INSERT/UPDATE/DELETE events; supports pagination through SearchInput.limit and SearchInput.offset. - Re-export SearchInput from src/types/search.ts so callers can type their input without reaching into internal packages. - Update src/api/index.ts and src/index.test.ts public-API guard. - Regenerate README.md API docs. Signed-off-by: zlayne <zlayne@redhat.com>
Verifies: - Search page loads and returns results via Apollo HTTP link - Search WebSocket proxy endpoint is reachable (WS transport for subscriptions) Signed-off-by: zlayne <zlayne@redhat.com>
Signed-off-by: zlayne <zlayne@redhat.com>
Signed-off-by: zlayne <zlayne@redhat.com>
Signed-off-by: zlayne <zlayne@redhat.com>
Signed-off-by: zlayne <zlayne@redhat.com>
Signed-off-by: zlayne <zlayne@redhat.com>
Signed-off-by: zlayne <zlayne@redhat.com>
Signed-off-by: zlayne <zlayne@redhat.com>
Signed-off-by: zlayne <zlayne@redhat.com>
Signed-off-by: zlayne <zlayne@redhat.com>
Signed-off-by: zlayne <zlayne@redhat.com>
Signed-off-by: zlayne <zlayne@redhat.com>
Signed-off-by: zlayne <zlayne@redhat.com>
Signed-off-by: zlayne <zlayne@redhat.com>
Signed-off-by: zlayne <zlayne@redhat.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Summary
Ticket Summary (Title):
ACM Console - multicluster-sdk should support Search API GraphQL Subscriptions
Ticket Link:
https://redhat.atlassian.net/browse/ACM-32322
Type of Change:
What
Adds two new public hooks to the
@stolostron/multicluster-sdkpackage:useFleetSearchSubscription(input)Wraps the generated
useSearchSubscriptionApollo hook with the sharedsearchClient. Opens a GraphQL WebSocket subscription and streams real-time change events from the search index. Returns[latestEvent, loading, error]— only the most recentEventis returned (not accumulated); callers react with auseEffectwatchinglatestEvent. Skips the WebSocket connection entirely wheninputisundefined.useFleetSearch<T>(input, subscriptionEnabled?)Combines a one-shot Apollo HTTP query (
useSearchResultItemsQuery) with an optional real-time subscription layer. WhensubscriptionEnabledistrue, the hook opens a WebSocket subscription viauseFleetSearchSubscriptionand patches locally-held results on INSERT, UPDATE, and DELETE events — keeping the data always up to date without polling. Pagination is supported by settinglimitandoffseton theSearchInputobject.Also re-exports
SearchInputfromsrc/types/search.tsso callers can type their input without reaching into internal packages.Why
The Search API already supports GraphQL subscriptions over WebSocket, but the
multicluster-sdkhad no public hook to consume them. This meant search results became stale and required polling (or full page refreshes) to stay current. With these hooks, consumers get live updates as resources are created, updated, or deleted in the search index.How to test
npm run setup(if not already done)npm run plugins— start in plugin modehttp://localhost:9000/multicloud/searchuseFleetSearchbase query)/proxy/searchwhen a subscription-enabled consumer is renderedUnit tests (automated)
E2E test (Playwright, run against cluster)
✅ Checklist
General
@param,@returns,@example)If Feature
npm run generate-doc)🗒️ Notes for Reviewers
useFleetSearchSubscriptionis the low-level primitive — it returns only the latest event (not an array). Callers accumulate events viauseEffectif needed.useFleetSearchusesuseStateinitialised from the query result and patches it in-place on each WebSocket event. WhensubscriptionEnabledflips tofalse, it resets to the base query data.eslint-disable-next-line react-hooks/exhaustive-depscomment on thesubscriptionEnabledtoggle effect is intentional — we only want to reset when the flag changes, not on everyqueryDatachange (which has its own effect).convertSearchItemToResourcecast usesas unknown as SearchResult<T>— same pattern asuseFleetSearchPoll— due to the conditional mapped type not being narrowable at the call site.