Skip to content

feat: add email template version history - #1822

Merged
ellen-wright merged 32 commits into
developfrom
1618-add-email-template-version-history
Nov 5, 2026
Merged

ellen-wright merged 32 commits into
developfrom
1618-add-email-template-version-history

Conversation

@ellen-wright

@ellen-wright ellen-wright commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

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 createNewVersion is 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_version_id template_id template version_number template_type created_at

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, getEmailVersions gets 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. getEmailVersion gets 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:
image

Tests included/Docs Updated?

  • I have added tests to cover my changes.
  • All relevant doc has been updated

@ellen-wright
ellen-wright requested a review from a team as a code owner September 23, 2026 15:02
@ellen-wright
ellen-wright requested review from SourangshuSTFC and removed request for a team and SourangshuSTFC September 23, 2026 15:02
@ellen-wright
ellen-wright marked this pull request as draft September 23, 2026 15:02
@zacharyjhankin

Copy link
Copy Markdown
Collaborator

Is this ready for review, because its got the review:please tag? Or not because it is in draft

@ellen-wright

Copy link
Copy Markdown
Contributor Author

@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 = ({

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@zacharyjhankin

Copy link
Copy Markdown
Collaborator

Architecture looks great to me overall, great change

@ellen-wright
ellen-wright marked this pull request as ready for review October 23, 2026 13:39
>
{version.versionNumber +
': ' +
version.createdTimeStamp}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick:
Other dates in the system translate out of the GMT stored in the DB.

>
{''}
</CopyToClipboard>
<br /> <small>Copy body to Clipboard</small>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@zacharyjhankin zacharyjhankin left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mutambaraf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can update the date is now too behind

{
constructor(
@inject(Tokens.TemplateVersionDataSource)
private templateDataSource: TemplateVersionDataSource

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a templateVersionDataSource

async createNewVersion(
emailTemplateId: number,
templateType: string,
template?: string | null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For typing purposes , I think this variable is always required because if its null we immediately return the fuction,

Comment on lines +54 to +63
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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;

@ellen-wright
ellen-wright merged commit cb05058 into develop Nov 5, 2026
26 checks passed
@ellen-wright
ellen-wright deleted the 1618-add-email-template-version-history branch November 5, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants