mirror of
https://github.com/home-assistant/frontend.git
synced 2025-05-16 07:58:44 +00:00
Handle logbook updates where the new records are in the middle of the old records (#13595)
This commit is contained in:
parent
8ee9655bd5
commit
5842b10a10
@ -377,16 +377,32 @@ export class HaLogbook extends LitElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const nonExpiredRecords = this._nonExpiredRecords(purgeBeforePythonTime);
|
const nonExpiredRecords = this._nonExpiredRecords(purgeBeforePythonTime);
|
||||||
this._logbookEntries = !nonExpiredRecords.length
|
|
||||||
? // All existing entries expired
|
// Entries are sorted in descending order with newest first.
|
||||||
newEntries
|
if (!nonExpiredRecords.length) {
|
||||||
: newEntries[0].when >= nonExpiredRecords[0].when
|
// We have no records left, so we can just replace the list
|
||||||
? // The new records are newer than the old records
|
this._logbookEntries = newEntries;
|
||||||
|
} else if (
|
||||||
|
newEntries[newEntries.length - 1].when > // oldest new entry
|
||||||
|
nonExpiredRecords[0].when // newest old entry
|
||||||
|
) {
|
||||||
|
// The new records are newer than the old records
|
||||||
// append the old records to the end of the new records
|
// append the old records to the end of the new records
|
||||||
newEntries.concat(nonExpiredRecords)
|
this._logbookEntries = newEntries.concat(nonExpiredRecords);
|
||||||
: // The new records are older than the old records
|
} else if (
|
||||||
|
nonExpiredRecords[nonExpiredRecords.length - 1].when > // oldest old entry
|
||||||
|
newEntries[0].when // newest new entry
|
||||||
|
) {
|
||||||
|
// The new records are older than the old records
|
||||||
// append the new records to the end of the old records
|
// append the new records to the end of the old records
|
||||||
nonExpiredRecords.concat(newEntries);
|
this._logbookEntries = nonExpiredRecords.concat(newEntries);
|
||||||
|
} else {
|
||||||
|
// The new records are in the middle of the old records
|
||||||
|
// so we need to re-sort them
|
||||||
|
this._logbookEntries = nonExpiredRecords
|
||||||
|
.concat(newEntries)
|
||||||
|
.sort((a, b) => b.when - a.when);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private _updateTraceContexts = throttle(async () => {
|
private _updateTraceContexts = throttle(async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user