-
Notifications
You must be signed in to change notification settings - Fork 6
feat(work-items): add query editor for SystemLink Work Items data source #735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shivanshu-ni
merged 38 commits into
main
from
users/shivanshu/feat/workitem-query-editor
Sep 2, 2026
Merged
Changes from 23 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
bdcb741
Feat(work-items): Initial Boilerplate
shivanshu-ni 769e5fb
Added workitems in example.yaml
shivanshu-ni a3b89df
feat(work-items): add SystemLink Work Items datasource configuration …
shivanshu-ni e28b279
feat(work-items): enhance WorkItemsDataSource and QueryEditor with de…
shivanshu-ni f287de3
feat(work-items): update datasource connection method to use POST for…
shivanshu-ni bb25723
refactor(work-items): remove unused WorkItemsConfigEditor and clean u…
shivanshu-ni fa68b82
refactor(work-items): remove Work Items datasource configuration from…
shivanshu-ni cd898db
Merge branch 'users/shivanshu/feat/workitem-initial' of https://githu…
shivanshu-ni efbfdfc
feat(work-items): refactor query editor and data source logic, add co…
shivanshu-ni ed599a2
feat(work-items): update take value handling in query editor and data…
shivanshu-ni ea014e8
feat(work-items): implement take value normalization and validation i…
shivanshu-ni 7b0dd78
feat(work-items): enhance take value handling in query editor and dat…
shivanshu-ni 08a6d2f
feat(docs): add README for SystemLink Work Items Data Source plugin
shivanshu-ni 15cdb5f
feat(work-items): add initial README for SystemLink Work Items dataso…
shivanshu-ni 29587bd
refactor(work-items): simplify WorkItemsDataSource and update query e…
shivanshu-ni 10b0041
Merge branch 'users/shivanshu/feat/workitem-initial' of https://githu…
shivanshu-ni 51cf0bf
refactor(work-items): remove unused import from WorkItemsDataSource
shivanshu-ni 32294b0
refactor(work-items): extract query editor labels into constants file
shivanshu-ni 20bbb26
Merge branch 'main' of https://github.com/ni/systemlink-grafana-plugi…
shivanshu-ni 7c79ab4
refactor(tests): consolidate imports in WorkItemsQueryEditor test file
shivanshu-ni 91938ef
feat(work-items): add properties selection to WorkItemsQueryEditor an…
shivanshu-ni 1b41eb9
fix(work-items): disambiguate Properties label lookup in query editor…
shivanshu-ni e7494ab
Add work-items acceptance test placeholder
Copilot 7c05a1a
fix(work-items): address review feedback
shivanshu-ni f8c782e
fix(work-items): enhance WorkItemsQueryEditor with validation and que…
shivanshu-ni 713f5e7
fix(work-items): Group order by and decending in one group
shivanshu-ni 9f11b72
fix(work-items): replace hardcoded take value with DEFAULT_TAKE const…
shivanshu-ni d05b387
feat(work-items): update default query properties (#738)
shivanshu-ni d0afbcb
fix(work-items): streamline WorkItemsQueryEditor layout and remove un…
shivanshu-ni 785eea3
Merge branch 'users/shivanshu/feat/workitem-query-editor' of https://…
shivanshu-ni 11f8c61
fix(tests): adjust offsetHeight mock and enhance properties output va…
shivanshu-ni 7023866
fix(tests): update userEvent usage in WorkItemsQueryEditor tests for …
shivanshu-ni 45adbd1
fix(tests): remove unnecessary typing in WorkItemsQueryEditor test fo…
shivanshu-ni 3c0f23d
fix(tests): simplify user interactions in WorkItemsQueryEditor tests …
shivanshu-ni f6c46f4
fix(tests): update WorkItemsQueryEditor tests to use new combobox and…
shivanshu-ni 85d20e8
fix(tests): update WorkItemsQueryEditor and WorkItemsDataSource tests…
shivanshu-ni f3b6a9d
fix(tests): enhance WorkItemsQueryEditor and WorkItemsDataSource test…
richie-ni c172b1a
fix: update query handling in WorkItemsQueryEditor for improved valid…
shivanshu-ni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # SystemLink Work Items data source | ||
| # SystemLink Work Items Data Source | ||
|
|
||
| This is a plugin for Work Items from the Work item service. It allows you to: | ||
| This is a plugin for Work Items from the Work Items service. It allows you to: | ||
|
|
||
| - Visualize work items metadata and count on a dashboard | ||
| - Visualize work item metadata and its count on a dashboard | ||
|
shivanshu-ni marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,94 @@ | ||
| import { WorkItemsDataSource } from './WorkItemsDataSource'; | ||
| import { setupDataSource } from 'test/fixtures'; | ||
| import { OrderByOptions, OutputType, WorkItemPropertiesOptions, WorkItemTypeOptions } from './types'; | ||
| import { TAKE_LIMIT } from './constants/QueryEditor.constants'; | ||
|
|
||
| describe('WorkItemsDataSource', () => { | ||
| it('returns an empty placeholder frame', async () => { | ||
| const [datasource] = setupDataSource(WorkItemsDataSource); | ||
| it('applies expected default query values', () => { | ||
| const [ds] = setupDataSource(WorkItemsDataSource); | ||
|
|
||
| const result = await datasource.runQuery({ refId: 'A' }, { scopedVars: {} } as any); | ||
| const query = ds.prepareQuery({ refId: 'A' }); | ||
|
|
||
| expect(query.outputType).toBe(OutputType.Properties); | ||
| expect(query.types).toEqual([WorkItemTypeOptions.All]); | ||
| expect(query.properties).toEqual([ | ||
| WorkItemPropertiesOptions.ID, | ||
| WorkItemPropertiesOptions.NAME, | ||
| WorkItemPropertiesOptions.TYPE, | ||
| WorkItemPropertiesOptions.STATE, | ||
| WorkItemPropertiesOptions.WORKSPACE, | ||
| ]); | ||
| expect(query.orderBy).toBe(OrderByOptions.UPDATED_AT); | ||
| expect(query.descending).toBe(true); | ||
| expect(query.take).toBe(1000); | ||
| }); | ||
|
|
||
| it('normalizes invalid types and defaults out-of-range take values', () => { | ||
| const [ds] = setupDataSource(WorkItemsDataSource); | ||
|
shivanshu-ni marked this conversation as resolved.
Outdated
|
||
|
|
||
| const invalidTakeQuery = ds.prepareQuery({ | ||
| refId: 'A', | ||
| types: [], | ||
| take: 12000, | ||
| }); | ||
|
|
||
|
shivanshu-ni marked this conversation as resolved.
Outdated
|
||
| const maxTakeQuery = ds.prepareQuery({ | ||
| refId: 'A', | ||
| take: TAKE_LIMIT, | ||
| }); | ||
|
|
||
| expect(invalidTakeQuery.types).toEqual([WorkItemTypeOptions.All]); | ||
| expect(invalidTakeQuery.take).toBe(1000); | ||
| expect(maxTakeQuery.take).toBe(TAKE_LIMIT); | ||
| }); | ||
|
|
||
| it('preserves an explicit empty properties selection instead of resetting to defaults', () => { | ||
| const [ds] = setupDataSource(WorkItemsDataSource); | ||
|
|
||
| const emptyPropertiesQuery = ds.prepareQuery({ refId: 'A', properties: [] }); | ||
| const customPropertiesQuery = ds.prepareQuery({ | ||
| refId: 'A', | ||
| properties: [WorkItemPropertiesOptions.ASSET_NAME], | ||
| }); | ||
| const undefinedPropertiesQuery = ds.prepareQuery({ refId: 'A' }); | ||
|
|
||
| expect(emptyPropertiesQuery.properties).toEqual([]); | ||
| expect(ds.isPropertiesValid(emptyPropertiesQuery.properties)).toBe(false); | ||
| expect(customPropertiesQuery.properties).toEqual([WorkItemPropertiesOptions.ASSET_NAME]); | ||
| expect(undefinedPropertiesQuery.properties).toEqual(ds.defaultQuery.properties); | ||
| }); | ||
|
|
||
| it('defaults take when it is negative or not finite', () => { | ||
| const [ds] = setupDataSource(WorkItemsDataSource); | ||
|
|
||
| const negativeTakeQuery = ds.prepareQuery({ refId: 'A', take: -1 }); | ||
| const nanTakeQuery = ds.prepareQuery({ refId: 'A', take: Number.NaN }); | ||
|
|
||
| expect(negativeTakeQuery.take).toBe(1000); | ||
| expect(nanTakeQuery.take).toBe(1000); | ||
| }); | ||
|
|
||
| it('returns a placeholder frame', async () => { | ||
| const [ds] = setupDataSource(WorkItemsDataSource); | ||
|
|
||
| const result = await ds.runQuery({ refId: 'A' }, { scopedVars: {} } as any); | ||
| expect(result).toEqual({ refId: 'A', name: 'A', fields: [] }); | ||
| }); | ||
|
shivanshu-ni marked this conversation as resolved.
Outdated
|
||
|
|
||
| it('tests datasource connection against the work-items service endpoint', async () => { | ||
| const [datasource] = setupDataSource(WorkItemsDataSource); | ||
| const postSpy = jest.spyOn(datasource, 'post').mockResolvedValue({} as any); | ||
| const [ds] = setupDataSource(WorkItemsDataSource); | ||
|
shivanshu-ni marked this conversation as resolved.
Outdated
|
||
| const postSpy = jest.spyOn(ds, 'post').mockResolvedValue({} as any); | ||
|
|
||
| const result = await datasource.testDatasource(); | ||
| const result = await ds.testDatasource(); | ||
|
|
||
| expect(postSpy).toHaveBeenCalledWith( | ||
| '/niworkitem/v1/query-workitems', | ||
| { take: 1 }, | ||
| { showErrorAlert: false } | ||
| ); | ||
| expect(postSpy).toHaveBeenCalledWith('/niworkitem/v1/query-workitems', { take: 1 }); | ||
| expect(result.status).toBe('success'); | ||
| }); | ||
|
|
||
| it('bubbles up exception when datasource connectivity check fails', async () => { | ||
| const [ds] = setupDataSource(WorkItemsDataSource); | ||
| jest.spyOn(ds, 'post').mockRejectedValue(new Error('Failed')); | ||
|
|
||
| await expect(ds.testDatasource()).rejects.toThrow('Failed'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 73 additions & 3 deletions
76
src/datasources/work-items/components/WorkItemsQueryEditor.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,84 @@ | ||
| import { screen } from '@testing-library/react'; | ||
| import { fireEvent, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { setupRenderer } from 'test/fixtures'; | ||
| import { labels, propertiesErrorMessages, takeErrorMessages } from '../constants/QueryEditor.constants'; | ||
| import { WorkItemsDataSource } from '../WorkItemsDataSource'; | ||
| import { OutputType, WorkItemPropertiesOptions } from '../types'; | ||
| import { WorkItemsQueryEditor } from './WorkItemsQueryEditor'; | ||
|
|
||
| describe('WorkItemsQueryEditor', () => { | ||
| it('shows placeholder message', () => { | ||
| it('renders controls', () => { | ||
| const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource); | ||
|
|
||
| render({}); | ||
|
|
||
| expect(screen.getByText('Work Items datasource query controls will be added in follow-up stories.')).toBeInTheDocument(); | ||
| expect(screen.getByRole('radio', { name: OutputType.Properties })).toBeTruthy(); | ||
| expect(screen.getByRole('radio', { name: OutputType.TotalCount })).toBeTruthy(); | ||
| expect(screen.getByText(labels.types)).toBeTruthy(); | ||
| expect(screen.getAllByText(labels.properties)[1]).toBeTruthy(); | ||
| expect(screen.getByText(labels.orderBy)).toBeTruthy(); | ||
| expect(screen.getByText(labels.descending)).toBeTruthy(); | ||
| expect(screen.getByText(labels.take)).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('hides properties-only controls for total count output', async () => { | ||
| const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource); | ||
|
|
||
| render({}); | ||
| await userEvent.click(screen.getByRole('radio', { name: OutputType.TotalCount })); | ||
|
|
||
| expect(screen.getAllByText(labels.properties)).toHaveLength(1); | ||
| expect(screen.queryByText(labels.orderBy)).toBeNull(); | ||
| expect(screen.queryByText(labels.descending)).toBeNull(); | ||
| expect(screen.queryByText(labels.take)).toBeNull(); | ||
| }); | ||
|
|
||
| it('renders default selected properties for properties output', () => { | ||
| const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource); | ||
|
|
||
| render({}); | ||
|
|
||
| expect(screen.getByText('Work item ID')).toBeTruthy(); | ||
|
shivanshu-ni marked this conversation as resolved.
Outdated
|
||
| expect(screen.getAllByText(labels.properties)[1]).toBeTruthy(); | ||
|
shivanshu-ni marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
|
||
| it('shows properties validation error when all properties are removed, and clears it (without restoring defaults) when a property is re-added', async () => { | ||
| const offsetHeightSpy = jest.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(30); | ||
|
|
||
| try { | ||
| const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource); | ||
| const [onChange] = render({ properties: [WorkItemPropertiesOptions.ID] }); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', { name: 'Remove Work item ID' })); | ||
|
|
||
| expect(screen.getByText(propertiesErrorMessages.atLeastOneRequired)).toBeTruthy(); | ||
| expect(onChange).toHaveBeenLastCalledWith(expect.objectContaining({ properties: [] })); | ||
|
|
||
| const propertiesCombobox = screen.getAllByRole('combobox')[1]; | ||
| await userEvent.click(propertiesCombobox); | ||
| await userEvent.type(propertiesCombobox, 'Work item name'); | ||
| await userEvent.click(await screen.findByRole('option', { name: 'Work item name' })); | ||
|
|
||
| expect(screen.queryByText(propertiesErrorMessages.atLeastOneRequired)).toBeNull(); | ||
| expect(onChange).toHaveBeenLastCalledWith( | ||
| expect.objectContaining({ properties: [WorkItemPropertiesOptions.NAME] }) | ||
| ); | ||
| } finally { | ||
| offsetHeightSpy.mockRestore(); | ||
| } | ||
| }); | ||
|
|
||
| it('shows take validation error and suppresses query execution for invalid take input', () => { | ||
| const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource); | ||
|
|
||
| const [onChange, onRunQuery] = render({}); | ||
| const takeInput = screen.getByRole('spinbutton'); | ||
|
|
||
| fireEvent.change(takeInput, { target: { value: '-5' } }); | ||
| fireEvent.blur(takeInput); | ||
|
|
||
| expect(screen.getByText(takeErrorMessages.greaterOrEqualToZero)).toBeTruthy(); | ||
| expect(onChange).not.toHaveBeenCalled(); | ||
| expect(onRunQuery).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.