-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4002 - TablePaginated: Filter by User Role + Admin users 'Role' (#4043)
* 4002 - Tablepaginated filter by user role/admin users role - Integration (#4038) * 4002 - Add Filter multi select type * 4002 - Add draft multi select to Users table * 2661 - Display all columns * 4002 - TablePaginated: Filter by User Role + Admin users 'Role' - Multiselect UI (#4049) * 4002 - Hide clear button in Text filter * 4002 - Add counter label for multi select * 4002 - Expose Select onMenuClose & onMenuOpen props * 4002 - Add Filter multiselect styling and tooltip * 4002 - Fix table overlapping select options * 4002 - Add spacing between label and search input * 4002 - Fix props order in Select * 4002 - Rename isTooltipVisible to canDisplayTooltip * 4002 - Rename MultiValue to MultiValueSummary * 4002 - Rename multiLabelKey to multiLabelSummaryKey * 4002 - Remove import as OriginalMultiValueProps * 4002 - Render Text x button conditionally * 4002 - Update useTooltipContent * 4002 - Fix styling
- Loading branch information
Showing
21 changed files
with
278 additions
and
29 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
src/client/components/Inputs/Select/Indicators/MultiValueSummary/MultiValueSummary.scss
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,5 @@ | ||
@import 'src/client/style/partials'; | ||
|
||
.select__multiValue-label { | ||
padding-right: $spacing-xxxs; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/client/components/Inputs/Select/Indicators/MultiValueSummary/MultiValueSummary.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,24 @@ | ||
import './MultiValueSummary.scss' | ||
import React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { MultiValueProps as OriginalMultiValueProps } from 'react-select' | ||
|
||
import { SelectProps } from 'client/components/Inputs/Select/types' | ||
|
||
type MultiValueProps = OriginalMultiValueProps & Pick<SelectProps, 'multiLabelSummaryKey'> | ||
|
||
export const MultiValueSummary: React.FC<MultiValueProps> = (props) => { | ||
const { getValue, index, multiLabelSummaryKey } = props | ||
const count = getValue().length | ||
const { t } = useTranslation() | ||
|
||
const displayCountLabel = index === 0 | ||
|
||
if (displayCountLabel) { | ||
return <span className="select__multiValue-label">{t(multiLabelSummaryKey, { count })}</span> | ||
} | ||
|
||
return null | ||
} | ||
|
||
export default MultiValueSummary |
1 change: 1 addition & 0 deletions
1
src/client/components/Inputs/Select/Indicators/MultiValueSummary/index.ts
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 @@ | ||
export { MultiValueSummary } from './MultiValueSummary' |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { ClearIndicator, DropdownIndicator, IndicatorsContainer } from './Indicators' | ||
export { MultiSelectOption } from './MultiSelectOption' | ||
export { MultiValueSummary } from './MultiValueSummary' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
align-items: center; | ||
display: flex; | ||
gap: $spacing-xxs; | ||
height: 30px; | ||
width: 100%; | ||
|
||
svg.icon_filter { | ||
|
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
53 changes: 53 additions & 0 deletions
53
src/client/components/TablePaginated/Filters/MultiSelect/MultiSelect.scss
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,53 @@ | ||
@import 'src/client/style/partials'; | ||
|
||
$icon-size: 14px; | ||
|
||
.filter-multiselect__tooltip-trigger { | ||
height: 100%; | ||
} | ||
|
||
div.filter-multiselect__container { | ||
border-radius: 2px; | ||
border: 1px solid $ui-border; | ||
font-size: $font-xxs; | ||
min-width: #{3 * $spacing-xl}; | ||
padding: 0; | ||
transition: all 0.2s ease; | ||
|
||
div.select__control { | ||
min-height: unset; | ||
padding: 0 6px; | ||
|
||
div.select__indicatorsContainer { | ||
div.select__clearIndicator { | ||
height: unset; | ||
width: unset; | ||
|
||
svg.icon { | ||
color: rgba(0, 0, 0, 0.5); | ||
height: $icon-size; | ||
width: $icon-size; | ||
} | ||
|
||
&:hover { | ||
background-color: unset; | ||
|
||
svg.icon { | ||
color: $ui-destructive; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
div.select__dropdownIndicator { | ||
svg { | ||
height: $icon-size; | ||
width: $icon-size; | ||
} | ||
} | ||
|
||
&.active { | ||
border: 1px solid $ui-accent; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/client/components/TablePaginated/Filters/MultiSelect/MultiSelect.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,65 @@ | ||
import './MultiSelect.scss' | ||
import React from 'react' | ||
|
||
import classNames from 'classnames' | ||
|
||
import { TablePaginatedFilterType } from 'meta/tablePaginated' | ||
import { TooltipId } from 'meta/tooltip' | ||
|
||
import { useAppDispatch } from 'client/store' | ||
import { TablePaginatedActions } from 'client/store/ui/tablePaginated' | ||
import { useTablePaginatedFilterValue } from 'client/store/ui/tablePaginated/hooks' | ||
import Select from 'client/components/Inputs/Select' | ||
import { TablePaginatedFilter } from 'client/components/TablePaginated/types' | ||
|
||
import { useTooltipContent } from './hooks/useTooltipContent' | ||
|
||
type Props = TablePaginatedFilter<TablePaginatedFilterType.MULTI_SELECT> & { | ||
path: string | ||
} | ||
|
||
const MultiSelect: React.FC<Props> = (props: Props) => { | ||
const { fieldName, label, path, options } = props | ||
|
||
const dispatch = useAppDispatch() | ||
|
||
const { hideTooltip, showTooltip, tooltipContent } = useTooltipContent({ fieldName, options, path }) | ||
|
||
const filterValue = useTablePaginatedFilterValue<Array<string>>(path, fieldName) | ||
|
||
const handleChange = (value: Array<string>) => { | ||
dispatch( | ||
TablePaginatedActions.setFilterValue({ | ||
fieldName, | ||
path, | ||
value, | ||
}) | ||
) | ||
} | ||
|
||
return ( | ||
<div | ||
className="filter-multiselect__tooltip-trigger" | ||
data-tooltip-content={tooltipContent} | ||
data-tooltip-id={TooltipId.info} | ||
> | ||
<Select | ||
classNames={{ | ||
container: classNames('filter-multiselect__container', { | ||
active: filterValue?.length > 0, | ||
}), | ||
}} | ||
isMulti | ||
multiLabelSummaryKey="admin.role" | ||
onChange={handleChange} | ||
onMenuClose={showTooltip} | ||
onMenuOpen={hideTooltip} | ||
options={options} | ||
placeholder={label} | ||
value={filterValue} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default MultiSelect |
57 changes: 57 additions & 0 deletions
57
src/client/components/TablePaginated/Filters/MultiSelect/hooks/useTooltipContent.ts
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,57 @@ | ||
import { useCallback, useMemo, useState } from 'react' | ||
|
||
import { Objects } from 'utils/objects' | ||
|
||
import { TablePaginatedFilterType } from 'meta/tablePaginated' | ||
|
||
import { useTablePaginatedFilterValue } from 'client/store/ui/tablePaginated/hooks' | ||
import { TablePaginatedFilter } from 'client/components/TablePaginated/types' | ||
|
||
type Props = { | ||
fieldName: string | ||
options: TablePaginatedFilter<TablePaginatedFilterType.MULTI_SELECT>['options'] | ||
path: string | ||
} | ||
|
||
type Returned = { | ||
hideTooltip: () => void | ||
showTooltip: () => void | ||
tooltipContent: string | null | ||
} | ||
|
||
export const useTooltipContent = (props: Props): Returned => { | ||
const { fieldName, options, path } = props | ||
const filterValue = useTablePaginatedFilterValue<Array<string>>(path, fieldName) | ||
const [canDisplayTooltip, setCanDisplayTooltip] = useState(true) | ||
|
||
const valueToLabelMap = useMemo<Record<string, string>>(() => { | ||
return options.reduce<Record<string, string>>((acc, { value, label }) => { | ||
return { ...acc, [value]: label } | ||
}, {}) | ||
}, [options]) | ||
|
||
const tooltipContent = useMemo<string | null>(() => { | ||
if (Objects.isEmpty(filterValue)) return null | ||
if (!canDisplayTooltip) return null | ||
|
||
const selectedLabels = filterValue.reduce<Array<string>>((acc, value) => { | ||
const label = valueToLabelMap[value] | ||
if (!Objects.isEmpty(label)) acc.push(label) | ||
return acc | ||
}, []) | ||
|
||
if (selectedLabels.length === 0) { | ||
return null | ||
} | ||
return selectedLabels.join(', ') | ||
}, [canDisplayTooltip, filterValue, valueToLabelMap]) | ||
|
||
const hideTooltip = useCallback(() => setCanDisplayTooltip(false), []) | ||
const showTooltip = useCallback(() => setCanDisplayTooltip(true), []) | ||
|
||
return { | ||
hideTooltip, | ||
showTooltip, | ||
tooltipContent, | ||
} | ||
} |
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
Oops, something went wrong.