-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Component-alize the MtnTable component, including a MtnStatusField fo…
…r filtering by status and a new MtnSearchField component. The new filter fields stores and reads the state in a URL search parameter. quick aria label fixes for MtnList
- Loading branch information
1 parent
75d90d7
commit b0ec7b6
Showing
6 changed files
with
140 additions
and
55 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
client/src/components/Mtn/MtnSearchField/MtnSearchField.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,45 @@ | ||
import React, { ChangeEventHandler, useEffect } from 'react'; | ||
import { Form } from 'react-bootstrap'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
|
||
interface MtnSearchFieldProps { | ||
value: string; | ||
onChange: ChangeEventHandler; | ||
} | ||
|
||
export function MtnSearchField({ value, onChange }: MtnSearchFieldProps) { | ||
const [searchParams, setSearchParams] = useSearchParams(); | ||
|
||
const setMtnSearchParam = (value: string) => { | ||
if (value) { | ||
searchParams.set('mtn', value); | ||
} else { | ||
searchParams.delete('mtn'); | ||
} | ||
setSearchParams(searchParams); | ||
}; | ||
|
||
const onBlur = () => { | ||
setMtnSearchParam(value); | ||
}; | ||
|
||
const onKeyReturn = (event: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (event.key === 'Enter') { | ||
setMtnSearchParam(value); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Form.Control | ||
id={'mtnGlobalSearch'} | ||
value={value ?? ''} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
onKeyUp={onKeyReturn} | ||
placeholder="search..." | ||
aria-label="search" | ||
/> | ||
</> | ||
); | ||
} |
70 changes: 70 additions & 0 deletions
70
client/src/components/Mtn/MtnStatusField/MtnStatusField.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,70 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
import Select from 'react-select'; | ||
|
||
export interface StatusOption { | ||
value: string; | ||
label: string; | ||
} | ||
|
||
const statusOptions: readonly StatusOption[] = [ | ||
{ value: 'Scheduled', label: 'Scheduled' }, | ||
{ value: 'InTransit', label: 'In Transit' }, | ||
{ value: 'ReadyForSignature', label: 'Ready to Sign' }, | ||
{ value: 'Corrected', label: 'Corrected' }, | ||
{ value: 'Signed', label: 'Signed' }, | ||
{ value: 'NotAssigned', label: 'Draft' }, | ||
{ value: 'UnderCorrection', label: 'Under Correction' }, | ||
]; | ||
|
||
interface MtnStatusFieldProps { | ||
onChange: (newValue: StatusOption | null) => void; | ||
} | ||
|
||
const parseSearchParam = (searchParam: string | null): StatusOption | null => { | ||
if (!searchParam) return null; | ||
const option = statusOptions.find( | ||
(option) => option.value.toLowerCase() === searchParam.toLowerCase() | ||
); | ||
return option || null; | ||
}; | ||
|
||
export function MtnStatusField({ onChange }: MtnStatusFieldProps) { | ||
const [searchParams, setSearchParams] = useSearchParams(); | ||
const statusParam = searchParams.get('status'); | ||
const [searchValue, setSearchValue] = useState<StatusOption | null>( | ||
parseSearchParam(statusParam) | ||
); | ||
|
||
const onSelection = (newValue: StatusOption | null) => { | ||
setSearchValue(newValue); | ||
}; | ||
|
||
useEffect(() => { | ||
onChange(searchValue); | ||
if (searchValue) { | ||
searchParams.set('status', searchValue?.value.toLowerCase()); | ||
} else { | ||
searchParams.delete('status'); | ||
} | ||
setSearchParams(searchParams); | ||
}, [searchValue]); | ||
|
||
return ( | ||
<div> | ||
<Select | ||
name="statusFilter" | ||
aria-label="status filter" | ||
value={searchValue} | ||
onChange={onSelection} | ||
options={statusOptions} | ||
isClearable={true} | ||
classNames={{ | ||
control: () => 'form-select py-0 ms-2 rounded-3', | ||
placeholder: () => 'p-0 m-0 ps-1', | ||
}} | ||
components={{ IndicatorSeparator: () => null, DropdownIndicator: () => null }} | ||
/> | ||
</div> | ||
); | ||
} |
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
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