From 035862bade2304567f59172db673e4edc3ac06e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Bedi?= Date: Tue, 5 Jul 2022 11:04:27 +0200 Subject: [PATCH] Fix: sql plugins feature --- .betterer.results | 17 ---------- package.json | 2 ++ public/app/features/plugins/sql/types.ts | 4 +-- .../plugins/sql/utils/useSqlChange.ts | 2 +- yarn.lock | 33 ++++++++++++++++++- 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/.betterer.results b/.betterer.results index 0451b551542..e1450844209 100644 --- a/.betterer.results +++ b/.betterer.results @@ -7760,28 +7760,11 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], - "public/app/plugins/datasource/mssql/query_ctrl.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"] - ], "public/app/plugins/datasource/mssql/response_parser.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], [0, 0, 0, "Do not use any type assertions.", "2"] ], - "public/app/plugins/datasource/mssql/specs/datasource.test.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"], - [0, 0, 0, "Unexpected any. Specify a different type.", "6"], - [0, 0, 0, "Unexpected any. Specify a different type.", "7"], - [0, 0, 0, "Unexpected any. Specify a different type.", "8"] - ], "public/app/plugins/datasource/mssql/types.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], diff --git a/package.json b/package.json index 058fda5e327..78e0665c3c1 100644 --- a/package.json +++ b/package.json @@ -90,6 +90,7 @@ "@babel/preset-env": "7.18.2", "@babel/preset-react": "7.18.6", "@babel/preset-typescript": "7.18.6", + "@babel/runtime": "7.18.6", "@betterer/betterer": "5.3.5", "@betterer/cli": "5.3.5", "@betterer/eslint": "5.3.5", @@ -390,6 +391,7 @@ "semver": "7.3.7", "slate": "0.47.8", "slate-plain-serializer": "0.7.10", + "sql-formatter-plus": "^1.3.6", "symbol-observable": "4.0.0", "test": "link:./public/test", "tether-drop": "https://github.com/torkelo/drop", diff --git a/public/app/features/plugins/sql/types.ts b/public/app/features/plugins/sql/types.ts index e6869254b9a..29ef49e4f22 100644 --- a/public/app/features/plugins/sql/types.ts +++ b/public/app/features/plugins/sql/types.ts @@ -119,7 +119,7 @@ export interface DB { tables: (dataset?: string) => Promise; fields: (query: SQLQuery, order?: boolean) => Promise; validateQuery: (query: SQLQuery, range?: TimeRange) => Promise; - dsID: () => string; + dsID: () => number; dispose?: (dsID?: string) => void; lookup: (path?: string) => Promise>; getSqlCompletionProvider: () => LanguageCompletionProvider; @@ -135,7 +135,7 @@ export interface QueryEditorProps { export interface ValidationResults { query: SQLQuery; - rawSql: string; + rawSql?: string; error: string; isError: boolean; isValid: boolean; diff --git a/public/app/features/plugins/sql/utils/useSqlChange.ts b/public/app/features/plugins/sql/utils/useSqlChange.ts index d326261ef1d..b7e0cbdfd51 100644 --- a/public/app/features/plugins/sql/utils/useSqlChange.ts +++ b/public/app/features/plugins/sql/utils/useSqlChange.ts @@ -14,7 +14,7 @@ export function useSqlChange({ query, onQueryChange, db }: UseSqlChange) { const onSqlChange = useCallback( (sql: SQLExpression) => { const toRawSql = db.toRawSql || defaultToRawSql; - const rawSql = toRawSql({ sql, dataset: query.dataset, table: query.table, refId: db.dsID() }); + const rawSql = toRawSql({ sql, dataset: query.dataset, table: query.table, refId: query.refId }); const newQuery: SQLQuery = { ...query, sql, rawSql }; onQueryChange(newQuery); }, diff --git a/yarn.lock b/yarn.lock index 9b3c50b1a2f..b810c4d4a02 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3177,6 +3177,16 @@ __metadata: languageName: node linkType: hard +"@babel/polyfill@npm:^7.6.0": + version: 7.12.1 + resolution: "@babel/polyfill@npm:7.12.1" + dependencies: + core-js: ^2.6.5 + regenerator-runtime: ^0.13.4 + checksum: 3f59a9d85a41b390b044a1be13e11ae6d8efbfcf4e07217964585c7cef337b828eecfc5e164083227189146d2b6efc1affae8f59c831438eb40b848ab6fe5f39 + languageName: node + linkType: hard + "@babel/preset-env@npm:7.18.2": version: 7.18.2 resolution: "@babel/preset-env@npm:7.18.2" @@ -3447,6 +3457,15 @@ __metadata: languageName: node linkType: hard +"@babel/runtime@npm:7.18.6": + version: 7.18.6 + resolution: "@babel/runtime@npm:7.18.6" + dependencies: + regenerator-runtime: ^0.13.4 + checksum: 8b707b64ae0524db617d0c49933b258b96376a38307dc0be8fb42db5697608bcc1eba459acce541e376cff5ed5c5287d24db5780bd776b7c75ba2c2e26ff8a2c + languageName: node + linkType: hard + "@babel/runtime@npm:^7.0.0, @babel/runtime@npm:^7.1.2, @babel/runtime@npm:^7.10.1, @babel/runtime@npm:^7.11.1, @babel/runtime@npm:^7.11.2, @babel/runtime@npm:^7.12.0, @babel/runtime@npm:^7.12.1, @babel/runtime@npm:^7.12.13, @babel/runtime@npm:^7.12.5, @babel/runtime@npm:^7.13.10, @babel/runtime@npm:^7.15.4, @babel/runtime@npm:^7.5.5, @babel/runtime@npm:^7.6.2, @babel/runtime@npm:^7.7.2, @babel/runtime@npm:^7.8.4, @babel/runtime@npm:^7.8.7, @babel/runtime@npm:^7.9.2": version: 7.15.4 resolution: "@babel/runtime@npm:7.15.4" @@ -16364,7 +16383,7 @@ __metadata: languageName: node linkType: hard -"core-js@npm:^2.0.0, core-js@npm:^2.4.0": +"core-js@npm:^2.0.0, core-js@npm:^2.4.0, core-js@npm:^2.6.5": version: 2.6.12 resolution: "core-js@npm:2.6.12" checksum: 44fa9934a85f8c78d61e0c8b7b22436330471ffe59ec5076fe7f324d6e8cf7f824b14b1c81ca73608b13bdb0fef035bd820989bf059767ad6fa13123bb8bd016 @@ -21079,6 +21098,7 @@ __metadata: "@babel/preset-env": 7.18.2 "@babel/preset-react": 7.18.6 "@babel/preset-typescript": 7.18.6 + "@babel/runtime": 7.18.6 "@betterer/betterer": 5.3.5 "@betterer/cli": 5.3.5 "@betterer/eslint": 5.3.5 @@ -21360,6 +21380,7 @@ __metadata: sinon: 14.0.0 slate: 0.47.8 slate-plain-serializer: 0.7.10 + sql-formatter-plus: ^1.3.6 style-loader: 3.3.1 stylelint: 14.9.1 stylelint-config-prettier: 9.0.3 @@ -34208,6 +34229,16 @@ __metadata: languageName: node linkType: hard +"sql-formatter-plus@npm:^1.3.6": + version: 1.3.6 + resolution: "sql-formatter-plus@npm:1.3.6" + dependencies: + "@babel/polyfill": ^7.6.0 + lodash: ^4.17.15 + checksum: 5c215f85936b3465d6778af868f0a8a2d3dd4b714ab95025c3b17b9748fe420ae2e128c523d50be0a43667bf8329a974f3248828971299146786e28d9714e752 + languageName: node + linkType: hard + "sqlstring@npm:^2.3.2": version: 2.3.3 resolution: "sqlstring@npm:2.3.3"