-
Notifications
You must be signed in to change notification settings - Fork 452
feat(ui,shared,localizations): Add test step for <ConfigureSSO />
#8544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4785e63
Rename `Flow.Part` from `test-sso` to `testSso`
LauraBeatris d3a056a
Introduce basic UI
LauraBeatris 97b0daa
Add localization keys
LauraBeatris 64f1280
Create test run URL
LauraBeatris 34d2f15
Introduce internal hook to fetch test runs
LauraBeatris d02c01a
Open drawer on test click
LauraBeatris 5497cac
Add how to fix section for test runs
LauraBeatris 731a332
Display parsed user info for success
LauraBeatris 0c30f01
Add pagination
LauraBeatris 476b485
Query for successful test on continue click
LauraBeatris 691c631
Add changeset
LauraBeatris 37a2316
Open drawer as relative to component content
LauraBeatris 15944be
Use invalidation key
LauraBeatris 807338e
Fix stale closure with `onCopy`
LauraBeatris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@clerk/localizations': patch | ||
| '@clerk/shared': patch | ||
| '@clerk/ui': patch | ||
| --- | ||
|
|
||
| Add test step for `<__experimental_ConfigureSSO />` |
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
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
31 changes: 31 additions & 0 deletions
31
packages/shared/src/react/hooks/useEnterpriseConnectionTestRuns.shared.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { useMemo } from 'react'; | ||
|
|
||
| import type { GetEnterpriseConnectionTestRunsParams } from '../../types/enterpriseConnectionTestRun'; | ||
| import { INTERNAL_STABLE_KEYS } from '../stable-keys'; | ||
| import { createCacheKeys } from './createCacheKeys'; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| export function useEnterpriseConnectionTestRunsCacheKeys(params: { | ||
| userId: string | null; | ||
| enterpriseConnectionId: string | null; | ||
| args: GetEnterpriseConnectionTestRunsParams; | ||
| }) { | ||
| const { userId, enterpriseConnectionId, args } = params; | ||
| return useMemo(() => { | ||
| return createCacheKeys({ | ||
| stablePrefix: INTERNAL_STABLE_KEYS.ENTERPRISE_CONNECTION_TEST_RUNS_KEY, | ||
| authenticated: Boolean(userId), | ||
| tracked: { | ||
| userId: userId ?? null, | ||
| enterpriseConnectionId: enterpriseConnectionId ?? null, | ||
| }, | ||
| untracked: { | ||
| args, | ||
| }, | ||
| }); | ||
| // The args object is intentionally serialized via the consumer to keep stability. | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [userId, enterpriseConnectionId, JSON.stringify(args)]); | ||
| } |
139 changes: 139 additions & 0 deletions
139
packages/shared/src/react/hooks/useEnterpriseConnectionTestRuns.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| import { useCallback, useEffect, useState } from 'react'; | ||
|
|
||
| import type { | ||
| EnterpriseConnectionTestRunResource, | ||
| GetEnterpriseConnectionTestRunsParams, | ||
| } from '../../types/enterpriseConnectionTestRun'; | ||
| import { useClerkInstanceContext } from '../contexts'; | ||
| import { useClerkQueryClient } from '../query/use-clerk-query-client'; | ||
| import { useClerkQuery } from '../query/useQuery'; | ||
| import { useUserBase } from './base/useUserBase'; | ||
| import { useClearQueriesOnSignOut } from './useClearQueriesOnSignOut'; | ||
| import { useEnterpriseConnectionTestRunsCacheKeys } from './useEnterpriseConnectionTestRuns.shared'; | ||
|
|
||
| const DEFAULT_POLL_INTERVAL_MS = 2_000; | ||
|
|
||
| export type UseEnterpriseConnectionTestRunsParams = { | ||
| enterpriseConnectionId: string | null; | ||
| /** | ||
| * Pass-through fetch parameters (pagination, status filter). | ||
| * Defaults to `{ initialPage: 1, pageSize: 10 }`. | ||
| */ | ||
| params?: GetEnterpriseConnectionTestRunsParams; | ||
| /** | ||
| * Polling interval (ms) applied between `revalidate()` and the moment the | ||
| * first record arrives in the response. | ||
| * | ||
| * @default 2000 | ||
| */ | ||
| pollIntervalMs?: number; | ||
| /** | ||
| * If `false`, the hook is dormant — no fetch, no polling. | ||
| * | ||
| * @default true | ||
| */ | ||
| enabled?: boolean; | ||
| }; | ||
|
|
||
| export type UseEnterpriseConnectionTestRunsReturn = { | ||
| data: EnterpriseConnectionTestRunResource[] | undefined; | ||
| totalCount: number | undefined; | ||
| error: Error | null; | ||
| isLoading: boolean; | ||
| isFetching: boolean; | ||
| /** | ||
| * `true` while the hook is actively polling for the first record to appear | ||
| */ | ||
| isPolling: boolean; | ||
| /** | ||
| * Force a refetch and (if the list is currently empty) arm polling | ||
| */ | ||
| revalidate: () => Promise<void>; | ||
| }; | ||
|
|
||
| /** | ||
| * Subscribes to the list of enterprise-connection test runs for the signed-in user | ||
| * | ||
| * @internal | ||
| */ | ||
| function useEnterpriseConnectionTestRuns( | ||
| params: UseEnterpriseConnectionTestRunsParams, | ||
| ): UseEnterpriseConnectionTestRunsReturn { | ||
| const { | ||
| enterpriseConnectionId, | ||
| params: fetchParams = { initialPage: 1, pageSize: 10 }, | ||
| pollIntervalMs = DEFAULT_POLL_INTERVAL_MS, | ||
| enabled = true, | ||
| } = params; | ||
|
|
||
| const clerk = useClerkInstanceContext(); | ||
| const user = useUserBase(); | ||
| const [queryClient] = useClerkQueryClient(); | ||
|
|
||
| const { queryKey, invalidationKey, stableKey, authenticated } = useEnterpriseConnectionTestRunsCacheKeys({ | ||
| userId: user?.id ?? null, | ||
| enterpriseConnectionId, | ||
| args: fetchParams, | ||
| }); | ||
|
|
||
| useClearQueriesOnSignOut({ | ||
| isSignedOut: user === null, | ||
| authenticated, | ||
| stableKeys: stableKey, | ||
| }); | ||
|
|
||
| const queryEnabled = enabled && clerk.loaded && Boolean(user) && Boolean(enterpriseConnectionId); | ||
|
|
||
| const [shouldPoll, setShouldPoll] = useState(false); | ||
|
|
||
| const query = useClerkQuery({ | ||
| queryKey, | ||
| queryFn: () => { | ||
| if (!enterpriseConnectionId) { | ||
| throw new Error('enterpriseConnectionId is required to fetch test runs'); | ||
| } | ||
| return user?.getEnterpriseConnectionTestRuns(enterpriseConnectionId, fetchParams); | ||
| }, | ||
| refetchInterval: q => { | ||
| if (!shouldPoll) { | ||
| return false; | ||
| } | ||
|
|
||
| const hasRows = (q.state.data?.data?.length ?? 0) > 0; | ||
| return hasRows ? false : pollIntervalMs; | ||
| }, | ||
| enabled: queryEnabled, | ||
| refetchIntervalInBackground: false, | ||
| }); | ||
|
LauraBeatris marked this conversation as resolved.
|
||
|
|
||
| const hasRows = (query.data?.data?.length ?? 0) > 0; | ||
|
|
||
| useEffect(() => { | ||
| if (shouldPoll && hasRows) { | ||
| setShouldPoll(false); | ||
| } | ||
| }, [shouldPoll, hasRows]); | ||
|
|
||
| const revalidate = useCallback(async () => { | ||
| // Only arm polling when there is nothing in the list yet — once any record | ||
| // has been seen, this is a one-shot refetch. | ||
| if (!hasRows) { | ||
| setShouldPoll(true); | ||
| } | ||
| await queryClient.invalidateQueries({ queryKey: invalidationKey }); | ||
| }, [queryClient, invalidationKey, hasRows]); | ||
|
|
||
| const isPolling = queryEnabled && shouldPoll && !hasRows; | ||
|
|
||
| return { | ||
| data: query.data?.data, | ||
| totalCount: query.data?.total_count, | ||
| error: query.error ?? null, | ||
| isLoading: query.isLoading, | ||
| isFetching: query.isFetching, | ||
| isPolling, | ||
| revalidate, | ||
| }; | ||
| } | ||
|
|
||
| export { useEnterpriseConnectionTestRuns as __internal_useEnterpriseConnectionTestRuns }; | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.