Skip to content

Commit

Permalink
Merge pull request #13 from openimis/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
xgill committed Aug 6, 2020
2 parents 5b69d0c + 5069877 commit 2ac8fee
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ None
* `debounceTime`: for pickers without cache, debounce time (ms) before triggering the search. Default: `800`
* `cacheDiagnoses`: wherever diagnoses picker caches the diagnoses or not
* `diagnosesMinCharLookup`: if diagnoses picker is not configured to cache diagnoses, minimum number of characters before trigring the search. Default: 2
* `cacheItems`: wherever items picker caches the diagnoses or not (default false, WARNING: when caching, the list is filtered with validity date = today)
* `itemsMinCharLookup`: if items picker is not configured to cache items, minimum number of characters before trigring the search. Default: 2
* `cacheServices`: wherever services picker caches the diagnoses or not (default false, WARNING: when caching, the list is filtered with validity date = today)
* `servicesMinCharLookup`: if services picker is not configured to cache services, minimum number of characters before trigring the search. Default: 2
* `DiagnosisPicker.selectThreshold`: Diagnosis suggestions count threshold under which the AutoSuggestion switch to a SelectInut (drop down list), default: 10
* `ItemPicker.selectThreshold`: Items suggestions count threshold under which the AutoSuggestion switch to a SelectInut (drop down list), default: 10
* `ServicePicker.selectThreshold`: Services suggestions count threshold under which the AutoSuggestion switch to a SelectInut (drop down list), default: 10
33 changes: 19 additions & 14 deletions src/pickers/ItemPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@ import React, { Component } from "react";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import { injectIntl } from 'react-intl';
import { formatMessage, AutoSuggestion, withModulesManager } from "@openimis/fe-core";
import { formatMessage, AutoSuggestion, withModulesManager, decodeId } from "@openimis/fe-core";
import { fetchItemPicker } from "../actions";
import _debounce from "lodash/debounce";

class ItemPicker extends Component {

constructor(props) {
super(props);
this.cache = props.modulesManager.getConf("fe-medical", "cacheItems", true);
this.selectThreshold = props.modulesManager.getConf("fe-medical", "ItemPicker.selectThreshold", 10);
}

componentDidMount() {
if (this.cache && !this.props.items) {
// prevent loading multiple times the cache when component is
// several times on tha page
setTimeout(
() => {
!this.props.fetching && !this.props.fetched && this.props.fetchItemPicker(this.props.modulesManager)
},
Math.floor(Math.random() * 300)
);
if (!this.props.items) {
// prevent loading multiple times the cache when component is
// several times on tha page
setTimeout(
() => {
!this.props.fetching && this.props.fetchItemPicker(this.props.modulesManager)
},
Math.floor(Math.random() * 300)
);
}
}

Expand All @@ -41,16 +40,21 @@ class ItemPicker extends Component {
onSuggestionSelected = v => this.props.onChange(v, this.formatSuggestion(v));

render() {
const { intl, items, withLabel = true, label, withPlaceholder = false, placeholder, value = null, reset,
const { intl, withLabel = true, label, withPlaceholder = false, placeholder, value = null, reset,
readOnly = false, required = false,
withNull = false, nullLabel = null
withNull = false, nullLabel = null,
filteredOnPriceList = null, itemsPricelists
} = this.props;
if (!this.props.items) return null;
let items = [...this.props.items]
if (!!filteredOnPriceList) {
items = items.filter(i => itemsPricelists[filteredOnPriceList][decodeId(i.id)] !== undefined)
}
return <AutoSuggestion
module="medical"
items={items}
label={!!withLabel && (label || formatMessage(intl, "medical", "Item"))}
placeholder={!!withPlaceholder ? (placeholder || formatMessage(intl, "medical", "ItemPicker.placehoder")) : null}
getSuggestions={this.cache ? null : this.debouncedGetSuggestion}
getSuggestionValue={this.formatSuggestion}
onSuggestionSelected={this.onSuggestionSelected}
value={value}
Expand All @@ -66,6 +70,7 @@ class ItemPicker extends Component {

const mapStateToProps = state => ({
items: state.medical.items,
itemsPricelists: !!state.medical_pricelist ? state.medical_pricelist.itemsPricelists : {},
fetching: state.medical.fetchingItems,
fetched: state.medical.fetchedItems,
});
Expand Down
15 changes: 10 additions & 5 deletions src/pickers/ServicePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Component } from "react";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import { injectIntl } from 'react-intl';
import { formatMessage, AutoSuggestion, withModulesManager } from "@openimis/fe-core";
import { formatMessage, AutoSuggestion, withModulesManager, decodeId } from "@openimis/fe-core";
import { fetchServicePicker } from "../actions";
import _debounce from "lodash/debounce";
import _ from "lodash";
Expand All @@ -11,12 +11,11 @@ class ServicePicker extends Component {

constructor(props) {
super(props);
this.cache = props.modulesManager.getConf("fe-medical", "cacheServices", true);
this.selectThreshold = props.modulesManager.getConf("fe-medical", "ServicePicker.selectThreshold", 10);
}

componentDidMount() {
if (this.cache && !this.props.services) {
if (!this.props.services) {
// prevent loading multiple times the cache when component is
// several times on tha page
setTimeout(
Expand Down Expand Up @@ -44,14 +43,19 @@ class ServicePicker extends Component {
render() {
const { intl, services, withLabel = true, label, withPlaceholder = false, placeholder, value, reset,
readOnly = false, required = false,
withNull = false, nullLabel = null
withNull = false, nullLabel = null,
filteredOnPriceList = null, servicesPricelists
} = this.props;
if (!this.props.services) return null;
let services = [...this.props.services]
if (!!filteredOnPriceList) {
services = services.filter(i => servicesPricelists[filteredOnPriceList][decodeId(i.id)] !== undefined)
}
return <AutoSuggestion
module="medical"
items={services}
label={!!withLabel && (label || formatMessage(intl, "medical", "Services"))}
placeholder={!!withPlaceholder ? (placeholder || formatMessage(intl, "medical", "ServicePicker.placehoder")) : null}
getSuggestions={this.cache ? null : this.debouncedGetSuggestion}
getSuggestionValue={this.formatSuggestion}
onSuggestionSelected={this.onSuggestionSelected}
value={value}
Expand All @@ -67,6 +71,7 @@ class ServicePicker extends Component {

const mapStateToProps = state => ({
services: state.medical.services,
servicesPricelists: !!state.medical_pricelist ? state.medical_pricelist.servicesPricelists : {},
fetching: state.medical.fetchingServices,
fetched: state.medical.fetchedServices,
});
Expand Down

0 comments on commit 2ac8fee

Please sign in to comment.