From 72ad626c89f237b43b99df3924b4c1de2b34f88a Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Thu, 17 Oct 2024 11:52:31 +0100 Subject: [PATCH 1/4] Store previous version of message, if edited. --- .../helpers/collaboration-utils.tsx | 9 ++++++--- .../local/molecules/collab-message-detail/index.tsx | 2 +- client/src/custom-types/message.d.ts | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/client/src/Components/local/molecules/collab-message-detail/helpers/collaboration-utils.tsx b/client/src/Components/local/molecules/collab-message-detail/helpers/collaboration-utils.tsx index 517dbeef54..9e83572b11 100644 --- a/client/src/Components/local/molecules/collab-message-detail/helpers/collaboration-utils.tsx +++ b/client/src/Components/local/molecules/collab-message-detail/helpers/collaboration-utils.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { ForceRole, FeedbackItem, MessageCustom, ChannelCollab } from 'src/custom-types' +import { ForceRole, FeedbackItem, MessageCustom, ChannelCollab, MessageStructure } from 'src/custom-types' /* Import Icons */ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' @@ -96,17 +96,20 @@ export const CollapsedFeedbackList = ({ onExpand, collapsed, feedback }: {onExpa ) } -export const injectFeedback = (message: MessageCustom, verb: string, feedback: string, role: ForceRole): MessageCustom => { +export const injectFeedback = (message: MessageCustom, verb: string, feedback: string, role: ForceRole, previous?: MessageStructure): MessageCustom => { const verbStr = '[' + verb + '] ' const withFeedback = verbStr + (feedback || '') // put message into feedback item + // is the new message different to the previous one? + const messageChanged = previous && JSON.stringify(message.message) !== JSON.stringify(previous) const feedbackItem: FeedbackItem = { fromId: role.roleId, fromName: role.roleName, fromForce: role.forceName, date: new Date().toISOString(), - feedback: withFeedback + feedback: withFeedback, + ...(messageChanged && { previous: previous }) } if (message.details.collaboration) { if (!message.details.collaboration.feedback) { diff --git a/client/src/Components/local/molecules/collab-message-detail/index.tsx b/client/src/Components/local/molecules/collab-message-detail/index.tsx index 82b0b644ee..d726d92b78 100644 --- a/client/src/Components/local/molecules/collab-message-detail/index.tsx +++ b/client/src/Components/local/molecules/collab-message-detail/index.tsx @@ -157,7 +157,7 @@ export const CollabMessageDetail: React.FC = ({ // different handling depending upon if it's a response that's being sent const updatedPart = isResponse ? answer : newMsg const changed = handler(role, verb, message, updatedPart, privateMessage) - const withFeedback = injectFeedback(changed, verb, '', role) + const withFeedback = injectFeedback(changed, verb, '', role, message.message) handleChange(withFeedback, true) } diff --git a/client/src/custom-types/message.d.ts b/client/src/custom-types/message.d.ts index 57e8b818ca..b66a2b25c0 100644 --- a/client/src/custom-types/message.d.ts +++ b/client/src/custom-types/message.d.ts @@ -93,6 +93,8 @@ export interface FeedbackItem { readonly date: string /** the feedback */ readonly feedback: string + /** the previous version of the message (if modified) */ + readonly previous?: MessageStructure } /** data for a message that is being From 427a7ba37f20cbf9e431e166f13701c9ce15ef37 Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Thu, 17 Oct 2024 16:08:34 +0100 Subject: [PATCH 2/4] name prop to show it's how to step backwards to previous version --- client/src/custom-types/message.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/custom-types/message.d.ts b/client/src/custom-types/message.d.ts index b66a2b25c0..3d59eaa019 100644 --- a/client/src/custom-types/message.d.ts +++ b/client/src/custom-types/message.d.ts @@ -93,8 +93,8 @@ export interface FeedbackItem { readonly date: string /** the feedback */ readonly feedback: string - /** the previous version of the message (if modified) */ - readonly previous?: MessageStructure + /** changes in the new version */ + readonly revert?: jsonpath.Operation[] } /** data for a message that is being From c73646f38c4e73da6de032068fbf02ee16098f07 Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Thu, 17 Oct 2024 16:09:02 +0100 Subject: [PATCH 3/4] store changes to get back to previous version --- .../collab-message-detail/helpers/collaboration-utils.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/Components/local/molecules/collab-message-detail/helpers/collaboration-utils.tsx b/client/src/Components/local/molecules/collab-message-detail/helpers/collaboration-utils.tsx index 9e83572b11..c48f2bbe35 100644 --- a/client/src/Components/local/molecules/collab-message-detail/helpers/collaboration-utils.tsx +++ b/client/src/Components/local/molecules/collab-message-detail/helpers/collaboration-utils.tsx @@ -9,6 +9,7 @@ import { expiredStorage } from 'src/config' import { formatFullDate } from 'src/Helpers' /* Import Stylesheet */ import styles from '../styles.module.scss' +import * as jsonpatch from 'fast-json-patch' export type ModalHandlerFn = (message: MessageCustom) => void @@ -109,7 +110,7 @@ export const injectFeedback = (message: MessageCustom, verb: string, feedback: s fromForce: role.forceName, date: new Date().toISOString(), feedback: withFeedback, - ...(messageChanged && { previous: previous }) + ...(messageChanged && { revert: jsonpatch.compare(message.message, previous) }) } if (message.details.collaboration) { if (!message.details.collaboration.feedback) { From d7012f0389dbc3b1a2c50bfb939fe3ebf512ef46 Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Fri, 18 Oct 2024 09:38:27 +0100 Subject: [PATCH 4/4] improve comment --- client/src/custom-types/message.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/custom-types/message.d.ts b/client/src/custom-types/message.d.ts index 3d59eaa019..dc2cdfa8d5 100644 --- a/client/src/custom-types/message.d.ts +++ b/client/src/custom-types/message.d.ts @@ -93,7 +93,7 @@ export interface FeedbackItem { readonly date: string /** the feedback */ readonly feedback: string - /** changes in the new version */ + /** deltas to get to the previous version */ readonly revert?: jsonpath.Operation[] }