diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-11-23 00:09:38 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-11-23 00:09:38 +0000 |
commit | aff67b6bbc28eba4d1f4a4a12e116e63ab4813ea (patch) | |
tree | b7892405559e1714c330ffb8ac9de9104296f4e3 /pw_web/log-viewer/src/components/log-view/log-view.ts | |
parent | 13960e09d00c4e8612da0a9084e0e051603f072b (diff) | |
parent | f054515492af5132f685cb23fe11891ee77104c9 (diff) | |
download | pigweed-aff67b6bbc28eba4d1f4a4a12e116e63ab4813ea.tar.gz |
Snap for 11135477 from f054515492af5132f685cb23fe11891ee77104c9 to 24Q1-releaseandroid-14.0.0_r37android-14.0.0_r36android-14.0.0_r35android-14.0.0_r34android-14.0.0_r33android-14.0.0_r32android-14.0.0_r31android-14.0.0_r30android-14.0.0_r29android14-qpr2-s5-releaseandroid14-qpr2-s4-releaseandroid14-qpr2-s3-releaseandroid14-qpr2-s2-releaseandroid14-qpr2-s1-releaseandroid14-qpr2-release
Change-Id: I018123259cd231d0e74933e492391999e36650e8
Diffstat (limited to 'pw_web/log-viewer/src/components/log-view/log-view.ts')
-rw-r--r-- | pw_web/log-viewer/src/components/log-view/log-view.ts | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/pw_web/log-viewer/src/components/log-view/log-view.ts b/pw_web/log-viewer/src/components/log-view/log-view.ts index e975c044f..900637e5c 100644 --- a/pw_web/log-viewer/src/components/log-view/log-view.ts +++ b/pw_web/log-viewer/src/components/log-view/log-view.ts @@ -55,47 +55,44 @@ export class LogView extends LitElement { @state() _lineWrap = false; + /** The field keys (column values) for the incoming log entries. */ + @state() + private _columnData: TableColumn[] = []; + + /** A string representing the value contained in the search field. */ + @state() + public searchText = ''; + + /** A StateStore object that stores state of views */ + @state() + _stateStore: StateStore = new LocalStorageState(); + + @query('log-list') _logList!: LogList; + /** * An array containing the logs that remain after the current filter has been * applied. */ - @state() private _filteredLogs: LogEntry[] = []; - /** The field keys (column values) for the incoming log entries. */ - @state() - private _columnData: TableColumn[] = []; - /** A function used for filtering rows that contain a certain substring. */ - @state() private _stringFilter: FilterFunction = () => true; /** * A function used for filtering rows that contain a timestamp within a * certain window. */ - @state() private _timeFilter: FilterFunction = () => true; - /** A string representing the value contained in the search field. */ - @state() - public searchText = ''; - - /** A StateStore object that stores state of views */ - @state() - _stateStore: StateStore = new LocalStorageState(); - - @state() - _state: State; - - @query('log-list') _logList!: LogList; + private _state: State; private _debounceTimeout: NodeJS.Timeout | null = null; + /** The number of elements in the `logs` array since last updated. */ + private _lastKnownLogLength: number = 0; + /** The amount of time, in ms, before the filter expression is executed. */ private readonly FILTER_DELAY = 100; - /** The number of elements in the `logs` array since last updated. */ - private lastKnownLogLength: number = 0; constructor() { super(); @@ -117,10 +114,13 @@ export class LogView extends LitElement { super.updated(changedProperties); if (changedProperties.has('logs')) { - const newLogs = this.logs.slice(this.lastKnownLogLength); - this.lastKnownLogLength = this.logs.length; + const newLogs = this.logs.slice(this._lastKnownLogLength); + this._lastKnownLogLength = this.logs.length; this.updateFieldsFromNewLogs(newLogs); + } + + if (changedProperties.has('logs') || changedProperties.has('searchText')) { this.filterLogs(); } @@ -263,16 +263,20 @@ export class LogView extends LitElement { } /** - * Combines constituent filter expressions and filters the logs. The filtered - * logs are stored in the `_filteredLogs` state property. + * Combines filter expressions and filters the logs. The filtered + * logs are stored in the `_filteredLogs` property. */ private filterLogs() { const combinedFilter = (logEntry: LogEntry) => this._timeFilter(logEntry) && this._stringFilter(logEntry); - this._filteredLogs = JSON.parse( - JSON.stringify(this.logs.filter(combinedFilter)), - ); + const newFilteredLogs = this.logs.filter(combinedFilter); + + if ( + JSON.stringify(newFilteredLogs) !== JSON.stringify(this._filteredLogs) + ) { + this._filteredLogs = newFilteredLogs; + } } private updateColumnData(event: CustomEvent) { @@ -322,7 +326,7 @@ export class LogView extends LitElement { render() { return html` <log-view-controls - .columnData=${[...this._columnData]} + .columnData=${this._columnData} .viewId=${this.id} .hideCloseButton=${!this.isOneOfMany} .stateStore=${this._stateStore} |