mirror of https://github.com/vector-im/riot-web
Extract SearchScope and SearchInfo into Searching (#12698)
* Extract SearchScope and SearchInfo into Searching Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * delint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * delint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Comments Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>pull/28217/head
parent
7a81470558
commit
72475240ec
|
@ -681,3 +681,49 @@ export default function eventSearch(
|
|||
return eventIndexSearch(client, term, roomId, abortSignal);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The scope for a message search, either in the current room or across all rooms.
|
||||
*/
|
||||
export enum SearchScope {
|
||||
Room = "Room",
|
||||
All = "All",
|
||||
}
|
||||
|
||||
/**
|
||||
* Information about a message search in progress.
|
||||
*/
|
||||
export interface SearchInfo {
|
||||
/**
|
||||
* Opaque ID for this search.
|
||||
*/
|
||||
searchId: number;
|
||||
/**
|
||||
* The room ID being searched, or undefined if searching all rooms.
|
||||
*/
|
||||
roomId?: string;
|
||||
/**
|
||||
* The search term.
|
||||
*/
|
||||
term: string;
|
||||
/**
|
||||
* The scope of the search.
|
||||
*/
|
||||
scope: SearchScope;
|
||||
/**
|
||||
* The promise for the search results.
|
||||
*/
|
||||
promise: Promise<ISearchResults>;
|
||||
/**
|
||||
* Controller for aborting the search.
|
||||
*/
|
||||
abortController?: AbortController;
|
||||
/**
|
||||
* Whether the search is currently awaiting data from the backend.
|
||||
*/
|
||||
inProgress?: boolean;
|
||||
/**
|
||||
* The total count of matching results as returned by the backend.
|
||||
*/
|
||||
count?: number;
|
||||
}
|
||||
|
|
|
@ -24,12 +24,11 @@ import {
|
|||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import ScrollPanel from "./ScrollPanel";
|
||||
import { SearchScope } from "../views/rooms/SearchBar";
|
||||
import Spinner from "../views/elements/Spinner";
|
||||
import { _t } from "../../languageHandler";
|
||||
import { haveRendererForEvent } from "../../events/EventTileFactory";
|
||||
import SearchResultTile from "../views/rooms/SearchResultTile";
|
||||
import { searchPagination } from "../../Searching";
|
||||
import { searchPagination, SearchScope } from "../../Searching";
|
||||
import Modal from "../../Modal";
|
||||
import ErrorDialog from "../views/dialogs/ErrorDialog";
|
||||
import ResizeNotifier from "../../utils/ResizeNotifier";
|
||||
|
|
|
@ -70,10 +70,10 @@ import TimelinePanel from "./TimelinePanel";
|
|||
import ErrorBoundary from "../views/elements/ErrorBoundary";
|
||||
import RoomPreviewBar from "../views/rooms/RoomPreviewBar";
|
||||
import RoomPreviewCard from "../views/rooms/RoomPreviewCard";
|
||||
import SearchBar, { SearchScope } from "../views/rooms/SearchBar";
|
||||
import SearchBar from "../views/rooms/SearchBar";
|
||||
import RoomUpgradeWarningBar from "../views/rooms/RoomUpgradeWarningBar";
|
||||
import AuxPanel from "../views/rooms/AuxPanel";
|
||||
import LegacyRoomHeader, { ISearchInfo } from "../views/rooms/LegacyRoomHeader";
|
||||
import LegacyRoomHeader from "../views/rooms/LegacyRoomHeader";
|
||||
import RoomHeader from "../views/rooms/RoomHeader";
|
||||
import { IOOBData, IThreepidInvite } from "../../stores/ThreepidInviteStore";
|
||||
import EffectsOverlay from "../views/elements/EffectsOverlay";
|
||||
|
@ -121,7 +121,7 @@ import { SDKContext } from "../../contexts/SDKContext";
|
|||
import { CallStore, CallStoreEvent } from "../../stores/CallStore";
|
||||
import { Call } from "../../models/Call";
|
||||
import { RoomSearchView } from "./RoomSearchView";
|
||||
import eventSearch from "../../Searching";
|
||||
import eventSearch, { SearchInfo, SearchScope } from "../../Searching";
|
||||
import VoipUserMapper from "../../VoipUserMapper";
|
||||
import { isCallEvent } from "./LegacyCallEventGrouper";
|
||||
import { WidgetType } from "../../widgets/WidgetType";
|
||||
|
@ -190,7 +190,7 @@ export interface IRoomState {
|
|||
/**
|
||||
* The state of an ongoing search if there is one.
|
||||
*/
|
||||
search?: ISearchInfo;
|
||||
search?: SearchInfo;
|
||||
callState?: CallState;
|
||||
activeCall: Call | null;
|
||||
canPeek: boolean;
|
||||
|
|
|
@ -18,7 +18,7 @@ limitations under the License.
|
|||
import React, { FC, useState, useMemo, useCallback } from "react";
|
||||
import classNames from "classnames";
|
||||
import { throttle } from "lodash";
|
||||
import { RoomStateEvent, ISearchResults } from "matrix-js-sdk/src/matrix";
|
||||
import { RoomStateEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { CallType } from "matrix-js-sdk/src/webrtc/call";
|
||||
import { IconButton, Tooltip } from "@vector-im/compound-web";
|
||||
import { ViewRoomOpts } from "@matrix-org/react-sdk-module-api/lib/lifecycles/RoomViewLifecycle";
|
||||
|
@ -38,7 +38,6 @@ import RoomName from "../elements/RoomName";
|
|||
import { E2EStatus } from "../../../utils/ShieldUtils";
|
||||
import { IOOBData } from "../../../stores/ThreepidInviteStore";
|
||||
import { RoomKnocksBar } from "./RoomKnocksBar";
|
||||
import { SearchScope } from "./SearchBar";
|
||||
import { aboveLeftOf, ContextMenuTooltipButton, useContextMenu } from "../../structures/ContextMenu";
|
||||
import RoomContextMenu from "../context_menus/RoomContextMenu";
|
||||
import { contextMenuBelow } from "./RoomTile";
|
||||
|
@ -70,6 +69,7 @@ import { SessionDuration } from "../voip/CallDuration";
|
|||
import RoomCallBanner from "../beacon/RoomCallBanner";
|
||||
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
|
||||
import { UIComponent } from "../../../settings/UIFeature";
|
||||
import { SearchInfo } from "../../../Searching";
|
||||
|
||||
class DisabledWithReason {
|
||||
public constructor(public readonly reason: string) {}
|
||||
|
@ -456,18 +456,6 @@ const CallLayoutSelector: FC<CallLayoutSelectorProps> = ({ call }) => {
|
|||
);
|
||||
};
|
||||
|
||||
export interface ISearchInfo {
|
||||
searchId: number;
|
||||
roomId?: string;
|
||||
term: string;
|
||||
scope: SearchScope;
|
||||
promise: Promise<ISearchResults>;
|
||||
abortController?: AbortController;
|
||||
|
||||
inProgress?: boolean;
|
||||
count?: number;
|
||||
}
|
||||
|
||||
export interface IProps {
|
||||
room: Room;
|
||||
oobData?: IOOBData;
|
||||
|
@ -478,7 +466,7 @@ export interface IProps {
|
|||
onAppsClick: (() => void) | null;
|
||||
e2eStatus: E2EStatus;
|
||||
appsShown: boolean;
|
||||
searchInfo?: ISearchInfo;
|
||||
searchInfo?: SearchInfo;
|
||||
excludedRightPanelPhaseButtons?: Array<RightPanelPhases>;
|
||||
showButtons?: boolean;
|
||||
enableRoomOptionsMenu?: boolean;
|
||||
|
|
|
@ -24,6 +24,7 @@ import { PosthogScreenTracker } from "../../../PosthogTrackers";
|
|||
import { getKeyBindingsManager } from "../../../KeyBindingsManager";
|
||||
import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
|
||||
import SearchWarning, { WarningKind } from "../elements/SearchWarning";
|
||||
import { SearchScope } from "../../../Searching";
|
||||
|
||||
interface IProps {
|
||||
onCancelClick: () => void;
|
||||
|
@ -36,11 +37,6 @@ interface IState {
|
|||
scope: SearchScope;
|
||||
}
|
||||
|
||||
export enum SearchScope {
|
||||
Room = "Room",
|
||||
All = "All",
|
||||
}
|
||||
|
||||
export default class SearchBar extends React.Component<IProps, IState> {
|
||||
private searchTerm: RefObject<HTMLInputElement> = createRef();
|
||||
|
||||
|
|
|
@ -29,15 +29,15 @@ import {
|
|||
import { defer } from "matrix-js-sdk/src/utils";
|
||||
|
||||
import { RoomSearchView } from "../../../src/components/structures/RoomSearchView";
|
||||
import { SearchScope } from "../../../src/components/views/rooms/SearchBar";
|
||||
import ResizeNotifier from "../../../src/utils/ResizeNotifier";
|
||||
import { stubClient } from "../../test-utils";
|
||||
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
|
||||
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
|
||||
import { searchPagination } from "../../../src/Searching";
|
||||
import { searchPagination, SearchScope } from "../../../src/Searching";
|
||||
|
||||
jest.mock("../../../src/Searching", () => ({
|
||||
searchPagination: jest.fn(),
|
||||
SearchScope: jest.requireActual("../../../src/Searching").SearchScope,
|
||||
}));
|
||||
|
||||
describe("<RoomSearchView/>", () => {
|
||||
|
|
|
@ -70,7 +70,7 @@ import WidgetUtils from "../../../src/utils/WidgetUtils";
|
|||
import { WidgetType } from "../../../src/widgets/WidgetType";
|
||||
import WidgetStore from "../../../src/stores/WidgetStore";
|
||||
import { ViewRoomErrorPayload } from "../../../src/dispatcher/payloads/ViewRoomErrorPayload";
|
||||
import { SearchScope } from "../../../src/components/views/rooms/SearchBar";
|
||||
import { SearchScope } from "../../../src/Searching";
|
||||
|
||||
const RoomView = wrapInMatrixClientContext(_RoomView);
|
||||
|
||||
|
|
|
@ -51,7 +51,6 @@ import {
|
|||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
||||
import RoomHeader, { IProps as RoomHeaderProps } from "../../../../src/components/views/rooms/LegacyRoomHeader";
|
||||
import { SearchScope } from "../../../../src/components/views/rooms/SearchBar";
|
||||
import { E2EStatus } from "../../../../src/utils/ShieldUtils";
|
||||
import { IRoomState } from "../../../../src/components/structures/RoomView";
|
||||
import RoomContext from "../../../../src/contexts/RoomContext";
|
||||
|
@ -69,6 +68,7 @@ import { shouldShowComponent } from "../../../../src/customisations/helpers/UICo
|
|||
import { UIComponent } from "../../../../src/settings/UIFeature";
|
||||
import WidgetUtils from "../../../../src/utils/WidgetUtils";
|
||||
import { ElementWidgetActions } from "../../../../src/stores/widgets/ElementWidgetActions";
|
||||
import { SearchScope } from "../../../../src/Searching";
|
||||
|
||||
jest.mock("../../../../src/customisations/helpers/UIComponents", () => ({
|
||||
shouldShowComponent: jest.fn(),
|
||||
|
|
|
@ -17,8 +17,9 @@ limitations under the License.
|
|||
import React from "react";
|
||||
import { fireEvent, render } from "@testing-library/react";
|
||||
|
||||
import SearchBar, { SearchScope } from "../../../../src/components/views/rooms/SearchBar";
|
||||
import SearchBar from "../../../../src/components/views/rooms/SearchBar";
|
||||
import { KeyBindingAction } from "../../../../src/accessibility/KeyboardShortcuts";
|
||||
import { SearchScope } from "../../../../src/Searching";
|
||||
|
||||
let mockCurrentEvent = KeyBindingAction.Enter;
|
||||
|
||||
|
|
Loading…
Reference in New Issue