-
Notifications
You must be signed in to change notification settings - Fork 2
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
CNFT1-331: Create operator dropdown component #1965
Open
joeaxcdw
wants to merge
5
commits into
main
Choose a base branch
from
CNFT1-3317-create-operator-dropdown-component
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.
+174
−6
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6ce8c62
Implement operator select box
joeaxcdw 2d696f7
Incorporate operator select in patient search form
joeaxcdw 84887fe
Comment out operator select until ready
joeaxcdw 25e9a9a
Merge branch 'main' into CNFT1-3317-create-operator-dropdown-component
joeaxcdw 077cb88
Support for basic operators
joeaxcdw 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 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
3 changes: 1 addition & 2 deletions
3
apps/modernization-ui/src/apps/search/patient/PatientCriteria/PatientCriteria.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
1 change: 1 addition & 0 deletions
1
apps/modernization-ui/src/apps/search/patient/PatientCriteria/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 { PatientCriteria } from './PatientCriteria'; |
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
68 changes: 68 additions & 0 deletions
68
apps/modernization-ui/src/components/FormInputs/OperatorSelect/OperatorSelect.spec.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,68 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { OperatorSelect, OperatorSelectProps } from './OperatorSelect'; | ||
import { basicOperators, defaultOperator, operators } from 'options/operator'; | ||
|
||
describe('OperatorSelect', () => { | ||
const mockOnChange = jest.fn(); | ||
|
||
const defaultProps: OperatorSelectProps = { | ||
id: 'operator-select', | ||
value: null, | ||
showLabel: false, | ||
sizing: 'compact', | ||
onChange: mockOnChange | ||
}; | ||
|
||
it('renders without crashing', () => { | ||
const { getByRole } = render(<OperatorSelect {...defaultProps} />); | ||
const selectElement = getByRole('combobox'); | ||
expect(selectElement).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays the operator label when showLabel is true', () => { | ||
const { getByLabelText } = render(<OperatorSelect {...defaultProps} showLabel={true} />); | ||
const labelElement = getByLabelText('Operator'); | ||
expect(labelElement).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not display the label when showLabel is false', () => { | ||
const { queryByLabelText } = render(<OperatorSelect {...defaultProps} showLabel={false} />); | ||
const labelElement = queryByLabelText('Operator'); | ||
expect(labelElement).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('calls onChange when an option is selected', () => { | ||
const { getByRole } = render(<OperatorSelect {...defaultProps} />); | ||
const selectElement = getByRole('combobox'); | ||
fireEvent.change(selectElement, { target: { value: operators[0].value } }); | ||
expect(mockOnChange).toHaveBeenCalledWith(operators[0]); | ||
}); | ||
|
||
it('displays the EQUAL operator by default', () => { | ||
const { getByRole } = render(<OperatorSelect {...defaultProps} />); | ||
const selectElement = getByRole('combobox') as HTMLSelectElement; | ||
expect(selectElement.value).toBe(defaultOperator.value); | ||
}); | ||
|
||
it('displays the correct initial value when specified', () => { | ||
const { getByRole } = render(<OperatorSelect {...defaultProps} value={operators[1]} />); | ||
const selectElement = getByRole('combobox') as HTMLSelectElement; | ||
expect(selectElement.value).toBe(operators[1].value); | ||
}); | ||
|
||
it('renders all of the operator options when mode is not specified', () => { | ||
const { getAllByRole } = render(<OperatorSelect {...defaultProps} />); | ||
const options = getAllByRole('option'); | ||
// all options + the placeholder | ||
expect(options.length).toBe(operators.length + 1); | ||
}); | ||
|
||
it('renders only the basic operator options when mode is basic', () => { | ||
const { getAllByRole } = render(<OperatorSelect {...defaultProps} mode="basic" />); | ||
const options = getAllByRole('option'); | ||
// basic options + the placeholder | ||
expect(options.length).toBe(basicOperators.length + 1); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
apps/modernization-ui/src/components/FormInputs/OperatorSelect/OperatorSelect.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,27 @@ | ||
import { Sizing } from 'components/Entry'; | ||
import { SingleSelect } from 'design-system/select'; | ||
import { Selectable } from 'options'; | ||
import { operators, defaultOperator, basicOperators } from 'options/operator'; | ||
|
||
export type OperatorSelectProps = { | ||
id: string; | ||
value?: Selectable | null; | ||
mode?: 'basic' | 'all'; | ||
showLabel?: boolean; | ||
sizing?: Sizing; | ||
onChange: (value?: Selectable) => void; | ||
}; | ||
|
||
export const OperatorSelect = ({ id, value, mode, showLabel = false, sizing, onChange }: OperatorSelectProps) => { | ||
return ( | ||
<SingleSelect | ||
value={value || defaultOperator} | ||
onChange={onChange} | ||
name={id} | ||
label={showLabel ? 'Operator' : ''} | ||
id={id} | ||
options={mode === 'basic' ? basicOperators : operators} | ||
sizing={sizing} | ||
/> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
apps/modernization-ui/src/components/FormInputs/OperatorSelect/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 { OperatorSelect } from './OperatorSelect'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './operators'; |
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,26 @@ | ||
import { Selectable, asSelectable, findByValue } from 'options'; | ||
|
||
const STARTS_WITH_OPERATOR = asSelectable('S', 'Starts with'); | ||
const CONTAINS_OPERATOR = asSelectable('C', 'Contains'); | ||
const EQUAL_OPERATOR = asSelectable('E', 'Equal'); | ||
const NOT_EQUAL_OPERATOR = asSelectable('N', 'Not equal'); | ||
const SOUNDS_LIKE_OPERATOR = asSelectable('L', 'Sounds like'); | ||
|
||
const operators: Selectable[] = [ | ||
STARTS_WITH_OPERATOR, | ||
CONTAINS_OPERATOR, | ||
EQUAL_OPERATOR, | ||
NOT_EQUAL_OPERATOR, | ||
SOUNDS_LIKE_OPERATOR | ||
]; | ||
|
||
/** A subset of operators: equals, not equals, contains */ | ||
const basicOperators: Selectable[] = [EQUAL_OPERATOR, NOT_EQUAL_OPERATOR, CONTAINS_OPERATOR]; | ||
|
||
/** The default operator to be used. Currently: EQUAL */ | ||
const defaultOperator = EQUAL_OPERATOR; | ||
|
||
const asSelectableOperator = (value: string | null | undefined) => | ||
(value && findByValue(operators, EQUAL_OPERATOR)(value)) || EQUAL_OPERATOR; | ||
|
||
export { operators, basicOperators, defaultOperator, asSelectableOperator }; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stevegsa please let me know what the actual values will be for these operators so I can fix it here.