-
Notifications
You must be signed in to change notification settings - Fork 361
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
feat: [M3-7883] - Add search and alphabetical sorting to Switch Account drawer #10515
Changes from all commits
c6532b2
c125a17
a092870
f0848a5
84cbb1c
11013b1
50b8fc0
b28e597
bc99281
8aea3a2
cf731df
45b43b9
b6e531b
9708b60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Added | ||
--- | ||
|
||
Alphabetical account sorting and search capabilities to Switch Account drawer ([#10515](https://github.com/linode/manager/pull/10515)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import { Stack } from 'src/components/Stack'; | |
import { Typography } from 'src/components/Typography'; | ||
import { useChildAccountsInfiniteQuery } from 'src/queries/account/account'; | ||
|
||
import type { UserType } from '@linode/api-v4'; | ||
import type { Filter, UserType } from '@linode/api-v4'; | ||
|
||
interface ChildAccountListProps { | ||
currentTokenWithBearer: string; | ||
|
@@ -24,6 +24,7 @@ interface ChildAccountListProps { | |
onClose: () => void; | ||
userType: UserType | undefined; | ||
}) => void; | ||
searchQuery: string; | ||
userType: UserType | undefined; | ||
} | ||
|
||
|
@@ -33,8 +34,17 @@ export const ChildAccountList = React.memo( | |
isLoading, | ||
onClose, | ||
onSwitchAccount, | ||
searchQuery, | ||
userType, | ||
}: ChildAccountListProps) => { | ||
const filter: Filter = { | ||
['+order']: 'asc', | ||
['+order_by']: 'company', | ||
}; | ||
if (searchQuery) { | ||
filter['company'] = { '+contains': searchQuery }; | ||
} | ||
|
||
const [ | ||
isSwitchingChildAccounts, | ||
setIsSwitchingChildAccounts, | ||
|
@@ -46,8 +56,10 @@ export const ChildAccountList = React.memo( | |
isError, | ||
isFetchingNextPage, | ||
isInitialLoading, | ||
isRefetching, | ||
refetch: refetchChildAccounts, | ||
} = useChildAccountsInfiniteQuery({ | ||
filter, | ||
headers: | ||
userType === 'proxy' | ||
? { | ||
|
@@ -57,7 +69,12 @@ export const ChildAccountList = React.memo( | |
}); | ||
const childAccounts = data?.pages.flatMap((page) => page.data); | ||
|
||
if (isInitialLoading) { | ||
if ( | ||
isInitialLoading || | ||
isLoading || | ||
isSwitchingChildAccounts || | ||
isRefetching | ||
) { | ||
return ( | ||
<Box display="flex" justifyContent="center"> | ||
<CircleProgress mini size={70} /> | ||
|
@@ -67,7 +84,13 @@ export const ChildAccountList = React.memo( | |
|
||
if (childAccounts?.length === 0) { | ||
return ( | ||
<Notice variant="info">There are no indirect customer accounts.</Notice> | ||
<Notice variant="info"> | ||
There are no child accounts | ||
{filter.hasOwnProperty('company') | ||
? ' that match this query' | ||
: undefined} | ||
. | ||
</Notice> | ||
); | ||
} | ||
|
||
|
@@ -119,11 +142,6 @@ export const ChildAccountList = React.memo( | |
|
||
return ( | ||
<Stack alignItems={'flex-start'} data-testid="child-account-list"> | ||
{(isSwitchingChildAccounts || isLoading) && ( | ||
<Box display="flex" justifyContent="center" width={'100%'}> | ||
<CircleProgress mini size={70} /> | ||
</Box> | ||
)} | ||
Comment on lines
-122
to
-126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why we were setting up loading spinners in two different places, but I removed this and added all conditions to L67-72. The addition of isRefetching handles loading state for the search queries. Reviewers should check that they're not seeing any unexpected behavior in our handling of loading state. |
||
{!isSwitchingChildAccounts && !isLoading && renderChildAccounts} | ||
{hasNextPage && <Waypoint onEnter={() => fetchNextPage()} />} | ||
{isFetchingNextPage && <CircleProgress mini />} | ||
|
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're not using "indirect customer", so updated the terminology here.