Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ on:
jobs:
cd:
name: CD
uses: grafana/plugin-ci-workflows/.github/workflows/cd.yml@ci-cd-workflows/v4.1.0
uses: grafana/plugin-ci-workflows/.github/workflows/cd.yml@ci-cd-workflows/v5.0.0
with:
go-version: '1.25'
golangci-lint-version: '2.4.0'
branch: ${{ github.event.inputs.branch }}
environment: ${{ github.event.inputs.environment }}
docs-only: ${{ fromJSON(github.event.inputs.docs-only) }}
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ on:
jobs:
ci:
name: CI
uses: grafana/plugin-ci-workflows/.github/workflows/ci.yml@ci-cd-workflows/v4.1.0
uses: grafana/plugin-ci-workflows/.github/workflows/ci.yml@ci-cd-workflows/v5.0.0
with:
go-version: '1.25'
golangci-lint-version: '2.4.0'
plugin-version-suffix: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || '' }}
run-playwright: true
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22
24
666 changes: 333 additions & 333 deletions .yarn/releases/yarn-4.9.3.cjs → .yarn/releases/yarn-4.12.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.9.3.cjs
yarnPath: .yarn/releases/yarn-4.12.0.cjs
127 changes: 60 additions & 67 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,81 +20,74 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@emotion/css": "11.10.6",
"@grafana/data": "^12.2.0",
"@grafana/i18n": "^12.2.0",
"@grafana/plugin-ui": "^0.10.9",
"@grafana/runtime": "^12.2.0",
"@grafana/schema": "^12.2.0",
"@grafana/ui": "^12.2.0",
"@emotion/css": "11.13.5",
"@grafana/data": "12.3.1",
"@grafana/i18n": "12.3.1",
"@grafana/plugin-ui": "0.12.1",
"@grafana/runtime": "12.3.1",
"@grafana/schema": "12.3.1",
"@grafana/ui": "12.3.1",
"react": "18.3.1",
"react-dom": "18.3.1",
"tslib": "2.5.3"
"tslib": "2.8.1"
},
"devDependencies": {
"@babel/core": "7.28.5",
"@changesets/cli": "^2.27.12",
"@grafana/e2e-selectors": "12.3.0",
"@grafana/eslint-config": "^8.2.0",
"@changesets/cli": "2.29.8",
"@grafana/e2e-selectors": "12.3.1",
"@grafana/eslint-config": "9.0.0",
"@grafana/plugin-e2e": "3.1.0",
"@grafana/plugin-meta-extractor": "^0.11.0",
"@grafana/tsconfig": "^2.0.0",
"@playwright/test": "^1.52.0",
"@stylistic/eslint-plugin-ts": "^2.9.0",
"@swc/core": "^1.3.90",
"@swc/helpers": "^0.5.0",
"@swc/jest": "^0.2.26",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "6.1.4",
"@testing-library/react": "14.0.0",
"@testing-library/user-event": "^14.5.1",
"@types/glob": "^8.0.0",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.20",
"@types/node": "^20.8.7",
"@grafana/plugin-meta-extractor": "0.11.0",
"@grafana/tsconfig": "2.0.1",
"@playwright/test": "1.57.0",
"@stylistic/eslint-plugin-ts": "4.4.1",
"@swc/core": "1.15.8",
"@swc/helpers": "0.5.18",
"@swc/jest": "0.2.39",
"@testing-library/dom": "10.4.1",
"@testing-library/jest-dom": "6.9.1",
"@testing-library/react": "16.3.1",
"@testing-library/user-event": "14.6.1",
"@types/jest": "30.0.0",
"@types/lodash": "4.17.21",
"@types/node": "25.0.3",
"@types/react": "18.3.27",
"@types/react-dom": "18.3.7",
"@types/react-router-dom": "^5.2.0",
"@typescript-eslint/eslint-plugin": "^8.3.0",
"@typescript-eslint/parser": "^8.3.0",
"copy-webpack-plugin": "^11.0.0",
"cspell": "6.31.3",
"css-loader": "^6.7.3",
"eslint": "^9.0.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-jsdoc": "^51.2.3",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-react": "^7.37.5",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-webpack-plugin": "^5.0.0",
"fork-ts-checker-webpack-plugin": "^8.0.0",
"glob": "^11.0.0",
"@typescript-eslint/eslint-plugin": "8.52.0",
"@typescript-eslint/parser": "8.52.0",
"copy-webpack-plugin": "13.0.1",
"cspell": "9.4.0",
"css-loader": "7.1.2",
"eslint": "9.39.2",
"eslint-config-prettier": "10.1.8",
"eslint-plugin-jsdoc": "61.5.0",
"eslint-plugin-prettier": "5.5.4",
"eslint-plugin-react": "7.37.5",
"eslint-plugin-react-hooks": "7.0.1",
"eslint-webpack-plugin": "5.0.2",
"fork-ts-checker-webpack-plugin": "9.1.0",
"glob": "13.0.0",
"identity-obj-proxy": "3.0.0",
"imports-loader": "^5.0.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"prettier": "^3.6.2",
"replace-in-file-webpack-plugin": "^1.0.6",
"rxjs": "^7.8.2",
"sass": "1.63.2",
"sass-loader": "13.3.3",
"semver": "^7.6.3",
"style-loader": "3.3.4",
"swc-loader": "^0.2.3",
"terser-webpack-plugin": "^5.3.10",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "5.5.4",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4",
"webpack-livereload-plugin": "^3.0.2",
"webpack-subresource-integrity": "^5.1.0",
"webpack-virtual-modules": "^0.6.2"
"imports-loader": "5.0.0",
"jest": "30.2.0",
"jest-environment-jsdom": "30.2.0",
"prettier": "3.7.4",
"replace-in-file-webpack-plugin": "1.0.6",
"rxjs": "7.8.2",
"sass": "1.97.2",
"sass-loader": "16.0.6",
"semver": "7.7.3",
"style-loader": "4.0.0",
"swc-loader": "0.2.6",
"terser-webpack-plugin": "5.3.16",
"ts-node": "10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "5.9.3",
"webpack": "5.104.1",
"webpack-cli": "6.0.1",
"webpack-livereload-plugin": "3.0.2",
"webpack-subresource-integrity": "5.1.0",
"webpack-virtual-modules": "0.6.2"
},
"resolutions": {
"js-yaml": "4.1.1",
"tmp": "0.2.5",
"brace-expansion": "2.0.2"
},
"packageManager": "yarn@4.9.3"
"packageManager": "yarn@4.12.0"
}
94 changes: 94 additions & 0 deletions src/views/QueryEditorRepository.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React from 'react';
import QueryEditorRepository from './QueryEditorRepository';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { components } from 'components/selectors';

describe('QueryEditorRepository', () => {
it('should render with initial props', () => {
const props = {
owner: 'grafana',
repository: 'grafana',
onChange: jest.fn(),
};
render(<QueryEditorRepository {...props} />);

expect(screen.getByLabelText(components.QueryEditor.Owner.input)).toHaveValue('grafana');
expect(screen.getByLabelText(components.QueryEditor.Repository.input)).toHaveValue('grafana');
});

it('should allow typing without calling onChange until blur', async () => {
const onChange = jest.fn();
const props = {
owner: '',
repository: '',
onChange,
};
render(<QueryEditorRepository {...props} />);

const ownerInput = screen.getByLabelText(components.QueryEditor.Owner.input);
await userEvent.type(ownerInput, 'grafana');

// onChange should not be called while typing
expect(onChange).not.toHaveBeenCalled();
// Local state should reflect the typed value
expect(ownerInput).toHaveValue('grafana');
});

it('should call onChange on blur with the typed value', async () => {
const onChange = jest.fn();
const props = {
owner: '',
repository: '',
onChange,
};
render(<QueryEditorRepository {...props} />);

const ownerInput = screen.getByLabelText(components.QueryEditor.Owner.input);
await userEvent.type(ownerInput, 'grafana');
await userEvent.tab(); // blur

expect(onChange).toHaveBeenCalledWith(
expect.objectContaining({
owner: 'grafana',
})
);
});

it('should update local state when props change externally', () => {
const onChange = jest.fn();
const props = {
owner: 'initial-owner',
repository: 'initial-repo',
onChange,
};
const { rerender } = render(<QueryEditorRepository {...props} />);

expect(screen.getByLabelText(components.QueryEditor.Owner.input)).toHaveValue('initial-owner');

// Simulate parent updating the props externally
rerender(<QueryEditorRepository {...props} owner="new-owner" repository="new-repo" />);

expect(screen.getByLabelText(components.QueryEditor.Owner.input)).toHaveValue('new-owner');
expect(screen.getByLabelText(components.QueryEditor.Repository.input)).toHaveValue('new-repo');
});

it('should NOT reset user input while typing (before blur)', async () => {
const onChange = jest.fn();
const props = {
owner: '',
repository: '',
onChange,
};
const { rerender } = render(<QueryEditorRepository {...props} />);

const ownerInput = screen.getByLabelText(components.QueryEditor.Owner.input);
await userEvent.type(ownerInput, 'grafana');

// Rerender with same props (simulating parent re-render without prop change)
rerender(<QueryEditorRepository {...props} />);

// User's typed value should be preserved, not reset to empty string
expect(ownerInput).toHaveValue('grafana');
});
});
16 changes: 11 additions & 5 deletions src/views/QueryEditorRepository.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState } from 'react';
import { Input, InlineLabel } from '@grafana/ui';
import { QueryEditorRow } from '../components/Forms';
import { RightColumnWidth, LeftColumnWidth } from './QueryEditor';
Expand All @@ -13,13 +13,19 @@ const QueryEditorRepositories = (props: Props) => {
const [repository, setRepository] = useState<string>(props.repository || '');
const [owner, setOwner] = useState<string>(props.owner || '');

useEffect(() => {
// Track previous props to sync state during render (avoids extra render pass from useEffect)
const [prevRepository, setPrevRepository] = useState(props.repository);
const [prevOwner, setPrevOwner] = useState(props.owner);

if (props.repository !== prevRepository) {
setPrevRepository(props.repository);
setRepository(props.repository || '');
}, [props.repository]);
}

useEffect(() => {
if (props.owner !== prevOwner) {
setPrevOwner(props.owner);
setOwner(props.owner || '');
}, [props.owner]);
}

return (
<QueryEditorRow>
Expand Down
21 changes: 17 additions & 4 deletions src/views/VariableQueryEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { InlineField } from '@grafana/ui';
import QueryEditor from './QueryEditor';
import { GitHubDataSource } from '../DataSource';
Expand All @@ -17,10 +17,23 @@ const VariableQueryEditor = (props: Props) => {
const definition = `${props.datasource.name} - ${props.query.queryType || DefaultQueryType}`;
const [choices, setChoices] = useState<string[]>();

useMemo(async () => {
if (isValid(props.query)) {
setChoices(await props.datasource.getChoices(props.query));
useEffect(() => {
// Used to ignore stale responses when the query changes before a fetch completes (race condition)
let ignore = false;

async function fetchData() {
if (isValid(props.query)) {
const result = await props.datasource.getChoices(props.query);
if (!ignore) {
setChoices(result);
}
}
}
fetchData();

return () => {
ignore = true;
};
}, [props.query, props.datasource]);

return (
Expand Down
Loading
Loading