From f9c70746d2b8eea015e1e58f6759e6fd95174949 Mon Sep 17 00:00:00 2001 From: olivier_bremaud Date: Tue, 25 Feb 2020 14:28:36 +0100 Subject: [PATCH] =?UTF-8?q?[Zucchini][Front][Back]=20Restitution=20de=20l'?= =?UTF-8?q?action=20effectu=C3=A9e=20lors=20de=20l'analyse=20sur=20la=20vu?= =?UTF-8?q?e=20d=C3=A9tail=20d'un=20scenario?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/comment/domain/Comment.java | 14 ++++++++++++-- .../backend/comment/rest/CommentResource.java | 2 +- .../comment/rest/CreateCommentRequest.java | 9 +++++++++ .../backend/comment/domain/CommentTest.java | 7 +++++-- zucchini-ui-frontend/src/api/scenarios.js | 7 +++++-- .../src/scenario/components/Comment.jsx | 19 +++++++++++++++++-- .../scenario/components/CommentContainer.js | 8 +++++++- .../src/scenario/components/CommentList.jsx | 1 + .../src/scenario/components/ScenarioPage.jsx | 2 +- zucchini-ui-frontend/src/scenario/model.js | 4 ++-- zucchini-ui-frontend/src/scenario/redux.js | 10 ++++++---- 11 files changed, 66 insertions(+), 17 deletions(-) diff --git a/zucchini-ui-backend/src/main/java/io/zucchiniui/backend/comment/domain/Comment.java b/zucchini-ui-backend/src/main/java/io/zucchiniui/backend/comment/domain/Comment.java index 373c5b8bf..ada6a4964 100644 --- a/zucchini-ui-backend/src/main/java/io/zucchiniui/backend/comment/domain/Comment.java +++ b/zucchini-ui-backend/src/main/java/io/zucchiniui/backend/comment/domain/Comment.java @@ -42,6 +42,8 @@ public class Comment extends BaseEntity { @Embedded(concreteClass = HashSet.class) private Set references; + private String analyseAction; + /** * Private constructor for Morphia. */ @@ -54,11 +56,12 @@ private Comment() { * @param references References * @param content Comment content */ - public Comment(final Iterable references, final String content) { + public Comment(final Iterable references, final String content, final String analyseAction) { id = UUID.randomUUID().toString(); date = ZonedDateTime.now(); this.references = Sets.newHashSet(references); this.content = Objects.requireNonNull(content); + this.analyseAction = analyseAction; } public void setContent(final String content) { @@ -81,9 +84,16 @@ public Set getReferences() { return Collections.unmodifiableSet(references); } + public String getAnalyseAction() { + return analyseAction; + } + + public void setAnalyseAction(String analyseAction) { + this.analyseAction = analyseAction; + } + @Override protected String getEntityId() { return id; } - } diff --git a/zucchini-ui-backend/src/main/java/io/zucchiniui/backend/comment/rest/CommentResource.java b/zucchini-ui-backend/src/main/java/io/zucchiniui/backend/comment/rest/CommentResource.java index 5e55599d8..75bb9f135 100644 --- a/zucchini-ui-backend/src/main/java/io/zucchiniui/backend/comment/rest/CommentResource.java +++ b/zucchini-ui-backend/src/main/java/io/zucchiniui/backend/comment/rest/CommentResource.java @@ -110,7 +110,7 @@ public Response create(@Valid @NotNull final CreateCommentRequest request) { LOGGER.info("Create comment with references {}", references); - final Comment comment = new Comment(references, request.getContent()); + final Comment comment = new Comment(references, request.getContent(), request.getAnalyseAction()); commentRepository.save(comment); final URI location = UriBuilder.fromUri(baseUri) diff --git a/zucchini-ui-backend/src/main/java/io/zucchiniui/backend/comment/rest/CreateCommentRequest.java b/zucchini-ui-backend/src/main/java/io/zucchiniui/backend/comment/rest/CreateCommentRequest.java index 3f761ca66..83a51372d 100644 --- a/zucchini-ui-backend/src/main/java/io/zucchiniui/backend/comment/rest/CreateCommentRequest.java +++ b/zucchini-ui-backend/src/main/java/io/zucchiniui/backend/comment/rest/CreateCommentRequest.java @@ -8,6 +8,8 @@ public class CreateCommentRequest { @NotEmpty private String content; + private String analyseAction; + public String getContent() { return content; } @@ -16,4 +18,11 @@ public void setContent(final String content) { this.content = content; } + public String getAnalyseAction() { + return analyseAction; + } + + public void setAnalyseAction(String analyseAction) { + this.analyseAction = analyseAction; + } } diff --git a/zucchini-ui-backend/src/test/java/io/zucchiniui/backend/comment/domain/CommentTest.java b/zucchini-ui-backend/src/test/java/io/zucchiniui/backend/comment/domain/CommentTest.java index 97297084f..5a8282fbf 100644 --- a/zucchini-ui-backend/src/test/java/io/zucchiniui/backend/comment/domain/CommentTest.java +++ b/zucchini-ui-backend/src/test/java/io/zucchiniui/backend/comment/domain/CommentTest.java @@ -20,18 +20,21 @@ public class CommentTest { private static final String CONTENT = "content"; + private static final String ANALYSE_ACTION = "analyseAction"; + @Test public void should_create_comment() throws Exception { // given final ZonedDateTime testStartDate = ZonedDateTime.now(); // when - final Comment comment = new Comment(REFERENCES, CONTENT); + final Comment comment = new Comment(REFERENCES, CONTENT, ANALYSE_ACTION); // then assertThat(comment.getId()).isNotEmpty(); Assertions.assertThat(comment.getReferences()).isEqualTo(REFERENCES); assertThat(comment.getContent()).isEqualTo(CONTENT); + assertThat(comment.getAnalyseAction()).isEqualTo(ANALYSE_ACTION); assertThat(comment.getDate()).isAfterOrEqualTo(testStartDate); assertThat(comment.getEntityId()).isEqualTo(comment.getId()); @@ -42,7 +45,7 @@ public void should_set_description() throws Exception { // given final String newContent = "newContent"; - final Comment comment = new Comment(REFERENCES, CONTENT); + final Comment comment = new Comment(REFERENCES, CONTENT, ANALYSE_ACTION); // when comment.setContent(newContent); diff --git a/zucchini-ui-frontend/src/api/scenarios.js b/zucchini-ui-frontend/src/api/scenarios.js index 99bdf8057..fbc0f30ca 100644 --- a/zucchini-ui-frontend/src/api/scenarios.js +++ b/zucchini-ui-frontend/src/api/scenarios.js @@ -108,10 +108,13 @@ class ScenariosApi { }); } - addComment({ scenarioId, comment }) { + addComment({ scenarioId, comment, analyseAction }) { return this.client.post({ path: `/${scenarioId}/comments/create`, - body: { content: comment }, + body: { + content: comment, + analyseAction: analyseAction + }, hasOutput: false }); } diff --git a/zucchini-ui-frontend/src/scenario/components/Comment.jsx b/zucchini-ui-frontend/src/scenario/components/Comment.jsx index 87c6f9714..8e691c926 100644 --- a/zucchini-ui-frontend/src/scenario/components/Comment.jsx +++ b/zucchini-ui-frontend/src/scenario/components/Comment.jsx @@ -11,6 +11,7 @@ export default class Comment extends React.PureComponent { static propTypes = { comment: PropTypes.object.isRequired, testRunId: PropTypes.string, + config: PropTypes.object, onChange: PropTypes.func.isRequired, onDelete: PropTypes.func.isRequired }; @@ -55,8 +56,7 @@ export default class Comment extends React.PureComponent { }; render() { - const { comment, testRunId } = this.props; - + const { comment, testRunId, config } = this.props; let testRunInfo = null; if (comment.testRunId === testRunId) { testRunInfo = (tir de test actuel); @@ -81,11 +81,26 @@ export default class Comment extends React.PureComponent { commentComponent = ; } + let correctionAction = null; + if (comment.analyseAction != null) { + let action = config.correctionActionConfig.find(a => { + return a.actionCode == comment.analyseAction; + }); + if (action != null) { + correctionAction = ( +
+ Action pour analyse : {action.actionLabel} +
+ ); + } + } + return (

Le {toNiceDate(comment.date)} {testRunInfo}

+ {correctionAction} {commentComponent}
); diff --git a/zucchini-ui-frontend/src/scenario/components/CommentContainer.js b/zucchini-ui-frontend/src/scenario/components/CommentContainer.js index 8acffa848..d2e3ef38d 100644 --- a/zucchini-ui-frontend/src/scenario/components/CommentContainer.js +++ b/zucchini-ui-frontend/src/scenario/components/CommentContainer.js @@ -5,13 +5,19 @@ import Comment from "./Comment"; import { deleteComment, updateCommentThenReload } from "../redux"; +const selectConfig = createSelector( + state => state.scenario.config, + config => config +); + const selectTestRunId = createSelector( state => state.scenario.scenario.testRunId || null, testRunId => testRunId ); const selectProps = createStructuredSelector({ - testRunId: selectTestRunId + testRunId: selectTestRunId, + config: selectConfig }); const CommentContainer = connect(selectProps, { diff --git a/zucchini-ui-frontend/src/scenario/components/CommentList.jsx b/zucchini-ui-frontend/src/scenario/components/CommentList.jsx index 5705bf083..e3d1b7f41 100644 --- a/zucchini-ui-frontend/src/scenario/components/CommentList.jsx +++ b/zucchini-ui-frontend/src/scenario/components/CommentList.jsx @@ -9,6 +9,7 @@ export default class CommentList extends React.PureComponent { }; render() { + console.log("CommentList", this.props); const { comments } = this.props; const commentList = comments.map(comment => { diff --git a/zucchini-ui-frontend/src/scenario/components/ScenarioPage.jsx b/zucchini-ui-frontend/src/scenario/components/ScenarioPage.jsx index f77fe8a20..25cf62697 100644 --- a/zucchini-ui-frontend/src/scenario/components/ScenarioPage.jsx +++ b/zucchini-ui-frontend/src/scenario/components/ScenarioPage.jsx @@ -147,7 +147,7 @@ export default class ScenarioPage extends React.Component {

Commentaires

- +

Ajouter un nouveau commentaire

diff --git a/zucchini-ui-frontend/src/scenario/model.js b/zucchini-ui-frontend/src/scenario/model.js index d72558620..98b3d1798 100644 --- a/zucchini-ui-frontend/src/scenario/model.js +++ b/zucchini-ui-frontend/src/scenario/model.js @@ -18,8 +18,8 @@ export function updateScenarioState({ scenarioId, newState }) { return scenariosApi.updateScenarioState({ scenarioId, newState }); } -export function addScenarioComment({ scenarioId, comment }) { - return scenariosApi.addComment({ scenarioId, comment }); +export function addScenarioComment({ scenarioId, comment, analyseAction }) { + return scenariosApi.addComment({ scenarioId, comment, analyseAction }); } export function deleteScenario({ scenarioId }) { diff --git a/zucchini-ui-frontend/src/scenario/redux.js b/zucchini-ui-frontend/src/scenario/redux.js index cc45a2321..010826e74 100644 --- a/zucchini-ui-frontend/src/scenario/redux.js +++ b/zucchini-ui-frontend/src/scenario/redux.js @@ -125,10 +125,11 @@ export function updateScenarioState({ scenarioId, newState }) { }; } -export function addScenarioComment({ scenarioId, comment }) { +export function addScenarioComment({ scenarioId, comment, analyseAction }) { + console.log(analyseAction); return { type: ADD_SCENARIO_COMMENT, - payload: model.addScenarioComment({ scenarioId, comment }), + payload: model.addScenarioComment({ scenarioId, comment, analyseAction }), meta: { scenarioId } @@ -153,9 +154,10 @@ export function updateScenarioStateAndComment({ scenarioId, newState, comment }) newState }) ); - + let analyseAction = newState.analyseAction; + console.log("updateScenarioStateAndComment", analyseAction); if (comment) { - await dispatch(addScenarioComment({ scenarioId, comment })); + await dispatch(addScenarioComment({ scenarioId, comment, analyseAction })); } await dispatch(loadScenarioPage({ scenarioId }));