Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTC-1089: fix resetting the search criteria in insuree module #64

Merged
merged 2 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 22 additions & 29 deletions src/components/FamilyFilter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { Component, Fragment } from "react";
import _debounce from "lodash/debounce";
import { withTheme, withStyles } from "@material-ui/core/styles";
import { injectIntl } from "react-intl";
import _debounce from "lodash/debounce";

import { Checkbox, FormControlLabel, Grid } from "@material-ui/core";
import { withTheme, withStyles } from "@material-ui/core/styles";

import {
withModulesManager,
formatMessage,
Expand All @@ -26,7 +28,6 @@ const styles = (theme) => ({

class FamilyFilter extends Component {
state = {
showHistory: false,
additionalFilters: {},
};

Expand All @@ -35,38 +36,30 @@ class FamilyFilter extends Component {
this.filterFamiliesOnMembers = this.props.modulesManager.getConf("fe-insuree", "filterFamiliesOnMembers", true);
}

componentDidUpdate(prevProps, prevState, snapshot) {
if (
prevProps.filters["showHistory"] !== this.props.filters["showHistory"] &&
!!this.props.filters["showHistory"] &&
this.state.showHistory !== this.props.filters["showHistory"]["value"]
) {
this.setState((sate, props) => ({ showHistory: props.filters["showHistory"]["value"] }));
}
}

debouncedOnChangeFilters = _debounce(
this.props.onChangeFilters,
this.props.modulesManager.getConf("fe-insuree", "debounceTime", 800),
this.props.modulesManager.getConf("fe-insuree", "debounceTime", 200),
);

_filterValue = (k) => {
const { filters } = this.props;
return !!filters && !!filters[k] ? filters[k].value : null;
};

_onChangeShowHistory = () => {
_filterTextFieldValue = (k) => {
const { filters } = this.props;
return !!filters && !!filters[k] ? filters[k].value : "";
};

_onChangeCheckbox = (key, value) => {
let filters = [
{
id: "showHistory",
value: !this.state.showHistory,
filter: `showHistory: ${!this.state.showHistory}`,
id: key,
value: value,
filter: `${key}: ${value}`,
},
];
this.props.onChangeFilters(filters);
this.setState((state) => ({
showHistory: !state.showHistory,
}));
};

personFilter = (anchor) => {
Expand All @@ -82,7 +75,7 @@ class FamilyFilter extends Component {
module="insuree"
label={`Family.${anchor}.chfId`}
name={`${anchor}_chfId`}
value={this._filterValue(`${anchor}.chfId`)}
value={this._filterTextFieldValue(`${anchor}.chfId`)}
onChange={(v) =>
this.debouncedOnChangeFilters([
{
Expand All @@ -105,7 +98,7 @@ class FamilyFilter extends Component {
module="insuree"
label={`Family.${anchor}.lastName`}
name={`${anchor}_lastName`}
value={this._filterValue(`${anchor}.lastName`)}
value={this._filterTextFieldValue(`${anchor}.lastName`)}
onChange={(v) =>
this.debouncedOnChangeFilters([
{
Expand All @@ -128,7 +121,7 @@ class FamilyFilter extends Component {
module="insuree"
label={`Family.${anchor}.otherNames`}
name={`${anchor}_givenName`}
value={this._filterValue(`${anchor}.givenName`)}
value={this._filterTextFieldValue(`${anchor}.givenName`)}
onChange={(v) =>
this.debouncedOnChangeFilters([
{
Expand Down Expand Up @@ -174,7 +167,7 @@ class FamilyFilter extends Component {
module="insuree"
label={`Family.${anchor}.phone`}
name={`${anchor}_phone`}
value={this._filterValue(`${anchor}.phone`)}
value={this._filterTextFieldValue(`${anchor}.phone`)}
onChange={(v) =>
this.debouncedOnChangeFilters([
{
Expand All @@ -197,7 +190,7 @@ class FamilyFilter extends Component {
module="insuree"
label={`Family.${anchor}.email`}
name={`${anchor}_email`}
value={this._filterValue(`${anchor}.email`)}
value={this._filterTextFieldValue(`${anchor}.email`)}
onChange={(v) =>
this.debouncedOnChangeFilters([
{
Expand Down Expand Up @@ -343,7 +336,7 @@ class FamilyFilter extends Component {
module="insuree"
label="Family.confirmationNo"
name="confirmationNo"
value={this._filterValue("confirmationNo")}
value={this._filterTextFieldValue("confirmationNo")}
onChange={(v) =>
this.debouncedOnChangeFilters([
{
Expand Down Expand Up @@ -395,8 +388,8 @@ class FamilyFilter extends Component {
control={
<Checkbox
color="primary"
checked={this.state.showHistory}
onChange={(e) => this._onChangeShowHistory()}
checked={!!this._filterValue("showHistory")}
onChange={(event) => this._onChangeCheckbox("showHistory", event.target.checked)}
/>
}
label={formatMessage(intl, "insuree", "FamilyFilter.showHistory")}
Expand Down
53 changes: 22 additions & 31 deletions src/components/InsureeFilter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { Component } from "react";
import _debounce from "lodash/debounce";
import { withTheme, withStyles } from "@material-ui/core/styles";
import { injectIntl } from "react-intl";
import _debounce from "lodash/debounce";

import { Checkbox, FormControlLabel, Grid } from "@material-ui/core";
import { withTheme, withStyles } from "@material-ui/core/styles";

import {
withModulesManager,
formatMessage,
Expand All @@ -27,41 +29,30 @@ const styles = (theme) => ({
const INSUREE_FILTER_CONTRIBUTION_KEY = "insuree.Filter";

class InsureeFilter extends Component {
state = {
showHistory: false,
};

componentDidUpdate(prevProps, prevState, snapshot) {
if (
prevProps.filters["showHistory"] !== this.props.filters["showHistory"] &&
!!this.props.filters["showHistory"] &&
this.state.showHistory !== this.props.filters["showHistory"]["value"]
) {
this.setState((state, props) => ({ showHistory: props.filters["showHistory"]["value"] }));
}
}

debouncedOnChangeFilter = _debounce(
this.props.onChangeFilters,
this.props.modulesManager.getConf("fe-insuree", "debounceTime", 800),
this.props.modulesManager.getConf("fe-insuree", "debounceTime", 200),
);

_filterValue = (k) => {
const { filters } = this.props;
return !!filters && !!filters[k] ? filters[k].value : null;
};
_onChangeShowHistory = () => {

_filterTextFieldValue = (k) => {
const { filters } = this.props;
return !!filters && !!filters[k] ? filters[k].value : "";
};

_onChangeCheckbox = (key, value) => {
let filters = [
{
id: "showHistory",
value: !this.state.showHistory,
filter: `showHistory: ${!this.state.showHistory}`,
id: key,
value: value,
filter: `${key}: ${value}`,
},
];
this.props.onChangeFilters(filters);
this.setState((state) => ({
showHistory: !state.showHistory,
}));
};

render() {
Expand Down Expand Up @@ -92,7 +83,7 @@ class InsureeFilter extends Component {
module="insuree"
label="Insuree.chfId"
name="chfId"
value={this._filterValue("chfId")}
value={this._filterTextFieldValue("chfId")}
onChange={(v) =>
this.debouncedOnChangeFilter([
{
Expand All @@ -115,7 +106,7 @@ class InsureeFilter extends Component {
module="insuree"
label="Insuree.lastName"
name="lastName"
value={this._filterValue("lastName")}
value={this._filterTextFieldValue("lastName")}
onChange={(v) =>
this.debouncedOnChangeFilter([
{
Expand All @@ -138,7 +129,7 @@ class InsureeFilter extends Component {
module="insuree"
label="Insuree.otherNames"
name="givenName"
value={this._filterValue("givenName")}
value={this._filterTextFieldValue("givenName")}
onChange={(v) =>
this.debouncedOnChangeFilter([
{
Expand Down Expand Up @@ -208,7 +199,7 @@ class InsureeFilter extends Component {
module="insuree"
label="Insuree.email"
name="email"
value={this._filterValue("email")}
value={this._filterTextFieldValue("email")}
onChange={(v) =>
this.debouncedOnChangeFilter([
{
Expand All @@ -231,7 +222,7 @@ class InsureeFilter extends Component {
module="insuree"
label="Insuree.phone"
name="phone"
value={this._filterValue("phone")}
value={this._filterTextFieldValue("phone")}
onChange={(v) =>
this.debouncedOnChangeFilter([
{
Expand Down Expand Up @@ -322,8 +313,8 @@ class InsureeFilter extends Component {
control={
<Checkbox
color="primary"
checked={this.state.showHistory}
onChange={(e) => this._onChangeShowHistory()}
checked={!!this._filterValue("showHistory")}
onChange={(event) => this._onChangeCheckbox("showHistory", event.target.checked)}
/>
}
label={formatMessage(intl, "insuree", "InsureeFilter.showHistory")}
Expand Down