Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 470
chore(clerk-js,types,localizations): Introduce minimum length for organization memberships search#5159
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
Closed
Uh oh!
There was an error while loading. Please reload this page.
Closed
chore(clerk-js,types,localizations): Introduce minimum length for organization memberships search #5159
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d05dc3e
Update input primitive to accept feedbackType prop
LauraBeatris 4cc4573
Introduce field control for min length validation
LauraBeatris bf6ccbf
Refactor debounce logic
LauraBeatris 851f2d4
Add localized key
LauraBeatris 5e1bc35
Leverage input value state from field control
LauraBeatris e295d16
Update changeset
LauraBeatris 700f1a7
Remove state sync with effect
LauraBeatris d97e4eb
Add portuguese translation
LauraBeatris 53abf16
Rename `MembersSearch` to `MembersSearchForm`
LauraBeatris 43ab187
Sanitize input props
LauraBeatris c264dc2
Add element descriptor for container
LauraBeatris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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/clerk-js': minor | ||
| '@clerk/types': minor | ||
| '@clerk/localizations': minor | ||
| --- | ||
| Introduce minimum length for organization memberships search |
2 changes: 1 addition & 1 deletion
2 packages/clerk-js/src/ui/components/OrganizationProfile/MembersActions.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
105 changes: 0 additions & 105 deletions
105 packages/clerk-js/src/ui/components/OrganizationProfile/MembersSearch.tsx
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
105 changes: 105 additions & 0 deletions
105 packages/clerk-js/src/ui/components/OrganizationProfile/MembersSearchForm.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,105 @@ | ||
| import type { useOrganization } from '@clerk/shared/react'; | ||
| import type { GetMembersParams } from '@clerk/types'; | ||
| import { useEffect } from 'react'; | ||
| import { sanitizeInputProps } from '../../../ui/primitives/hooks'; | ||
| import { descriptors, Flex, Icon, localizationKeys, useLocalizations } from '../../customizables'; | ||
| import { InputWithIcon } from '../../elements'; | ||
| import { Field } from '../../elements/FieldControl'; | ||
| import { MagnifyingGlass } from '../../icons'; | ||
| import { Spinner } from '../../primitives'; | ||
| import { useFormControl } from '../../utils'; | ||
| import { ACTIVE_MEMBERS_PAGE_SIZE } from './OrganizationMembers'; | ||
| type MembersSearchProps = { | ||
| /** | ||
| * Controlled query param state by parent component | ||
| */ | ||
| query: GetMembersParams['query']; | ||
| /** | ||
| * Paginated organization memberships | ||
| */ | ||
| memberships: ReturnType<typeof useOrganization>['memberships']; | ||
| /** | ||
| * Handler for value changes | ||
| */ | ||
| onChange: (query: string) => void; | ||
| /** | ||
| * Minimum search length to trigger query | ||
| */ | ||
| minLength: number; | ||
| }; | ||
| export const MembersSearchForm = ({ memberships, onChange, minLength }: MembersSearchProps) => { | ||
| const { t } = useLocalizations(); | ||
| const searchField = useFormControl('search', '', { | ||
| type: 'search', | ||
| label: '', | ||
| placeholder: localizationKeys('organizationProfile.membersPage.action__search'), | ||
| }); | ||
| const { placeholder, ...inputProps } = sanitizeInputProps(searchField); | ||
| const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
| const value = event.target.value.trim(); | ||
| searchField.onChange(event); | ||
| onChange(value); | ||
| if (value.length >= minLength) { | ||
| searchField.clearFeedback(); | ||
| return; | ||
| } | ||
| searchField.setInfo(t(localizationKeys('organizationProfile.membersPage.action__search_minLength'))); | ||
| }; | ||
| // If search is not performed on a initial page, resets pagination offset | ||
| // based on the response count | ||
| useEffect(() => { | ||
| if (!searchField.value || !memberships?.data) { | ||
| return; | ||
| } | ||
| const hasOnePageLeft = (memberships?.count ?? 0) <= ACTIVE_MEMBERS_PAGE_SIZE; | ||
| if (hasOnePageLeft) { | ||
| memberships?.fetchPage?.(1); | ||
| } | ||
| }, [searchField.value, memberships]); | ||
| const isFetchingNewData = searchField.value && !!memberships?.isLoading && !!memberships.data?.length; | ||
| return ( | ||
| <Flex | ||
| sx={{ minWidth: '50%', position: 'relative' }} | ||
| direction='col' | ||
| elementDescriptor={descriptors.organizationProfileMembersSearchContainer} | ||
| > | ||
| <Field.Root {...searchField}> | ||
| <InputWithIcon | ||
| type='search' | ||
| spellCheck={false} | ||
| aria-label='Search' | ||
| autoCapitalize='none' | ||
| minLength={minLength} | ||
| onFocus={inputProps.onFocus} | ||
| onBlur={inputProps.onBlur} | ||
| onChange={handleChange} | ||
| placeholder={t(localizationKeys('organizationProfile.membersPage.action__search'))} | ||
| elementDescriptor={descriptors.organizationProfileMembersSearchInput} | ||
| leftIcon={ | ||
| isFetchingNewData ? ( | ||
| <Spinner size='xs' /> | ||
| ) : ( | ||
| <Icon | ||
| icon={MagnifyingGlass} | ||
| elementDescriptor={descriptors.organizationProfileMembersSearchInputIcon} | ||
| /> | ||
| ) | ||
| } | ||
| /> | ||
| <Field.Feedback /> | ||
| </Field.Root> | ||
| </Flex> | ||
| ); | ||
| }; | ||
15 changes: 8 additions & 7 deletions
15 packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationMembers.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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should follow up with descriptors for these elements. There currently is no way to target MemberSearchForm elements with the appearance prop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a descriptor for the container on 8e0b49d
Now we have the following: