-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ui] Move column selector to tabletoolbar and change it to combobox t…
…o handle more columns
- Loading branch information
Showing
5 changed files
with
169 additions
and
87 deletions.
There are no files selected for viewing
This file contains 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,34 @@ | ||
"use client"; | ||
import { Button } from "@/components/ui/button"; | ||
import { Settings2 } from "lucide-react"; | ||
import { useTableColumns } from "../table-columns"; | ||
import { ColumnSelector } from "./column-selector"; | ||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
} from "@/components/ui/popover"; | ||
export const ColumnSelectorButton = () => { | ||
const { columns, toggleColumn, profiles, setProfile } = useTableColumns(); | ||
return ( | ||
<Popover> | ||
<PopoverTrigger asChild> | ||
<Button | ||
variant="secondary" | ||
className="hidden lg:flex items-center ml-auto space-x-2 h-9 p-2" | ||
> | ||
<Settings2 size={17} /> | ||
<span>Column Settings</span> | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent align="end" className="w-[300px] p-0"> | ||
<ColumnSelector | ||
columns={columns} | ||
onToggleColumn={toggleColumn} | ||
profiles={profiles} | ||
setProfile={setProfile} | ||
/> | ||
</PopoverContent> | ||
</Popover> | ||
); | ||
}; |
This file contains 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 |
---|---|---|
@@ -1,71 +1,100 @@ | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuLabel, | ||
DropdownMenuSeparator, | ||
DropdownMenuCheckboxItem, | ||
DropdownMenuTrigger, | ||
} from "@/components/ui/dropdown-menu"; | ||
import { Settings2 } from "lucide-react"; | ||
import { Check } from "lucide-react"; | ||
import { ColumnProfile, TableColumn } from "../search.d"; | ||
import { isEqual } from "moderndash"; | ||
|
||
import { | ||
Command, | ||
CommandGroup, | ||
CommandInput, | ||
CommandItem, | ||
CommandList, | ||
CommandSeparator, | ||
} from "@/components/ui/command"; | ||
interface ColumnSelectorProps { | ||
columns: TableColumn[]; | ||
onToggleColumn: (column: TableColumn) => void; | ||
profiles: Record<ColumnProfile, TableColumn[]>; | ||
setProfile: (profile: ColumnProfile) => void; | ||
} | ||
|
||
export function ColumnSelector({ | ||
columns, | ||
onToggleColumn, | ||
profiles, | ||
setProfile, | ||
}: ColumnSelectorProps) { | ||
return ( | ||
<DropdownMenu modal={false}> | ||
<DropdownMenuTrigger asChild> | ||
<Button variant="ghost" size="sm"> | ||
<Settings2 className="h-4 w-4" /> | ||
<span className="sr-only">Column Settings</span> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent align="end" className="w-[200px]"> | ||
<DropdownMenuLabel>Toggle Columns</DropdownMenuLabel> | ||
<DropdownMenuSeparator /> | ||
{columns.map((column) => ( | ||
<DropdownMenuCheckboxItem | ||
key={`column-selector-${column.code}${column.type === "Adaptable" ? "-" + column.stat_code : ""}`} | ||
checked={column.type == "Always" ? true : column.visible} | ||
onCheckedChange={() => onToggleColumn(column)} | ||
disabled={column.type == "Always" ? true : false} | ||
<Command> | ||
<CommandInput placeholder="Columns" /> | ||
<CommandList> | ||
<CommandGroup heading="Toggle Columns"> | ||
{columns.map((column) => ( | ||
<CommandItem | ||
key={`column-selector-${column.code}${column.type === "Adaptable" ? "-" + column.stat_code : ""}`} | ||
value={column.label} | ||
onSelect={() => onToggleColumn(column)} | ||
disabled={column.type == "Always" ? true : false} | ||
className="space-x-2" | ||
> | ||
<Check | ||
size={14} | ||
className={ | ||
column.type === "Always" || column.visible | ||
? "opacity-100" | ||
: "opacity-0" | ||
} | ||
/> | ||
<span>{column.label}</span> | ||
</CommandItem> | ||
))} | ||
</CommandGroup> | ||
<CommandSeparator /> | ||
<CommandGroup heading="Profiles"> | ||
<CommandItem | ||
onSelect={() => setProfile("Brief")} | ||
value="Brief" | ||
className="space-x-2" | ||
> | ||
<Check | ||
size={14} | ||
className={ | ||
profiles && isEqual(columns, profiles["Brief"]) | ||
? "opacity-100" | ||
: "opacity-0" | ||
} | ||
/> | ||
<span>Brief</span> | ||
</CommandItem> | ||
<CommandItem | ||
onSelect={() => setProfile("Regular")} | ||
value="Regular" | ||
className="space-x-2" | ||
> | ||
<Check | ||
size={14} | ||
className={ | ||
profiles && isEqual(columns, profiles["Regular"]) | ||
? "opacity-100" | ||
: "opacity-0" | ||
} | ||
/> | ||
<span>Regular</span> | ||
</CommandItem> | ||
<CommandItem | ||
onSelect={() => setProfile("Detailed")} | ||
value="Detailed" | ||
className="space-x-2" | ||
> | ||
{column.label} | ||
</DropdownMenuCheckboxItem> | ||
))} | ||
<DropdownMenuSeparator /> | ||
<DropdownMenuLabel>Profiles</DropdownMenuLabel> | ||
<DropdownMenuCheckboxItem | ||
checked={profiles && isEqual(columns, profiles["Brief"])} | ||
onCheckedChange={() => setProfile("Brief")} | ||
> | ||
Brief | ||
</DropdownMenuCheckboxItem> | ||
<DropdownMenuCheckboxItem | ||
checked={profiles && isEqual(columns, profiles["Regular"])} | ||
onCheckedChange={() => setProfile("Regular")} | ||
> | ||
Regular | ||
</DropdownMenuCheckboxItem> | ||
<DropdownMenuCheckboxItem | ||
checked={profiles && isEqual(columns, profiles["Detailed"])} | ||
onCheckedChange={() => setProfile("Detailed")} | ||
> | ||
Detailed | ||
</DropdownMenuCheckboxItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
<Check | ||
size={14} | ||
className={ | ||
profiles && isEqual(columns, profiles["Detailed"]) | ||
? "opacity-100" | ||
: "opacity-0" | ||
} | ||
/> | ||
<span>Detailed</span> | ||
</CommandItem> | ||
</CommandGroup> | ||
</CommandList> | ||
</Command> | ||
); | ||
} |
This file contains 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 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 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