This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 831
Allows search to recognize full room links #8275
Merged
artcodespace
merged 33 commits into
matrix-org:develop
from
bolu-tife:fix/matrix-link-search
May 9, 2023
Merged
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
97bcf1d
fix matrix search link
bolu-tife 604a6ed
fix matrix search link
bolu-tife 9ba6051
fix: allow full link search
bolu-tife 9d10d95
fix: allow full link search on new search feature
bolu-tife 85c9d66
improve transformSearchTerm function
bolu-tife 225bcab
improve transformSearchTerm function
bolu-tife b0f2b91
Merge branch 'develop' into fix/matrix-link-search
bolu-tife 4c6e4c0
add review changes
bolu-tife bef2ac5
Signed-off-by: Boluwatife Omosowon <boluomosowon@gmail.com>
bolu-tife a33c486
Merge branch 'develop' into fix/matrix-link-search
bolu-tife 1dba919
add angle brackets to copyright email title
bolu-tife c26fbf2
removed extra space
bolu-tife bd46c1e
merged develop into branch
3adaca0
Update src/utils/SearchInput.ts
bolu-tife 201679f
Merge branch 'fix/matrix-link-search' of https://github.com/bolu-tife…
2dfea11
fixed spolight dialog search for room and user links
23b9f10
added tests for transformSearchTerm
897a099
removed transformSearchTerm from room search bar
db0a434
Merge branch 'develop' into fix/matrix-link-search
bolu-tife 2380985
Merge branch 'matrix-org:develop' into fix/matrix-link-search
bolu-tife 9877e29
replaces two test cases to one that should return the primaryEntityId…
818fe72
Merge branch 'develop' into fix/matrix-link-search
bolu-tife 67da64d
Merge branch 'develop' into fix/matrix-link-search
bolu-tife a8364e6
corrected ts issues
49fcb95
Merge branch 'fix/matrix-link-search' of https://github.com/bolu-tife…
d63b7e8
Merge branch 'develop' into fix/matrix-link-search
bolu-tife f42aea9
changed type of transformSearchTerm to string
a973adf
changed return value from empty string to the original search term if…
89d7636
changed return value from empty string to the original search term if…
377fd93
refactored transformSearchTerm and added a new test case
bd055d5
rewrote transformSearchTerm doc
682d3f8
changed mocked return values of test case - should return the origina…
825e1ce
lint corrections
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Copyright 2023 Boluwatife Omosowon <boluomosowon@gmail.com> | ||
|
||
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 ?? ""; | ||
return searchTerm; | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Copyright 2023 Boluwatife Omosowon <boluomosowon@gmail.com> | ||
|
||
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); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you suggest i return an empty string or the original search term in cases where the parseLink.primaryEntityId is null? My solution returns an empty string. I can always change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the description in the comments, it seems to make sense to me to return the
searchTerm
if theparseLink.primaryEntityId
is null, so I think you could do something like:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated my pr to reflect this. Do I need to account for this scenario as a test case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point - a test to check that when
parseLink.primaryEntityId
returns null, we get the original searchTerm back would be a good addition.