44 BookOpenIcon ,
55 InformationCircleIcon ,
66 LockClosedIcon ,
7+ MagnifyingGlassIcon ,
78 PencilSquareIcon ,
89 PlusIcon ,
910 TrashIcon ,
@@ -33,6 +34,7 @@ import { Input } from "~/components/primitives/Input";
3334import { InputGroup } from "~/components/primitives/InputGroup" ;
3435import { Label } from "~/components/primitives/Label" ;
3536import { NavBar , PageAccessories , PageTitle } from "~/components/primitives/PageHeader" ;
37+ import { Paragraph } from "~/components/primitives/Paragraph" ;
3638import { Switch } from "~/components/primitives/Switch" ;
3739import {
3840 Table ,
@@ -46,6 +48,7 @@ import {
4648import { SimpleTooltip } from "~/components/primitives/Tooltip" ;
4749import { prisma } from "~/db.server" ;
4850import { useEnvironment } from "~/hooks/useEnvironment" ;
51+ import { useFuzzyFilter } from "~/hooks/useFuzzyFilter" ;
4952import { useOrganization } from "~/hooks/useOrganizations" ;
5053import { useProject } from "~/hooks/useProject" ;
5154import { redirectWithSuccessMessage } from "~/models/message.server" ;
@@ -66,6 +69,7 @@ import { EnvironmentVariablesRepository } from "~/v3/environmentVariables/enviro
6669import {
6770 DeleteEnvironmentVariableValue ,
6871 EditEnvironmentVariableValue ,
72+ EnvironmentVariable ,
6973} from "~/v3/environmentVariables/repository" ;
7074
7175export const meta : MetaFunction = ( ) => {
@@ -197,6 +201,11 @@ export default function Page() {
197201 const organization = useOrganization ( ) ;
198202 const project = useProject ( ) ;
199203 const environment = useEnvironment ( ) ;
204+ const { filterText, setFilterText, filteredItems } =
205+ useFuzzyFilter < EnvironmentVariableWithSetValues > ( {
206+ items : environmentVariables ,
207+ keys : [ "key" , "value" ] ,
208+ } ) ;
200209
201210 // Add isFirst and isLast to each environment variable
202211 // They're set based on if they're the first or last time that `key` has been seen in the list
@@ -205,15 +214,15 @@ export default function Page() {
205214 const keyOccurrences = new Map < string , number > ( ) ;
206215
207216 // First pass: count total occurrences of each key
208- environmentVariables . forEach ( ( variable ) => {
217+ filteredItems . forEach ( ( variable ) => {
209218 keyOccurrences . set ( variable . key , ( keyOccurrences . get ( variable . key ) || 0 ) + 1 ) ;
210219 } ) ;
211220
212221 // Second pass: add isFirstTime, isLastTime, and occurrences flags
213222 const seenKeys = new Set < string > ( ) ;
214223 const currentOccurrences = new Map < string , number > ( ) ;
215224
216- return environmentVariables . map ( ( variable ) => {
225+ return filteredItems . map ( ( variable ) => {
217226 // Track current occurrence number for this key
218227 const currentCount = ( currentOccurrences . get ( variable . key ) || 0 ) + 1 ;
219228 currentOccurrences . set ( variable . key , currentCount ) ;
@@ -233,7 +242,7 @@ export default function Page() {
233242 occurences : totalOccurrences ,
234243 } ;
235244 } ) ;
236- } , [ environmentVariables ] ) ;
245+ } , [ filteredItems ] ) ;
237246
238247 return (
239248 < PageContainer >
@@ -252,24 +261,35 @@ export default function Page() {
252261 < PageBody scrollable = { false } >
253262 < div className = { cn ( "flex h-full flex-col" ) } >
254263 { environmentVariables . length > 0 && (
255- < div className = "flex items-center justify-end gap-2 px-2 py-2" >
256- < Switch
257- variant = "small"
258- label = "Reveal values"
259- checked = { revealAll }
260- onCheckedChange = { ( e ) => setRevealAll ( e . valueOf ( ) ) }
264+ < div className = "flex items-center justify-between gap-2 px-2 py-2" >
265+ < Input
266+ placeholder = "Search variables"
267+ variant = "tertiary"
268+ icon = { MagnifyingGlassIcon }
269+ fullWidth = { true }
270+ value = { filterText }
271+ onChange = { ( e ) => setFilterText ( e . target . value ) }
272+ autoFocus
261273 />
262- < LinkButton
263- to = { v3NewEnvironmentVariablesPath ( organization , project , environment ) }
264- variant = "primary/small"
265- LeadingIcon = { PlusIcon }
266- shortcut = { { key : "n" } }
267- >
268- Add new
269- </ LinkButton >
274+ < div className = "flex items-center justify-end gap-2" >
275+ < Switch
276+ variant = "small"
277+ label = "Reveal values"
278+ checked = { revealAll }
279+ onCheckedChange = { ( e ) => setRevealAll ( e . valueOf ( ) ) }
280+ />
281+ < LinkButton
282+ to = { v3NewEnvironmentVariablesPath ( organization , project , environment ) }
283+ variant = "primary/small"
284+ LeadingIcon = { PlusIcon }
285+ shortcut = { { key : "n" } }
286+ >
287+ Add new
288+ </ LinkButton >
289+ </ div >
270290 </ div >
271291 ) }
272- < Table containerClassName = { cn ( environmentVariables . length === 0 && "border-t-0" ) } >
292+ < Table containerClassName = { cn ( filteredItems . length === 0 && "border-t-0" ) } >
273293 < TableHeader >
274294 < TableRow >
275295 < TableHeaderCell className = "w-[25%]" > Key</ TableHeaderCell >
@@ -353,17 +373,23 @@ export default function Page() {
353373 ) : (
354374 < TableRow >
355375 < TableCell colSpan = { 4 } >
356- < div className = "flex flex-col items-center justify-center gap-y-4 py-8" >
357- < Header2 > You haven't set any environment variables yet.</ Header2 >
358- < LinkButton
359- to = { v3NewEnvironmentVariablesPath ( organization , project , environment ) }
360- variant = "primary/medium"
361- LeadingIcon = { PlusIcon }
362- shortcut = { { key : "n" } }
363- >
364- Add new
365- </ LinkButton >
366- </ div >
376+ { environmentVariables . length === 0 ? (
377+ < div className = "flex flex-col items-center justify-center gap-y-4 py-8" >
378+ < Header2 > You haven't set any environment variables yet.</ Header2 >
379+ < LinkButton
380+ to = { v3NewEnvironmentVariablesPath ( organization , project , environment ) }
381+ variant = "primary/medium"
382+ LeadingIcon = { PlusIcon }
383+ shortcut = { { key : "n" } }
384+ >
385+ Add new
386+ </ LinkButton >
387+ </ div >
388+ ) : (
389+ < div className = "flex flex-col items-center justify-center gap-y-4 py-8" >
390+ < Paragraph > No variables match your search.</ Paragraph >
391+ </ div >
392+ ) }
367393 </ TableCell >
368394 </ TableRow >
369395 ) }
0 commit comments