Skip to content

Commit 114285d

Browse files
author
Guust
committed
implement authorfilter with ParsedInputFilterModel changes
1 parent 247943b commit 114285d

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

lib/public/components/Filters/LogsFilter/author/AuthorFilterModel.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,31 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313

14-
import { FilterInputModel } from '../../common/filters/FilterInputModel.js';
14+
import { ParsedInputFilterModel } from '../../common/filters/ParsedInputFilterModel.js';
15+
16+
/**
17+
* Parse raw author input into a normalized array.
18+
*
19+
* @param {string} raw a raw, comma-seperated string
20+
* @returns {string}
21+
*/
22+
const parseAuthors = (raw) => raw
23+
.split(',')
24+
.map((author) => author.trim())
25+
.filter(Boolean)
26+
.join(',');
1527

1628
/**
1729
* Model to handle the state of the Author Filter
1830
*/
19-
export class AuthorFilterModel extends FilterInputModel {
31+
export class AuthorFilterModel extends ParsedInputFilterModel {
2032
/**
2133
* Constructor
2234
*
2335
* @constructor
2436
*/
2537
constructor() {
26-
super();
38+
super(parseAuthors);
2739
}
2840

2941
/**
@@ -49,21 +61,7 @@ export class AuthorFilterModel extends FilterInputModel {
4961
this._raw += super.isEmpty ? '!Anonymous' : ', !Anonymous';
5062
}
5163

52-
this._value = this.valueFromRaw(this._raw);
53-
this.notify();
54-
}
55-
56-
/**
57-
* Reset the filter to its default value and notify the observers.
58-
*
59-
* @return {void}
60-
*/
61-
clear() {
62-
if (this.isEmpty) {
63-
return;
64-
}
65-
66-
super.reset();
64+
this._value = this._parse(this._raw);
6765
this.notify();
6866
}
6967
}

lib/public/components/Filters/LogsFilter/author/authorFilter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const authorFilterTextInput = (authorFilterModel) => h('input.w-40', {
3636
*/
3737
const resetAuthorFilterButton = (authorFilterModel) => h(
3838
'.btn.btn-pill.f7',
39-
{ disabled: authorFilterModel.isEmpty, onclick: () => authorFilterModel.clear() },
39+
{ disabled: authorFilterModel.isEmpty, onclick: () => authorFilterModel.reset() },
4040
iconX(),
4141
);
4242

0 commit comments

Comments
 (0)