Skip to content

Commit cfe2e41

Browse files
committed
Pulled from main.
2 parents b4ecf68 + 8ec159d commit cfe2e41

File tree

6 files changed

+39
-13
lines changed

6 files changed

+39
-13
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"react-use": "^17.3.1",
4141
"react-virtualized-auto-sizer": "^1.0.6",
4242
"sql-formatter-plus": "^1.3.6",
43-
"tslib": "2.5.3",
44-
"uuid": "^8.3.2"
43+
"tslib": "2.5.3"
4544
},
4645
"devDependencies": {
4746
"@babel/core": "^7.21.4",
@@ -58,7 +57,6 @@
5857
"@types/node": "^20.8.7",
5958
"@types/react-router-dom": "^5.2.0",
6059
"@types/testing-library__jest-dom": "5.14.8",
61-
"@types/uuid": "^8.3.1",
6260
"@typescript-eslint/eslint-plugin": "^5.42.1",
6361
"@typescript-eslint/parser": "^5.42.1",
6462
"copy-webpack-plugin": "^11.0.0",

src/components/DatasetSelector.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface DatasetSelectorProps extends ResourceSelectorProps {
1212
applyDefault?: boolean;
1313
disabled?: boolean;
1414
onChange: (v: SelectableValue) => void;
15+
inputId?: string;
1516
}
1617

1718
export const DatasetSelector: React.FC<DatasetSelectorProps> = ({
@@ -23,6 +24,7 @@ export const DatasetSelector: React.FC<DatasetSelectorProps> = ({
2324
disabled,
2425
className,
2526
applyDefault,
27+
inputId,
2628
}) => {
2729
const state = useAsync(async () => {
2830
const datasets = await apiClient.getDatasets(location, project);
@@ -52,6 +54,7 @@ export const DatasetSelector: React.FC<DatasetSelectorProps> = ({
5254
<Select
5355
className={className}
5456
aria-label="Dataset selector"
57+
inputId={inputId}
5558
value={value}
5659
options={state.value}
5760
onChange={onChange}

src/components/ProjectSelector.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ interface ProjectSelectorProps extends Omit<ResourceSelectorProps, 'location'> {
1010
value?: string;
1111
applyDefault?: boolean;
1212
onChange: (v: SelectableValue) => void;
13+
inputId?: string;
1314
}
1415

15-
export const ProjectSelector: React.FC<ProjectSelectorProps> = ({ apiClient, value, onChange, applyDefault }) => {
16+
export const ProjectSelector: React.FC<ProjectSelectorProps> = ({
17+
apiClient,
18+
value,
19+
onChange,
20+
applyDefault,
21+
inputId,
22+
}) => {
1623
const theme = useTheme2();
1724
const state = useAsync(async () => {
1825
const projects = await apiClient.getProjects();
@@ -63,6 +70,7 @@ export const ProjectSelector: React.FC<ProjectSelectorProps> = ({ apiClient, val
6370
<EditorField label="Project" width={25} error={getErrorMessage()} invalid={!!state.error}>
6471
<Select
6572
aria-label="Project selector"
73+
inputId={inputId}
6674
value={state.loading ? null : value}
6775
options={state.loading ? [] : state.value || [{ label: value, value }]}
6876
onChange={onChange}

src/components/QueryHeader.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { SelectableValue } from '@grafana/data';
22
import { EditorField, EditorHeader, EditorMode, EditorRow, FlexItem, InlineSelect, Space } from '@grafana/experimental';
33
import { Button, InlineSwitch, RadioButtonGroup, Tooltip } from '@grafana/ui';
44
import { BigQueryAPI } from 'api';
5-
import React, { useCallback, useState } from 'react';
5+
import React, { useCallback, useId, useState } from 'react';
66
import { useCopyToClipboard } from 'react-use';
77
import { toRawSql } from 'utils/sql.utils';
88
import { PROCESSING_LOCATIONS, QUERY_FORMAT_OPTIONS } from '../constants';
@@ -11,7 +11,6 @@ import { ConfirmModal } from './ConfirmModal';
1111
import { DatasetSelector } from './DatasetSelector';
1212
import { ProjectSelector } from './ProjectSelector';
1313
import { TableSelector } from './TableSelector';
14-
import { v4 as uuidv4 } from 'uuid';
1514

1615
interface QueryHeaderProps {
1716
query: QueryWithDefaults;
@@ -42,6 +41,7 @@ export function QueryHeader({
4241
const { location, editorMode } = query;
4342
const [_, copyToClipboard] = useCopyToClipboard();
4443
const [showConfirm, setShowConfirm] = useState(false);
44+
const htmlId = useId();
4545

4646
const onEditorModeChange = useCallback(
4747
(newEditorMode: EditorMode) => {
@@ -160,7 +160,7 @@ export function QueryHeader({
160160
{editorMode === EditorMode.Builder && (
161161
<>
162162
<InlineSwitch
163-
id={`bq-filter-${uuidv4()}}`}
163+
id={`bq-filter-${htmlId}}`}
164164
label="Filter"
165165
transparent={true}
166166
showLabel={true}
@@ -172,7 +172,7 @@ export function QueryHeader({
172172
/>
173173

174174
<InlineSwitch
175-
id={`bq-group-${uuidv4()}}`}
175+
id={`bq-group-${htmlId}}`}
176176
label="Group"
177177
transparent={true}
178178
showLabel={true}
@@ -184,7 +184,7 @@ export function QueryHeader({
184184
/>
185185

186186
<InlineSwitch
187-
id={`bq-order-${uuidv4()}}`}
187+
id={`bq-order-${htmlId}}`}
188188
label="Order"
189189
transparent={true}
190190
showLabel={true}
@@ -196,7 +196,7 @@ export function QueryHeader({
196196
/>
197197

198198
<InlineSwitch
199-
id={`bq-preview-${uuidv4()}}`}
199+
id={`bq-preview-${htmlId}}`}
200200
label="Preview"
201201
transparent={true}
202202
showLabel={true}
@@ -243,12 +243,19 @@ export function QueryHeader({
243243
<Space v={0.5} />
244244

245245
<EditorRow>
246-
<ProjectSelector apiClient={apiClient} value={query.project} onChange={onProjectChange} applyDefault />
246+
<ProjectSelector
247+
apiClient={apiClient}
248+
value={query.project}
249+
onChange={onProjectChange}
250+
applyDefault
251+
inputId={`bq-project-${htmlId}`}
252+
/>
247253

248254
<EditorField label="Dataset" width={25}>
249255
<DatasetSelector
250256
apiClient={apiClient}
251257
location={query.location}
258+
inputId={`bq-dataset-${htmlId}`}
252259
value={query.dataset === undefined ? null : query.dataset}
253260
project={query.project}
254261
onChange={onDatasetChange}
@@ -259,6 +266,7 @@ export function QueryHeader({
259266
<TableSelector
260267
apiClient={apiClient}
261268
query={query}
269+
inputId={`bq-table-${htmlId}`}
262270
value={query.table === undefined ? null : query.table}
263271
onChange={onTableChange}
264272
applyDefault

src/components/TableSelector.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@ interface TableSelectorProps extends ResourceSelectorProps {
99
value: string | null;
1010
query: QueryWithDefaults;
1111
onChange: (v: SelectableValue) => void;
12+
inputId?: string;
1213
}
1314

14-
export const TableSelector: React.FC<TableSelectorProps> = ({ apiClient, query, value, className, onChange }) => {
15+
export const TableSelector: React.FC<TableSelectorProps> = ({
16+
apiClient,
17+
query,
18+
value,
19+
className,
20+
onChange,
21+
inputId,
22+
}) => {
1523
const state = useAsync(async () => {
1624
if (!query.dataset) {
1725
return [];
@@ -24,6 +32,7 @@ export const TableSelector: React.FC<TableSelectorProps> = ({ apiClient, query,
2432
<Select
2533
className={className}
2634
disabled={state.loading}
35+
inputId={inputId}
2736
aria-label="Table selector"
2837
value={value}
2938
options={state.value}

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,7 @@
23352335
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.3.tgz#3d06b6769518450871fbc40770b7586334bdfd90"
23362336
integrity sha512-THo502dA5PzG/sfQH+42Lw3fvmYkceefOspdCwpHRul8ik2Jv1K8I5OZz1AT3/rs46kwgMCe9bSBmDLYkkOMGg==
23372337

2338-
"@types/uuid@^8.3.1", "@types/uuid@^8.3.3":
2338+
"@types/uuid@^8.3.3":
23392339
version "8.3.4"
23402340
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc"
23412341
integrity sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==

0 commit comments

Comments
 (0)