Skip to content

Commit 3dac5da

Browse files
authored
feature: Add event handlers for saved search and bookmark actions (#1408)
This adds event listeners for the following events: - saved-search-saved - saved-search-edited - saved-search-deleted - saved-search-bookmarked - saved-search-unbookmarked Future PR(s) will emit those events. We create the event listeners so that anywhere in the app can emit an event and the appBookmarkInfo will update. And as a result, all the subscribers to appBookmarkInfo will get the new state automatically. saved-search-bookmarked can use the same event listener method as saved-search-saved because: 1. The saved search owner can't toggle its bookmark status (like in issue tracker). 2. As a result of point number 1, non owners can be the only users toggling. Which means it can use `handleSavedSearchSaved` since it just adds the saved search to the user's array locally. The above also applies for saved-search-unbookmarked and saved-search-deleted Other changes: - On the overview page component, since we recently change the load task to disable autoRun and control when it runs, add a new check that verifies that we have not loaded this current saved search before.
1 parent 2021acc commit 3dac5da

File tree

3 files changed

+479
-7
lines changed

3 files changed

+479
-7
lines changed

frontend/src/static/js/components/webstatus-overview-page.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ import {
4040
appBookmarkInfoContext,
4141
AppBookmarkInfo,
4242
savedSearchHelpers,
43+
SavedSearchScope,
4344
} from '../contexts/app-bookmark-info-context.js';
45+
import {UserSavedSearch} from '../utils/constants.js';
4446

4547
@customElement('webstatus-overview-page')
4648
export class OverviewPage extends LitElement {
@@ -67,6 +69,8 @@ export class OverviewPage extends LitElement {
6769
@state()
6870
appBookmarkInfo?: AppBookmarkInfo;
6971

72+
_lastUserSavedSearch?: UserSavedSearch;
73+
7074
constructor() {
7175
super();
7276

@@ -119,20 +123,48 @@ export class OverviewPage extends LitElement {
119123
},
120124
});
121125
}
126+
127+
areUserSavedSearchesDifferent(
128+
current?: UserSavedSearch,
129+
incoming?: UserSavedSearch,
130+
): boolean {
131+
// Could be a completely different search or a more recently updated search
132+
return (
133+
current?.id !== incoming?.id ||
134+
current?.updated_at !== incoming?.updated_at
135+
);
136+
}
137+
122138
protected willUpdate(changedProperties: PropertyValueMap<this>): void {
123139
if (
124140
changedProperties.has('apiClient') ||
125141
changedProperties.has('location') ||
126142
changedProperties.has('appBookmarkInfo')
127143
) {
144+
if (this.apiClient === undefined) {
145+
return;
146+
}
147+
const incomingCurrentSavedSearch =
148+
savedSearchHelpers.getCurrentSavedSearch(
149+
this.appBookmarkInfo,
150+
this.location,
151+
);
152+
const userSavedSearch =
153+
incomingCurrentSavedSearch?.scope === SavedSearchScope.UserSavedSearch
154+
? incomingCurrentSavedSearch.value
155+
: undefined;
128156
if (
129-
this.apiClient !== undefined &&
130-
this.currentLocation?.search !== this.location.search &&
157+
(this.currentLocation?.search !== this.location.search ||
158+
this.areUserSavedSearchesDifferent(
159+
this._lastUserSavedSearch,
160+
userSavedSearch,
161+
)) &&
131162
!savedSearchHelpers.isBusyLoadingSavedSearchInfo(
132163
this.appBookmarkInfo,
133164
this.location,
134165
)
135166
) {
167+
this._lastUserSavedSearch = userSavedSearch;
136168
void this.loadingTask.run();
137169
}
138170
}

0 commit comments

Comments
 (0)