|
| 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 |
| 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