-
Notifications
You must be signed in to change notification settings - Fork 458
feat: context values - implement multi-select dropdown on envs #6239
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
Open
talissoncosta
wants to merge
7
commits into
main
Choose a base branch
from
feat/multi-select-dropdown
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+461
−350
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a148b36
feat: add multi-select on envs and refactor layout
talissoncosta 1cd271f
refactor: extract logic and clean up
talissoncosta 006eb98
fix: prevent breaking input on multi-select
talissoncosta f76b9fc
refactor: split components into smaller files and keep the selected o…
talissoncosta e310d5c
fix: fix operation transitions values
talissoncosta f20a63c
fix: use button to handle tag removal
talissoncosta 1af4e3e
feat: update placeholder
talissoncosta 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 was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
frontend/web/components/base/select/multi-select/CustomMultiValue.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,47 @@ | ||
| import { MultiValueProps } from 'react-select/lib/components/MultiValue' | ||
| import { MultiSelectOption } from './MultiSelect' | ||
|
|
||
| export const CustomMultiValue = ({ | ||
| color, | ||
| data, | ||
| removeProps, | ||
| }: MultiValueProps<MultiSelectOption> & { color?: string }) => { | ||
| return ( | ||
| <div | ||
| className='d-flex align-items-center' | ||
| style={{ | ||
| backgroundColor: color, | ||
| borderRadius: '4px', | ||
| color: 'white', | ||
| fontSize: '12px', | ||
| maxWidth: '150px', | ||
| overflow: 'hidden', | ||
| padding: '2px 6px', | ||
| textOverflow: 'ellipsis', | ||
| whiteSpace: 'nowrap', | ||
| maxHeight: '24px' | ||
| }} | ||
| > | ||
| <span | ||
| className='mr-1' | ||
| style={{ | ||
| overflow: 'hidden', | ||
| textOverflow: 'ellipsis', | ||
| whiteSpace: 'nowrap', | ||
| }} | ||
| > | ||
| {data.label} | ||
| </span> | ||
| <span | ||
| onClick={() => removeProps?.onClick?.(data)} | ||
| style={{ | ||
| cursor: 'pointer', | ||
| fontSize: '14px', | ||
| lineHeight: '1', | ||
| }} | ||
| > | ||
| × | ||
| </span> | ||
| </div> | ||
| ) | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
frontend/web/components/base/select/multi-select/CustomOption.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,33 @@ | ||
|
|
||
| import { OptionProps } from 'react-select/lib/components/Option' | ||
| import { MultiSelectOption } from './MultiSelect' | ||
|
|
||
| export const CustomOption = ({ | ||
| children, | ||
| color, | ||
| ...props | ||
| }: OptionProps<MultiSelectOption> & { color?: string }) => { | ||
| return ( | ||
| <div | ||
| {...props.innerProps} | ||
| className={`d-flex align-items-center p-2 ${ | ||
| props.isFocused ? 'bg-light' : '' | ||
| }`} | ||
| style={{ cursor: 'pointer' }} | ||
| > | ||
| {color && ( | ||
| <div | ||
| style={{ | ||
| backgroundColor: color, | ||
| borderRadius: '2px', | ||
| flexShrink: 0, | ||
| height: '12px', | ||
| marginRight: '8px', | ||
| width: '12px', | ||
| }} | ||
| /> | ||
| )} | ||
| <span>{children}</span> | ||
| </div> | ||
| ) | ||
| } |
105 changes: 105 additions & 0 deletions
105
frontend/web/components/base/select/multi-select/MultiSelect.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,105 @@ | ||
| import classNames from 'classnames' | ||
| import React, { FC } from 'react' | ||
| import { MultiValueProps } from 'react-select/lib/components/MultiValue' | ||
| import { OptionProps } from 'react-select/lib/components/Option' | ||
|
|
||
| import { CustomMultiValue } from './CustomMultiValue' | ||
| import { CustomOption } from './CustomOption' | ||
|
|
||
| export interface MultiSelectOption { | ||
| label: string | ||
| value: string | ||
| } | ||
|
|
||
| export interface MultiSelectProps { | ||
| selectedValues: string[] | ||
| onSelectionChange: (selectedValues: string[]) => void | ||
| options: MultiSelectOption[] | ||
| colorMap?: Map<string, string> | ||
| label?: string | ||
| placeholder?: string | ||
| className?: string | ||
| disabled?: boolean | ||
| size?: 'small' | 'default' | 'large' | ||
| hideSelectedOptions?: boolean | ||
| inline?: boolean | ||
| } | ||
|
|
||
| export const MultiSelect: FC<MultiSelectProps> = ({ | ||
| className = '', | ||
| colorMap, | ||
| disabled = false, | ||
| label, | ||
| onSelectionChange, | ||
| options, | ||
| placeholder = 'Select options...', | ||
| selectedValues, | ||
| size = 'default', | ||
| hideSelectedOptions = false, | ||
| }) => { | ||
| return ( | ||
| <div className={classNames( | ||
| className, | ||
| label ? `d-flex flex-column gap-2` : '' | ||
| )}> | ||
| {label && <label>{label}</label>} | ||
| <Select | ||
| isMulti | ||
| hideSelectedOptions={hideSelectedOptions} | ||
| closeMenuOnSelect={false} | ||
| placeholder={placeholder} | ||
| isDisabled={disabled} | ||
| size={size} | ||
| onChange={(selectedOptions: MultiSelectOption[]) => { | ||
| const values = selectedOptions | ||
| ? selectedOptions.map((opt: MultiSelectOption) => opt.value) | ||
| : [] | ||
| onSelectionChange(values) | ||
| }} | ||
| components={{ | ||
| MultiValue: (props: MultiValueProps<MultiSelectOption>) => ( | ||
| <CustomMultiValue | ||
| {...props} | ||
| color={colorMap?.get(props.data.value) || '#5D6D7E'} | ||
| /> | ||
| ), | ||
| ...(colorMap ? {Option: (props: OptionProps<MultiSelectOption>) => <CustomOption | ||
| {...props} | ||
| color={colorMap.get(props.data.value)} | ||
| />} : {}), | ||
| }} | ||
| value={selectedValues.map((value) => ({ | ||
| label: options.find((opt) => opt.value === value)?.label || value, | ||
| value, | ||
| }))} | ||
| options={options} | ||
| className='react-select react-select__extensible w-100' | ||
| styles={{ | ||
| control: (base: any) => ({ | ||
| ...base, | ||
| cursor: 'pointer', | ||
| }), | ||
| multiValue: (base: any) => ({ | ||
| ...base, | ||
| flexShrink: 0, | ||
| margin: '2px', | ||
| }), | ||
| valueContainer: (base: any) => ({ | ||
| ...base, | ||
| flexWrap: 'nowrap', | ||
talissoncosta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| gap: '2px', | ||
| paddingBottom: '6px', | ||
| paddingTop: '6px', | ||
| flex: 1 | ||
| }), | ||
| input: (base: any) => ({ | ||
| ...base, | ||
| margin: 0, | ||
| paddingBottom: 0, | ||
| paddingTop: 0, | ||
| }), | ||
| }} | ||
| /> | ||
| </div> | ||
| ) | ||
| } | ||
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 @@ | ||
| export { MultiSelect } from './MultiSelect' |
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
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.