-
Notifications
You must be signed in to change notification settings - Fork 562
feat: use dropdown for values with context environment #5832
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
Zaimwa9
merged 14 commits into
main
from
feat/use-dropdown-for-values-with-context-environment
Aug 11, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
61f1926
feat/wip-environment-values-in-dropdown
Zaimwa9 f32b7db
feat/changed-no-options-text
Zaimwa9 f848f67
feat/added-value-control-in-env-dropdown
Zaimwa9 e30329b
feat/finetuning-types
Zaimwa9 8e5e7e1
Merge branch 'main' of github.com:Flagsmith/flagsmith into feat/use-d…
Zaimwa9 3493a9b
feat/fixed-props-deconstruction
Zaimwa9 c94c1b7
feat/added-search-option
Zaimwa9 62ccaa5
feat/re-added-data-test
Zaimwa9 ceaf5a2
feat: added-clearable-and-trait-hint
Zaimwa9 897f50f
Update frontend/web/components/base/SearchableDropdown.tsx
Zaimwa9 53f91ce
Merge branch 'main' of github.com:Flagsmith/flagsmith into feat/use-d…
Zaimwa9 2a7e17c
feat: only-show-dropdown-for-matches-operator
Zaimwa9 564ff3b
Merge branch 'feat/use-dropdown-for-values-with-context-environment' …
Zaimwa9 0f98037
feat: wording
Zaimwa9 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import Icon from 'components/Icon' | ||
| import React from 'react' | ||
| export interface OptionType { | ||
| enabled?: boolean | ||
| label: string | ||
| value: string | ||
| } | ||
|
|
||
| export interface GroupedOptionType { | ||
| label: React.ReactNode | ||
| options: OptionType[] | ||
| } | ||
|
|
||
| export const GroupLabel = ({ | ||
| groupName, | ||
| tooltipText, | ||
| }: { | ||
| groupName: string | ||
| tooltipText?: string | ||
| }) => { | ||
| return ( | ||
| <div className='d-flex align-items-center gap-1'> | ||
| <div>{groupName}</div> | ||
| {tooltipText && ( | ||
| <Tooltip | ||
| title={ | ||
| <h5 className='mb-1 cursor-pointer'> | ||
| <Icon name='info-outlined' height={16} width={16} /> | ||
| </h5> | ||
| } | ||
| place='right' | ||
| > | ||
| {tooltipText} | ||
| </Tooltip> | ||
| )} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| interface SearchableDropdownProps { | ||
| placeholder: string | ||
| options: OptionType[] | GroupedOptionType[] | ||
| value: string | number | null | ||
| dataTest?: string | ||
| isSearchable?: boolean | ||
| displayedLabel?: string | ||
| noOptionsMessage?: string | ||
| maxMenuHeight?: number | ||
| onBlur?: (e: OptionType | null) => void | ||
| onInputChange?: (e: string, metadata: any) => void | ||
| onChange?: (e: OptionType) => void | ||
| isMulti?: boolean | ||
| isClearable?: boolean | ||
| components?: any | ||
| } | ||
|
|
||
| const SearchableDropdown: React.FC<SearchableDropdownProps> = ({ | ||
| components, | ||
| dataTest, | ||
| displayedLabel, | ||
| isClearable = false, | ||
| isMulti, | ||
| isSearchable, | ||
| maxMenuHeight, | ||
| noOptionsMessage, | ||
| onBlur, | ||
| onChange, | ||
| onInputChange, | ||
| options, | ||
| placeholder, | ||
| value, | ||
| }) => { | ||
| return ( | ||
| <Select | ||
| data-test={dataTest} | ||
| placeholder={placeholder} | ||
| value={value ? { label: displayedLabel || value, value: value } : null} | ||
| onBlur={onBlur} | ||
| isSearchable={isSearchable} | ||
| onInputChange={onInputChange} | ||
| onChange={onChange} | ||
| options={options} | ||
| maxMenuHeight={maxMenuHeight} | ||
| isMulti={isMulti} | ||
| {...(noOptionsMessage | ||
| ? { noOptionsMessage: () => noOptionsMessage } | ||
| : {})} | ||
| isClearable={isClearable} | ||
| className={`react-select ${ | ||
| isClearable && value ? 'clearable-dropdown' : '' | ||
| }`} | ||
| components={components} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| export default SearchableDropdown | ||
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
91 changes: 91 additions & 0 deletions
91
frontend/web/components/segments/Rule/components/EnvironmentSelectDropdown.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,91 @@ | ||
| import React, { useEffect, useState } from 'react' | ||
| import SearchableDropdown, { | ||
| GroupLabel, | ||
| OptionType, | ||
| } from 'components/base/SearchableDropdown' | ||
| import { useGetEnvironmentsQuery } from 'common/services/useEnvironment' | ||
| import Utils from 'common/utils/utils' | ||
|
|
||
| interface EnvironmentSelectDropdownProps { | ||
| projectId: number | ||
| dataTest?: string | ||
| onChange?: (value: string) => void | ||
| value?: string | number | boolean | null | ||
| } | ||
| const EnvironmentSelectDropdown: React.FC<EnvironmentSelectDropdownProps> = ({ | ||
| dataTest, | ||
| onChange, | ||
| projectId, | ||
| value, | ||
| }) => { | ||
| const [localCurrentValue, setLocalCurrentValue] = useState(value || '') | ||
| const { data } = useGetEnvironmentsQuery({ projectId: projectId?.toString() }) | ||
| const environments = data?.results | ||
|
|
||
| useEffect(() => { | ||
| setLocalCurrentValue(value || '') | ||
| }, [value]) | ||
|
|
||
| const isEditing = localCurrentValue !== value | ||
| const isExistingEnvironment = environments?.find( | ||
| (environment) => environment.name === value, | ||
| ) | ||
|
|
||
| const customSelectionAsOption = | ||
| localCurrentValue && (isEditing || !isExistingEnvironment) | ||
| ? [ | ||
| { | ||
| label: <GroupLabel groupName='Custom selection' />, | ||
| options: [ | ||
| { | ||
| label: localCurrentValue?.toString(), | ||
| value: localCurrentValue?.toString(), | ||
| }, | ||
| ], | ||
| }, | ||
| ] | ||
| : [] | ||
|
|
||
| const environmentOptions = [ | ||
| { | ||
| label: <GroupLabel groupName='Environments' />, | ||
| options: | ||
| environments?.map((environment) => ({ | ||
| label: Utils.capitalize(environment.name), | ||
| value: environment.name, | ||
| })) || [], | ||
| }, | ||
| ] | ||
|
|
||
| const allOptions = [...customSelectionAsOption, ...environmentOptions] | ||
|
|
||
| return ( | ||
| <SearchableDropdown | ||
| options={allOptions} | ||
| value={value?.toString() || null} | ||
| placeholder={'Environment'} | ||
| noOptionsMessage={'No environment matches your search'} | ||
| isClearable={true} | ||
| maxMenuHeight={280} | ||
| dataTest={dataTest} | ||
| onInputChange={(e: string, metadata: any) => { | ||
| if (metadata.action !== 'input-change') { | ||
| return | ||
| } | ||
| setLocalCurrentValue(e) | ||
| }} | ||
| onBlur={() => { | ||
| if (onChange && localCurrentValue !== value) { | ||
| onChange(localCurrentValue?.toString() || '') | ||
| } | ||
| }} | ||
| onChange={(e: OptionType) => { | ||
| if (onChange) { | ||
| onChange(Utils.safeParseEventValue(e?.value || '')) | ||
| } | ||
| }} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| export default EnvironmentSelectDropdown |
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.