Skip to content

Commit c71ad35

Browse files
committed
feat(PR Reviews): query editor
1 parent 614a07a commit c71ad35

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

Diff for: src/types/query.ts

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface RepositoryOptions {
1010
export interface GitHubQuery extends Indexable, DataQuery, RepositoryOptions {
1111
options?:
1212
| PullRequestsOptions
13+
| PullRequestReviewsOptions
1314
| ReleasesOptions
1415
| LabelsOptions
1516
| TagsOptions
@@ -40,6 +41,11 @@ export interface PullRequestsOptions extends Indexable {
4041
query?: string;
4142
}
4243

44+
export interface PullRequestReviewsOptions extends Indexable {
45+
timeField?: PullRequestTimeField;
46+
query?: string;
47+
}
48+
4349
export interface CommitsOptions extends Indexable {
4450
gitRef?: string;
4551
}

Diff for: src/views/QueryEditor.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import QueryEditorCommits from './QueryEditorCommits';
1212
import QueryEditorIssues from './QueryEditorIssues';
1313
import QueryEditorMilestones from './QueryEditorMilestones';
1414
import QueryEditorPullRequests from './QueryEditorPullRequests';
15+
import QueryEditorPullRequestReviews from './QueryEditorPullRequestReviews';
1516
import QueryEditorTags from './QueryEditorTags';
1617
import QueryEditorContributors from './QueryEditorContributors';
1718
import QueryEditorLabels from './QueryEditorLabels';
@@ -78,6 +79,11 @@ const queryEditors: {
7879
<QueryEditorPullRequests {...(props.query.options || {})} onChange={onChange} />
7980
),
8081
},
82+
[QueryType.Pull_Request_Reviews]: {
83+
component: (props: Props, onChange: (val: any) => void) => (
84+
<QueryEditorPullRequestReviews {...(props.query.options || {})} onChange={onChange} />
85+
),
86+
},
8187
[QueryType.Vulnerabilities]: {
8288
component: (props: Props, onChange: (val: any) => void) => (
8389
<QueryEditorVulnerabilities {...(props.query.options || {})} />

Diff for: src/views/QueryEditorPullRequestReviews.tsx

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import React, { useState } from 'react';
2+
import { Input, Select, InlineField } from '@grafana/ui';
3+
import { SelectableValue } from '@grafana/data';
4+
import { RightColumnWidth, LeftColumnWidth } from './QueryEditor';
5+
import { PullRequestTimeField } from '../constants';
6+
import type { PullRequestReviewsOptions } from '../types/query';
7+
8+
interface Props extends PullRequestReviewsOptions {
9+
onChange: (value: PullRequestReviewsOptions) => void;
10+
}
11+
12+
const timeFieldOptions: Array<SelectableValue<PullRequestTimeField>> = Object.keys(PullRequestTimeField)
13+
.filter((_, i) => PullRequestTimeField[i] !== undefined)
14+
.map((_, i) => {
15+
return {
16+
label: `${PullRequestTimeField[i]}`,
17+
value: i as PullRequestTimeField,
18+
};
19+
});
20+
21+
const defaultTimeField = timeFieldOptions[0].value;
22+
23+
const QueryEditorPullRequestReviews = (props: Props) => {
24+
const [query, setQuery] = useState<string>(props.query || '');
25+
return (
26+
<>
27+
<InlineField
28+
labelWidth={LeftColumnWidth * 2}
29+
label="Query"
30+
tooltip={() => (
31+
<>
32+
For more information, visit&nbsp;
33+
<a
34+
href="https://docs.github.com/en/github/searching-for-information-on-github/searching-issues-and-pull-requests"
35+
target="_blank"
36+
rel="noreferrer"
37+
>
38+
https://docs.github.com/en/github/searching-for-information-on-github/searching-issues-and-pull-requests
39+
</a>
40+
</>
41+
)}
42+
interactive={true}
43+
>
44+
<Input
45+
value={query}
46+
width={RightColumnWidth}
47+
onChange={(el) => setQuery(el.currentTarget.value)}
48+
onBlur={(el) =>
49+
props.onChange({
50+
...props,
51+
query: el.currentTarget.value,
52+
})
53+
}
54+
/>
55+
</InlineField>
56+
<InlineField
57+
labelWidth={LeftColumnWidth * 2}
58+
label="Time Field"
59+
tooltip="The time field to filter on the time range. WARNING: If selecting 'None', be mindful of the amount of data being queried. On larger repositories, querying all pull requests could easily cause rate limiting"
60+
>
61+
<Select
62+
width={RightColumnWidth}
63+
options={timeFieldOptions}
64+
value={props.timeField || defaultTimeField}
65+
onChange={(opt) =>
66+
props.onChange({
67+
...props,
68+
timeField: opt.value,
69+
})
70+
}
71+
/>
72+
</InlineField>
73+
</>
74+
);
75+
};
76+
77+
export default QueryEditorPullRequestReviews;

0 commit comments

Comments
 (0)