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:
Domagoj Kriskovic
2023-12-05 10:39:12 +01:00
committed by Copybot
parent 23a35aa0d2
commit e46decbbcf
3 changed files with 20 additions and 30 deletions

View File

@@ -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 } =

View File

@@ -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

View File

@@ -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
}