Repository navigation
feat: add email template version history - #1822
Conversation
…hub.com/UserOfficeProject/user-office-core into 1618-add-email-template-version-history
|
Is this ready for review, because its got the review:please tag? Or not because it is in draft |
|
@zacharyjhankin it is not fully ready but the functionality is ready to be reviewed, there are some extras that need adding but I wanted some feedback on the functionality before I continue, please feel free to give any feedback you have, but be aware there may be small changes still coming |
| emailTemplateVersionNumber: number; | ||
| }; | ||
|
|
||
| const EmailTemplateVersionViewer = ({ |
There was a problem hiding this comment.
It doesn't seem to save a version template for the very first time you make a email, that would be nice if it could
|
Architecture looks great to me overall, great change |
…hub.com/UserOfficeProject/user-office-core into 1618-add-email-template-version-history
| > | ||
| {version.versionNumber + | ||
| ': ' + | ||
| version.createdTimeStamp} |
There was a problem hiding this comment.
nitpick:
Other dates in the system translate out of the GMT stored in the DB.
| > | ||
| {''} | ||
| </CopyToClipboard> | ||
| <br /> <small>Copy body to Clipboard</small> |
There was a problem hiding this comment.
nitpick:
It would make more sense to me to have this on the right of the text. Or even better have the entire string clickable to be copy to clipboard?
There was a problem hiding this comment.
Looks great.
You will have to merge: https://github.com/UserOfficeProject/user-office-core/pull/1947/changes for it to actually work. But that was my fault as it was one of my comments on the constraint, that actually needs a 3 value, not a 2 value. You can ignore my "nitpicks"
mutambaraf
left a comment
There was a problem hiding this comment.
Just a few comments but looks good. It is also worthy thinking if I created an empty version do we want to save it or just ignore it.
| DO | ||
| $$ | ||
| BEGIN | ||
| IF register_patch('AddTemplateVersionTable.sql', 'ellenwright', 'Add template version table', '2026-08-20') THEN |
There was a problem hiding this comment.
I think we can update the date is now too behind
| { | ||
| constructor( | ||
| @inject(Tokens.TemplateVersionDataSource) | ||
| private templateDataSource: TemplateVersionDataSource |
There was a problem hiding this comment.
I think this is a templateVersionDataSource
| async createNewVersion( | ||
| emailTemplateId: number, | ||
| templateType: string, | ||
| template?: string | null |
There was a problem hiding this comment.
For typing purposes , I think this variable is always required because if its null we immediately return the fuction,
| const templates = await this.getVersions(emailTemplateId, templateType); | ||
| const versionNumbers: number[] = []; | ||
| let newVersionNumber; | ||
| templates.versions.map((t) => versionNumbers.push(t.versionNumber)); | ||
|
|
||
| if (versionNumbers.length != 0) { | ||
| newVersionNumber = Math.max(...versionNumbers) + 1; | ||
| } else { | ||
| newVersionNumber = 1; | ||
| } |
There was a problem hiding this comment.
| const templates = await this.getVersions(emailTemplateId, templateType); | |
| const versionNumbers: number[] = []; | |
| let newVersionNumber; | |
| templates.versions.map((t) => versionNumbers.push(t.versionNumber)); | |
| if (versionNumbers.length != 0) { | |
| newVersionNumber = Math.max(...versionNumbers) + 1; | |
| } else { | |
| newVersionNumber = 1; | |
| } | |
| const newVersionNumber = | |
| templates.versions.reduce((max, t) => Math.max(max, t.versionNumber), 0) + | |
| 1; |
Description
refs: UserOfficeProject/issue-tracker#1738
Adds ability to have a version history for email templates.
Motivation and Context
When updating an email template at the moment the previous version of the template is lost, this ensures that all updates to the email templates are stored in case they need to be reinstated.
How Has This Been Tested
Tests to be added
Changes
When updating an email template
createNewVersionis called. This saves the updated body and subject of the email as a new version. This is added as a new row to the new template_versions database table. The body and subject are stored as a JSON.The new table is made to be flexible so that in the future other templates contents can be stored here as well:
template - JSON of template - not fixed to a certain template format
template_type - for example 'EMAIL'
A new tab is added to the email template editor modal ‘Version History’
A user can select a version number from the dropdown,
getEmailVersionsgets all versions of a given template.The corresponding subject and body are given to the user along with the render of the pug template so that the user can see what the selected version looks like.
getEmailVersiongets corresponding body and subject for the selected template.There is an option to copy the body to the clipboard and a user can then paste it in the edit tab to reinstate the selected version.
demo-email-version-history.mp4
Additional changes:
New TemplateVersionDatasource that can be used for other template versioning down the line.

Addition of timestamp (created_at) to the list of version numbers dropdown.
Example:
Tests included/Docs Updated?