Skip to content

Commit 2e41dc3

Browse files
freddidierRTEClementBouvierN
authored andcommitted
Simplify interface for getting user response from template (#7952)
Signed-off-by: freddidierRTE <[email protected]>
1 parent ea34215 commit 2e41dc3

File tree

19 files changed

+138
-81
lines changed

19 files changed

+138
-81
lines changed

config/docker/externalJs/CustomScreenExample.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
const responseCards = [];
121121
const responseData = { "choice1": ["on"], "choice2": ["on"], "choice3": ["on"] }
122122
cards.forEach((card) => {
123-
responseCards.push({ responseCardData: responseData });
123+
responseCards.push({ data: responseData });
124124
});
125125
return { valid: true, errorMsg: '', responseCards: responseCards };
126126
}
@@ -132,7 +132,7 @@
132132
const responseCards = [];
133133
const responseData = {}
134134
cards.forEach((card) => {
135-
responseCards.push({ responseCardData: responseData });
135+
responseCards.push({ data: responseData });
136136
});
137137
return { valid: true, errorMsg: '', responseCards: responseCards };
138138
}

src/docs/asciidoc/reference_doc/response_cards.adoc

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2018-2024 RTE (http://www.rte-france.com)
1+
// Copyright (c) 2018-2025 RTE (http://www.rte-france.com)
22
// See AUTHORS.txt
33
// This document is subject to the terms of the Creative Commons Attribution 4.0 International license.
44
// If a copy of the license was not distributed with this
@@ -121,17 +121,18 @@ which returns an object containing the following fields :
121121

122122
- valid (_boolean_) : true if the user input is valid
123123
- errorMsg (_string_) : message in case of invalid user input. If valid is true this field is not necessary.
124-
- responseCardData (_any_) : the user input to send in the data field of the child card. If valid is false this field is not necessary.
125-
- responseState : name of the response state to use. This field is not mandatory, if it is not set the state defined in
124+
- responseCard:
125+
* data (_any_) : the user input to send in the data field of the child card.
126+
* state : name of the response state to use. This field is not mandatory, if it is not set the state defined in
126127
`config.json` will be used for the response.
127-
- publisher (_string_) : the id of the Entity to be used as publisher of the response. This field is not mandatory, if it is not set the publisher will be the user entity, in case the user belongs to a single entity, or it will be choosen by the user between his available entities.
128-
- actions (_string array_) : an optional field used to define a set of predetermined actions that will be executed upon receiving the response card. The available actions include:
129-
* PROPAGATE_READ_ACK_TO_PARENT_CARD : when receiving the child card, the status of the parent card should be considered as 'unread' and 'not acknowledged' until the user reads or acknowledge it again.
128+
* publisher (_string_) : the id of the Entity to be used as publisher of the response. This field is not mandatory, if it is not set the publisher will be the user entity, in case the user belongs to a single entity, or it will be choosen by the user between his available entities.
129+
* actions (_string array_) : an optional field used to define a set of predetermined actions that will be executed upon receiving the response card. The available actions include:
130+
** PROPAGATE_READ_ACK_TO_PARENT_CARD : when receiving the child card, the status of the parent card should be considered as 'unread' and 'not acknowledged' until the user reads or acknowledge it again.
130131

131132

132133
This method is to be registered via `opfab.currentCard.registerFunctionToGetUserResponse`, the method will be called by OperatorFabric when the user clicks on the button to send the response.
133134

134-
In the example below, the `getUserResponse` creates a `responseCardData` object by retrieving the user's inputs from the HTML.
135+
In the example below, the `getUserResponse` creates a `responseCard` object by retrieving the user's inputs from the HTML.
135136
In addition, if the user chose several options, it overrides the response state defined in the `config.json` with another
136137
state.
137138

src/docs/asciidoc/reference_doc/ui_api.adoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -721,17 +721,17 @@ FilterModel object has the following fields:
721721
It is possible to respond to a card from the template by calling the following function (instead of using the "send response" button) :
722722

723723
```
724-
opfab.cards.sendResponseCard(parentCard,responseData).then(...);
724+
opfab.cards.sendResponseCard(parentCard,responseCard).then(...);
725725
```
726726
The function returns a `Promise<void>`. The promise will be resolved when the response is sent and rejected with an error message if an error occurs.
727727

728728
The `parentCard` parameter is the parent card object (can be obtained from the current card object).
729729

730-
The `responseData` object has the following fields:
730+
The `responseCard` object has the following fields:
731731

732-
- `responseCardData`: The data field to include in the response card.
732+
- `data`: The data field to include in the response card.
733733
- `actions`: The actions field value for the response card. This field is optional.
734-
- `responseState`: The state field value for the response card. This field is optional (default value is defined in the state process definition).
734+
- `state`: The state field value for the response card. This field is optional (default value is defined in the state process definition).
735735
- `publisher`: The publisher field value for the response card. This field is optional (default value is the first current user entity that is allowed to respond).
736736

737737

src/docs/asciidoc/reference_doc/ui_customization.adoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ To do this, add a `responseButtons` array to the custom screen object. Each butt
435435
- `getUserResponses: A function that takes an array of cards as a parameter and returns an object containing the following fields:
436436
- `valid`: A boolean indicating if the action is valid.
437437
- `errorMsg`: An error message to display if the action is not valid.
438-
- `responseCards`: An array of response cards to send with the following structure with a `responseCardData` field containing the response card data field.
438+
- `responseCards`: An array of response cards to send with a `data` field containing the response card data field.
439439

440440

441441

@@ -456,7 +456,7 @@ const customScreenExample = {
456456
const responseCards = [];
457457
const responseData = { "choice1": ["on"], "choice2": ["on"], "choice3": ["on"] }
458458
cards.forEach((card) => {
459-
responseCards.push({ responseCardData: responseData });
459+
responseCards.push({ data: responseData });
460460
});
461461
return { valid: true, errorMsg: '', responseCards: responseCards };
462462
}
@@ -468,7 +468,7 @@ const customScreenExample = {
468468
const responseCards = [];
469469
const responseData = {}
470470
cards.forEach((card) => {
471-
responseCards.push({ responseCardData: responseData });
471+
responseCards.push({ data: responseData });
472472
});
473473
return { valid: true, errorMsg: '', responseCards: responseCards };
474474
}

src/docs/asciidoc/resources/migration_guide_to_4.7.adoc

+38
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,41 @@
1111

1212
A new setting to activate or not the templating of emails has been added in the settings screen of the user.
1313
This setting can be hidden in the configuration file of the web-ui by the field "settings.settingsScreen.hiddenSettings" by adding the value "disableCardContentInEmails".
14+
15+
16+
== Response card
17+
18+
The object that should be returned by the method registered via `opfab.currentCard.registerFunctionToGetUserResponse` is to be changed.
19+
20+
Previously, the object was structured as follows:
21+
22+
----
23+
{
24+
valid: true/false,
25+
errorMsg: string,
26+
responseCardData: string,
27+
responseState: string,
28+
publisher: string,
29+
actions: [string]
30+
}
31+
----
32+
33+
Now, all elements related to the response card are encapsulated within a `responseCard` object:
34+
35+
----
36+
{
37+
valid: true/false,
38+
errorMsg: string,
39+
responseCard: {
40+
data: string,
41+
state: string,
42+
publisher: string,
43+
actions: [string]
44+
}
45+
}
46+
----
47+
48+
Note that the `responseState` field has been renamed to `state`.
49+
50+
The old structure will be supported as a fallback for a limited time, it is recommended to update your code to use the new structure.
51+
`

src/test/resources/bundles/conferenceAndITIncidentExample/template/incidentInProgress.handlebars

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Copyright (c) 2020-2023, RTE (http://www.rte-france.com) -->
1+
<!-- Copyright (c) 2020-2025, RTE (http://www.rte-france.com) -->
22
<!-- See AUTHORS.txt -->
33
<!-- This Source Code Form is subject to the terms of the Mozilla Public -->
44
<!-- License, v. 2.0. If a copy of the MPL was not distributed with this -->
@@ -148,7 +148,7 @@
148148
149149
return {
150150
valid: true,
151-
responseCardData: responseCardData
151+
responseCardData: responseCardData // keep the deprecated way for testing only
152152
};
153153
});
154154
}

src/test/resources/bundles/defaultProcess_V1/template/question.handlebars

+9-7
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,14 @@
9696
9797
const result = {
9898
valid: true,
99-
responseCardData: responseCardData
99+
responseCard:{
100+
data: responseCardData
101+
}
100102
};
101103
102104
// If the user chose several options, we decide to move the process to a specific state, for example to ask a follow-up question (what's their preferred option).
103105
const choiceRequiresFollowUp = Object.entries(responseCardData).length > 1;
104-
if (choiceRequiresFollowUp) result['responseState'] = 'multipleOptionsResponseState';
106+
if (choiceRequiresFollowUp) result.responseCard['state'] = 'multipleOptionsResponseState';
105107
106108
return result;
107109
@@ -162,15 +164,15 @@
162164
(key in responseCardData) ? responseCardData[key].push(value) : responseCardData[key] = [value];
163165
}
164166
165-
const result = {
166-
responseCardData: responseCardData
167-
};
167+
const responseCard= {
168+
data: responseCardData
169+
}
168170
169171
// If the user chose several options, we decide to move the process to a specific state, for example to ask a follow-up question (what's their preferred option).
170172
const choiceRequiresFollowUp = Object.entries(responseCardData).length > 1;
171-
if (choiceRequiresFollowUp) result['responseState'] = 'multipleOptionsResponseState';
173+
if (choiceRequiresFollowUp) responseCard['state'] = 'multipleOptionsResponseState';
172174
173175
174-
opfab.cards.sendResponseCard(opfab.currentCard.getCard(), result);
176+
opfab.cards.sendResponseCard(opfab.currentCard.getCard(), responseCard);
175177
}
176178
</script>

src/test/resources/bundles/messageOrQuestionExample/template/confirmation.handlebars

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Copyright (c) 2022-2024, RTE (http://www.rte-france.com) -->
1+
<!-- Copyright (c) 2022-2025, RTE (http://www.rte-france.com) -->
22
<!-- See AUTHORS.txt -->
33
<!-- This Source Code Form is subject to the terms of the Mozilla Public -->
44
<!-- License, v. 2.0. If a copy of the MPL was not distributed with this -->
@@ -89,7 +89,7 @@
8989
confirm: confirm,
9090
message: message
9191
};
92-
return {
92+
return { //keep deprecated format for testing only
9393
valid: true,
9494
publisher : publisher,
9595
responseCardData: responseCardData,
@@ -128,4 +128,4 @@
128128
129129
</script>
130130

131-
</p>
131+
</p>

ui/main/src/app/api/cards.api.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export function initCardsAPI() {
1818
getCards: function (cardsFilters) {
1919
return firstValueFrom(CardsService.fetchFilteredCards(cardsFilters));
2020
},
21-
sendResponseCard: function (parentCard, responseData) {
22-
return CardResponseService.sendResponse(parentCard, responseData);
21+
sendResponseCard: function (parentCard, responseCard) {
22+
return CardResponseService.sendResponse(parentCard, responseCard);
2323
}
2424
};
2525
}

ui/main/src/app/builtInTemplates/message-or-question-list/card/message-or-question-listCardTemplateView.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ describe('MessageOrQuestionList Card template', () => {
4343
view.listenToInputFieldVisibility((visible) => (inputFieldVisibility = visible));
4444
expect(inputFieldVisibility).toBeFalse();
4545
});
46-
it('GIVEN input is "my response" and "Yes" WHEN get user response THEN responseCardData.comment is "my_response", responseCardData.agreement is "Yes" and response is valid', () => {
46+
it('GIVEN input is "my response" and "Yes" WHEN get user response THEN responseCard.data.comment is "my_response", responseCard.data.agreement is "Yes" and response is valid', () => {
4747
// Simulate input "my response"
4848
view.setFunctionToGetResponseInput(() => {
4949
return [true, 'my response'];
5050
});
5151

5252
const userResponse = CardTemplateGateway.getUserResponseFromTemplate(undefined);
5353
expect(userResponse.valid).toBeTrue();
54-
expect(userResponse.responseCardData.comment).toEqual('my response');
55-
expect(userResponse.responseCardData.agreement).toEqual(true);
54+
expect(userResponse.responseCard.data.comment).toEqual('my response');
55+
expect(userResponse.responseCard.data.agreement).toEqual(true);
5656
});
5757

5858
it('Given a question card WHEN user card is locked THEN response input is hidden', () => {

ui/main/src/app/builtInTemplates/message-or-question-list/card/message-or-question-listCardTemplateView.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2023-2024, RTE (http://www.rte-france.com)
1+
/* Copyright (c) 2023-2025, RTE (http://www.rte-france.com)
22
* See AUTHORS.txt
33
* This Source Code Form is subject to the terms of the Mozilla Public
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -29,7 +29,7 @@ export class MessageOrQuestionListCardTemplateView {
2929
public setFunctionToGetResponseInput(getResponseInput: Function) {
3030
opfab.currentCard.registerFunctionToGetUserResponse(() => {
3131
const response = getResponseInput();
32-
return {valid: true, responseCardData: {agreement: response[0], comment: response[1]}};
32+
return {valid: true, responseCard: {data: {agreement: response[0], comment: response[1]}}};
3333
});
3434
}
3535

ui/main/src/app/builtInTemplates/question/card/questionCardTemplateView.spec.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ describe('Question Card template', () => {
7272
expect(inputFieldVisibility).toBeTrue();
7373
});
7474

75-
it('GIVEN input is "my response" WHEN get user response THEN responseCardData.responses[0].response is] "my_response" and response is valid', () => {
75+
it('GIVEN input is "my response" WHEN get user response THEN responseCard.data.responses[0].response is] "my_response" and response is valid', () => {
7676
// Simulate input "my response"
7777
view.setFunctionToGetResponseInput(() => 'my response', false);
7878

7979
const userResponse = CardTemplateGateway.getUserResponseFromTemplate(undefined);
8080
expect(userResponse.valid).toBeTrue();
81-
expect(userResponse.responseCardData.responses[0].response).toEqual('my response');
81+
expect(userResponse.responseCard.data.responses[0].response).toEqual('my response');
8282
});
8383

8484
it('GIVEN 2 child cards WHEN listen to child card THEN received 2 response', () => {
@@ -131,12 +131,12 @@ describe('Question Card template', () => {
131131
const userResponse = CardTemplateGateway.getUserResponseFromTemplate('entity1');
132132

133133
expect(userResponse.valid).toBeTrue();
134-
expect(userResponse.responseCardData.responses[0].response).toEqual('response_entity1');
135-
expect(userResponse.responseCardData.responses[0].responseDate).toEqual(
134+
expect(userResponse.responseCard.data.responses[0].response).toEqual('response_entity1');
135+
expect(userResponse.responseCard.data.responses[0].responseDate).toEqual(
136136
new Date('2024-06-01T09:15:00').getTime()
137137
);
138-
expect(userResponse.responseCardData.responses[1].response).toEqual('my 2nd response');
139-
expect(userResponse.responseCardData.responses[1].responseDate).toEqual(
138+
expect(userResponse.responseCard.data.responses[1].response).toEqual('my 2nd response');
139+
expect(userResponse.responseCard.data.responses[1].responseDate).toEqual(
140140
new Date('2024-06-01T09:24:00').getTime()
141141
);
142142
});
@@ -160,9 +160,7 @@ describe('Question Card template', () => {
160160
const userResponse = CardTemplateGateway.getUserResponseFromTemplate('entity1');
161161

162162
expect(userResponse.valid).toBeTrue();
163-
expect(userResponse.responseCardData.responses.length).toEqual(1);
164-
expect(userResponse.responseCardData.responses[0].response).toEqual('my 2nd response');
165-
expect(userResponse.responseCardData.responses[0].responseDate).toEqual(
163+
expect(userResponse.responseCard.data.responses[0].responseDate).toEqual(
166164
new Date('2024-06-01T09:24:00').getTime()
167165
);
168166
});

ui/main/src/app/builtInTemplates/question/card/questionCardTemplateView.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2023-2024, RTE (http://www.rte-france.com)
1+
/* Copyright (c) 2023-2025, RTE (http://www.rte-france.com)
22
* See AUTHORS.txt
33
* This Source Code Form is subject to the terms of the Mozilla Public
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -40,7 +40,7 @@ export class QuestionCardTemplateView {
4040
response: response
4141
});
4242

43-
return {valid: true, responseCardData: {responses: responseHistory}};
43+
return {valid: true, responseCard: {data: {responses: responseHistory}}};
4444
});
4545
}
4646

0 commit comments

Comments
 (0)