-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OLMIS-7987: fixed orderable filter PR:
- Loading branch information
1 parent
d688dd6
commit 55cedf2
Showing
3 changed files
with
24 additions
and
17 deletions.
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
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 |
---|---|---|
|
@@ -13,8 +13,9 @@ | |
* http://www.gnu.org/licenses. For additional information contact [email protected]. | ||
*/ | ||
|
||
import React from 'react'; | ||
import React, { useMemo } from 'react'; | ||
import SelectSearch from 'react-select-search'; | ||
import getService from '../react-components/utils/angular-utils'; | ||
|
||
const filterOptions = options => { | ||
return searchValue => { | ||
|
@@ -24,7 +25,7 @@ const filterOptions = options => { | |
|
||
const lowercaseSearchValue = searchValue.toLowerCase(); | ||
|
||
return options.filter(option => option.name.toLowerCase().includes(lowercaseSearchValue)); | ||
return options.filter(option => option.name && option.name.toLowerCase().includes(lowercaseSearchValue)); | ||
}; | ||
}; | ||
|
||
|
@@ -44,16 +45,16 @@ const mapClassName = key => { | |
}; | ||
|
||
export const SearchSelect = ({ | ||
options, | ||
onChange, | ||
value, | ||
placeholder = 'Select an option', | ||
emptyMsg = 'Not found', | ||
disabled = false, | ||
objectKey = null, | ||
}) => { | ||
|
||
const renderOption = (props, {name}, snapshot, className) => { | ||
options, | ||
onChange, | ||
value, | ||
placeholder = 'requisition.orderCreate.searchSelect.placeholder', | ||
emptyMsg = 'requisition.orderCreate.searchSelect.empty.message', | ||
disabled = false, | ||
objectKey = null, | ||
}) => { | ||
const { formatMessage } = useMemo(() => getService('messageService'), []); | ||
const renderOption = (props, { name }, snapshot, className) => { | ||
return ( | ||
<button {...props} className={className} type="button"> | ||
<span>{name}</span> | ||
|
@@ -66,7 +67,7 @@ export const SearchSelect = ({ | |
|
||
return ( | ||
<div className={'input-wrapper'}> | ||
<input {...valueProps} className={className} value={inputVal}/> | ||
<input {...valueProps} className={className} value={inputVal} /> | ||
<i | ||
className="fa fa-times clear-icon" | ||
aria-hidden="true" | ||
|
@@ -97,20 +98,20 @@ export const SearchSelect = ({ | |
<SelectSearch | ||
className={mapClassName} | ||
disabled={disabled} | ||
emptyMessage={emptyMsg} | ||
emptyMessage={formatMessage(emptyMsg)} | ||
filterOptions={filterOptions} | ||
onChange={handleOnChange} | ||
options={ | ||
options.map( | ||
({value, name}) => { | ||
({ value, name }) => { | ||
return { | ||
name: name, | ||
value: objectKey ? _.get(value, objectKey) : value | ||
}; | ||
} | ||
) | ||
} | ||
placeholder={placeholder} | ||
placeholder={formatMessage(placeholder)} | ||
renderOption={renderOption} | ||
renderValue={renderValue} | ||
search | ||
|