Skip to content

Commit

Permalink
URL: Used updated query URL if changed outside of component
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanahuckova committed Jun 20, 2024
1 parent cd1de97 commit fe88a19
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/editors/query/query.url.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from "react";

Check failure on line 1 in src/editors/query/query.url.test.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `"react"` with `'react'`
import { URL } from "./query.url";

Check failure on line 2 in src/editors/query/query.url.test.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `"./query.url"` with `'./query.url'`
import { screen, render } from "@testing-library/react";

Check failure on line 3 in src/editors/query/query.url.test.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `"@testing-library/react"` with `'@testing-library/react'`
import { InfinityQuery } from "types";

Check failure on line 4 in src/editors/query/query.url.test.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `"types"` with `'types'`

describe("URL", () => {

Check failure on line 6 in src/editors/query/query.url.test.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `"URL"` with `'URL'`
it("should show changed URL", () => {

Check failure on line 7 in src/editors/query/query.url.test.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `"should·show·changed·URL"` with `'should·show·changed·URL'`
const mockQuery1 = {
url: "https://example1.com",

Check failure on line 9 in src/editors/query/query.url.test.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `"https://example1.com"` with `'https://example1.com'`
type: 'json',
source: 'url',
} as InfinityQuery;

const props = {
query: mockQuery1,
onChange: jest.fn(),
onRunQuery: jest.fn(),
onShowUrlOptions: jest.fn(),
}

Check failure on line 19 in src/editors/query/query.url.test.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

const { rerender } = render(<URL {...props}/>);

Check failure on line 21 in src/editors/query/query.url.test.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `·`
expect(screen.getByDisplayValue('https://example1.com')).toBeInTheDocument()

Check failure on line 22 in src/editors/query/query.url.test.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

const mockQuery2 = {
url: "https://example2.com",
type: 'json',
source: 'url',
} as InfinityQuery;

rerender(<URL {...props} query={mockQuery2}/>);
expect(screen.getByDisplayValue('https://example2.com')).toBeInTheDocument()
});
});
7 changes: 6 additions & 1 deletion src/editors/query/query.url.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { InlineFormLabel, CodeEditor, Select, Input, RadioButtonGroup, Icon } from '@grafana/ui';
import { EditorRow } from './../../components/extended/EditorRow';
import { EditorField } from './../../components/extended/EditorField';
Expand Down Expand Up @@ -73,6 +73,11 @@ export const URL = ({ query, onChange, onRunQuery, onShowUrlOptions }: { query:
onChange({ ...query, url });
onRunQuery();
};

useEffect(() => {
setURL(query.url ?? '')
}, [query.url])

return (
<EditorField label="URL" horizontal={true}>
<Input
Expand Down

0 comments on commit fe88a19

Please sign in to comment.