-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
332 additions
and
101 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
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,133 @@ | ||
import { Cross2Icon, MixerHorizontalIcon } from "@radix-ui/react-icons"; | ||
import { type Table } from "@tanstack/react-table"; | ||
|
||
import { Button } from "~/components/ui/button"; | ||
import { Input } from "~/components/ui/input"; | ||
import { DataTableFacetedFilter } from "./data-table-faceted-filter"; | ||
import { ResourceConfigurationLabels, ResourceTypeLabels } from "../Resource"; | ||
import type { ResourceConfiguration, ResourceType } from "@prisma/client"; | ||
import { api } from "~/utils/api"; | ||
import { useMediaQuery } from "~/hooks/use-media-query"; | ||
|
||
import { | ||
Drawer, | ||
DrawerClose, | ||
DrawerContent, | ||
DrawerDescription, | ||
DrawerFooter, | ||
DrawerHeader, | ||
DrawerTitle, | ||
DrawerTrigger, | ||
} from "~/components/ui/drawer"; | ||
import { cn } from "~/lib/utils"; | ||
|
||
interface DataTableFiltersProps<TData> { | ||
table: Table<TData>; | ||
} | ||
|
||
function DataTableFiltersContent<TData>({ | ||
table, | ||
className, | ||
}: DataTableFiltersProps<TData> & { className?: string }) { | ||
const isFiltered = table.getState().columnFilters.length > 0; | ||
const { data: categories, isLoading: isLoadingCategories } = | ||
api.category.getAll.useQuery(); | ||
|
||
return ( | ||
<div className={cn("flex flex-1 items-center space-x-2", className)}> | ||
<Input | ||
placeholder="Filter Title..." | ||
value={(table.getColumn("title")?.getFilterValue() as string) ?? ""} | ||
onChange={(event) => | ||
table.getColumn("title")?.setFilterValue(event.target.value) | ||
} | ||
className="h-8 w-[150px] lg:w-[250px]" | ||
/> | ||
{table.getColumn("categories") && ( | ||
<DataTableFacetedFilter | ||
column={table.getColumn("categories")} | ||
title="Category" | ||
options={(categories ?? []).map(({ id, name }) => ({ | ||
label: name, | ||
value: id, | ||
}))} | ||
disabled={isLoadingCategories} | ||
/> | ||
)} | ||
{table.getColumn("type") && ( | ||
<DataTableFacetedFilter | ||
column={table.getColumn("type")} | ||
title="Type" | ||
options={Object.keys(ResourceTypeLabels).map((type) => ({ | ||
label: ResourceTypeLabels[type as ResourceType], | ||
value: type, | ||
}))} | ||
/> | ||
)} | ||
{table.getColumn("configuration") && ( | ||
<DataTableFacetedFilter | ||
column={table.getColumn("configuration")} | ||
title="Configuration" | ||
options={Object.keys(ResourceConfigurationLabels).map( | ||
(configuration) => ({ | ||
label: | ||
ResourceConfigurationLabels[ | ||
configuration as ResourceConfiguration | ||
], | ||
value: configuration, | ||
}), | ||
)} | ||
/> | ||
)} | ||
{isFiltered && ( | ||
<Button | ||
variant="ghost" | ||
onClick={() => table.resetColumnFilters()} | ||
className="h-8 px-2 lg:px-3" | ||
> | ||
Reset | ||
<Cross2Icon className="ml-2 h-4 w-4" /> | ||
</Button> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export function DataTableFilters<TData>({ | ||
table, | ||
}: DataTableFiltersProps<TData>) { | ||
const isDesktop = useMediaQuery("(min-width: 768px)"); | ||
|
||
if (isDesktop) { | ||
return <DataTableFiltersContent table={table} />; | ||
} | ||
|
||
return ( | ||
<Drawer> | ||
<DrawerTrigger asChild> | ||
<Button variant="outline"> | ||
<MixerHorizontalIcon className="mr-2 h-4 w-4" /> Filters | ||
</Button> | ||
</DrawerTrigger> | ||
<DrawerContent> | ||
<div className="mx-auto w-full max-w-sm"> | ||
<DrawerHeader> | ||
<DrawerTitle> | ||
<MixerHorizontalIcon className="mr-2 inline h-4 w-4" /> | ||
Filters | ||
</DrawerTitle> | ||
</DrawerHeader> | ||
<DataTableFiltersContent | ||
table={table} | ||
className="flex-col items-stretch space-x-0 space-y-2 p-4 [&>*]:w-full" | ||
/> | ||
<DrawerFooter className="pt-4"> | ||
<DrawerClose asChild> | ||
<Button variant="outline">Close</Button> | ||
</DrawerClose> | ||
</DrawerFooter> | ||
</div> | ||
</DrawerContent> | ||
</Drawer> | ||
); | ||
} |
File renamed without changes.
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,20 @@ | ||
"use client"; | ||
|
||
import { type Table } from "@tanstack/react-table"; | ||
import { DataTableViewOptions } from "./data-table-view-options"; | ||
import { DataTableFilters } from "./data-table-filters"; | ||
|
||
interface DataTableToolbarProps<TData> { | ||
table: Table<TData>; | ||
} | ||
|
||
export function DataTableToolbar<TData>({ | ||
table, | ||
}: DataTableToolbarProps<TData>) { | ||
return ( | ||
<div className="flex items-center justify-between"> | ||
<DataTableFilters table={table} /> | ||
<DataTableViewOptions table={table} /> | ||
</div> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.