From 17c7e394cf0f899362e0448b01287a1ad19d7f8e Mon Sep 17 00:00:00 2001 From: martinboulais <31805063+martinboulais@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:05:21 +0100 Subject: [PATCH 1/2] [O2B-1181] Add easy to reach no-anonymous toggle --- lib/public/Model.js | 3 +++ .../LogsFilter/author/AuthorFilterModel.js | 9 ++++++--- .../Filters/LogsFilter/author/authorFilter.js | 17 +++++++---------- lib/public/views/Logs/Overview/index.js | 2 ++ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/public/Model.js b/lib/public/Model.js index 195255e8af..37643d476b 100644 --- a/lib/public/Model.js +++ b/lib/public/Model.js @@ -81,6 +81,9 @@ export default class Model extends Observable { this.simulationPasses = new SimulationPassesModel(this); this.simulationPasses.bubbleTo(this); + /** + * @type {LogsModel} + */ this.logs = new LogsModel(this); this.logs.bubbleTo(this); diff --git a/lib/public/components/Filters/LogsFilter/author/AuthorFilterModel.js b/lib/public/components/Filters/LogsFilter/author/AuthorFilterModel.js index b2ac5a5577..fe06709fdd 100644 --- a/lib/public/components/Filters/LogsFilter/author/AuthorFilterModel.js +++ b/lib/public/components/Filters/LogsFilter/author/AuthorFilterModel.js @@ -40,12 +40,15 @@ export class AuthorFilterModel extends FilterInputModel { * * @returns {void} */ - applyExcludeAnonymousFilter() { + toggleAnonymousFilter() { if (this.isAnonymousExcluded()) { - return; + this._raw = this._raw.split(',') + .filter((author) => author.trim() !== '!Anonymous') + .join(','); + } else { + this._raw += super.isEmpty ? '!Anonymous' : ', !Anonymous'; } - this._raw += super.isEmpty ? '!Anonymous' : ', !Anonymous'; this._value = this.valueFromRaw(this._raw); this.notify(); } diff --git a/lib/public/components/Filters/LogsFilter/author/authorFilter.js b/lib/public/components/Filters/LogsFilter/author/authorFilter.js index c3b8a75dcc..d5fe5a7a45 100644 --- a/lib/public/components/Filters/LogsFilter/author/authorFilter.js +++ b/lib/public/components/Filters/LogsFilter/author/authorFilter.js @@ -13,6 +13,7 @@ import { h } from '/js/src/index.js'; import { iconX } from '/js/src/icons.js'; +import { switchInput } from '../../../common/form/switchInput.js'; /** * Returns a text input field that can be used to filter logs by author @@ -40,19 +41,15 @@ const resetAuthorFilterButton = (authorFilterModel) => h( ); /** - * Returns a button that can be used to exclude anonymous authors + * Returns a toggle that can be used to exclude anonymous authors * * @param {AuthorFilterModel} authorFilterModel The author filter model object * @return {Component} A button component that can be used to exclude anonymous authors */ -const excludeAnonymousButton = (authorFilterModel) => h( - 'input.btn.btn-primary', - { - type: 'button', - value: 'No Anonymous', - disabled: authorFilterModel.isAnonymousExcluded(), - onclick: () => authorFilterModel.applyExcludeAnonymousFilter(), - }, +export const excludeAnonymousLogAuthorToggle = (authorFilterModel) => switchInput( + authorFilterModel.isAnonymousExcluded(), + () => authorFilterModel.toggleAnonymousFilter(), + { labelAfter: 'No Anonymous' }, ); /** @@ -64,5 +61,5 @@ const excludeAnonymousButton = (authorFilterModel) => h( export const authorFilter = ({ authorFilter }) => h('.flex-row.items-center.g3', [ authorFilterTextInput(authorFilter), resetAuthorFilterButton(authorFilter), - excludeAnonymousButton(authorFilter), + excludeAnonymousLogAuthorToggle(authorFilter), ]); diff --git a/lib/public/views/Logs/Overview/index.js b/lib/public/views/Logs/Overview/index.js index 585954f94a..99d41bbfd9 100644 --- a/lib/public/views/Logs/Overview/index.js +++ b/lib/public/views/Logs/Overview/index.js @@ -18,6 +18,7 @@ import { estimateDisplayableRowsCount } from '../../../utilities/estimateDisplay import { paginationComponent } from '../../../components/Pagination/paginationComponent.js'; import { frontLink } from '../../../components/common/navigation/frontLink.js'; import { filtersPanelPopover } from '../../../components/Filters/common/filtersPanelPopover.js'; +import { excludeAnonymousLogAuthorToggle } from '../../../components/Filters/LogsFilter/author/authorFilter.js'; const TABLEROW_HEIGHT = 69; // Estimate of the navbar and pagination elements height total; Needs to be updated in case of changes; @@ -37,6 +38,7 @@ const logOverviewScreen = ({ logs: { overviewModel: logsOverviewModel } }) => { return h('', [ h('.flex-row.justify-between.header-container.pv2', [ filtersPanelPopover(logsOverviewModel, logsActiveColumns), + excludeAnonymousLogAuthorToggle(logsOverviewModel.authorFilter), actionButtons(), ]), h('.w-100.flex-column', [ From 63913433480926a8a1b5a7027852b35e88904d91 Mon Sep 17 00:00:00 2001 From: martinboulais <31805063+martinboulais@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:13:11 +0100 Subject: [PATCH 2/2] Place properly the toggle --- lib/public/views/Logs/Overview/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/public/views/Logs/Overview/index.js b/lib/public/views/Logs/Overview/index.js index 99d41bbfd9..3bf08845da 100644 --- a/lib/public/views/Logs/Overview/index.js +++ b/lib/public/views/Logs/Overview/index.js @@ -37,8 +37,10 @@ const logOverviewScreen = ({ logs: { overviewModel: logsOverviewModel } }) => { return h('', [ h('.flex-row.justify-between.header-container.pv2', [ - filtersPanelPopover(logsOverviewModel, logsActiveColumns), - excludeAnonymousLogAuthorToggle(logsOverviewModel.authorFilter), + h('.flex-row.g3', [ + filtersPanelPopover(logsOverviewModel, logsActiveColumns), + excludeAnonymousLogAuthorToggle(logsOverviewModel.authorFilter), + ]), actionButtons(), ]), h('.w-100.flex-column', [