Skip to content

Commit

Permalink
Ensure 'clear filters' clears all filters and doesn't just reset them…
Browse files Browse the repository at this point in the history
… to initial state
  • Loading branch information
rogup committed May 10, 2024
1 parent 6f01e69 commit a846e47
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/map-app/app/map-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class MapUI {
};

EventBus.Map.initiativeClicked.sub(initiative => this.onInitiativeClicked(initiative));
EventBus.Map.resetSearch.sub(() => this.resetSearch());
EventBus.Map.clearFiltersAndSearch.sub(() => this.clearFiltersAndSearch());
}

// This inspects the config and constructs an appropriate set of
Expand Down Expand Up @@ -114,8 +114,8 @@ export class MapUI {
this.stateManager.clearPropFilter(filterName);
}

resetSearch(): void {
this.stateManager.reset();
clearFiltersAndSearch(): void {
this.stateManager.clearFiltersAndSearch();
}

/// Returns a list of property values matching the given filter
Expand Down
4 changes: 0 additions & 4 deletions src/map-app/app/presenter/sidebar/initiatives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ export class InitiativesSidebarPresenter extends BaseSidebarPresenter {
this.parent.mapui.performSearch(text);
}

resetSearch() {
this.parent.mapui.resetSearch();
}

changeSearchText(txt: string) {
this.view.changeSearchText(txt);
}
Expand Down
27 changes: 19 additions & 8 deletions src/map-app/app/state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ export class AppState {
);
return new AppStateChange(textSearch, result);
}

clearTextSearch(): AppStateChange|undefined {
return this.addTextSearch(new TextSearch(''));
}

addPropEquality(propEq: PropEquality): AppStateChange|undefined {
const oldPropFilter = this.propFilters[propEq.propName];
Expand Down Expand Up @@ -200,6 +196,17 @@ export class AppState {
);
return new AppStateChange(action, result);
}

removePropEqualitiesAndClearTextSearch(): AppStateChange|undefined {
if (Object.keys(this.propFilters).length === 0 && this.textSearch.searchText === '')
return undefined; // No change

const result = new AppState(
this.allInitiatives,
this.allInitiatives
);
return new AppStateChange(undefined, result);
}
}


Expand Down Expand Up @@ -335,10 +342,6 @@ export class StateManager {
this.onChange(stateChange);
}

clearTextSearch(): void {
return this.textSearch(new TextSearch(''));
}

propFilter(propEq: PropEquality): void {
const stateChange = this.stack.current.result.addPropEquality(propEq);
if (stateChange === undefined)
Expand All @@ -363,6 +366,14 @@ export class StateManager {
this.onChange(stateChange);
}

clearFiltersAndSearch(): void {
const stateChange = this.stack.current.result.removePropEqualitiesAndClearTextSearch();
if (stateChange === undefined)
return; // No change
this.stack.push(stateChange);
this.onChange(stateChange);
}

altValues(propName: string) {
return this.stack.current.result.altValues(propName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/map-app/app/view/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class SidebarView extends BaseView {
.attr("class", "w3-button w3-border-0 ml-auto")
.attr("title", labels.showDirectory)
.on("click", () => {
this.presenter.mapui.resetSearch();
this.presenter.mapui.clearFiltersAndSearch();
this.hideInitiativeList();
this.presenter.changeSidebar("directory");

Expand Down
4 changes: 2 additions & 2 deletions src/map-app/app/view/sidebar/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ export abstract class BaseSidebarView extends BaseView {
.attr("class", "w3-button w3-border-0 mobile-only")
.attr("title", labels.showDirectory)
.on("click", function () {
EventBus.Map.clearFiltersAndSearch.pub();
EventBus.Sidebar.hideInitiativeList.pub();
EventBus.Sidebar.showDirectory.pub();
EventBus.Map.resetSearch.pub();
EventBus.Markers.needToShowLatestSelection.pub([]);
})
.append("i")
Expand All @@ -177,8 +177,8 @@ export abstract class BaseSidebarView extends BaseView {
.attr("class", "ml-auto clear-filters-button")
.text(labels.clearFilters)
.on("click", () => {
EventBus.Map.clearFiltersAndSearch.pub();
EventBus.Sidebar.hideInitiativeList.pub();
EventBus.Map.resetSearch.pub();
EventBus.Markers.needToShowLatestSelection.pub([]);
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/map-app/app/view/sidebar/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class DirectorySidebarView extends BaseSidebarView {
.classed(classname, true)
.classed("sea-directory-field", true)
.on("click", (event: MouseEvent) => {
this.presenter.parent.mapui.resetSearch();
this.presenter.parent.mapui.clearFiltersAndSearch();
this.presenter.parent.mapui.changeFilters(propName, propValue);
EventBus.Sidebar.showInitiativeList.pub();
this.resetFilterSearch();
Expand Down
2 changes: 1 addition & 1 deletion src/map-app/eventbus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export namespace EventBus {
export const selectAndZoomOnInitiative = new PostalTopic<SelectAndZoomData>("Map.selectAndZoomOnInitiative");
export const initiativeClicked = new PostalTopic<Initiative|undefined>("Map.initiativeClicked");
export const setActiveArea = new PostalTopic<ActiveArea>("Map.setActiveArea");
export const resetSearch = new PostalTopic("Map.resetSearch");
export const clearFiltersAndSearch = new PostalTopic("Map.clearFiltersAndSearch");
}
export namespace Marker {
export const selectionToggled = new PostalTopic<Initiative>("Marker.SelectionToggled");
Expand Down

0 comments on commit a846e47

Please sign in to comment.