-
Notifications
You must be signed in to change notification settings - Fork 26
Feature/ticketless client tags in query editor #317
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
61c6a88
cb6e6e4
f083525
c0996b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { QueryEditorProps } from '@grafana/data'; | |
| import { DataSource } from './datasource'; | ||
| import { TrinoDataSourceOptions, TrinoQuery, defaultQuery, SelectableFormatOptions } from './types'; | ||
| import { FormatSelect, QueryCodeEditor } from '@grafana/aws-sdk'; | ||
| import { Input } from '@grafana/ui'; // <-- ADD THIS | ||
|
||
|
|
||
| type Props = QueryEditorProps<DataSource, TrinoQuery, TrinoDataSourceOptions>; | ||
|
|
||
|
|
@@ -12,26 +13,43 @@ export function QueryEditor(props: Props) { | |
| ...props.query, | ||
| }; | ||
|
|
||
| const onClientTagsChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
| props.onChange({ | ||
| ...props.query, | ||
| clientTags: event.target.value, | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="gf-form-group"> | ||
| <h6>Frames</h6> | ||
| <FormatSelect | ||
| query={props.query} | ||
| options={SelectableFormatOptions} | ||
| onChange={props.onChange} | ||
| onRunQuery={props.onRunQuery} | ||
| /> | ||
| </div> | ||
| <div style={{ minWidth: '400px', marginLeft: '10px', flex: 1 }}> | ||
| <QueryCodeEditor | ||
| language="sql" | ||
| query={queryWithDefaults} | ||
| onChange={props.onChange} | ||
| onRunQuery={props.onRunQuery} | ||
| getSuggestions={() => []} | ||
| /> | ||
| </div> | ||
| <div className="gf-form-group"> | ||
| <h6>Frames</h6> | ||
| <FormatSelect | ||
| query={props.query} | ||
| options={SelectableFormatOptions} | ||
| onChange={props.onChange} | ||
| onRunQuery={props.onRunQuery} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="gf-form-group"> | ||
| <h6>Client Tags</h6> | ||
| <Input | ||
| value={queryWithDefaults.clientTags || ''} | ||
| placeholder="e.g. tag1,tag2,tag3" | ||
| onChange={onClientTagsChange} | ||
| /> | ||
| </div> | ||
|
|
||
| <div style={{ minWidth: '400px', marginLeft: '10px', flex: 1 }}> | ||
| <QueryCodeEditor | ||
| language="sql" | ||
| query={queryWithDefaults} | ||
| onChange={props.onChange} | ||
| onRunQuery={props.onRunQuery} | ||
| getSuggestions={() => []} | ||
| /> | ||
| </div> | ||
| </> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,37 @@ async function runQueryAndCheckResults(page: Page) { | |
| await expect(page.getByTestId('data-testid table body')).toContainText(/.*1995-01-19 0.:00:005703857F.*/); | ||
| } | ||
|
|
||
| async function runQueryAndRetrunRequset( | ||
|
||
| page: Page, | ||
| clientTag: string | ||
| ): Promise<import('@playwright/test').Request > { | ||
| await page.getByLabel(EXPORT_DATA).click(); | ||
| await page.getByTestId('data-testid TimePicker Open Button').click(); | ||
| await page.getByTestId('data-testid Time Range from field').fill('1995-01-01'); | ||
| await page.getByTestId('data-testid Time Range to field').fill('1995-12-31'); | ||
| await page.getByTestId('data-testid TimePicker submit button').click(); | ||
| await page.locator('div').filter({ hasText: /^Format asChoose$/ }).locator('svg').click(); | ||
| await page.getByRole('option', { name: 'Table' }).click(); | ||
| await page.getByTestId('data-testid Code editor container').click(); | ||
|
|
||
| await page.locator('div').filter({hasText: /^Client Tags$/}).locator('input').fill(clientTag); | ||
| // Commit the input change | ||
| await page.keyboard.press('Tab'); | ||
|
|
||
| const [response] = await Promise.all([ | ||
| page.waitForResponse( | ||
| res => res.url().includes('/api/ds/query') && res.request().method() === 'POST', | ||
| { timeout: 30000 } | ||
| ), | ||
| page.getByTestId('data-testid RefreshPicker run button').click() | ||
| ]); | ||
|
|
||
| await expect(page.getByTestId('data-testid table body')).toContainText(/.*1995-01-19.*/); | ||
|
|
||
| return response.request(); | ||
| } | ||
|
|
||
|
|
||
| test('test with access token', async ({ page }) => { | ||
| await login(page); | ||
| await goToTrinoSettings(page); | ||
|
|
@@ -91,3 +122,16 @@ test('test with client tags', async ({ page }) => { | |
| await setupDataSourceWithClientTags(page, 'tag1,tag2,tag3'); | ||
| await runQueryAndCheckResults(page); | ||
| }); | ||
|
|
||
| test('query editor client tags override datasource-level tags', async ({ page }) => { | ||
| await login(page); | ||
| await goToTrinoSettings(page); | ||
| await setupDataSourceWithClientTags(page, 'datasourceTag'); | ||
|
|
||
| const request = await runQueryAndRetrunRequset(page, 'editorTag'); | ||
|
|
||
| expect(request).toBeDefined(); | ||
| const body = JSON.parse(request.postData() || '{}'); | ||
| expect(body.queries?.[0]?.clientTags).toBe('editorTag'); | ||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're not referencing
dsanywhere, so this method doesn't need to be bound to it. Remove(ds *SQLDatasourceWithTrinoUserContext), and place it afterinjectAccessToken.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't look done, have you not pushed some changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe some thing tin the sqush, any way trying again