Skip to content

Commit 0e6ecfb

Browse files
selection edge case + tag fixed
1 parent bc411c1 commit 0e6ecfb

File tree

1 file changed

+116
-49
lines changed

1 file changed

+116
-49
lines changed

frontend/src/components/admin/BatchTestReassignmentAndCancellation/BatchTestReassignmentAndCancelation.js

Lines changed: 116 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
PasswordInput,
1717
Checkbox,
1818
FormGroup,
19+
Tag,
1920
} from "@carbon/react";
2021
import { FormattedMessage, injectIntl, useIntl } from "react-intl";
2122
import PageBreadCrumb from "../../common/PageBreadCrumb.js";
@@ -53,9 +54,11 @@ function BatchTestReassignmentAndCancelation() {
5354

5455
const [saveButton, setSaveButton] = useState(true);
5556
const [isLoading, setIsLoading] = useState(true);
56-
const [sampleTypeList, setSampleTypeList] = useState(null);
57+
const [currentTest, setCurrentTest] = useState(true);
58+
const [replaceWith, setReplaceWith] = useState(false);
59+
const [batchTestGet, setBatchTestGet] = useState(null);
60+
const [batchTestPost, setBatchTestPost] = useState(null);
5761
const [sampleTypeListShow, setSampleTypeListShow] = useState([]);
58-
const [sampleTypeListPost, setSampleTypeListPost] = useState(null);
5962
const [sampleTypeToGetId, setSampleTypeToGetId] = useState(null);
6063
const [sampleTypeToGetIdData, setSampleTypeToGetIdData] = useState([]);
6164
const [sampleTypeTestIdToGetIdPending, setSampleTestTypeToGetPending] =
@@ -64,6 +67,10 @@ function BatchTestReassignmentAndCancelation() {
6467
sampleTypeTestIdToGetIdPendingData,
6568
setSampleTestTypeToGetPendingData,
6669
] = useState({});
70+
const [sampleTestTypeToGetTagList, setSampleTestTypeToGetTagList] = useState(
71+
[],
72+
);
73+
const [jsonWad, setJsonWad] = useState({});
6774

6875
useEffect(() => {
6976
componentMounted.current = true;
@@ -82,7 +89,7 @@ function BatchTestReassignmentAndCancelation() {
8289
if (!res) {
8390
setIsLoading(true);
8491
} else {
85-
setSampleTypeList(res);
92+
setBatchTestGet(res);
8693
}
8794
};
8895

@@ -117,33 +124,33 @@ function BatchTestReassignmentAndCancelation() {
117124
}, [sampleTypeTestIdToGetIdPending]);
118125

119126
useEffect(() => {
120-
if (sampleTypeList) {
127+
if (batchTestGet) {
121128
const BatchTestReassignmentInfoToPost = {
122-
formName: sampleTypeList.formName,
123-
formMethod: sampleTypeList.formMethod,
124-
cancelAction: sampleTypeList.cancelAction,
125-
submitOnCancel: sampleTypeList.submitOnCancel,
126-
cancelMethod: sampleTypeList.cancelMethod,
127-
sampleList: sampleTypeList.sampleList,
128-
statusChangedSampleType: sampleTypeList.statusChangedSampleType,
129-
statusChangedCurrentTest: sampleTypeList.statusChangedCurrentTest,
130-
statusChangedNextTest: sampleTypeList.statusChangedNextTest,
131-
jsonWad: sampleTypeList.jsonWad,
129+
formName: batchTestGet.formName,
130+
formMethod: batchTestGet.formMethod,
131+
cancelAction: batchTestGet.cancelAction,
132+
submitOnCancel: batchTestGet.submitOnCancel,
133+
cancelMethod: batchTestGet.cancelMethod,
134+
sampleList: batchTestGet.sampleList,
135+
statusChangedSampleType: batchTestGet.statusChangedSampleType,
136+
statusChangedCurrentTest: batchTestGet.statusChangedCurrentTest,
137+
statusChangedNextTest: batchTestGet.statusChangedNextTest,
138+
jsonWad: batchTestGet.jsonWad,
132139
};
140+
setBatchTestPost(BatchTestReassignmentInfoToPost);
133141
setSampleTypeListShow((prevSampleTypeListShow) => [
134142
...prevSampleTypeListShow,
135143
{ id: "0", value: "Select SampleType" },
136-
...sampleTypeList.sampleList,
144+
...batchTestGet.sampleList,
137145
]);
138-
setSampleTypeListPost(BatchTestReassignmentInfoToPost);
139146
}
140-
}, [sampleTypeList]);
147+
}, [batchTestGet]);
141148

142149
function batchTestReassignmentPostCall() {
143150
setIsLoading(true);
144151
postToOpenElisServerJsonResponse(
145152
`/rest/BatchTestReassignment`,
146-
JSON.stringify(sampleTypeListPost),
153+
JSON.stringify(batchTestPost),
147154
(res) => {
148155
sampleTypeListPostCallback(res);
149156
},
@@ -179,30 +186,57 @@ function BatchTestReassignmentAndCancelation() {
179186
}
180187
}
181188

182-
function handleStatusChange(e) {
189+
function handleCheckboxChange(id, index) {
183190
setSaveButton(false);
184-
setSampleTypeListPost((prevUserDataPost) => ({
185-
...prevUserDataPost,
186-
statusChangedSampleType: e.target.value,
187-
statusChangedCurrentTest: e.target.value,
188-
statusChangedNextTest: e.target.value,
189-
jsonWad: e.target.value,
190-
}));
191-
}
192-
193-
function handleCheckboxChange(id) {
194-
setSaveButton(false);
195-
setSampleTypeListPost();
191+
setJsonWad({});
196192
}
197193

198194
function handleSampleTypeListSelectId(e) {
199195
setSaveButton(false);
200196
setSampleTypeToGetId(e.target.value);
197+
setBatchTestPost((prevUserDataPost) => ({
198+
...prevUserDataPost,
199+
statusChangedSampleType: e.target.value,
200+
}));
201201
}
202202

203203
function handleSampleTypeListSelectIdTest(e) {
204204
setSaveButton(false);
205205
setSampleTestTypeToGetPending(e.target.value);
206+
setBatchTestPost((prevUserDataPost) => ({
207+
...prevUserDataPost,
208+
statusChangedCurrentTest: e.target.value,
209+
}));
210+
}
211+
212+
const handleSampleTypeListSelectIdTestTag = (e) => {
213+
const selectedTestId = e.target.value;
214+
const testName = e.target.options[e.target.selectedIndex].text;
215+
216+
const existingIndex = sampleTestTypeToGetTagList.findIndex(
217+
(item) => item.id === selectedTestId,
218+
);
219+
220+
if (existingIndex !== -1) {
221+
const updatedList = [...sampleTestTypeToGetTagList];
222+
updatedList.splice(existingIndex, 1);
223+
setSampleTestTypeToGetTagList(updatedList);
224+
} else {
225+
const selectedTest = {
226+
id: selectedTestId,
227+
name: testName,
228+
};
229+
setSampleTestTypeToGetTagList([
230+
...sampleTestTypeToGetTagList,
231+
selectedTest,
232+
]);
233+
}
234+
};
235+
236+
function handleRemoveSampleTypeListSelectIdTestTag(indexToRemove) {
237+
setSampleTestTypeToGetTagList((prevTags) =>
238+
prevTags.filter((_, index) => index !== indexToRemove),
239+
);
206240
}
207241

208242
if (!isLoading) {
@@ -278,10 +312,10 @@ function BatchTestReassignmentAndCancelation() {
278312
labelText={intl.formatMessage({
279313
id: "label.includeInactiveTests",
280314
})}
281-
checked={true}
282-
// onChange={() => {
283-
// handleCheckboxChange(section.roleId);
284-
// }}
315+
checked={currentTest}
316+
onChange={() => {
317+
setCurrentTest(!currentTest);
318+
}}
285319
/>
286320
<br />
287321
<Select
@@ -321,10 +355,10 @@ function BatchTestReassignmentAndCancelation() {
321355
labelText={intl.formatMessage({
322356
id: "label.cancel.test.no.replace",
323357
})}
324-
checked={false}
325-
// onChange={() => {
326-
// handleCheckboxChange(section.roleId);
327-
// }}
358+
checked={replaceWith}
359+
onChange={() => {
360+
setReplaceWith(!replaceWith);
361+
}}
328362
/>
329363
<br />
330364
<Select
@@ -336,7 +370,8 @@ function BatchTestReassignmentAndCancelation() {
336370
? sampleTypeToGetIdData.tests[0]
337371
: ""
338372
}
339-
onChange={(e) => handleSampleTypeListSelectIdTest(e)}
373+
disabled={replaceWith}
374+
onChange={(e) => handleSampleTypeListSelectIdTestTag(e)}
340375
>
341376
{sampleTypeToGetIdData &&
342377
sampleTypeToGetIdData.tests &&
@@ -356,6 +391,31 @@ function BatchTestReassignmentAndCancelation() {
356391
/>
357392
)}
358393
</Select>
394+
<div
395+
className={"searchTestText"}
396+
style={{ marginBottom: "1.188rem" }}
397+
>
398+
{sampleTestTypeToGetTagList &&
399+
sampleTestTypeToGetTagList.length ? (
400+
<>
401+
{sampleTestTypeToGetTagList.map((section, index) => (
402+
<Tag
403+
filter
404+
key={`testTags_` + index}
405+
onClose={() =>
406+
handleRemoveSampleTypeListSelectIdTestTag(index)
407+
}
408+
style={{ marginRight: "0.5rem" }}
409+
type={"red"}
410+
>
411+
{section.name}
412+
</Tag>
413+
))}
414+
</>
415+
) : (
416+
<></>
417+
)}
418+
</div>
359419
</Column>
360420
</Grid>
361421
<br />
@@ -393,7 +453,7 @@ function BatchTestReassignmentAndCancelation() {
393453
})}
394454
checked={false}
395455
onChange={() => {
396-
handleCheckboxChange(item.id);
456+
handleCheckboxChange(item.id, index);
397457
}}
398458
/>
399459
</div>
@@ -428,7 +488,7 @@ function BatchTestReassignmentAndCancelation() {
428488
})}
429489
checked={false}
430490
onChange={() => {
431-
handleCheckboxChange(item.id);
491+
handleCheckboxChange(item.id, index);
432492
}}
433493
/>
434494
</div>
@@ -463,7 +523,7 @@ function BatchTestReassignmentAndCancelation() {
463523
})}
464524
checked={false}
465525
onChange={() => {
466-
handleCheckboxChange(item.id);
526+
handleCheckboxChange(item.id, index);
467527
}}
468528
/>
469529
</div>
@@ -498,7 +558,7 @@ function BatchTestReassignmentAndCancelation() {
498558
})}
499559
checked={false}
500560
onChange={() => {
501-
handleCheckboxChange(item.id);
561+
handleCheckboxChange(item.id, index);
502562
}}
503563
/>
504564
</div>
@@ -533,17 +593,17 @@ function BatchTestReassignmentAndCancelation() {
533593
</div>
534594
<button
535595
onClick={() => {
536-
console.log(sampleTypeList.sampleList);
596+
console.log(batchTestGet.sampleList);
537597
}}
538598
>
539-
sampleTypeList.sampleList
599+
batchTestGet.sampleList
540600
</button>
541601
<button
542602
onClick={() => {
543-
console.log(sampleTypeListPost);
603+
console.log(batchTestPost);
544604
}}
545605
>
546-
sampleTypeListPost
606+
batchTestPost
547607
</button>
548608
<button
549609
onClick={() => {
@@ -566,6 +626,13 @@ function BatchTestReassignmentAndCancelation() {
566626
>
567627
sampleTypeTestIdToGetIdPendingData
568628
</button>
629+
<button
630+
onClick={() => {
631+
console.log(jsonWad);
632+
}}
633+
>
634+
jsonWad
635+
</button>
569636
</div>
570637
</>
571638
);
@@ -577,4 +644,4 @@ export default injectIntl(BatchTestReassignmentAndCancelation);
577644
// single labNo selection fix needed
578645
// SelectAll function fix
579646
// post call checkup
580-
// defaultValues CONSOLE.error fix values fix
647+
// multi-select need to implement

0 commit comments

Comments
 (0)