From 91f4c5a01bb642c6acf39c4efa6aab870e1dc12b Mon Sep 17 00:00:00 2001 From: I558191 Date: Tue, 18 Jun 2024 13:58:45 +0200 Subject: [PATCH 1/5] Feat: Add updated_at field to issues (#313) (#315) Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> --- pkg/github/issues.go | 3 +++ pkg/github/issues_test.go | 9 +++++++ pkg/github/testdata/issues.golden.jsonc | 32 +++++++++++++++++-------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/pkg/github/issues.go b/pkg/github/issues.go index 08a142be..32963dcc 100644 --- a/pkg/github/issues.go +++ b/pkg/github/issues.go @@ -18,6 +18,7 @@ type Issue struct { Title string ClosedAt githubv4.DateTime CreatedAt githubv4.DateTime + UpdatedAt githubv4.DateTime Closed bool Author struct { models.User `graphql:"... on User"` @@ -40,6 +41,7 @@ func (c Issues) Frames() data.Frames { data.NewField("closed", nil, []bool{}), data.NewField("created_at", nil, []time.Time{}), data.NewField("closed_at", nil, []*time.Time{}), + data.NewField("updated_at", nil, []time.Time{}), ) for _, v := range c { @@ -58,6 +60,7 @@ func (c Issues) Frames() data.Frames { v.Closed, v.CreatedAt.Time, closedAt, + v.UpdatedAt.Time, ) } diff --git a/pkg/github/issues_test.go b/pkg/github/issues_test.go index 29fb9c44..8ed9cbbb 100644 --- a/pkg/github/issues_test.go +++ b/pkg/github/issues_test.go @@ -49,6 +49,9 @@ func TestIssuesDataframe(t *testing.T) { CreatedAt: githubv4.DateTime{ Time: createdAt, }, + UpdatedAt: githubv4.DateTime{ + Time: createdAt, + }, Closed: false, Author: struct { models.User "graphql:\"... on User\"" @@ -87,6 +90,9 @@ func TestIssuesDataframe(t *testing.T) { CreatedAt: githubv4.DateTime{ Time: createdAt, }, + UpdatedAt: githubv4.DateTime{ + Time: createdAt.Add(time.Hour * 6), + }, Closed: true, Author: struct { models.User "graphql:\"... on User\"" @@ -125,6 +131,9 @@ func TestIssuesDataframe(t *testing.T) { CreatedAt: githubv4.DateTime{ Time: createdAt, }, + UpdatedAt: githubv4.DateTime{ + Time: createdAt, + }, Closed: false, Author: struct { models.User "graphql:\"... on User\"" diff --git a/pkg/github/testdata/issues.golden.jsonc b/pkg/github/testdata/issues.golden.jsonc index df150a07..283eed3e 100644 --- a/pkg/github/testdata/issues.golden.jsonc +++ b/pkg/github/testdata/issues.golden.jsonc @@ -2,16 +2,16 @@ // // Frame[0] // Name: issues -// Dimensions: 8 Fields by 3 Rows -// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+ -// | Name: title | Name: author | Name: author_company | Name: repo | Name: number | Name: closed | Name: created_at | Name: closed_at | -// | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | -// | Type: []string | Type: []string | Type: []string | Type: []string | Type: []int64 | Type: []bool | Type: []time.Time | Type: []*time.Time | -// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+ -// | Issue #1 | firstUser | ACME Corp | grafana/grafana | 1 | false | 2020-08-25 16:21:56 +0000 +0000 | null | -// | Issue #2 | secondUser | ACME Corp | grafana/grafana | 2 | true | 2020-08-25 16:21:56 +0000 +0000 | 2020-08-25 22:21:56 +0000 +0000 | -// | Issue #3 | firstUser | ACME Corp | grafana/grafana | 3 | false | 2020-08-25 16:21:56 +0000 +0000 | null | -// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+ +// Dimensions: 9 Fields by 3 Rows +// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+---------------------------------+ +// | Name: title | Name: author | Name: author_company | Name: repo | Name: number | Name: closed | Name: created_at | Name: closed_at | Name: updated_at | +// | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | +// | Type: []string | Type: []string | Type: []string | Type: []string | Type: []int64 | Type: []bool | Type: []time.Time | Type: []*time.Time | Type: []time.Time | +// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+---------------------------------+ +// | Issue #1 | firstUser | ACME Corp | grafana/grafana | 1 | false | 2020-08-25 16:21:56 +0000 +0000 | null | 2020-08-25 16:21:56 +0000 +0000 | +// | Issue #2 | secondUser | ACME Corp | grafana/grafana | 2 | true | 2020-08-25 16:21:56 +0000 +0000 | 2020-08-25 22:21:56 +0000 +0000 | 2020-08-25 22:21:56 +0000 +0000 | +// | Issue #3 | firstUser | ACME Corp | grafana/grafana | 3 | false | 2020-08-25 16:21:56 +0000 +0000 | null | 2020-08-25 16:21:56 +0000 +0000 | +// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+---------------------------------+ // // // 🌟 This was machine generated. Do not edit. 🌟 @@ -78,6 +78,13 @@ "frame": "time.Time", "nullable": true } + }, + { + "name": "updated_at", + "type": "time", + "typeInfo": { + "frame": "time.Time" + } } ] }, @@ -122,6 +129,11 @@ null, 1598394116000, null + ], + [ + 1598372516000, + 1598394116000, + 1598372516000 ] ] } From e8bbb6ab822c1a820c9704b1c647733674337d4d Mon Sep 17 00:00:00 2001 From: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Date: Tue, 18 Jun 2024 15:10:36 +0200 Subject: [PATCH 2/5] Feature: Add UpdatedAt time field for Issues query (#321) --- pkg/models/issues.go | 4 +++- src/components/selectors.ts | 3 +++ src/types.ts | 1 + src/views/QueryEditorIssues.test.tsx | 19 +++++++++++++++++++ src/views/QueryEditorIssues.tsx | 2 ++ 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/views/QueryEditorIssues.test.tsx diff --git a/pkg/models/issues.go b/pkg/models/issues.go index daa2cdbf..17ec4374 100644 --- a/pkg/models/issues.go +++ b/pkg/models/issues.go @@ -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 diff --git a/src/components/selectors.ts b/src/components/selectors.ts index 5f46eba3..efc6ec74 100644 --- a/src/components/selectors.ts +++ b/src/components/selectors.ts @@ -23,6 +23,9 @@ export const components = { Number: { input: 'Query editor number', }, + Issues: { + timeFieldInput: 'Query editor issues time field', + }, }, AnnotationEditor: { container: 'Annotation editor container', diff --git a/src/types.ts b/src/types.ts index c7420653..1ed57114 100644 --- a/src/types.ts +++ b/src/types.ts @@ -66,6 +66,7 @@ export enum PullRequestTimeField { export enum IssueTimeField { CreatedAt, ClosedAt, + UpdatedAt, } export enum WorkflowsTimeField { diff --git a/src/views/QueryEditorIssues.test.tsx b/src/views/QueryEditorIssues.test.tsx new file mode 100644 index 00000000..a60884dc --- /dev/null +++ b/src/views/QueryEditorIssues.test.tsx @@ -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(); + 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(); + }); +}); diff --git a/src/views/QueryEditorIssues.tsx b/src/views/QueryEditorIssues.tsx index bb7d8ded..822cfc0b 100644 --- a/src/views/QueryEditorIssues.tsx +++ b/src/views/QueryEditorIssues.tsx @@ -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; @@ -58,6 +59,7 @@ const QueryEditorIssues = (props: Props) => { tooltip="The time field to filter on the time range" > setQuery(el.currentTarget.value)} - onBlur={(el) => props.onChange({ ...props, query: el.currentTarget.value })} - /> - - - ); -}; +import React from 'react'; +const QueryEditorVulnerabilities = () => <>; export default QueryEditorVulnerabilities;