Skip to content

Commit

Permalink
Ensuring flight search submits on change (#15)
Browse files Browse the repository at this point in the history
* Ensuring flight flagger search submits on change

---------

Co-authored-by: jackson <Jackson Hyde>
  • Loading branch information
jacksonhyde authored Jun 28, 2024
1 parent 8bdccd9 commit 4d24370
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/components/FlightFlagger/FlightFlaggerFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,18 @@ export const FlightFlaggerFilters = ({nationalities, ageGroups, submitCallback,

const handleTextInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const name: string = event.target.name
const ageGroupPayload: string[] = selectedAgeGroups.map((ageGroup: AutocompleteOption) => ageGroup.title)
const nationalityPayload: string[] = selectedNationalities.map((nationality: AutocompleteOption) => nationality.title)
setSearchFlags({
...searchFlags,
[name]: event.target.value
})
submitCallback({
...searchFlags,
selectedNationalities: nationalityPayload,
selectedAgeGroups: ageGroupPayload,
flightNumber: event.target.value
});
}

const handleInputSubmit = (event: React.KeyboardEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -117,8 +125,8 @@ export const FlightFlaggerFilters = ({nationalities, ageGroups, submitCallback,
return <>
<Grid container sx={{backgroundColor: '#F3F5F9', width: '100%', ml:0, pt: 2}} flexWrap={{xs: 'wrap', md: 'nowrap'}} spacing={2}>
<Grid item flexGrow={0}>
<InputLabel htmlFor="flight-number" sx={{mb:1}}><strong>Enter flight number</strong></InputLabel>
<FormControl variant="outlined">
<InputLabel htmlFor="flight-number" sx={{mb:1}}><strong>Enter flight details</strong></InputLabel>
<FormControl variant="outlined" sx={{minWidth: '365px'}}>
<OutlinedInput
sx={{backgroundColor: '#fff'}}
size="small"
Expand All @@ -127,7 +135,7 @@ export const FlightFlaggerFilters = ({nationalities, ageGroups, submitCallback,
onChange={handleTextInputChange}
onKeyDown={handleInputSubmit}
value={searchFlags.flightNumber}
placeholder="Enter flight number"
placeholder="Enter flight number, origin or country"
startAdornment={
<InputAdornment position="start">
<SearchIcon/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/FlightFlagger/__tests__/FlightFlagger.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe("Flight Flagger", () => {
expect(filters).toHaveStyle(`height: auto`)
});

const flightNumber = screen.getByLabelText('Enter flight number')
const flightNumber = screen.getByLabelText('Enter flight details')
fireEvent.change(flightNumber, {target: {value: 'BA1234'}})

const nationalitiesAutocomplete = screen.getByTestId('nationalities-autocomplete');
Expand Down Expand Up @@ -165,7 +165,7 @@ describe("Flight Flagger", () => {
expect(filters).toHaveStyle(`height: auto`)
});

const flightNumber = screen.getByLabelText('Enter flight number')
const flightNumber = screen.getByLabelText('Enter flight details')
fireEvent.change(flightNumber, {target: {value: 'BA1234'}})
fireEvent.keyDown(flightNumber, { key: 'Enter' })

Expand Down

0 comments on commit 4d24370

Please sign in to comment.