Skip to content

Commit 07567e2

Browse files
author
Guust
committed
implement authorfilter with ParsedInputFilterModel changes
1 parent 247943b commit 07567e2

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,30 @@
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[]|string}
21+
*/
22+
const parseAuthors = (raw) => raw
23+
.split(',')
24+
.map((author) => author.trim())
25+
.filter(Boolean);
1526

1627
/**
1728
* Model to handle the state of the Author Filter
1829
*/
19-
export class AuthorFilterModel extends FilterInputModel {
30+
export class AuthorFilterModel extends ParsedInputFilterModel {
2031
/**
2132
* Constructor
2233
*
2334
* @constructor
2435
*/
2536
constructor() {
26-
super();
37+
super(parseAuthors);
2738
}
2839

2940
/**
@@ -49,21 +60,7 @@ export class AuthorFilterModel extends FilterInputModel {
4960
this._raw += super.isEmpty ? '!Anonymous' : ', !Anonymous';
5061
}
5162

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();
63+
this._value = this._parse(this._raw);
6764
this.notify();
6865
}
6966
}

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)