Skip to content
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
bdcb741
Feat(work-items): Initial Boilerplate
shivanshu-ni Aug 12, 2026
769e5fb
Added workitems in example.yaml
shivanshu-ni Aug 12, 2026
a3b89df
feat(work-items): add SystemLink Work Items datasource configuration …
shivanshu-ni Aug 12, 2026
e28b279
feat(work-items): enhance WorkItemsDataSource and QueryEditor with de…
shivanshu-ni Aug 16, 2026
f287de3
feat(work-items): update datasource connection method to use POST for…
shivanshu-ni Aug 19, 2026
bb25723
refactor(work-items): remove unused WorkItemsConfigEditor and clean u…
shivanshu-ni Aug 19, 2026
fa68b82
refactor(work-items): remove Work Items datasource configuration from…
shivanshu-ni Aug 19, 2026
cd898db
Merge branch 'users/shivanshu/feat/workitem-initial' of https://githu…
shivanshu-ni Aug 19, 2026
efbfdfc
feat(work-items): refactor query editor and data source logic, add co…
shivanshu-ni Aug 19, 2026
ed599a2
feat(work-items): update take value handling in query editor and data…
shivanshu-ni Aug 19, 2026
ea014e8
feat(work-items): implement take value normalization and validation i…
shivanshu-ni Aug 19, 2026
7b0dd78
feat(work-items): enhance take value handling in query editor and dat…
shivanshu-ni Aug 19, 2026
08a6d2f
feat(docs): add README for SystemLink Work Items Data Source plugin
shivanshu-ni Aug 20, 2026
15cdb5f
feat(work-items): add initial README for SystemLink Work Items dataso…
shivanshu-ni Aug 24, 2026
29587bd
refactor(work-items): simplify WorkItemsDataSource and update query e…
shivanshu-ni Aug 24, 2026
10b0041
Merge branch 'users/shivanshu/feat/workitem-initial' of https://githu…
shivanshu-ni Aug 24, 2026
51cf0bf
refactor(work-items): remove unused import from WorkItemsDataSource
shivanshu-ni Aug 24, 2026
32294b0
refactor(work-items): extract query editor labels into constants file
shivanshu-ni Aug 27, 2026
20bbb26
Merge branch 'main' of https://github.com/ni/systemlink-grafana-plugi…
shivanshu-ni Aug 28, 2026
7c79ab4
refactor(tests): consolidate imports in WorkItemsQueryEditor test file
shivanshu-ni Aug 28, 2026
91938ef
feat(work-items): add properties selection to WorkItemsQueryEditor an…
shivanshu-ni Aug 28, 2026
1b41eb9
fix(work-items): disambiguate Properties label lookup in query editor…
shivanshu-ni Aug 28, 2026
e7494ab
Add work-items acceptance test placeholder
Copilot Aug 28, 2026
7c05a1a
fix(work-items): address review feedback
shivanshu-ni Aug 29, 2026
f8c782e
fix(work-items): enhance WorkItemsQueryEditor with validation and que…
shivanshu-ni Aug 31, 2026
713f5e7
fix(work-items): Group order by and decending in one group
shivanshu-ni Sep 1, 2026
9f11b72
fix(work-items): replace hardcoded take value with DEFAULT_TAKE const…
shivanshu-ni Sep 1, 2026
d05b387
feat(work-items): update default query properties (#738)
shivanshu-ni Sep 2, 2026
d0afbcb
fix(work-items): streamline WorkItemsQueryEditor layout and remove un…
shivanshu-ni Sep 2, 2026
785eea3
Merge branch 'users/shivanshu/feat/workitem-query-editor' of https://…
shivanshu-ni Sep 2, 2026
11f8c61
fix(tests): adjust offsetHeight mock and enhance properties output va…
shivanshu-ni Sep 2, 2026
7023866
fix(tests): update userEvent usage in WorkItemsQueryEditor tests for …
shivanshu-ni Sep 2, 2026
45adbd1
fix(tests): remove unnecessary typing in WorkItemsQueryEditor test fo…
shivanshu-ni Sep 2, 2026
3c0f23d
fix(tests): simplify user interactions in WorkItemsQueryEditor tests …
shivanshu-ni Sep 2, 2026
f6c46f4
fix(tests): update WorkItemsQueryEditor tests to use new combobox and…
shivanshu-ni Sep 2, 2026
85d20e8
fix(tests): update WorkItemsQueryEditor and WorkItemsDataSource tests…
shivanshu-ni Sep 2, 2026
f3b6a9d
fix(tests): enhance WorkItemsQueryEditor and WorkItemsDataSource test…
richie-ni Sep 2, 2026
c172b1a
fix: update query handling in WorkItemsQueryEditor for improved valid…
shivanshu-ni Sep 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
47 changes: 39 additions & 8 deletions src/datasources/work-items/WorkItemsDataSource.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
import { WorkItemsDataSource } from './WorkItemsDataSource';
import { setupDataSource } from 'test/fixtures';
import { OrderByOptions, OutputType, WorkItemPropertiesOptions, WorkItemTypeOptions } from './types';

describe('WorkItemsDataSource', () => {
it('returns an empty placeholder frame', async () => {
it('applies expected default query values', () => {
const [datasource] = setupDataSource(WorkItemsDataSource);

const result = await datasource.runQuery({ refId: 'A' }, { scopedVars: {} } as any);
expect(result).toEqual({ refId: 'A', name: 'A', fields: [] });
const query = datasource.prepareQuery({ refId: 'A' });

expect(query.outputType).toBe(OutputType.Properties);
expect(query.types).toEqual(Object.values(WorkItemTypeOptions));
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('preserves explicit selections instead of resetting them to defaults', () => {
const [datasource] = setupDataSource(WorkItemsDataSource);

const clearedQuery = datasource.prepareQuery({
refId: 'A',
types: [],
properties: [],
take: 12000,
});

Comment thread
shivanshu-ni marked this conversation as resolved.
Outdated
expect(clearedQuery.types).toEqual([]);
expect(clearedQuery.properties).toEqual([]);
expect(clearedQuery.take).toBe(12000);
});

it('tests datasource connection against the work-items service endpoint', async () => {
Expand All @@ -15,11 +43,14 @@ describe('WorkItemsDataSource', () => {

const result = await datasource.testDatasource();

expect(postSpy).toHaveBeenCalledWith(
'/niworkitem/v1/query-workitems',
{ take: 1 },
{ showErrorAlert: false }
);
expect(postSpy).toHaveBeenCalledWith('/niworkitem/v1/query-workitems', { take: 1 }, { showErrorAlert: false });
expect(result.status).toBe('success');
});

it('bubbles up exception when datasource connectivity check fails', async () => {
const [datasource] = setupDataSource(WorkItemsDataSource);
jest.spyOn(datasource, 'post').mockRejectedValue(new Error('Failed'));

await expect(datasource.testDatasource()).rejects.toThrow('Failed');
});
});
29 changes: 27 additions & 2 deletions src/datasources/work-items/WorkItemsDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ import {
} from '@grafana/data';
import { BackendSrv, TemplateSrv, getBackendSrv, getTemplateSrv } from '@grafana/runtime';
import { DataSourceBase } from 'core/DataSourceBase';
import { WorkItemsQuery } from './types';
import { QueryBuilderOption } from 'core/types';
import {
OrderByOptions,
OutputType,
WorkItemPropertiesOptions,
WorkItemsQuery,
WorkItemTypeOptions,
} from './types';
import { DEFAULT_TAKE } from './constants';

export class WorkItemsDataSource extends DataSourceBase<WorkItemsQuery> {
constructor(
Expand All @@ -20,8 +28,25 @@ export class WorkItemsDataSource extends DataSourceBase<WorkItemsQuery> {
baseUrl = `${this.instanceSettings.url}/niworkitem/v1`;
queryWorkItemsUrl = `${this.baseUrl}/query-workitems`;

defaultQuery = {};
defaultQuery = {
outputType: OutputType.Properties,
types: Object.values(WorkItemTypeOptions),
Comment thread
richie-ni marked this conversation as resolved.
properties: [
WorkItemPropertiesOptions.ID,
WorkItemPropertiesOptions.NAME,
WorkItemPropertiesOptions.TYPE,
WorkItemPropertiesOptions.STATE,
WorkItemPropertiesOptions.WORKSPACE,
Comment thread
shivanshu-ni marked this conversation as resolved.
Outdated
],
orderBy: OrderByOptions.UPDATED_AT,
descending: true,
take: DEFAULT_TAKE,
};

// TODO: AB#3923375 - Dummy Query By scaffolding for the query editor PR
globalVariableOptions = (): QueryBuilderOption[] => this.getVariableOptions();
Comment thread
shivanshu-ni marked this conversation as resolved.
Outdated

// TODO: AB#3923375 - Query work items and return the requested properties instead of an empty frame.
async runQuery(query: WorkItemsQuery, _options: DataQueryRequest<WorkItemsQuery>): Promise<DataFrameDTO> {
return {
Comment thread
shivanshu-ni marked this conversation as resolved.
refId: query.refId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,102 @@
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, typesErrorMessages } from '../constants/QueryEditor.constants';
import { WorkItemsDataSource } from '../WorkItemsDataSource';
import { OutputType, WorkItemPropertiesOptions, WorkItemTypeOptions } 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();
Comment thread
shivanshu-ni marked this conversation as resolved.
Outdated
expect(screen.getAllByText(labels.properties)[1]).toBeTruthy();
Comment thread
shivanshu-ni marked this conversation as resolved.
Outdated
});

describe('validation', () => {
it('shows types validation error when all types are removed instead of restoring the default selection', async () => {
Comment thread
shivanshu-ni marked this conversation as resolved.
Outdated
const offsetHeightSpy = jest.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(30);

try {
const render = setupRenderer(WorkItemsQueryEditor, WorkItemsDataSource);
const [onChange] = render({ types: [WorkItemTypeOptions.WorkOrders] });

await userEvent.click(screen.getByRole('button', { name: 'Remove Work orders' }));

expect(screen.getByText(typesErrorMessages.atLeastOneRequired)).toBeTruthy();
expect(onChange).toHaveBeenLastCalledWith(expect.objectContaining({ types: [] }));
} finally {
offsetHeightSpy.mockRestore();
}
});

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();
});
});
});
Loading
Loading