-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[WEB-4885] feat: new filters architecture and UI components #7802
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
Show all changes
8 commits
Select commit
Hold shift + click to select a range
46d35c8
feat: add rich filters types
prateekshourya29 86d7caf
feat: add rich filters constants
prateekshourya29 0865d0c
feat: add rich filters utils
prateekshourya29 76ef433
feat: add rich filters store in shared state package
prateekshourya29 855f9e5
feat: add rich filters UI components
prateekshourya29 8586a31
fix: make setLoading optional in loadOptions function for improved fl…
prateekshourya29 8bbe04c
chore: minor improvements to rich filters
prateekshourya29 3ce6789
fix: formatting
prateekshourya29 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
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
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
106 changes: 106 additions & 0 deletions
106
apps/web/core/components/rich-filters/add-filters-button.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,106 @@ | ||
| import React from "react"; | ||
| import { observer } from "mobx-react"; | ||
| import { ListFilter } from "lucide-react"; | ||
| // plane imports | ||
| import { IFilterInstance } from "@plane/shared-state"; | ||
| import { LOGICAL_OPERATOR, TExternalFilter, TFilterProperty } from "@plane/types"; | ||
| import { CustomSearchSelect, getButtonStyling, TButtonVariant } from "@plane/ui"; | ||
| import { cn, getOperatorForPayload } from "@plane/utils"; | ||
|
|
||
| export type TAddFilterButtonProps<P extends TFilterProperty, E extends TExternalFilter> = { | ||
| buttonConfig?: { | ||
| label?: string; | ||
| variant?: TButtonVariant; | ||
| className?: string; | ||
| defaultOpen?: boolean; | ||
| iconConfig?: { | ||
| shouldShowIcon: boolean; | ||
| iconComponent?: React.ReactNode; | ||
| }; | ||
| isDisabled?: boolean; | ||
| }; | ||
| filter: IFilterInstance<P, E>; | ||
| onFilterSelect?: (id: string) => void; | ||
| }; | ||
|
|
||
| export const AddFilterButton = observer( | ||
| <P extends TFilterProperty, E extends TExternalFilter>(props: TAddFilterButtonProps<P, E>) => { | ||
| const { filter, buttonConfig, onFilterSelect } = props; | ||
| const { | ||
| label = "Filters", | ||
| variant = "link-neutral", | ||
| className, | ||
| defaultOpen = false, | ||
| iconConfig = { shouldShowIcon: true }, | ||
| isDisabled = false, | ||
| } = buttonConfig || {}; | ||
|
|
||
| // Transform available filter configs to CustomSearchSelect options format | ||
| const filterOptions = filter.configManager.allAvailableConfigs.map((config) => ({ | ||
| value: config.id, | ||
| content: ( | ||
| <div className="flex items-center gap-2 text-custom-text-200 transition-all duration-200 ease-in-out"> | ||
| {config.icon && ( | ||
| <config.icon className="size-4 text-custom-text-300 transition-transform duration-200 ease-in-out" /> | ||
| )} | ||
| <span>{config.label}</span> | ||
| </div> | ||
| ), | ||
| query: config.label.toLowerCase(), | ||
| })); | ||
|
|
||
| // If all filters are applied, show disabled options | ||
| const allFiltersApplied = filterOptions.length === 0; | ||
| const displayOptions = allFiltersApplied | ||
| ? [ | ||
| { | ||
| value: "all_filters_applied", | ||
| content: <div className="text-custom-text-400 italic">All filters applied</div>, | ||
| query: "all filters applied", | ||
| disabled: true, | ||
| }, | ||
| ] | ||
| : filterOptions; | ||
|
|
||
| const handleFilterSelect = (property: P) => { | ||
| const config = filter.configManager.getConfigByProperty(property); | ||
| if (config && config.firstOperator) { | ||
| const { operator, isNegation } = getOperatorForPayload(config.firstOperator); | ||
| filter.addCondition( | ||
| LOGICAL_OPERATOR.AND, | ||
| { | ||
| property: config.id, | ||
| operator, | ||
| value: undefined, | ||
| }, | ||
| isNegation | ||
| ); | ||
| onFilterSelect?.(property); | ||
| } | ||
| }; | ||
|
|
||
| if (isDisabled) return null; | ||
| return ( | ||
| <div className="relative transition-all duration-200 ease-in-out"> | ||
| <CustomSearchSelect | ||
| defaultOpen={defaultOpen} | ||
| value={""} | ||
| onChange={handleFilterSelect} | ||
| options={displayOptions} | ||
| optionsClassName="w-56" | ||
| maxHeight="full" | ||
| placement="bottom-start" | ||
| disabled={isDisabled} | ||
| customButtonClassName={cn(getButtonStyling(variant, "sm"), className)} | ||
| customButton={ | ||
| <div className="flex items-center gap-1"> | ||
| {iconConfig.shouldShowIcon && | ||
| (iconConfig.iconComponent || <ListFilter className="size-4 text-custom-text-200" />)} | ||
| {label} | ||
| </div> | ||
| } | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
| ); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.