Commit e2597c26 authored by henrik.prangel's avatar henrik.prangel
Browse files

JUT-103 Add validation field to message

parent f57a6740
......@@ -56,6 +56,9 @@ public class Message implements Serializable {
@JsonIgnoreProperties(value = "messages", allowSetters = true)
private User author;
@Column(name = "validated")
private Boolean validated;
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return id;
......@@ -185,6 +188,14 @@ public class Message implements Serializable {
this.vote = vote;
}
public Boolean getValidated() {
return validated;
}
public void setValidated(Boolean validated) {
this.validated = validated;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
......
......@@ -35,6 +35,8 @@ public class MessageDTO implements Serializable {
private Long authorId;
private Boolean validated;
@Size(max = 50)
private String authorFirstName;
......@@ -181,6 +183,14 @@ public class MessageDTO implements Serializable {
this.vote = vote;
}
public Boolean getValidated() {
return validated;
}
public void setValidated(Boolean validated) {
this.validated = validated;
}
@Override
public boolean equals(Object o) {
if (this == o) {
......
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<!--
Added new field to chat
-->
<changeSet id="20201109160000-1" author="henrik_prangel">
<addColumn tableName="message">
<column name="validated" type="boolean">
<constraints nullable="true"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>
......@@ -26,6 +26,7 @@
<include file="config/liquibase/changelog/20201015101000_added_labeled_row_to_chat.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20201019140000_added_vote_field_to_message_entity.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20201021113000_added_last_referer_field_to_chat.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/20201109160000_added_validated_by_data_scientist.xml" relativeToChangelogFile="false"/>
<!-- jhipster-needle-liquibase-add-constraints-changelog - JHipster will add liquibase constraints changelogs here -->
<!-- jhipster-needle-liquibase-add-incremental-changelog - JHipster will add incremental liquibase changelogs here -->
</databaseChangeLog>
......@@ -18,6 +18,9 @@ export default () => next => action => {
*/
return next(action)
.then(response => {
if (action.meta && action.meta.skipNotification) {
return;
}
if (action.meta && action.meta.successMessage) {
toast.success(action.meta.successMessage);
} else if (response && response.action && response.action.payload && response.action.payload.headers) {
......
......@@ -11,6 +11,7 @@ export const ACTION_TYPES = {
SET_CHAT_AS_LABELED: 'labeling/SET_CHAT_AS_LABELED',
ADD_LABELED_MESSAGE: 'labeling/ADD_LABELED_MESSAGE',
REMOVE_LABELED_MESSAGE: 'labeling/REMOVE_LABELED_MESSAGE',
UPDATE_MESSAGE: 'labeling/UPDATE_MESSAGE'
};
const initialState = {
......@@ -121,6 +122,18 @@ export const setActiveLabelingChatId = (newActiveChatId) => {
}
}
export const updateMessage = (message) => async dispatch => {
const requestUrl = `api/messages`;
return await dispatch({
type: ACTION_TYPES.UPDATE_MESSAGE,
payload: axios.put(requestUrl, cleanEntity(message)),
meta: {
skipNotification: true,
}
})
}
export const updateLabeledMessagesList = (labeledMessage, isLabeled) => {
let type;
......
......@@ -3,12 +3,13 @@ import { useDispatch } from 'react-redux';
import { translate, Translate } from 'react-jhipster';
import { Button } from 'reactstrap'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { updateLabeledMessagesList } from '../labeling.reducer';
import { updateLabeledMessagesList, updateMessage } from '../labeling.reducer';
import LabeledText from "app/modules/training-interface/labeling/messages/labeled-text";
import { MESSAGE_VOTE_VALUES } from "app/config/constants";
export const TrainingMessage = props => {
const {trainingMessage, messageIntent} = props;
const {trainingMessage, messageWithBotInterpretedIntent} = props;
const messageIntent = messageWithBotInterpretedIntent.interpretedIntent;
const initialMessageIntent = {name: messageIntent, example: trainingMessage.text, classes: "intent-identifier"};
const dispatch = useDispatch();
......@@ -16,6 +17,7 @@ export const TrainingMessage = props => {
const [labelingMenuOpen, setLabelingMenuOpen] = useState(false);
const [defaultIntent, setDefaultIntent] = useState(messageIntent);
const [highlightedText, setHighlightedText] = useState("");
const [orginallyInterpretedIntent, setOrginallyInterpretedIntent] = useState(messageIntent);
const [messageIntents, setMessageIntents] = useState(messageIntent ? [initialMessageIntent] : []);
const [colorList, setColorList] = useState(['lightblue', 'cornflowerblue', 'cadetblue', 'dodgerblue', 'slategray', 'lightsteelblue']);
const [lastUsedColor, setLastUsedColor] = useState("");
......@@ -101,11 +103,24 @@ export const TrainingMessage = props => {
setMessageIntents(updatedMessageIntents)
}
const updateMessageValidatedFieldIfBotInterpretedIntent = () => {
if (messageIntents.length === 1 && messageIntents[0].name.trim() === orginallyInterpretedIntent) {
if (!isLabeled) {
messageWithBotInterpretedIntent.validated = true;
dispatch(updateMessage(messageWithBotInterpretedIntent));
} else {
messageWithBotInterpretedIntent.validated = false;
dispatch(updateMessage(messageWithBotInterpretedIntent));
}
}
}
const changeMessageLabeledState = () => {
setIsLabeled(!isLabeled)
if (!isLabeled) {
setLabelingMenuOpen(false)
}
updateMessageValidatedFieldIfBotInterpretedIntent();
dispatch(updateLabeledMessagesList({messageId: trainingMessage.id, intentObjects: messageIntents}, !isLabeled))
}
......
......@@ -30,9 +30,9 @@ export const TrainingMessages = (props: ITrainingMessagesProp) => {
}
}, [expiredChats])
const getMessageIntent = (index) => {
const getMessageWithBotInterpretedIntent = (index) => {
if (messages[index + 1] && messages[index + 1].interpretedIntent) {
return messages[index + 1].interpretedIntent;
return messages[index + 1];
}
return ""
}
......@@ -46,7 +46,10 @@ export const TrainingMessages = (props: ITrainingMessagesProp) => {
<div className="messagelist-content ti-message-list-container">
<div className="messages-container">
{messages.map((message, index) => (
<TrainingMessage trainingMessage={message} key={message.id} messageIntent={getMessageIntent(index)}/>
<TrainingMessage trainingMessage={message}
key={message.id}
messageWithBotInterpretedIntent={getMessageWithBotInterpretedIntent(index)}
/>
))}
</div>
</div>
......
......@@ -11,6 +11,7 @@ export interface IMessage {
chatId?: number;
authorId?: number;
authorName?: string;
validated?: boolean;
}
export const defaultValue: Readonly<IMessage> = {};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment