Skip to content
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

feat: Highlight selected options #4311

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions frontend/web/components/EnvironmentSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ const EnvironmentSelect: FC<EnvironmentSelectType> = ({
...rest
}) => {
const { data } = useGetEnvironmentsQuery({ projectId: `${projectId}` })
const foundValue = useMemo(
() =>
data?.results?.find((environment) => `${environment[idField]}` === value),
[value, data, idField],
)

const environments = useMemo(() => {
return (data?.results || [])
?.map((v) => ({
Expand All @@ -43,16 +39,23 @@ const EnvironmentSelect: FC<EnvironmentSelectType> = ({
return true
})
}, [data?.results, ignore, idField])

const foundValue = useMemo(
() =>
environments.find((environment) => `${environment.value}` === `${value}`),
[value, environments],
)

if (readOnly) {
return <div className='mb-2'>{foundValue?.name}</div>
return <div className='mb-2'>{foundValue?.label}</div>
}
return (
<div>
<Select
{...rest}
value={
foundValue
? { label: foundValue.name, value: `${foundValue.id}` }
? foundValue
: {
label:
label ||
Expand Down
20 changes: 19 additions & 1 deletion frontend/web/project/project-components.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PureComponent } from 'react'
import Select from 'react-select'
import Select, { components } from 'react-select'
import Button from 'components/base/forms/Button'
import Paging from 'components/Paging'
import ToggleChip from 'components/ToggleChip'
Expand All @@ -12,6 +12,8 @@ import ProjectProvider from 'common/providers/ProjectProvider'
import AccountProvider from 'common/providers/AccountProvider'
import OrganisationProvider from 'common/providers/OrganisationProvider'
import Panel from 'components/base/grid/Panel'
import { checkmark, checkmarkCircle } from 'ionicons/icons'
import { IonIcon } from '@ionic/react'

window.AppActions = require('../../common/dispatcher/app-actions')
window.Actions = require('../../common/dispatcher/action-constants')
Expand Down Expand Up @@ -80,6 +82,21 @@ window.Loader = class extends PureComponent {
window.Tooltip = Tooltip

global.ToggleChip = ToggleChip

// Custom Option component to show the tick mark next to selected option in the dropdown
const Option = (props) => {
return (
<components.Option {...props}>
<div className={'d-flex justify-content-between align-items-center'}>
{props.data.label}
{props.isSelected && (
<IonIcon icon={checkmarkCircle} className='text-primary' />
)}
</div>
</components.Option>
)
}

global.Select = class extends PureComponent {
static displayName = 'Select'

Expand Down Expand Up @@ -122,6 +139,7 @@ global.Select = class extends PureComponent {
className={`react-select ${props.size ? props.size : ''}`}
classNamePrefix='react-select'
{...props}
components={{ ...(props.components || {}), Option }}
/>
</div>
)
Expand Down
Loading