Skip to content

Commit e30f817

Browse files
search
Change: search-ui
1 parent bc127d5 commit e30f817

File tree

11 files changed

+216
-179
lines changed

11 files changed

+216
-179
lines changed

Cargo.lock

Lines changed: 71 additions & 146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ libc = "0.2.167"
2929
regex = "1.11.2"
3030
rs_tracing = { version = "1.1.0", features = ["rs_tracing"] }
3131
serde = { version = "1.0.215", features = ["std", "derive"] }
32-
serde_json = "1.0.145"
32+
serde_json = "1.0.143"
3333
serde_yaml = "0.9.34"
3434
toml = "0.8.19"
3535
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
36-
tempfile = "3.22.0"
36+
tempfile = "3.14.0"
3737
hex = "0.4.3"
3838

3939
[workspace.dependencies.git2]
@@ -73,6 +73,6 @@ version = "0.1.41"
7373
features = ["max_level_trace", "release_max_level_trace"]
7474

7575
[workspace.dependencies.clap]
76-
version = "4.5.47"
76+
version = "4.5.45"
7777
features = ["derive", "help", "std", "usage"]
7878
default-features = false

josh-core/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ backtrace = "0.3.74"
1414
bitvec = "1.0.1"
1515
git-version = "0.3.9"
1616
git2 = { workspace = true }
17-
gix-object = "0.50.2"
17+
gix-object = "0.49.1"
1818
glob = "0.3.1"
1919
hex = { workspace = true }
2020
indoc = "2.0.5"
2121
itertools = "0.14.0"
2222
lazy_static = { workspace = true }
23-
log = "0.4.28"
23+
log = "0.4.22"
2424
percent-encoding = "2.3.1"
2525
pest = "2.7.14"
26-
pest_derive = "2.8.2"
26+
pest_derive = "2.7.14"
2727
rayon = "1.11.0"
2828
regex = { workspace = true }
2929
rs_tracing = { workspace = true }

josh-core/src/filter/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ enum Op {
156156
Subdir(std::path::PathBuf),
157157
Workspace(std::path::PathBuf),
158158

159-
Pattern(String),
159+
Glob(String),
160160
Message(String),
161161

162162
Compose(Vec<Filter>),
@@ -486,7 +486,7 @@ fn spec2(op: &Op) -> String {
486486
Op::Subdir(path) => format!(":/{}", parse::quote_if(&path.to_string_lossy())),
487487
Op::File(path) => format!("::{}", parse::quote_if(&path.to_string_lossy())),
488488
Op::Prefix(path) => format!(":prefix={}", parse::quote_if(&path.to_string_lossy())),
489-
Op::Pattern(pattern) => format!("::{}", parse::quote_if(pattern)),
489+
Op::Glob(pattern) => format!("::{}", parse::quote_if(pattern)),
490490
Op::Author(author, email) => {
491491
format!(":author={};{}", parse::quote(author), parse::quote(email))
492492
}
@@ -590,7 +590,9 @@ fn get_workspace<'a>(repo: &'a git2::Repository, tree: &'a git2::Tree<'a>, path:
590590
.id();
591591
let ws_blob = tree::get_blob(repo, tree, &ws_path);
592592

593-
if let Some(f) = WORKSPACES.lock().unwrap().get(&ws_id) {
593+
let mut workspaces = WORKSPACES.lock().unwrap();
594+
595+
if let Some(f) = workspaces.get(&ws_id) {
594596
*f
595597
} else {
596598
let f = parse::parse(&ws_blob).unwrap_or_else(|_| to_filter(Op::Empty));
@@ -600,7 +602,7 @@ fn get_workspace<'a>(repo: &'a git2::Repository, tree: &'a git2::Tree<'a>, path:
600602
} else {
601603
to_filter(Op::Empty)
602604
};
603-
WORKSPACES.lock().unwrap().insert(ws_id, f);
605+
workspaces.insert(ws_id, f);
604606
f
605607
}
606608
}
@@ -1009,7 +1011,7 @@ fn apply2<'a>(
10091011
Ok(t)
10101012
}
10111013

1012-
Op::Pattern(pattern) => {
1014+
Op::Glob(pattern) => {
10131015
let pattern = glob::Pattern::new(pattern)?;
10141016
let options = glob::MatchOptions {
10151017
case_sensitive: true,

josh-core/src/filter/opt.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,8 @@ pub fn invert(filter: Filter) -> JoshResult<Filter> {
494494
Op::Subdir(path) => Some(Op::Prefix(path)),
495495
Op::File(path) => Some(Op::File(path)),
496496
Op::Prefix(path) => Some(Op::Subdir(path)),
497-
Op::Pattern(pattern) => Some(Op::Pattern(pattern)),
497+
Op::Glob(pattern) => Some(Op::Glob(pattern)),
498498
Op::Rev(_) => Some(Op::Nop),
499-
Op::RegexReplace(_) => Some(Op::Nop),
500499
_ => None,
501500
};
502501

josh-core/src/filter/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn parse_item(pair: pest::iterators::Pair<Rule>) -> JoshResult<Op> {
7777
to_filter(make_op(&["prefix", arg])?),
7878
))
7979
} else if arg.contains('*') {
80-
Ok(Op::Pattern(arg.to_string()))
80+
Ok(Op::Glob(arg.to_string()))
8181
} else {
8282
Ok(Op::File(Path::new(arg).to_owned()))
8383
}

josh-graphql/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ lazy_static = { workspace = true }
1919
[dependencies.chrono]
2020
default-features = false
2121
features = ["alloc", "std"]
22-
version = "0.4.42"
22+
version = "0.4.38"

josh-proxy/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ tracing-opentelemetry = "0.31.0"
4040
tracing-subscriber = { workspace = true }
4141
unindent = "0.2.3"
4242
url = "2.5.4"
43-
uuid = { version = "1.18.1", features = ["v4"] }
43+
uuid = { version = "1.18.0", features = ["v4"] }
4444
josh-rpc = { path = "../josh-rpc" }
4545
tokio-util = { workspace = true }
4646
tempfile = { workspace = true }

josh-ui/src/App.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,26 @@ function Changes() {
221221
</div>
222222
}
223223

224+
function Search() {
225+
const param = useStrictGetSearchParam()
226+
227+
useTitleEffect(`Search - ${param('repo')} - Josh`)
228+
229+
return <div>
230+
<TopNav
231+
repo={param('repo')}
232+
page="search"
233+
filter={param('filter')} />
234+
235+
<SearchResults
236+
repo={param('repo')}
237+
filter={param('filter')}
238+
searchstr={param('q')}
239+
navigateCallback={useNavigateCallback()}
240+
/>
241+
</div>
242+
}
243+
224244

225245
function View() {
226246
const param = useStrictGetSearchParam()

josh-ui/src/Search.tsx

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import React from "react";
2+
import {GraphQLClient} from 'graphql-request'
3+
import {getServer} from "./Server";
4+
import {NavigateCallback, NavigateTargetType, QUERY_CHANGES} from "./Navigation";
5+
import {match} from "ts-pattern";
6+
7+
export type SearchBrowserProps = {
8+
repo: string
9+
filter: string
10+
searchstr: string
11+
rev: string
12+
navigateCallback: NavigateCallback
13+
}
14+
15+
type State = {
16+
results: SearchResult[]
17+
client: GraphQLClient
18+
}
19+
20+
export class SearchResults extends React.Component<SearchBrowserProps, State> {
21+
state: State = {
22+
results: [],
23+
client: new GraphQLClient(`${getServer()}/~/graphql/${this.props.repo}`, {
24+
mode: 'cors'
25+
}),
26+
};
27+
28+
startRequest() {
29+
this.state.client.rawRequest(QUERY_SEARCH, {
30+
searchstr: this.props.searchstr
31+
filter: this.props.filter,
32+
rev: this.props.rev
33+
}).then((d) => {
34+
const data = d.data
35+
36+
this.setState({
37+
results: data.results
38+
})
39+
})
40+
}
41+
42+
componentDidMount() {
43+
this.startRequest()
44+
}
45+
46+
componentDidUpdate(
47+
prevProps: Readonly<ChangesBrowserProps>,
48+
prevState: Readonly<State>,
49+
snapshot?: any)
50+
{
51+
if (prevProps !== this.props) {
52+
this.setState({
53+
results: [],
54+
})
55+
56+
this.startRequest()
57+
}
58+
}
59+
60+
componentWillUnmount() {
61+
// TODO cancel request?
62+
}
63+
64+
renderList(values: SearchResult[]) {
65+
66+
const navigateBrowse = (rev: string, path: string, e: React.MouseEvent<HTMLDivElement>) => {
67+
this.props.navigateCallback(NavigateTargetType.File, {
68+
repo: this.props.repo,
69+
path: path,
70+
filter: this.props.filter,
71+
rev: rev,
72+
})
73+
}
74+
75+
return values.map((ee) => {
76+
let entry = ee.commit;
77+
return <div key={entry.hash} className="commit-list-entry">
78+
<div className="changes-list-entry" >
79+
<span
80+
className="change-summary"
81+
onClick={navigateChange.bind(this, entry.original.hash)}>
82+
{entry.summary}
83+
</span>
84+
<span
85+
className="name"
86+
onClick={navigateChange.bind(this, entry.original.hash)}>
87+
{ee.name.replace("refs/heads/","")}
88+
</span>
89+
<span className="change-hash"
90+
onClick={navigateBrowse.bind(this, entry.original.hash)}>
91+
92+
{entry.hash.slice(0,6)}</span>
93+
</div>
94+
</div>
95+
96+
})
97+
}
98+
99+
render() {
100+
if (this.state.refs.length === 0) {
101+
return <div className={'history-browser-loading'}>Loading...</div>
102+
} else {
103+
return <div className={'changes-browser-list'}>
104+
{this.renderList(this.state.refs)}
105+
</div>
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)