Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Allows search to recognize full room links #8275

Merged
merged 33 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
97bcf1d
fix matrix search link
bolu-tife Apr 10, 2022
604a6ed
fix matrix search link
bolu-tife Apr 10, 2022
9ba6051
fix: allow full link search
bolu-tife Apr 10, 2022
9d10d95
fix: allow full link search on new search feature
bolu-tife Apr 10, 2022
85c9d66
improve transformSearchTerm function
bolu-tife Apr 10, 2022
225bcab
improve transformSearchTerm function
bolu-tife Apr 10, 2022
b0f2b91
Merge branch 'develop' into fix/matrix-link-search
bolu-tife Apr 14, 2022
4c6e4c0
add review changes
bolu-tife Apr 15, 2022
bef2ac5
Signed-off-by: Boluwatife Omosowon <[email protected]>
bolu-tife Apr 16, 2022
a33c486
Merge branch 'develop' into fix/matrix-link-search
bolu-tife Apr 16, 2022
1dba919
add angle brackets to copyright email title
bolu-tife Apr 16, 2022
c26fbf2
removed extra space
bolu-tife Apr 17, 2022
bd46c1e
merged develop into branch
Mar 3, 2023
3adaca0
Update src/utils/SearchInput.ts
bolu-tife Mar 6, 2023
201679f
Merge branch 'fix/matrix-link-search' of https://github.com/bolu-tife…
Mar 6, 2023
2dfea11
fixed spolight dialog search for room and user links
Mar 7, 2023
23b9f10
added tests for transformSearchTerm
Mar 7, 2023
897a099
removed transformSearchTerm from room search bar
Mar 7, 2023
db0a434
Merge branch 'develop' into fix/matrix-link-search
bolu-tife Mar 7, 2023
2380985
Merge branch 'matrix-org:develop' into fix/matrix-link-search
bolu-tife Apr 21, 2023
9877e29
replaces two test cases to one that should return the primaryEntityId…
May 1, 2023
818fe72
Merge branch 'develop' into fix/matrix-link-search
bolu-tife May 1, 2023
67da64d
Merge branch 'develop' into fix/matrix-link-search
bolu-tife May 2, 2023
a8364e6
corrected ts issues
May 3, 2023
49fcb95
Merge branch 'fix/matrix-link-search' of https://github.com/bolu-tife…
May 3, 2023
d63b7e8
Merge branch 'develop' into fix/matrix-link-search
bolu-tife May 3, 2023
f42aea9
changed type of transformSearchTerm to string
May 3, 2023
a973adf
changed return value from empty string to the original search term if…
May 5, 2023
89d7636
changed return value from empty string to the original search term if…
May 5, 2023
377fd93
refactored transformSearchTerm and added a new test case
May 5, 2023
bd055d5
rewrote transformSearchTerm doc
May 5, 2023
682d3f8
changed mocked return values of test case - should return the origina…
May 5, 2023
825e1ce
lint corrections
May 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import { isLocalRoom } from "../../../../utils/localRoom/isLocalRoom";
import RoomAvatar from "../../avatars/RoomAvatar";
import { useFeatureEnabled } from "../../../../hooks/useSettings";
import { filterBoolean } from "../../../../utils/arrays";
import { transformSearchTerm } from "../../../../utils/SearchInput";

const MAX_RECENT_SEARCHES = 10;
const SECTION_LIMIT = 50; // only show 50 results per section for performance reasons
Expand Down Expand Up @@ -466,7 +467,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
const [spaceResults, spaceResultsLoading] = useSpaceResults(activeSpace ?? undefined, query);

const setQuery = (e: ChangeEvent<HTMLInputElement>): void => {
const newQuery = e.currentTarget.value;
const newQuery = transformSearchTerm(e.currentTarget.value);
_setQuery(newQuery);
};
useEffect(() => {
Expand Down
30 changes: 30 additions & 0 deletions src/utils/SearchInput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright 2023 Boluwatife Omosowon <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { parsePermalink } from "./permalinks/Permalinks";

/**
* Parse a search string and return either a room ID/alias/userId or the original search term if it does
* not look like a permalink.
* E.g https://matrix.to/#/#element-dev:matrix.org returns #element-dev:matrix.org
* @param {string} searchTerm The search term.
* @returns {string} The room ID or alias, or the original search term if it doesn't look like a permalink.
*/
export function transformSearchTerm(searchTerm: string): string {
const parseLink = parsePermalink(searchTerm);
if (parseLink) return parseLink?.primaryEntityId ?? searchTerm;
return searchTerm;
bolu-tife marked this conversation as resolved.
Show resolved Hide resolved
}
45 changes: 45 additions & 0 deletions test/utils/SearchInput-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright 2023 Boluwatife Omosowon <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { mocked } from "jest-mock";

import { parsePermalink } from "../../src/utils/permalinks/Permalinks";
import { transformSearchTerm } from "../../src/utils/SearchInput";

jest.mock("../../src/utils/permalinks/Permalinks");

describe("transforming search term", () => {
it("should return the primaryEntityId if the search term was a permalink", () => {
const roomLink = "https://matrix.to/#/#element-dev:matrix.org";
const parsedPermalink = "#element-dev:matrix.org"

mocked(parsePermalink).mockReturnValue({
primaryEntityId: parsedPermalink,
roomIdOrAlias: parsedPermalink,
eventId: "",
userId: "",
viaServers: [],
sigil: "",
});

expect(transformSearchTerm(roomLink)).toBe(parsedPermalink);
});

it("should return the original search term if the search term was not a permalink", () => {
const searchTerm = "search term";
mocked(parsePermalink).mockReturnValue(null);
expect(transformSearchTerm(searchTerm)).toBe(searchTerm);
});
});