Bring back filter all spaces behaviour
parent
a70be45b6e
commit
4079b03ae0
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { createRef } from "react";
|
import { createRef } from "react";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
|
import { Room } from "matrix-js-sdk/src/models/room";
|
||||||
|
|
||||||
import defaultDispatcher from "../../dispatcher/dispatcher";
|
import defaultDispatcher from "../../dispatcher/dispatcher";
|
||||||
import { _t } from "../../languageHandler";
|
import { _t } from "../../languageHandler";
|
||||||
|
@ -27,7 +28,7 @@ import RoomListStore from "../../stores/room-list/RoomListStore";
|
||||||
import { NameFilterCondition } from "../../stores/room-list/filters/NameFilterCondition";
|
import { NameFilterCondition } from "../../stores/room-list/filters/NameFilterCondition";
|
||||||
import { getKeyBindingsManager, RoomListAction } from "../../KeyBindingsManager";
|
import { getKeyBindingsManager, RoomListAction } from "../../KeyBindingsManager";
|
||||||
import { replaceableComponent } from "../../utils/replaceableComponent";
|
import { replaceableComponent } from "../../utils/replaceableComponent";
|
||||||
import SpaceStore, { UPDATE_SELECTED_SPACE } from "../../stores/SpaceStore";
|
import SpaceStore, { UPDATE_SELECTED_SPACE, UPDATE_TOP_LEVEL_SPACES } from "../../stores/SpaceStore";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
isMinimized: boolean;
|
isMinimized: boolean;
|
||||||
|
@ -41,6 +42,7 @@ interface IProps {
|
||||||
interface IState {
|
interface IState {
|
||||||
query: string;
|
query: string;
|
||||||
focused: boolean;
|
focused: boolean;
|
||||||
|
inSpaces: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@replaceableComponent("structures.RoomSearch")
|
@replaceableComponent("structures.RoomSearch")
|
||||||
|
@ -55,11 +57,13 @@ export default class RoomSearch extends React.PureComponent<IProps, IState> {
|
||||||
this.state = {
|
this.state = {
|
||||||
query: "",
|
query: "",
|
||||||
focused: false,
|
focused: false,
|
||||||
|
inSpaces: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.dispatcherRef = defaultDispatcher.register(this.onAction);
|
this.dispatcherRef = defaultDispatcher.register(this.onAction);
|
||||||
// clear filter when changing spaces, in future we may wish to maintain a filter per-space
|
// clear filter when changing spaces, in future we may wish to maintain a filter per-space
|
||||||
SpaceStore.instance.on(UPDATE_SELECTED_SPACE, this.clearInput);
|
SpaceStore.instance.on(UPDATE_SELECTED_SPACE, this.clearInput);
|
||||||
|
SpaceStore.instance.on(UPDATE_TOP_LEVEL_SPACES, this.onSpaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidUpdate(prevProps: Readonly<IProps>, prevState: Readonly<IState>): void {
|
public componentDidUpdate(prevProps: Readonly<IProps>, prevState: Readonly<IState>): void {
|
||||||
|
@ -80,8 +84,15 @@ export default class RoomSearch extends React.PureComponent<IProps, IState> {
|
||||||
public componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
defaultDispatcher.unregister(this.dispatcherRef);
|
defaultDispatcher.unregister(this.dispatcherRef);
|
||||||
SpaceStore.instance.off(UPDATE_SELECTED_SPACE, this.clearInput);
|
SpaceStore.instance.off(UPDATE_SELECTED_SPACE, this.clearInput);
|
||||||
|
SpaceStore.instance.off(UPDATE_TOP_LEVEL_SPACES, this.onSpaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private onSpaces = (spaces: Room[]) => {
|
||||||
|
this.setState({
|
||||||
|
inSpaces: spaces.length > 0,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
private onAction = (payload: ActionPayload) => {
|
private onAction = (payload: ActionPayload) => {
|
||||||
if (payload.action === 'view_room' && payload.clear_search) {
|
if (payload.action === 'view_room' && payload.clear_search) {
|
||||||
this.clearInput();
|
this.clearInput();
|
||||||
|
@ -153,6 +164,11 @@ export default class RoomSearch extends React.PureComponent<IProps, IState> {
|
||||||
'mx_RoomSearch_inputExpanded': this.state.query || this.state.focused,
|
'mx_RoomSearch_inputExpanded': this.state.query || this.state.focused,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let placeholder = _t("Filter");
|
||||||
|
if (this.state.inSpaces) {
|
||||||
|
placeholder = _t("Filter all spaces");
|
||||||
|
}
|
||||||
|
|
||||||
let icon = (
|
let icon = (
|
||||||
<div className='mx_RoomSearch_icon' />
|
<div className='mx_RoomSearch_icon' />
|
||||||
);
|
);
|
||||||
|
@ -166,7 +182,7 @@ export default class RoomSearch extends React.PureComponent<IProps, IState> {
|
||||||
onBlur={this.onBlur}
|
onBlur={this.onBlur}
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
onKeyDown={this.onKeyDown}
|
onKeyDown={this.onKeyDown}
|
||||||
placeholder={_t("Filter")}
|
placeholder={placeholder}
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
|
@ -19,6 +19,7 @@ import React, {useState} from "react";
|
||||||
import { _t } from "../../../languageHandler";
|
import { _t } from "../../../languageHandler";
|
||||||
import RoomListStore, { LISTS_UPDATE_EVENT } from "../../../stores/room-list/RoomListStore";
|
import RoomListStore, { LISTS_UPDATE_EVENT } from "../../../stores/room-list/RoomListStore";
|
||||||
import {useEventEmitter} from "../../../hooks/useEventEmitter";
|
import {useEventEmitter} from "../../../hooks/useEventEmitter";
|
||||||
|
import SpaceStore from "../../../stores/SpaceStore";
|
||||||
|
|
||||||
const RoomListNumResults: React.FC = () => {
|
const RoomListNumResults: React.FC = () => {
|
||||||
const [count, setCount] = useState<number>(null);
|
const [count, setCount] = useState<number>(null);
|
||||||
|
@ -34,7 +35,10 @@ const RoomListNumResults: React.FC = () => {
|
||||||
if (typeof count !== "number") return null;
|
if (typeof count !== "number") return null;
|
||||||
|
|
||||||
return <div className="mx_LeftPanel_roomListFilterCount">
|
return <div className="mx_LeftPanel_roomListFilterCount">
|
||||||
{ _t("%(count)s results", { count }) }
|
{ SpaceStore.instance.spacePanelSpaces.length
|
||||||
|
? _t("%(count)s results in all spaces", { count })
|
||||||
|
: _t("%(count)s results", { count })
|
||||||
|
}
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -601,7 +601,11 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
|
||||||
|
|
||||||
let rooms = this.matrixClient.getVisibleRooms().filter(r => VisibilityProvider.instance.isRoomVisible(r));
|
let rooms = this.matrixClient.getVisibleRooms().filter(r => VisibilityProvider.instance.isRoomVisible(r));
|
||||||
|
|
||||||
if (this.prefilterConditions.length > 0) {
|
// if spaces are enabled only consider the prefilter conditions when there are no runtime conditions
|
||||||
|
// for the search all spaces feature
|
||||||
|
if (this.prefilterConditions.length > 0
|
||||||
|
&& (!SettingsStore.getValue("feature_spaces") || !this.filterConditions.length)
|
||||||
|
) {
|
||||||
rooms = rooms.filter(r => {
|
rooms = rooms.filter(r => {
|
||||||
for (const filter of this.prefilterConditions) {
|
for (const filter of this.prefilterConditions) {
|
||||||
if (!filter.isVisible(r)) {
|
if (!filter.isVisible(r)) {
|
||||||
|
@ -660,7 +664,7 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
|
||||||
* and thus might not cause an update to the store immediately.
|
* and thus might not cause an update to the store immediately.
|
||||||
* @param {IFilterCondition} filter The filter condition to add.
|
* @param {IFilterCondition} filter The filter condition to add.
|
||||||
*/
|
*/
|
||||||
public addFilter(filter: IFilterCondition): void {
|
public async addFilter(filter: IFilterCondition): Promise<void> {
|
||||||
if (SettingsStore.getValue("advancedRoomListLogging")) {
|
if (SettingsStore.getValue("advancedRoomListLogging")) {
|
||||||
// TODO: Remove debug: https://github.com/vector-im/element-web/issues/14602
|
// TODO: Remove debug: https://github.com/vector-im/element-web/issues/14602
|
||||||
console.log("Adding filter condition:", filter);
|
console.log("Adding filter condition:", filter);
|
||||||
|
@ -672,6 +676,12 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
|
||||||
promise = this.recalculatePrefiltering();
|
promise = this.recalculatePrefiltering();
|
||||||
} else {
|
} else {
|
||||||
this.filterConditions.push(filter);
|
this.filterConditions.push(filter);
|
||||||
|
// Runtime filters with spaces disable prefiltering for the search all spaces feature
|
||||||
|
if (SettingsStore.getValue("feature_spaces")) {
|
||||||
|
// this has to be awaited so that `setKnownRooms` is called in time for the `addFilterCondition` below
|
||||||
|
// this way the runtime filters are only evaluated on one dataset and not both.
|
||||||
|
await this.recalculatePrefiltering();
|
||||||
|
}
|
||||||
if (this.algorithm) {
|
if (this.algorithm) {
|
||||||
this.algorithm.addFilterCondition(filter);
|
this.algorithm.addFilterCondition(filter);
|
||||||
}
|
}
|
||||||
|
@ -699,6 +709,10 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
|
||||||
if (this.algorithm) {
|
if (this.algorithm) {
|
||||||
this.algorithm.removeFilterCondition(filter);
|
this.algorithm.removeFilterCondition(filter);
|
||||||
}
|
}
|
||||||
|
// Runtime filters with spaces disable prefiltering for the search all spaces feature
|
||||||
|
if (SettingsStore.getValue("feature_spaces")) {
|
||||||
|
promise = this.recalculatePrefiltering();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
idx = this.prefilterConditions.indexOf(filter);
|
idx = this.prefilterConditions.indexOf(filter);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
|
|
Loading…
Reference in New Issue