mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Fix last edit date for labels in history panel (#16113)
* Fix label edit date in history panel * format fix GitOrigin-RevId: 0cd31166a170674216fc8928178add3c36a3fb3c
This commit is contained in:
committed by
Copybot
parent
23a35aa0d2
commit
e46decbbcf
@@ -180,13 +180,8 @@ function useHistory() {
|
||||
|
||||
Promise.all([updatesPromise, labelsPromise])
|
||||
.then(([{ updates: updatesData, nextBeforeTimestamp }, labels]) => {
|
||||
const lastUpdateToV = updatesData.length ? updatesData[0].toV : null
|
||||
const lastUpdatedTimestamp = updatesData.length
|
||||
? updatesData[0].meta.end_ts
|
||||
: null
|
||||
|
||||
if (labels) {
|
||||
setLabels(loadLabels(labels, lastUpdateToV, lastUpdatedTimestamp))
|
||||
setLabels(loadLabels(labels, updatesData))
|
||||
}
|
||||
|
||||
const { updates, visibleUpdateCount, freeHistoryLimitHit } =
|
||||
|
||||
@@ -36,11 +36,7 @@ function useAddOrRemoveLabels() {
|
||||
if (labels) {
|
||||
const nonPseudoLabels = labels.filter(isLabel)
|
||||
const processedNonPseudoLabels = labelsHandler(nonPseudoLabels)
|
||||
const newLabels = loadLabels(
|
||||
processedNonPseudoLabels,
|
||||
tempUpdates[0].toV,
|
||||
tempUpdates[0].meta.end_ts
|
||||
)
|
||||
const newLabels = loadLabels(processedNonPseudoLabels, tempUpdates)
|
||||
setLabels(newLabels)
|
||||
|
||||
return newLabels
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
} from '../services/types/label'
|
||||
import { Nullable } from '../../../../../types/utils'
|
||||
import { Selection } from '../services/types/selection'
|
||||
import { Update } from '../services/types/update'
|
||||
|
||||
export const isPseudoLabel = (
|
||||
label: LoadedLabel
|
||||
@@ -35,8 +36,7 @@ const deletePseudoCurrentStateLabelIfExistent = (labels: LoadedLabel[]) => {
|
||||
|
||||
const addPseudoCurrentStateLabelIfNeeded = (
|
||||
labels: LoadedLabel[],
|
||||
mostRecentVersion: Nullable<number>,
|
||||
lastUpdatedTimestamp: Nullable<number>
|
||||
mostRecentVersion: Nullable<number>
|
||||
) => {
|
||||
if (!labels.length || labels[0].version !== mostRecentVersion) {
|
||||
const pseudoCurrentStateLabel: PseudoCurrentStateLabel = {
|
||||
@@ -44,39 +44,38 @@ const addPseudoCurrentStateLabelIfNeeded = (
|
||||
isPseudoCurrentStateLabel: true,
|
||||
version: mostRecentVersion,
|
||||
created_at: new Date().toISOString(),
|
||||
lastUpdatedTimestamp,
|
||||
lastUpdatedTimestamp: null,
|
||||
}
|
||||
return [pseudoCurrentStateLabel, ...labels]
|
||||
}
|
||||
return labels
|
||||
}
|
||||
|
||||
const addLastUpdatedTimestamp = (
|
||||
labels: LoadedLabel[],
|
||||
lastUpdatedTimestamp: Nullable<number>
|
||||
) => {
|
||||
return labels.map(label => ({
|
||||
...label,
|
||||
lastUpdatedTimestamp,
|
||||
}))
|
||||
const addLastUpdatedTimestamp = (labels: LoadedLabel[], updates: Update[]) => {
|
||||
return labels.map(label => {
|
||||
const lastUpdatedTimestamp = updates.find(update =>
|
||||
update.labels.find(l => l.id === label.id)
|
||||
)?.meta.end_ts
|
||||
|
||||
return {
|
||||
...label,
|
||||
lastUpdatedTimestamp: lastUpdatedTimestamp || null,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const loadLabels = (
|
||||
labels: Label[],
|
||||
lastUpdateToV: Nullable<number>,
|
||||
lastUpdatedTimestamp: Nullable<number>
|
||||
) => {
|
||||
export const loadLabels = (labels: Label[], updates: Update[]) => {
|
||||
const lastUpdateToV = updates.length ? updates[0].toV : null
|
||||
const sortedLabels = sortLabelsByVersionAndDate(labels)
|
||||
const labelsWithoutPseudoLabel =
|
||||
deletePseudoCurrentStateLabelIfExistent(sortedLabels)
|
||||
const labelsWithPseudoLabelIfNeeded = addPseudoCurrentStateLabelIfNeeded(
|
||||
labelsWithoutPseudoLabel,
|
||||
lastUpdateToV,
|
||||
lastUpdatedTimestamp
|
||||
lastUpdateToV
|
||||
)
|
||||
const labelsWithLastUpdatedTimestamp = addLastUpdatedTimestamp(
|
||||
labelsWithPseudoLabelIfNeeded,
|
||||
lastUpdatedTimestamp
|
||||
updates
|
||||
)
|
||||
return labelsWithLastUpdatedTimestamp
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user