Skip to content

Commit 1921893

Browse files
authored
Merge pull request #2363 from navikt/archived-old-versions-preview
Archived old versions preview
2 parents d0e9aea + 6b4f369 commit 1921893

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/main/resources/lib/external-archive/get-archived-content.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ const getPreArchivedVersions = (contentId: string, repoId: string) => {
6363
}).filter((version) => version.nodePath.startsWith('/content'));
6464
};
6565

66-
export const getArchivedContent = (idOrArchivedPath: string, repoId: string, time?: string) => {
66+
export const getArchivedContent = (
67+
idOrArchivedPath: string,
68+
repoId: string,
69+
time?: string,
70+
versionId?: string
71+
) => {
6772
const contentRef = getArchivedContentRef(idOrArchivedPath);
6873

6974
const repoConnection = getRepoConnection({ branch: 'draft', repoId });
@@ -76,18 +81,24 @@ export const getArchivedContent = (idOrArchivedPath: string, repoId: string, tim
7681

7782
const preArchivedVersions = getPreArchivedVersions(archivedNode._id, repoId);
7883

79-
const requestedVersion = time
84+
const versionNode = versionId
85+
? preArchivedVersions.find((v) => v.versionId === versionId)
86+
: undefined;
87+
88+
const contentTime = versionNode ? versionNode.timestamp : time;
89+
90+
const requestedVersion = contentTime
8091
? getContentVersionFromTime({
8192
nodeKey: contentRef,
82-
unixTime: getUnixTimeFromDateTimeString(time),
93+
unixTime: getUnixTimeFromDateTimeString(contentTime),
8394
repoId,
8495
branch: 'draft',
8596
getOldestIfNotFound: false,
8697
})
8798
: preArchivedVersions[0];
8899
if (!requestedVersion) {
89100
logger.info(
90-
`No live version found for content - ${contentRef} in repo ${repoId} (time: ${time})`
101+
`No live version found for content - ${contentRef} in repo ${repoId} (time: ${contentTime})`
91102
);
92103
return null;
93104
}

src/main/resources/lib/utils/version-utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ export const getContentVersionFromTime = ({
8282
if (!length) {
8383
return null;
8484
}
85-
8685
// Return the newest version which is equal to or older than the requested time
8786
const foundVersion = contentVersions.find((version) => {
8887
const versionUnixTime = getUnixTimeFromDateTimeString(version.timestamp);

src/main/resources/services/externalArchive/content/content.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ const resolveToContentTimestamp = (content: Content, locale: string) => {
3838
const getContentRenderProps = (
3939
content: Content,
4040
locale: string,
41-
resolveToTs: boolean,
41+
versionId: string | undefined,
4242
isArchived: boolean
4343
) => {
44+
const resolveToTs = !!versionId;
4445
if (isArchived) {
4546
return getArchivedContent(
4647
content._id,
4748
getLayersData().localeToRepoIdMap[locale],
48-
content.archivedTime || content.modifiedTime || content.createdTime
49+
undefined,
50+
versionId
4951
);
5052
}
5153

@@ -93,7 +95,7 @@ export const externalArchiveContentService = (req: XP.Request) => {
9395
};
9496
}
9597

96-
const contentRenderProps = getContentRenderProps(content, locale, !!versionId, isArchived);
98+
const contentRenderProps = getContentRenderProps(content, locale, versionId, isArchived);
9799

98100
const versions = getPublishedAndModifiedVersions(content._id, locale).filter(
99101
(v) => !v.shouldExclude

0 commit comments

Comments
 (0)