Skip to content

Commit 9073f07

Browse files
authored
Merge pull request #44 from Y-Note-SAS/OP-2546
Filter service/item in pricelist by name or code #OP-2546
2 parents 6c13ded + eaed987 commit 9073f07

5 files changed

Lines changed: 12 additions & 86 deletions

File tree

src/components/PricelistForm.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const PricelistForm = (props) => {
2121
details,
2222
isValid,
2323
clearMedicalPricelists,
24-
onChangeFilters
2524
} = props;
2625

2726
const canSave = () => pricelist.name && pricelist.pricelistDate && !pricelist.validityTo && isValid === true;
@@ -50,7 +49,6 @@ const PricelistForm = (props) => {
5049
details={details}
5150
fetchDetails={fetchDetails}
5251
openDirty={onSave}
53-
onChangeFilters={onChangeFilters}
5452
actions={[
5553
{
5654
doIt: onReset,

src/components/PricelistGeneralPanel.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
medicalItemsSetValid,
1919
} from "../actions";
2020
import { SERVICES_PRICELIST_TYPE } from "../constants";
21+
import { first } from "lodash";
2122

2223
const styles = (theme) => ({
2324
item: theme.paper.item,
@@ -44,10 +45,12 @@ class PricelistGeneralPanel extends FormPanel {
4445
return shouldValidate;
4546
};
4647
onCodeChange = (value) => {
47-
this.props.onChangeFilters([{ id: "code", value, filter: `code_Icontains: "${value}"` }]);
48+
let filters = [`code_Icontains: "${value}"`, `first: 20`];
49+
this.props.fetchDetails(filters);
4850
};
4951
onNameChange = (value) => {
50-
this.props.onChangeFilters([{ id: "name", value, filter: `name_Icontains: "${value}"` }]);
52+
let filters = [`name_Icontains: "${value}"`, `first: 20`];
53+
this.props.fetchDetails(filters);
5154
};
5255

5356
render() {
@@ -101,15 +104,15 @@ class PricelistGeneralPanel extends FormPanel {
101104
<TextInput
102105
module="medical"
103106
label={`medical_pricelist.table.code`}
104-
value={edited?.code ?? ""}
107+
value={edited.code}
105108
onChange={this.triggerDebounceCode}
106109
/>
107110
</Grid>
108111
<Grid item xs={2} className={classes.item}>
109112
<TextInput
110-
module="insuree"
113+
module="medical_pricelist"
111114
label={!!this.props.activeType && this.props.activeType === 'items' ? `medical_pricelist.table.medicalItemName`: `medical_pricelist.table.medicalServiceName`}
112-
value={edited?.serviceName ?? ""}
115+
value={edited.serviceOrItemName}
113116
onChange={this.triggerDebounceName}
114117
readOnly={readOnly}
115118
/>

src/pages/ItemsPricelistDetailsPage.js

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const styles = (theme) => ({
1717
page: theme.page,
1818
locked: theme.page.locked,
1919
});
20-
import { formatGraphQLFilters } from "../utils";
2120

2221
const ItemsPriceListDetailsPage = (props) => {
2322
const {
@@ -38,7 +37,6 @@ const ItemsPriceListDetailsPage = (props) => {
3837
const [isLocked, setLocked] = useState(false);
3938
const [resetKey, setResetKey] = useState(null);
4039
const [pricelist, setPricelist] = useState({});
41-
const [filters, setFilters] = useState([])
4240

4341
useEffect(() => {
4442
if (match.params.price_list_id) {
@@ -54,31 +52,6 @@ const ItemsPriceListDetailsPage = (props) => {
5452
}
5553
}, [props.pricelist]);
5654

57-
useEffect(() => {
58-
if (filters.length > 0) {
59-
fetchDetails();
60-
}
61-
}, [filters]);
62-
63-
const onChangeFilters = (newFilters) => {
64-
setFilters(prevFilters => {
65-
const updatedFilters = [...prevFilters];
66-
67-
newFilters.forEach(newFilter => {
68-
const existingIndex = updatedFilters.findIndex(f => f.id === newFilter.id);
69-
70-
if (existingIndex >= 0) {
71-
// Si le filtre existe déjà, le met à jour
72-
updatedFilters[existingIndex] = newFilter;
73-
} else {
74-
// Sinon, ajoute le nouveau filtre
75-
updatedFilters.push(newFilter);
76-
}
77-
});
78-
79-
return updatedFilters;
80-
});
81-
};
8255
const onSave = (pricelist) => {
8356
setLocked(true);
8457
if (pricelist.uuid) {
@@ -101,9 +74,8 @@ const ItemsPriceListDetailsPage = (props) => {
10174
setResetKey(Date.now());
10275
};
10376

104-
const fetchDetails = () => {
105-
const formattedFilters = formatGraphQLFilters(filters);
106-
fetchItemsPricelistDetails(modulesManager, formattedFilters, pricelist?.id);
77+
const fetchDetails = (filters) => {
78+
fetchItemsPricelistDetails(modulesManager, filters, pricelist?.id);
10779
};
10880

10981
return (
@@ -121,7 +93,6 @@ const ItemsPriceListDetailsPage = (props) => {
12193
onReset={onReset}
12294
details={details}
12395
fetchDetails={fetchDetails}
124-
onChangeFilters={onChangeFilters}
12596
/>
12697
)}
12798
</ErrorBoundary>

src/pages/ServicesPricelistDetailsPage.js

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const styles = (theme) => ({
1717
page: theme.page,
1818
locked: theme.page.locked,
1919
});
20-
import { formatGraphQLFilters } from "../utils";
2120

2221
const ServicesPriceListDetailsPage = (props) => {
2322
const {
@@ -38,7 +37,6 @@ const ServicesPriceListDetailsPage = (props) => {
3837
const [isLocked, setLocked] = useState(false);
3938
const [resetKey, setResetKey] = useState(null);
4039
const [pricelist, setPricelist] = useState({});
41-
const [filters, setFilters] = useState([])
4240

4341
useEffect(() => {
4442
if (match.params.price_list_id) {
@@ -54,11 +52,6 @@ const ServicesPriceListDetailsPage = (props) => {
5452
}
5553
}, [props.pricelist]);
5654

57-
useEffect(() => {
58-
if (filters.length > 0) {
59-
fetchDetails();
60-
}
61-
}, [filters]);
6255
const onSave = (pricelist) => {
6356
setLocked(true);
6457
if (pricelist.uuid) {
@@ -81,30 +74,8 @@ const ServicesPriceListDetailsPage = (props) => {
8174
setResetKey(Date.now());
8275
};
8376

84-
85-
86-
const fetchDetails = () => {
87-
const formattedFilters = formatGraphQLFilters(filters);
88-
fetchServicesPricelistDetails(modulesManager, formattedFilters, pricelist?.id);
89-
};
90-
const onChangeFilters = (newFilters) => {
91-
setFilters(prevFilters => {
92-
const updatedFilters = [...prevFilters];
93-
94-
newFilters.forEach(newFilter => {
95-
const existingIndex = updatedFilters.findIndex(f => f.id === newFilter.id);
96-
97-
if (existingIndex >= 0) {
98-
// Si le filtre existe déjà, le met à jour
99-
updatedFilters[existingIndex] = newFilter;
100-
} else {
101-
// Sinon, ajoute le nouveau filtre
102-
updatedFilters.push(newFilter);
103-
}
104-
});
105-
106-
return updatedFilters;
107-
});
77+
const fetchDetails = (filters) => {
78+
fetchServicesPricelistDetails(modulesManager, filters, pricelist?.id);
10879
};
10980

11081
return (
@@ -122,7 +93,6 @@ const ServicesPriceListDetailsPage = (props) => {
12293
onReset={onReset}
12394
details={details}
12495
fetchDetails={fetchDetails}
125-
onChangeFilters={onChangeFilters}
12696
/>
12797
)}
12898
</ErrorBoundary>

src/utils.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)