Files
supabase/apps/studio/components/interfaces/Auth/Users/UsersGridComponents.tsx
T
Joshen Lim 09a1f431bc Mass update for all lucide icon imports to use the component with Icon suffix (#51659)
## Context

This is largely just a mechanical change here:
Opting to use lucide icons with the `Icon` suffix across all icon
imports within `studio`
- so that it’s clearer which components are icons + reduces the
possibility of name collision with our own components
- e.g <User /> vs <UserIcon />

Also added a eslint rule for this:
<img width="1069" height="167" alt="image"
src="https://github.com/user-attachments/assets/7f36f443-5ca2-4bf6-8d22-86e774513bfc"
/>

And updated `AGENTS.md` as such:
```
Icons come from `lucide-react`, always imported with the `Icon` suffix (`import { CheckIcon, Trash2Icon } from 'lucide-react'`) — never the bare names (`Check`) or `Check as CheckIcon` aliases (lint-enforced).
```
2026-10-14 12:56:55 +02:00

112 lines
3.3 KiB
TypeScript

import { ChevronDownIcon, SortAscIcon, SortDescIcon } from 'lucide-react'
import { useEffect, useRef, useState } from 'react'
import { useHeaderRowSelection } from 'react-data-grid'
import {
Button,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from 'ui'
// [Joshen] Currently not being used, refer to Users.utils -> formatUserColumns for more info
export const SelectHeaderCell = ({
selectedUsers,
allRowsSelected,
}: {
selectedUsers: Set<any>
allRowsSelected: boolean
}) => {
const inputRef = useRef<HTMLInputElement>(null)
const { isRowSelected, onRowSelectionChange } = useHeaderRowSelection()
const isIndeterminate = selectedUsers.size > 0 && !allRowsSelected
useEffect(() => {
if (inputRef.current) inputRef.current.indeterminate = isIndeterminate
}, [isIndeterminate])
return (
<div className="px-4 flex items-center sb-grid">
<div className="sb-grid-select-cell__header">
<input
ref={inputRef}
type="checkbox"
aria-label="Select-all"
className="sb-grid-select-cell__header__input"
disabled={false}
checked={isRowSelected}
onChange={(e) => onRowSelectionChange({ checked: e.target.checked })}
/>
</div>
</div>
)
}
export const HeaderCell = ({
col,
specificFilterColumn,
setSortByValue,
}: {
col: any
specificFilterColumn: string
setSortByValue: (value: string) => void
}) => {
const ref = useRef<number>(0)
const [open, setOpen] = useState(false)
useEffect(() => {
ref.current = Number(new Date())
}, [open])
return (
<div className="flex items-center justify-between font-normal text-xs w-full">
<div className="flex items-center gap-x-2">
<p className="text-foreground!">{col.name}</p>
</div>
{specificFilterColumn === 'freeform' && ['created_at', 'email', 'phone'].includes(col.id) && (
<DropdownMenu
open={open}
onOpenChange={(val) => {
// [Joshen] This is a temp hack between the DropdownMenu and react data grid
// as the header cell is selectable, which takes the focus away from the dropdown menu
// causing it to close immediately.
if (val === false && Number(new Date()) - ref.current > 100) setOpen(val)
}}
>
<DropdownMenuTrigger asChild>
<Button
variant="text"
icon={<ChevronDownIcon />}
className="p-0 h-5 w-5"
onClick={() => setOpen(!open)}
/>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-36">
<DropdownMenuItem
className="flex items-center gap-x-2"
onClick={() => {
setOpen(false)
setSortByValue(`${col.id}:desc`)
}}
>
<SortDescIcon size={14} />
Sort descending
</DropdownMenuItem>
<DropdownMenuItem
className="flex items-center gap-x-2"
onClick={() => {
setOpen(false)
setSortByValue(`${col.id}:asc`)
}}
>
<SortAscIcon size={14} />
Sort ascending
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)}
</div>
)
}