Skip to content

Commit 1bb0c99

Browse files
dhernandez-quoinjtoliver-quoin
authored andcommitted
Merged in r2-3035-add-service-view-list (pull request #7091)
R2-3035 - PCM - Cannot add service from cases list view Approved-by: Joshua Toliver
2 parents b662667 + a5b80d8 commit 1bb0c99

File tree

8 files changed

+148
-29
lines changed

8 files changed

+148
-29
lines changed

app/javascript/components/application/selectors.js

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export const getAllWorkflowLabels = (state, recordType) => {
7878
}, []);
7979
};
8080

81+
export const getServicesForm = (state, id) => selectModule(state, id).getIn(["options", "services_form"]);
82+
8183
export const getConsentform = (state, id) => selectModule(state, id).getIn(["options", "consent_form"]);
8284

8385
export const selectUserIdle = state => state.getIn([NAMESPACE, "userIdle"], false);

app/javascript/components/record-actions/action-form/component.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useI18n } from "../../i18n";
88
import { constructInitialValues } from "../../record-form";
99
import { ID_FIELD, MODULES, RECORD_TYPES } from "../../../config";
1010
import { saveRecord, selectRecordsByIndexes } from "../../records";
11-
import { compactValues } from "../../record-form/utils";
11+
import { compactBlank } from "../../record-form/utils";
1212
import submitForm from "../../../libs/submit-form";
1313
import resetForm from "../../../libs/reset-form";
1414
import { fetchAlerts } from "../../nav/action-creators";
@@ -97,7 +97,7 @@ function Component({
9797
data: {
9898
[subformName]: [
9999
{
100-
...compactValues(values, initialFormValues)
100+
...compactBlank(values, initialFormValues)
101101
}
102102
]
103103
},

app/javascript/components/record-actions/add-service/component.jsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22

33
import PropTypes from "prop-types";
44

5+
import { useMemoizedSelector } from "../../../libs";
6+
import { getServicesForm } from "../../application/selectors";
57
import Fields from "../add-incident/fields";
68
import { ACTIONS } from "../../permissions";
79
import { SERVICE_DIALOG } from "../constants";
810
import ActionForm from "../action-form";
911

10-
import { NAME, SERVICES_SUBFORM, SERVICES_SUBFORM_NAME } from "./constants";
12+
import { NAME, SERVICES_SUBFORM_NAME } from "./constants";
13+
14+
function Component({ open, close, pending, recordType, selectedRowsIndex, setPending, primeroModule }) {
15+
const servicesFormId = useMemoizedSelector(state => getServicesForm(state, primeroModule));
1116

12-
function Component({ open, close, pending, recordType, selectedRowsIndex, setPending }) {
1317
const props = {
1418
dialogTitle: "actions.services_section_from_case",
1519
dialogName: SERVICE_DIALOG,
16-
formName: SERVICES_SUBFORM,
20+
formName: servicesFormId,
1721
subFormName: SERVICES_SUBFORM_NAME,
1822
recordAction: ACTIONS.SERVICES_SECTION_FROM_CASE,
1923
creationMessage: "actions.services_from_case_creation_success",
@@ -33,6 +37,7 @@ Component.propTypes = {
3337
close: PropTypes.func,
3438
open: PropTypes.bool,
3539
pending: PropTypes.bool,
40+
primeroModule: PropTypes.string,
3641
records: PropTypes.array,
3742
recordType: PropTypes.string,
3843
selectedRowsIndex: PropTypes.array,

app/javascript/components/record-actions/add-service/component.spec.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved.
22
import { fromJS, Map, OrderedMap } from "immutable";
33

4+
import { PrimeroModuleRecord } from "../../application/records";
45
import { mountedComponent, screen } from "../../../test-utils";
56
import { FieldRecord, FormSectionRecord } from "../../record-form/records";
67
import { RECORD_PATH } from "../../../config";
@@ -9,6 +10,21 @@ import AddService from "./component";
910

1011
describe("<AddService />", () => {
1112
const initialState = Map({
13+
application: fromJS({
14+
modules: [
15+
PrimeroModuleRecord({
16+
unique_id: "app-module",
17+
name: "AM",
18+
associated_record_types: ["case"],
19+
options: {
20+
services_form: "services"
21+
}
22+
})
23+
]
24+
}),
25+
user: fromJS({
26+
modules: ["app-module"]
27+
}),
1228
records: fromJS({
1329
cases: {
1430
data: [
@@ -20,7 +36,8 @@ describe("<AddService />", () => {
2036
owned_by: "primero_cp",
2137
status: "open",
2238
registration_date: "2020-01-07",
23-
id: "d9df44fb-95d0-4407-91fd-ed18c19be1ad"
39+
id: "d9df44fb-95d0-4407-91fd-ed18c19be1ad",
40+
module_id: "app-module"
2441
}
2542
]
2643
}
@@ -55,7 +72,7 @@ describe("<AddService />", () => {
5572
order_form_group: 110,
5673
parent_form: "case",
5774
editable: true,
58-
module_ids: ["primeromodule-cp"],
75+
module_ids: ["app-module"],
5976
form_group_id: "services_follow_up",
6077
form_group_name: { en: "Services / Follow Up" },
6178
fields: [1],
@@ -116,6 +133,7 @@ describe("<AddService />", () => {
116133
pending: false,
117134
recordType: RECORD_PATH.cases,
118135
selectedRowsIndex: [0],
136+
primeroModule: "app-module",
119137
setPending: () => {}
120138
};
121139

app/javascript/components/record-actions/container.jsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import Menu from "../menu";
1414
import { useDialog } from "../action-dialog";
1515
import useMemoizedSelector from "../../libs/use-memoized-selector";
1616
import useIncidentFromCase from "../records/use-incident-form-case";
17-
import { getRecordFormsByUniqueIdWithFallback } from "../record-form/selectors";
17+
import { getRecordFormsByUniqueIdWithFallback, getServicesRecordForm } from "../record-form/selectors";
1818
import { selectRecordsByIndexes } from "../records";
1919

2020
import { INCIDENT_SUBFORM, INCIDENTS_SUBFORM_NAME } from "./add-incident/constants";
21-
import { SERVICES_SUBFORM, SERVICES_SUBFORM_NAME } from "./add-service/constants";
21+
import { SERVICES_SUBFORM_NAME } from "./add-service/constants";
2222
import {
2323
REQUEST_APPROVAL_DIALOG,
2424
APPROVAL_DIALOG,
@@ -83,14 +83,13 @@ function Container({
8383
})
8484
).first();
8585
const serviceForm = useMemoizedSelector(state =>
86-
getRecordFormsByUniqueIdWithFallback(state, {
86+
getServicesRecordForm(state, {
8787
checkVisible: false,
88-
formName: SERVICES_SUBFORM,
8988
primeroModule,
9089
recordType: RECORD_TYPES[recordType],
9190
fallbackModule: MODULES.CP
9291
})
93-
).first();
92+
);
9493

9594
const handleDialogClick = dialog => {
9695
setDialog({ dialog, open: true });

app/javascript/components/record-actions/container.spec.js

+95-15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { OrderedMap, fromJS } from "immutable";
55
import { mountedComponent, screen, fireEvent } from "../../test-utils";
66
import { ACTIONS } from "../permissions";
77
import { FieldRecord, FormSectionRecord } from "../record-form/records";
8+
import { PrimeroModuleRecord } from "../application/records";
89

910
import RecordActions from "./container";
1011
import {
@@ -147,19 +148,33 @@ describe("<RecordActions />", () => {
147148
flag_count: 0,
148149
short_id: "b575f47",
149150
age: 15,
150-
workflow: "new"
151+
workflow: "new",
152+
module_id: "primeromodule-cp"
151153
}
152154
],
153155
filters: {
154156
status: ["true"]
155157
}
156158
}
157159
},
158-
user: {
160+
application: fromJS({
161+
modules: [
162+
PrimeroModuleRecord({
163+
unique_id: "primeromodule-cp",
164+
name: "Primero Module CP",
165+
associated_record_types: ["case"],
166+
options: {
167+
services_form: "services"
168+
}
169+
})
170+
]
171+
}),
172+
user: fromJS({
159173
permissions: {
160174
cases: [ACTIONS.MANAGE, ACTIONS.EXPORT_JSON]
161-
}
162-
},
175+
},
176+
modules: ["primeromodule-cp"]
177+
}),
163178
forms
164179
});
165180

@@ -412,10 +427,17 @@ describe("<RecordActions />", () => {
412427

413428
it("renders MenuItem with Add Services Provision option", () => {
414429
mountedComponent(
415-
<RecordActions recordType="cases" mode={{ isShow: true }} showListActions />,
430+
<RecordActions
431+
recordType="cases"
432+
currentPage={0}
433+
selectedRecords={{ 0: [0] }}
434+
mode={{ isShow: true }}
435+
showListActions
436+
/>,
416437
fromJS({
417438
records: {
418439
cases: {
440+
data: [{ module_id: "primeromodule-cp" }],
419441
filters: {
420442
id_search: true
421443
}
@@ -424,7 +446,20 @@ describe("<RecordActions />", () => {
424446
user: {
425447
permissions: {
426448
cases: [ACTIONS.MANAGE]
427-
}
449+
},
450+
modules: ["primeromodule-cp"]
451+
},
452+
application: {
453+
modules: [
454+
PrimeroModuleRecord({
455+
unique_id: "primeromodule-cp",
456+
name: "Primero Module CP",
457+
associated_record_types: ["case"],
458+
options: {
459+
services_form: "services"
460+
}
461+
})
462+
]
428463
},
429464
forms
430465
})
@@ -696,7 +731,8 @@ describe("<RecordActions />", () => {
696731
flag_count: 0,
697732
short_id: "b575f47",
698733
age: 15,
699-
workflow: "new"
734+
workflow: "new",
735+
module_id: "primeromodule-cp"
700736
}
701737
],
702738
filters: {
@@ -708,8 +744,21 @@ describe("<RecordActions />", () => {
708744
user: {
709745
permissions: {
710746
cases: [ACTIONS.MANAGE]
711-
}
747+
},
748+
modules: ["primeromodule-cp"]
712749
},
750+
application: fromJS({
751+
modules: [
752+
PrimeroModuleRecord({
753+
unique_id: "primeromodule-cp",
754+
name: "Primero Module CP",
755+
associated_record_types: ["case"],
756+
options: {
757+
services_form: "services"
758+
}
759+
})
760+
]
761+
}),
713762
forms
714763
});
715764
const propsRecordSelected = {
@@ -829,7 +878,8 @@ describe("<RecordActions />", () => {
829878
flag_count: 0,
830879
short_id: "b575f47",
831880
age: 15,
832-
workflow: "new"
881+
workflow: "new",
882+
module_id: "primeromodule-cp"
833883
},
834884
{
835885
sex: "male",
@@ -846,7 +896,8 @@ describe("<RecordActions />", () => {
846896
flag_count: 0,
847897
short_id: "c23a5fca",
848898
age: 5,
849-
workflow: "new"
899+
workflow: "new",
900+
module_id: "primeromodule-cp"
850901
}
851902
],
852903
metadata: {
@@ -862,8 +913,21 @@ describe("<RecordActions />", () => {
862913
user: {
863914
permissions: {
864915
cases: [ACTIONS.MANAGE]
865-
}
916+
},
917+
modules: ["primeromodule-cp"]
866918
},
919+
application: fromJS({
920+
modules: [
921+
PrimeroModuleRecord({
922+
unique_id: "primeromodule-cp",
923+
name: "Primero Module CP",
924+
associated_record_types: ["case"],
925+
options: {
926+
services_form: "services"
927+
}
928+
})
929+
]
930+
}),
867931
forms
868932
});
869933

@@ -934,7 +998,8 @@ describe("<RecordActions />", () => {
934998
flag_count: 0,
935999
short_id: "b575f47",
9361000
age: 15,
937-
workflow: "new"
1001+
workflow: "new",
1002+
module_id: "primeromodule-cp"
9381003
},
9391004
{
9401005
sex: "male",
@@ -951,7 +1016,8 @@ describe("<RecordActions />", () => {
9511016
flag_count: 0,
9521017
short_id: "c23a5fca",
9531018
age: 5,
954-
workflow: "new"
1019+
workflow: "new",
1020+
module_id: "primeromodule-cp"
9551021
},
9561022
{
9571023
sex: "female",
@@ -968,7 +1034,8 @@ describe("<RecordActions />", () => {
9681034
flag_count: 0,
9691035
short_id: "9C68741",
9701036
age: 7,
971-
workflow: "new"
1037+
workflow: "new",
1038+
module_id: "primeromodule-cp"
9721039
}
9731040
],
9741041
metadata: {
@@ -984,8 +1051,21 @@ describe("<RecordActions />", () => {
9841051
user: {
9851052
permissions: {
9861053
cases: [ACTIONS.MANAGE]
987-
}
1054+
},
1055+
modules: ["primeromodule-cp"]
9881056
},
1057+
application: fromJS({
1058+
modules: [
1059+
PrimeroModuleRecord({
1060+
unique_id: "primeromodule-cp",
1061+
name: "Primero Module CP",
1062+
associated_record_types: ["case"],
1063+
options: {
1064+
services_form: "services"
1065+
}
1066+
})
1067+
]
1068+
}),
9891069
forms
9901070
});
9911071

app/javascript/components/record-form/selectors.js

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { getLocale } from "../i18n/selectors";
2424
import { getRecordFormAlerts, getSelectedRecordData, selectRecord } from "../records";
2525
import { selectorEqualityFn } from "../../libs/use-memoized-selector";
2626
import { getPermittedFormsIds } from "../user";
27+
import { getServicesForm } from "../application/selectors";
2728

2829
import getDefaultForms from "./form/utils/get-default-forms";
2930
import NAMESPACE from "./namespace";
@@ -366,6 +367,15 @@ export const getRecordFormsByUniqueIdWithFallback = (state, query) => {
366367
return form;
367368
};
368369

370+
export const getServicesRecordForm = (state, query) => {
371+
const servicesFormId = getServicesForm(state, query.primeroModule || query.fallbackModule);
372+
373+
return getRecordFormsByUniqueIdWithFallback(state, {
374+
...query,
375+
formName: servicesFormId
376+
})?.first();
377+
};
378+
369379
export const getIncidentFromCaseForm = (state, query) =>
370380
getRecordFormsByUniqueId(state, { ...query, formName: INCIDENT_FROM_CASE, getFirst: true });
371381

0 commit comments

Comments
 (0)