Skip to content

Commit f161cae

Browse files
author
Guust
committed
chore: move all filters denoted as so to a filteringModel
1 parent 722caf7 commit f161cae

4 files changed

Lines changed: 56 additions & 36 deletions

File tree

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ export const excludeAnonymousLogAuthorToggle = (authorFilterModel) => switchInpu
5555
/**
5656
* Returns a authorFilter component with text input, reset button, and anonymous exclusion button.
5757
*
58-
* @param {LogModel} logModel the log model object
59-
* @returns {Component} the author filter component
58+
* @param {LogsOverviewModel} logsOverviewModel the log overview model
59+
* @param {FilteringModel} logsOverviewModel.filteringModel the runs overview model
60+
* @return {Component} the filter component
6061
*/
61-
export const authorFilter = ({ authorFilter }) => h('.flex-row.items-center.g3', [
62-
authorFilterTextInput(authorFilter),
63-
resetAuthorFilterButton(authorFilter),
64-
excludeAnonymousLogAuthorToggle(authorFilter),
62+
export const authorFilter = ({ filteringModel }) => h('.flex-row.items-center.g3', [
63+
authorFilterTextInput(filteringModel.get('authorFilter')),
64+
resetAuthorFilterButton(filteringModel.get('authorFilter')),
65+
excludeAnonymousLogAuthorToggle(filteringModel.get('authorFilter')),
6566
]);

lib/public/views/Logs/ActiveColumns/logsActiveColumns.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,16 @@ export const logsActiveColumns = {
7171
visible: true,
7272
sortable: true,
7373
size: 'w-30',
74-
filter: ({ titleFilter }) => textFilter(
75-
titleFilter,
74+
75+
/**
76+
* Title filter component
77+
*
78+
* @param {LogsOverviewModel} logOverviewModel the logs overview model
79+
* @param {FilteringModel} logOverviewModel.filteringModel filtering model
80+
* @return {Component} the filter component
81+
*/
82+
filter: ({ filteringModel }) => textFilter(
83+
filteringModel.get('titleFilter'),
7684
{
7785
id: 'titleFilterText',
7886
class: 'w-75 mt1',
@@ -92,8 +100,16 @@ export const logsActiveColumns = {
92100
name: 'Content',
93101
visible: false,
94102
size: 'w-10',
95-
filter: ({ contentFilter }) => textFilter(
96-
contentFilter,
103+
104+
/**
105+
* Content filter component
106+
*
107+
* @param {LogsOverviewModel} logOverviewModel the logs overview model
108+
* @param {FilteringModel} logOverviewModel.filteringModel filtering model
109+
* @return {Component} the filter component
110+
*/
111+
filter: ({ filteringModel }) => textFilter(
112+
filteringModel.get('contentFilter'),
97113
{
98114
id: 'contentFilterText',
99115
class: 'w-75 mt1',

lib/public/views/Logs/Overview/LogsOverviewModel.js

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { AuthorFilterModel } from '../../../components/Filters/LogsFilter/author
2020
import { PaginationModel } from '../../../components/Pagination/PaginationModel.js';
2121
import { getRemoteDataSlice } from '../../../utilities/fetch/getRemoteDataSlice.js';
2222
import { tagsProvider } from '../../../services/tag/tagsProvider.js';
23+
import { FilteringModel } from '../../../components/Filters/common/FilteringModel.js';
2324

2425
/**
2526
* Model representing handlers for log entries page
@@ -36,6 +37,12 @@ export class LogsOverviewModel extends Observable {
3637
constructor(model, excludeAnonymous = false) {
3738
super();
3839

40+
this._filteringModel = new FilteringModel({
41+
authorFilter: new AuthorFilterModel(),
42+
titleFilter: new FilterInputModel(),
43+
contentFilter: new FilterInputModel(),
44+
});
45+
3946
// Sub-models
4047
this._listingTagsFilterModel = new TagFilterModel(tagsProvider.items$);
4148
this._listingTagsFilterModel.observe(() => this._applyFilters());
@@ -49,16 +56,6 @@ export class LogsOverviewModel extends Observable {
4956
this._pagination.observe(() => this.fetchLogs());
5057
this._pagination.itemsPerPageSelector$.observe(() => this.notify());
5158

52-
// Filtering models
53-
this._authorFilter = new AuthorFilterModel();
54-
this._registerFilter(this._authorFilter);
55-
56-
this._titleFilter = new FilterInputModel();
57-
this._registerFilter(this._titleFilter);
58-
59-
this._contentFilter = new FilterInputModel();
60-
this._registerFilter(this._contentFilter);
61-
6259
this._logs = RemoteData.NotAsked();
6360

6461
const updateDebounceTime = () => {
@@ -67,7 +64,7 @@ export class LogsOverviewModel extends Observable {
6764
model.appConfiguration$.observe(() => updateDebounceTime());
6865
updateDebounceTime();
6966

70-
excludeAnonymous && this._authorFilter.update('!Anonymous');
67+
excludeAnonymous && this._filteringModel.get('authorFilter').update('!Anonymous');
7168

7269
this.reset(false);
7370
}
@@ -119,10 +116,7 @@ export class LogsOverviewModel extends Observable {
119116
* @return {undefined}
120117
*/
121118
reset(fetch = true) {
122-
this.titleFilter.reset();
123-
this.contentFilter.reset();
124-
this.authorFilter.reset();
125-
119+
this._filteringModel.reset();
126120
this.createdFilterFrom = '';
127121
this.createdFilterTo = '';
128122

@@ -153,9 +147,7 @@ export class LogsOverviewModel extends Observable {
153147
*/
154148
isAnyFilterActive() {
155149
return (
156-
!this._titleFilter.isEmpty
157-
|| !this._contentFilter.isEmpty
158-
|| !this._authorFilter.isEmpty
150+
!this._filteringModel.isAnyFilterActive()
159151
|| this.createdFilterFrom !== ''
160152
|| this.createdFilterTo !== ''
161153
|| !this.listingTagsFilterModel.isEmpty
@@ -289,6 +281,15 @@ export class LogsOverviewModel extends Observable {
289281
}
290282
}
291283

284+
/**
285+
* Return the model managing all filters
286+
*
287+
* @return {FilteringModel} the filtering model
288+
*/
289+
get filteringModel() {
290+
return this._filteringModel;
291+
}
292+
292293
/**
293294
* Return the model handling the filtering on tags
294295
*
@@ -375,16 +376,18 @@ export class LogsOverviewModel extends Observable {
375376
_getFilterQueryParams() {
376377
const sortOn = this._overviewSortModel.appliedOn;
377378
const sortDirection = this._overviewSortModel.appliedDirection;
378-
379+
const titleFilter = this._filteringModel.get('titleFilter');
380+
const contentFilter = this._filteringModel.get('contentFilter');
381+
const authorFilter = this._filteringModel.get('authorFilter');
379382
return {
380-
...!this._titleFilter.isEmpty && {
381-
'filter[title]': this._titleFilter.value,
383+
...!titleFilter.isEmpty && {
384+
'filter[title]': titleFilter.value,
382385
},
383-
...!this._contentFilter.isEmpty && {
384-
'filter[content]': this._contentFilter.value,
386+
...!contentFilter.isEmpty && {
387+
'filter[content]': contentFilter.value,
385388
},
386-
...!this._authorFilter.isEmpty && {
387-
'filter[author]': this._authorFilter.value,
389+
...!authorFilter.isEmpty && {
390+
'filter[author]': authorFilter,
388391
},
389392
...this.createdFilterFrom && {
390393
'filter[created][from]':

lib/public/views/Logs/Overview/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const logOverviewScreen = ({ logs: { overviewModel: logsOverviewModel } }) => {
3939
h('#main-action-bar.flex-row.justify-between.header-container.pv2', [
4040
h('.flex-row.g3', [
4141
filtersPanelPopover(logsOverviewModel, logsActiveColumns),
42-
excludeAnonymousLogAuthorToggle(logsOverviewModel.authorFilter),
42+
excludeAnonymousLogAuthorToggle(logsOverviewModel.filteringModel.get('authorFilter')),
4343
]),
4444
actionButtons(),
4545
]),

0 commit comments

Comments
 (0)