forked from Cloud-Pipelines/pipeline-editor
-
Notifications
You must be signed in to change notification settings - Fork 5
Add pipeline filters bar with advanced search and sorting #1871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
260 changes: 260 additions & 0 deletions
260
src/components/Home/PipelineSection/PipelineFiltersBar.tsx
This file contains hidden or 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,260 @@ | ||
| import { format } from "date-fns"; | ||
| import type { ReactNode } from "react"; | ||
| import { useState } from "react"; | ||
|
|
||
| import { Badge } from "@/components/ui/badge"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { | ||
| Collapsible, | ||
| CollapsibleContent, | ||
| CollapsibleTrigger, | ||
| } from "@/components/ui/collapsible"; | ||
| import { DatePickerWithRange } from "@/components/ui/date-picker"; | ||
| import { Icon } from "@/components/ui/icon"; | ||
| import { Input } from "@/components/ui/input"; | ||
| import { BlockStack, InlineStack } from "@/components/ui/layout"; | ||
| import { | ||
| Select, | ||
| SelectContent, | ||
| SelectItem, | ||
| SelectTrigger, | ||
| SelectValue, | ||
| } from "@/components/ui/select"; | ||
| import { Text } from "@/components/ui/typography"; | ||
|
|
||
| import type { FilterBarProps, PipelineSortField } from "./usePipelineFilters"; | ||
|
|
||
| const SORT_FIELD_OPTIONS: { value: PipelineSortField; label: string }[] = [ | ||
| { value: "modified_at", label: "Date" }, | ||
| { value: "name", label: "Name" }, | ||
| ]; | ||
|
|
||
| function isValidSortField(value: string): value is PipelineSortField { | ||
| return SORT_FIELD_OPTIONS.some((opt) => opt.value === value); | ||
| } | ||
|
|
||
| interface PipelineFiltersBarProps { | ||
| filters: FilterBarProps; | ||
| actions?: ReactNode; | ||
| } | ||
|
|
||
| export function PipelineFiltersBar({ | ||
| filters, | ||
| actions, | ||
| }: PipelineFiltersBarProps) { | ||
| const { | ||
| searchQuery, | ||
| setSearchQuery, | ||
| dateRange, | ||
| setDateRange, | ||
| sortField, | ||
| setSortField, | ||
| sortDirection, | ||
| setSortDirection, | ||
| componentQuery, | ||
| setComponentQuery, | ||
| hasActiveFilters, | ||
| activeFilterCount, | ||
| clearFilters, | ||
| totalCount, | ||
| filteredCount, | ||
| } = filters; | ||
| const [isAdvancedOpen, setIsAdvancedOpen] = useState(false); | ||
|
|
||
| const isSortDescending = sortDirection === "desc"; | ||
|
|
||
| const handleSortFieldChange = (value: string) => { | ||
| if (isValidSortField(value)) setSortField(value); | ||
| }; | ||
|
|
||
| const toggleSortDirection = () => { | ||
| setSortDirection(isSortDescending ? "asc" : "desc"); | ||
| }; | ||
|
|
||
| const allBadges: Array<{ | ||
| key: string; | ||
| label: string; | ||
| onRemove: () => void; | ||
| }> = []; | ||
|
|
||
| if (searchQuery) { | ||
| allBadges.push({ | ||
| key: "search", | ||
| label: `Search: ${searchQuery}`, | ||
| onRemove: () => setSearchQuery(""), | ||
| }); | ||
| } | ||
|
|
||
| if (dateRange?.from || dateRange?.to) { | ||
| const fromStr = dateRange.from ? format(dateRange.from, "MMM d") : ""; | ||
| const toStr = dateRange.to ? format(dateRange.to, "MMM d") : ""; | ||
| const separator = fromStr && toStr ? " – " : ""; | ||
| allBadges.push({ | ||
| key: "date_range", | ||
| label: `${fromStr}${separator}${toStr}`, | ||
| onRemove: () => setDateRange(undefined), | ||
| }); | ||
| } | ||
|
|
||
| if (componentQuery) { | ||
| allBadges.push({ | ||
| key: "component", | ||
| label: `Component: ${componentQuery}`, | ||
| onRemove: () => setComponentQuery(""), | ||
| }); | ||
| } | ||
|
|
||
| return ( | ||
| <Collapsible open={isAdvancedOpen} onOpenChange={setIsAdvancedOpen}> | ||
| <BlockStack gap="3"> | ||
| {/* Row 1: Basic Filters */} | ||
| <InlineStack gap="3" align="center"> | ||
| {/* Search */} | ||
| <div className="relative flex-1 min-w-0"> | ||
| <Icon | ||
| name="Search" | ||
| className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground" | ||
| /> | ||
| <Input | ||
| placeholder="Search..." | ||
| value={searchQuery} | ||
| onChange={(e) => setSearchQuery(e.target.value)} | ||
| className="pl-9 pr-8 w-full" | ||
| /> | ||
| {searchQuery && ( | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| onClick={() => setSearchQuery("")} | ||
| className="absolute right-2 top-1/2 -translate-y-1/2 size-6 text-muted-foreground hover:text-foreground" | ||
| aria-label="Clear search" | ||
| > | ||
| <Icon name="X" size="sm" /> | ||
| </Button> | ||
| )} | ||
| </div> | ||
|
|
||
| {/* Date Range */} | ||
| <div className="shrink-0"> | ||
| <DatePickerWithRange | ||
| value={dateRange} | ||
| onChange={setDateRange} | ||
| placeholder="Last edited range" | ||
| /> | ||
| </div> | ||
|
|
||
| {/* Sort Controls */} | ||
| <InlineStack gap="1" align="center" className="shrink-0"> | ||
| <Select value={sortField} onValueChange={handleSortFieldChange}> | ||
| <SelectTrigger className="w-24"> | ||
| <SelectValue placeholder="Sort" /> | ||
| </SelectTrigger> | ||
| <SelectContent> | ||
| {SORT_FIELD_OPTIONS.map((opt) => ( | ||
| <SelectItem key={opt.value} value={opt.value}> | ||
| {opt.label} | ||
| </SelectItem> | ||
| ))} | ||
| </SelectContent> | ||
| </Select> | ||
| <Button variant="ghost" size="icon" onClick={toggleSortDirection}> | ||
| {isSortDescending ? ( | ||
| <Icon name="ArrowDownAZ" /> | ||
| ) : ( | ||
| <Icon name="ArrowUpAZ" /> | ||
| )} | ||
| </Button> | ||
| </InlineStack> | ||
|
|
||
| {/* Advanced Toggle */} | ||
| <CollapsibleTrigger asChild> | ||
| <Button | ||
| variant={componentQuery ? "secondary" : "outline"} | ||
| size="sm" | ||
| className="shrink-0" | ||
| > | ||
| Advanced | ||
| {componentQuery && ( | ||
| <Badge variant="secondary" className="ml-1.5 h-5 min-w-5 px-1"> | ||
| 1 | ||
| </Badge> | ||
| )} | ||
| {isAdvancedOpen ? ( | ||
| <Icon name="ChevronUp" className="ml-1" /> | ||
| ) : ( | ||
| <Icon name="ChevronDown" className="ml-1" /> | ||
| )} | ||
| </Button> | ||
| </CollapsibleTrigger> | ||
|
|
||
| {actions} | ||
| </InlineStack> | ||
|
|
||
| {/* Row 2: Advanced (Collapsible) */} | ||
| <CollapsibleContent> | ||
| <BlockStack | ||
| gap="2" | ||
| className="rounded-md border bg-muted/30 px-4 py-3" | ||
| > | ||
| <Text size="sm" weight="semibold"> | ||
| Contains component | ||
| </Text> | ||
| <InlineStack align="start"> | ||
| <Input | ||
| placeholder="Component name..." | ||
| value={componentQuery} | ||
| onChange={(e) => setComponentQuery(e.target.value)} | ||
| className="pr-8 w-xs" | ||
| /> | ||
| {componentQuery && ( | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| onClick={() => setComponentQuery("")} | ||
| className="absolute right-2 top-1/2 -translate-y-1/2 size-6 text-muted-foreground hover:text-foreground" | ||
| aria-label="Clear component filter" | ||
| > | ||
| <Icon name="X" size="sm" /> | ||
| </Button> | ||
| )} | ||
| </InlineStack> | ||
| </BlockStack> | ||
| </CollapsibleContent> | ||
|
|
||
| {/* Row 3: Count + Active filter badges */} | ||
| {(hasActiveFilters || totalCount > 0) && ( | ||
| <InlineStack gap="2" align="center" blockAlign="center"> | ||
| <Text size="sm" tone="subdued"> | ||
| Showing {filteredCount} of {totalCount} pipelines | ||
| </Text> | ||
|
|
||
| <div className="flex-1" /> | ||
|
|
||
| {hasActiveFilters && ( | ||
| <InlineStack gap="2" align="center"> | ||
| {allBadges.map((badge) => ( | ||
| <Badge key={badge.key} variant="outline"> | ||
| {badge.label} | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| onClick={badge.onRemove} | ||
| className="ml-1 size-4 hover:text-destructive hover:bg-transparent" | ||
| aria-label={`Remove ${badge.label} filter`} | ||
| > | ||
| <Icon name="X" size="xs" /> | ||
| </Button> | ||
| </Badge> | ||
| ))} | ||
|
|
||
| <Button variant="ghost" size="sm" onClick={clearFilters}> | ||
| Clear all ({activeFilterCount}) | ||
| </Button> | ||
| </InlineStack> | ||
| )} | ||
| </InlineStack> | ||
| )} | ||
| </BlockStack> | ||
| </Collapsible> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking outloud: this remind me a TagList component from another PR https://app.graphite.com/github/pr/TangleML/tangle-ui/1848?ref=gt-pasteable-stack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can come back to this once that PR is in.