Skip to content

Commit 1429673

Browse files
fix: Add App search component (#639)
* feat: make sure cusror is focused on search box on trigerr, fix: button title, fix: improve search app matching * feat: focus cusror on search box, clear search on exit * fix: remove unnecessary setTimeout Signed-off-by: rohan <[email protected]> --------- Signed-off-by: rohan <[email protected]> Co-authored-by: rohan <[email protected]>
1 parent 72b6116 commit 1429673

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

frontend/app/[team]/access/members/_components/AddAppToMemberButton.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import GetApps from '@/graphql/queries/getApps.gql'
66
import { Menu, Transition } from '@headlessui/react'
77
import { useQuery } from '@apollo/client'
88
import Link from 'next/link'
9-
import { Fragment, useState } from 'react'
10-
import { FaPlus, FaChevronDown, FaSearch, FaTimesCircle, FaArrowRight } from 'react-icons/fa'
9+
import { Fragment, useRef, useState } from 'react'
10+
import { FaPlus, FaSearch, FaTimesCircle, FaArrowRight } from 'react-icons/fa'
1111
import Spinner from '@/components/common/Spinner'
1212
import clsx from 'clsx'
1313
import { EmptyState } from '@/components/common/EmptyState'
@@ -20,6 +20,7 @@ export const AddAppToMemberButton = (props: {
2020
}) => {
2121
const { member, organisationId, teamSlug } = props
2222
const [searchQuery, setSearchQuery] = useState('')
23+
const searchInputRef = useRef<HTMLInputElement>(null)
2324

2425
// Fetch all apps the active user has access to
2526
const { data: allAppsData, loading: loadingApps } = useQuery<Query>(GetApps, {
@@ -47,7 +48,7 @@ export const AddAppToMemberButton = (props: {
4748
return (
4849
<Menu as="div" className="relative inline-block text-left group">
4950
<Menu.Button as={Fragment}>
50-
<Button variant="primary" disabled={loadingApps}>
51+
<Button variant="primary" title="Add Member to App" disabled={loadingApps}>
5152
{loadingApps ? (
5253
<Spinner size="sm" />
5354
) : (
@@ -65,6 +66,8 @@ export const AddAppToMemberButton = (props: {
6566
leave="transition duration-75 ease-out"
6667
leaveFrom="transform scale-100 opacity-100"
6768
leaveTo="transform scale-95 opacity-0"
69+
afterEnter={() => searchInputRef.current?.focus()}
70+
afterLeave={() => setSearchQuery('')}
6871
>
6972
<Menu.Items className="absolute z-10 right-0 origin-top-right mt-2 flex flex-col w-min divide-y divide-neutral-500/40 p-px rounded-md bg-neutral-200 dark:bg-neutral-800 shadow-lg ring-1 ring-inset ring-neutral-500/40 focus:outline-none">
7073
<div>
@@ -78,6 +81,8 @@ export const AddAppToMemberButton = (props: {
7881
value={searchQuery}
7982
onChange={(e) => setSearchQuery(e.target.value)}
8083
onClick={(e) => e.stopPropagation()}
84+
ref={searchInputRef}
85+
autoFocus
8186
/>
8287
<FaTimesCircle
8388
className={clsx(

frontend/app/[team]/access/service-accounts/[account]/_components/AddAppsToServiceAccountsButton.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useContext, useState } from 'react'
1+
import { useContext, useState, useRef } from 'react'
22
import { useQuery } from '@apollo/client'
33
import { Menu, Transition } from '@headlessui/react'
44
import { Fragment } from 'react'
@@ -27,6 +27,7 @@ export const AddAppButton = ({
2727
const { activeOrganisation: organisation } = useContext(organisationContext)
2828

2929
const [searchQuery, setSearchQuery] = useState('')
30+
const searchInputRef = useRef<HTMLInputElement>(null)
3031

3132
const { data, loading } = useQuery<Query>(GetApps, {
3233
variables: { organisationId: organisation?.id },
@@ -46,14 +47,14 @@ export const AddAppButton = ({
4647
const filteredApps =
4748
searchQuery === ''
4849
? apps
49-
: apps.filter((app: AppType) => app?.name?.toLowerCase().includes(searchQuery))
50+
: apps.filter((app: AppType) => app?.name?.toLowerCase().includes(searchQuery.toLowerCase()))
5051

5152
return (
5253
<Menu as="div" className="relative group">
5354
{({ open }) => (
5455
<>
5556
<Menu.Button as={Fragment}>
56-
<Button variant="primary" title="Create a new sync">
57+
<Button variant="primary" title="Add App to Service Account">
5758
<FaPlus /> Add App
5859
</Button>
5960
</Menu.Button>
@@ -69,6 +70,8 @@ export const AddAppButton = ({
6970
'absolute z-10 mt-2',
7071
alignMenuRight ? 'origin-bottom-left left-0' : 'origin-bottom-right right-0'
7172
)}
73+
afterEnter={() => searchInputRef.current?.focus()}
74+
afterLeave={() => setSearchQuery('')}
7275
>
7376
<Menu.Items as={Fragment}>
7477
<div className="flex flex-col w-min divide-y divide-neutral-500/40 p-px rounded-md bg-neutral-200 dark:bg-neutral-800 shadow-lg ring-1 ring-inset ring-neutral-500/40 focus:outline-none">
@@ -82,6 +85,8 @@ export const AddAppButton = ({
8285
className="custom bg-zinc-100 dark:bg-zinc-800"
8386
value={searchQuery}
8487
onChange={(e) => setSearchQuery(e.target.value)}
88+
ref={searchInputRef}
89+
autoFocus
8590
/>
8691
<FaTimesCircle
8792
className={clsx(

0 commit comments

Comments
 (0)