Skip to content

Commit

Permalink
Feature: Add UpdatedAt time field for Issues query (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanahuckova authored Jun 18, 2024
1 parent 91f4c5a commit e8bbb6a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/models/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ const (
IssueCreatedAt IssueTimeField = iota
// IssueClosedAt is used when filtering when an Issue was closed
IssueClosedAt
// IssueUpdatedAt is used when filtering when an Issue was updated (last time)
IssueUpdatedAt
)

func (d IssueTimeField) String() string {
return [...]string{"created", "closed"}[d]
return [...]string{"created", "closed", "updated"}[d]
}

// ListIssuesOptions provides options when retrieving issues
Expand Down
3 changes: 3 additions & 0 deletions src/components/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export const components = {
Number: {
input: 'Query editor number',
},
Issues: {
timeFieldInput: 'Query editor issues time field',
},
},
AnnotationEditor: {
container: 'Annotation editor container',
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export enum PullRequestTimeField {
export enum IssueTimeField {
CreatedAt,
ClosedAt,
UpdatedAt,
}

export enum WorkflowsTimeField {
Expand Down
19 changes: 19 additions & 0 deletions src/views/QueryEditorIssues.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import QueryEditorIssues from './QueryEditorIssues';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { components } from 'components/selectors';

describe('QueryEditorIssues', () => {
it('should have CreatedAt, ClosedAt and UpdatedAt time field option', async () => {
const props = {
onChange: jest.fn(),
};
render(<QueryEditorIssues {...props} />);
expect(screen.getByText('Time Field')).toBeInTheDocument();
userEvent.click(screen.getByTestId(components.QueryEditor.Issues.timeFieldInput));
expect(await screen.findByText('CreatedAt')).toBeInTheDocument();
expect(await screen.findByText('ClosedAt')).toBeInTheDocument();
expect(await screen.findByText('UpdatedAt')).toBeInTheDocument();
});
});
2 changes: 2 additions & 0 deletions src/views/QueryEditorIssues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Input, Select, InlineField } from '@grafana/ui';
import { SelectableValue } from '@grafana/data';
import { IssuesOptions, IssueTimeField } from '../types';
import { RightColumnWidth, LeftColumnWidth } from './QueryEditor';
import { components } from 'components/selectors';

interface Props extends IssuesOptions {
onChange: (value: IssuesOptions) => void;
Expand Down Expand Up @@ -58,6 +59,7 @@ const QueryEditorIssues = (props: Props) => {
tooltip="The time field to filter on the time range"
>
<Select
data-testid={components.QueryEditor.Issues.timeFieldInput}
width={RightColumnWidth}
options={timeFieldOptions}
value={props.timeField || defaultTimeField}
Expand Down

0 comments on commit e8bbb6a

Please sign in to comment.