-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤖 backported "Large category picker in bulk filter modal" (#24490)
* Create Large Category Picker (#24378) * prettier fix Co-authored-by: Ryan Laurie <30528226+iethree@users.noreply.github.com> Co-authored-by: Ryan Laurie <iethree@gmail.com>
- Loading branch information
1 parent
46be3f7
commit 4bf28e8
Showing
10 changed files
with
266 additions
and
73 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
80 changes: 80 additions & 0 deletions
80
...uery_builder/components/filters/modals/InlineCategoryPicker/LargeCategoryFilterPicker.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,80 @@ | ||
import React from "react"; | ||
import { t } from "ttag"; | ||
|
||
import type Filter from "metabase-lib/lib/queries/structured/Filter"; | ||
import type StructuredQuery from "metabase-lib/lib/queries/StructuredQuery"; | ||
import type Dimension from "metabase-lib/lib/Dimension"; | ||
import { pluralize } from "metabase/lib/formatting"; | ||
|
||
import Icon from "metabase/components/Icon"; | ||
|
||
import { BulkFilterSelect } from "../BulkFilterSelect"; | ||
import { TokenFieldContainer, AddText } from "./InlineCategoryPicker.styled"; | ||
|
||
import { | ||
TokenFieldItem, | ||
TokenFieldAddon, | ||
} from "metabase/components/TokenFieldItem"; | ||
|
||
import { isValidOption } from "./utils"; | ||
|
||
interface LargeCategoryFilterPickerProps { | ||
query: StructuredQuery; | ||
filter: Filter; | ||
dimension: Dimension; | ||
onChange: (newFilter: Filter) => void; | ||
onClear: () => void; | ||
} | ||
|
||
export function LargeCategoryFilterPicker({ | ||
query, | ||
filter, | ||
dimension, | ||
onChange, | ||
onClear, | ||
}: LargeCategoryFilterPickerProps) { | ||
const filterValues = filter.arguments().filter(isValidOption); | ||
|
||
const removeValue = (value: string | number) => | ||
onChange( | ||
filter.setArguments( | ||
filterValues.filter(filterValue => filterValue !== value), | ||
), | ||
); | ||
|
||
const preventDefault = (e: React.SyntheticEvent) => e.preventDefault(); | ||
|
||
return ( | ||
<BulkFilterSelect | ||
query={query} | ||
filter={filter} | ||
dimension={dimension} | ||
handleChange={onChange} | ||
handleClear={onClear} | ||
customTrigger={({ onClick }) => ( | ||
<TokenFieldContainer | ||
data-testid="large-category-picker" | ||
onClick={onClick} | ||
> | ||
{filterValues.map(filterValue => ( | ||
<TokenFieldItem key={filterValue} isValid onClick={preventDefault}> | ||
<span>{filterValue}</span> | ||
<TokenFieldAddon | ||
isValid | ||
onClick={e => { | ||
e.stopPropagation(); | ||
removeValue(filterValue); | ||
}} | ||
> | ||
<Icon name="close" className="flex align-center" size={12} /> | ||
</TokenFieldAddon> | ||
</TokenFieldItem> | ||
))} | ||
<AddText data-testid="select-filter-option"> | ||
{t`Select ${pluralize(dimension.displayName().toLowerCase())}...`} | ||
</AddText> | ||
</TokenFieldContainer> | ||
)} | ||
/> | ||
); | ||
} |
Oops, something went wrong.