Skip to content

Commit

Permalink
OLMIS-7987: fixed orderable filter PR:
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikNoga committed Oct 22, 2024
1 parent d688dd6 commit 55cedf2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
5 changes: 5 additions & 0 deletions src/requisition-order-create/order-create-tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ const OrderCreateTab = ({ passedOrder,
const { formatMessage } = useMemo(() => getService('messageService'), []);
const columns = useMemo(() => orderTableColumns(isTableReadOnly, formatMessage), []);
const orderCreatePrintService = useMemo(() => getService('orderCreatePrintService'), []);
const loadingModalService = useMemo(() => getService('loadingModalService'), []);

useMemo(() => {
if (cachedOrderableOptions?.length) {
setOrderableOptions(cachedOrderableOptions);
return;
}

loadingModalService.open();
stockCardSummaryRepositoryImpl.query({
programId: order.program.id,
facilityId: order.requestingFacility.id
Expand All @@ -42,6 +44,9 @@ const OrderCreateTab = ({ passedOrder,
}));

setOrderableOptions(orderableOptionsValue);
loadingModalService.close();
}).catch(() => {
loadingModalService.close();
});
}, []);

Expand Down
3 changes: 2 additions & 1 deletion src/requisition-order-create/order-create.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
routes.$inject = ['$stateProvider', 'ADMINISTRATION_RIGHTS'];

function routes($stateProvider, ADMINISTRATION_RIGHTS) {
var showRequisitionLessOrder = '@@SHOW_REQUISITION_LESS_ORDER' !== 'false';
var showRequisitionLessOrder = true;
// '@@SHOW_REQUISITION_LESS_ORDER' !== 'false';

$stateProvider.state('openlmis.requisitions.orderCreate', {
url: '/orderCreate',
Expand Down
33 changes: 17 additions & 16 deletions src/requisition-order-create/search-select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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));
};
};

Expand All @@ -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>
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 55cedf2

Please sign in to comment.