forked from harness/canary
-
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.
feat: add filter/sort functionality (#4)
* feat: add filter/sort functionality fix: minor changes refactor: structures of the filters component fix: minor changes fix: lock file * fix: minor changes * fix: minor changes * feat: style adjustment * fix: styles for filter date * refactor: structure * fix: minor changes * feat: add todos * fix: minor changes * fix: minor changes * fix: minor changes * feat: structure optimization * feat: add comments * feat: add more options for filters * feat: add states for repo list * feat: add filtering for calendar is_between * feat: add text type filter * feat: add number type filter * fix: minor changes * chore: add small adjustments feat: add auto opening of the filter when selected feat: filter improvements (#8) * refactor: component BranchSelector * fix: updated common layout and navbar * fix: fixes for updated common layout and navbar * feat: add filter/sort functionality (#4) * feat: add filter/sort functionality fix: minor changes refactor: structures of the filters component fix: minor changes fix: lock file * fix: minor changes * fix: minor changes * feat: style adjustment * fix: styles for filter date * refactor: structure * fix: minor changes * feat: add todos * fix: minor changes * fix: minor changes * fix: minor changes * feat: structure optimization * feat: add comments * feat: add more options for filters * feat: add states for repo list * feat: add filtering for calendar is_between * feat: add text type filter * feat: add number type filter * fix: minor changes * chore: add small adjustments * refactor: using types * feat: add an additional filter call button * fix: minor changes * feat: add save logic * fix: minor changes * feat: small improvements in saving filters * feat: expanding the functionality of the calendar * feat: override the save logic * chore: add small adjustments * fix: minor changes * fix: minor changes * fix: minor changes --------- Co-authored-by: Alex Zemlyakov <[email protected]> fix: conflicts with old branch selector component
- Loading branch information
1 parent
13acaab
commit 77931d7
Showing
34 changed files
with
7,318 additions
and
6,717 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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
169 changes: 169 additions & 0 deletions
169
packages/playground/src/components/filters/filter-trigger.tsx
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,169 @@ | ||
import { FilterOption, SortOption } from './types' | ||
import { UseFiltersReturn } from './use-filters' | ||
|
||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuTrigger, | ||
Icon, | ||
Input | ||
} from '@harnessio/canary' | ||
|
||
interface BaseFilterTriggerProps { | ||
type: 'filter' | 'sort' | ||
options: FilterOption[] | SortOption[] | ||
customLabel?: React.ReactNode | string | ||
hideCount?: boolean | ||
dropdownAlign?: 'start' | 'end' | ||
} | ||
|
||
interface FilterTriggerFilterProps extends BaseFilterTriggerProps { | ||
type: 'filter' | ||
options: FilterOption[] | ||
activeFilters: UseFiltersReturn['activeFilters'] | ||
onChange: UseFiltersReturn['handleFilterChange'] | ||
onReset?: UseFiltersReturn['handleResetFilters'] | ||
searchQueries: UseFiltersReturn['searchQueries'] | ||
onSearchChange: UseFiltersReturn['handleSearchChange'] | ||
} | ||
|
||
interface FilterTriggerSortProps extends BaseFilterTriggerProps { | ||
type: 'sort' | ||
options: SortOption[] | ||
activeFilters: UseFiltersReturn['activeSorts'] | ||
onChange: UseFiltersReturn['handleSortChange'] | ||
onReset: UseFiltersReturn['handleResetSorts'] | ||
searchQueries: UseFiltersReturn['searchQueries'] | ||
onSearchChange: UseFiltersReturn['handleSearchChange'] | ||
} | ||
|
||
type FilterTriggerProps = FilterTriggerFilterProps | FilterTriggerSortProps | ||
|
||
const LABELS = { | ||
filter: { | ||
defaultLabel: 'Filter', | ||
inputPlaceholder: 'Filter by...', | ||
buttonLabel: 'Reset filters' | ||
}, | ||
sort: { | ||
defaultLabel: 'Sort', | ||
inputPlaceholder: 'Sort by...', | ||
buttonLabel: 'Reset sort' | ||
} | ||
} | ||
|
||
const FilterTrigger = ({ | ||
type, | ||
activeFilters, | ||
customLabel, | ||
hideCount, | ||
dropdownAlign = 'end', | ||
onChange, | ||
onReset, | ||
searchQueries, | ||
onSearchChange, | ||
options | ||
}: FilterTriggerProps) => { | ||
const { defaultLabel, inputPlaceholder, buttonLabel } = LABELS[type] | ||
const displayLabel = customLabel || defaultLabel | ||
|
||
const isFilterOption = (option: FilterOption | SortOption): option is FilterOption => { | ||
return 'type' in option && (option as FilterOption).type !== undefined | ||
} | ||
|
||
const isSortOption = (option: FilterOption | SortOption): option is SortOption => { | ||
return !('type' in option) | ||
} | ||
|
||
const onChangeOption = (option: FilterOption | SortOption) => { | ||
if (type === 'filter') { | ||
if (isFilterOption(option)) { | ||
onChange( | ||
{ | ||
type: option.value | ||
}, | ||
option.conditions?.[0].value | ||
) | ||
} | ||
} else { | ||
if (isSortOption(option)) { | ||
onChange({ | ||
type: option.value, | ||
direction: 'desc' | ||
}) | ||
} | ||
} | ||
} | ||
|
||
const filteredBySearchOptions = options.filter( | ||
option => !searchQueries.menu[type] || option.label.toLowerCase().includes(searchQueries.menu[type].toLowerCase()) | ||
) | ||
|
||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger className="flex items-center gap-x-1.5"> | ||
<span className="text-foreground-2 hover:text-foreground-1 text-14 flex items-center gap-x-1"> | ||
{displayLabel} | ||
{!hideCount && activeFilters.length > 0 && ( | ||
<span className="text-foreground-2 bg-background-2 text-11 border-borders-5 flex h-[18px] min-w-[17px] items-center justify-center rounded border px-1"> | ||
{activeFilters.length} | ||
</span> | ||
)} | ||
</span> | ||
{!customLabel && <Icon className="chevron-down text-icons-4" name="chevron-fill-down" size={6} />} | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent className="min-w-[224px] p-0" align={dropdownAlign}> | ||
<div className="border-borders-4 relative flex items-center justify-between border-b px-3 py-2.5"> | ||
<Input | ||
type="text" | ||
placeholder={inputPlaceholder} | ||
value={searchQueries.menu[type] || ''} | ||
onChange={e => onSearchChange(type, e.target.value, 'menu')} | ||
onKeyDown={e => e.stopPropagation()} | ||
onClick={e => e.preventDefault()} | ||
/> | ||
|
||
{searchQueries.menu[type] && ( | ||
<div className="absolute right-3"> | ||
<button | ||
className="text-foreground-4 hover:text-foreground-1 flex p-1.5 transition-colors duration-200" | ||
onClick={e => { | ||
e.preventDefault() | ||
onSearchChange(type, '', 'menu') | ||
}}> | ||
<Icon className="rotate-45" name="plus" size={12} /> | ||
</button> | ||
</div> | ||
)} | ||
</div> | ||
|
||
<div className="p-1"> | ||
{filteredBySearchOptions.map(option => ( | ||
<DropdownMenuItem key={option.value} onSelect={() => onChangeOption(option)}> | ||
{option.label} | ||
</DropdownMenuItem> | ||
))} | ||
|
||
{filteredBySearchOptions.length === 0 && ( | ||
<div className="flex items-center justify-center p-4"> | ||
<span className="text-foreground-2 text-14 leading-none">No results</span> | ||
</div> | ||
)} | ||
</div> | ||
|
||
{onReset && ( | ||
<div className="border-borders-4 border-t p-1"> | ||
<DropdownMenuItem asChild> | ||
<button className="w-full font-medium" onClick={onReset}> | ||
{buttonLabel} | ||
</button> | ||
</DropdownMenuItem> | ||
</div> | ||
)} | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
) | ||
} | ||
|
||
export default FilterTrigger |
Oops, something went wrong.