From de956fc3d8956fc663807c120097f0b010de0bdc Mon Sep 17 00:00:00 2001 From: Scott Lepper Date: Wed, 20 Jul 2022 12:50:08 -0400 Subject: [PATCH] Core code editor/builder components (#52421) * migrate experimental to core grafana - update refs Co-authored-by: Dominik Prokop --- .betterer.results | 38 +- package.json | 1 - .../QueryEditor/AccessoryButton.tsx | 23 + .../components/QueryEditor/EditorField.tsx | 79 ++ .../QueryEditor/EditorFieldGroup.tsx | 9 + .../components/QueryEditor/EditorHeader.tsx | 25 + .../src/components/QueryEditor/EditorList.tsx | 49 + .../src/components/QueryEditor/EditorRow.tsx | 30 + .../src/components/QueryEditor/EditorRows.tsx | 13 + .../components/QueryEditor/EditorSwitch.tsx | 25 + .../src/components/QueryEditor/FlexItem.tsx | 10 + .../components/QueryEditor/InlineSelect.tsx | 89 ++ .../src/components/QueryEditor/InputGroup.tsx | 54 ++ .../src/components/QueryEditor/Space.tsx | 40 + .../src/components/QueryEditor/Stack.tsx | 30 + .../src/components/QueryEditor/index.ts | 13 + packages/grafana-ui/src/components/index.ts | 1 + .../alerting/unified/AlertsFolderView.tsx | 3 +- .../components/alert-groups/MatcherFilter.tsx | 3 +- .../components/rule-editor/DetailsStep.tsx | 3 +- .../rule-editor/rule-types/RuleTypePicker.tsx | 3 +- .../unified/components/rules/RulesFilter.tsx | 3 +- .../components/silences/SilencesFilter.tsx | 3 +- .../components/silences/SilencesTable.tsx | 3 +- .../SaveDashboard/forms/SaveDashboardForm.tsx | 3 +- .../forms/SaveProvisionedDashboardForm.tsx | 3 +- .../features/expressions/components/Math.tsx | 3 +- .../app/features/inspector/QueryInspector.tsx | 3 +- public/app/features/org/UserInviteForm.tsx | 14 +- .../plugins/sql/components/QueryEditor.tsx | 4 +- .../plugins/sql/components/QueryHeader.tsx | 18 +- .../features/plugins/sql/components/index.ts | 2 + .../query-editor-raw/QueryEditorRaw.tsx | 6 +- .../sql/components/query-editor-raw/README.md | 135 +++ .../components/query-editor-raw/SQLEditor.tsx | 405 ++++++++ .../sql/components/query-editor-raw/index.ts | 1 + .../visual-query-builder/GroupByRow.tsx | 3 +- .../visual-query-builder/OrderByRow.tsx | 3 +- .../visual-query-builder/SelectRow.tsx | 3 +- .../visual-query-builder/VisualEditor.tsx | 2 +- .../components/visual-query-builder/index.ts | 1 + public/app/features/plugins/sql/constants.ts | 2 +- public/app/features/plugins/sql/defaults.ts | 4 +- public/app/features/plugins/sql/index.ts | 22 + .../app/features/plugins/sql/mocks/Monaco.ts | 26 + .../features/plugins/sql/mocks/TextModel.ts | 21 + .../sql/mocks/queries/multiLineFullQuery.ts | 214 +++++ .../multiLineFullQueryWithAggregation.ts | 229 +++++ .../mocks/queries/multiLineMultipleColumns.ts | 269 ++++++ .../sql/mocks/queries/singleLineEmptyQuery.ts | 6 + .../sql/mocks/queries/singleLineFullQuery.ts | 196 ++++ .../singleLineFullQueryWithAggregation.ts | 209 +++++ .../queries/singleLineMultipleColumns.ts | 250 +++++ .../sql/mocks/queries/singleLineTwoQueries.ts | 385 ++++++++ .../singleLineTwoQueriesWithAggregation.ts | 415 +++++++++ .../features/plugins/sql/mocks/testData.ts | 9 + .../plugins/sql/standardSql/definition.ts | 24 + .../getStandardSuggestions.test.ts | 273 ++++++ .../sql/standardSql/getStandardSuggestions.ts | 34 + .../standardSql/getStatementPosition.test.ts | 184 ++++ .../sql/standardSql/getStatementPosition.ts | 31 + .../plugins/sql/standardSql/language.ts | 880 ++++++++++++++++++ .../plugins/sql/standardSql/macros.ts | 67 ++ .../standardSuggestionsRegistry.ts | 425 +++++++++ .../statementPositionResolversRegistry.ts | 244 +++++ .../standardSql/suggestionsKindRegistry.ts | 146 +++ .../features/plugins/sql/standardSql/types.ts | 52 ++ .../features/plugins/sql/test-utils/index.ts | 11 + .../sql/test-utils/statementPosition.ts | 63 ++ .../plugins/sql/test-utils/testQueries.txt | 21 + .../features/plugins/sql/test-utils/types.ts | 11 + public/app/features/plugins/sql/types.ts | 256 ++++- .../features/plugins/sql/utils/LinkedToken.ts | 176 ++++ .../features/plugins/sql/utils/commands.ts | 4 + .../features/plugins/sql/utils/debugger.ts | 12 + .../sql/utils/getSuggestionKind.test.ts | 31 + .../plugins/sql/utils/getSuggestionKind.ts | 22 + .../sql/utils/linkedTokenBuilder.test.ts | 72 ++ .../plugins/sql/utils/linkedTokenBuilder.ts | 56 ++ .../plugins/sql/utils/toCompletionItem.ts | 19 + .../features/plugins/sql/utils/tokenUtils.ts | 57 ++ .../app/features/plugins/sql/utils/types.ts | 14 + public/app/features/scenes/SceneListPage.tsx | 3 +- .../scenes/components/NestedScene.tsx | 3 +- .../LabelsToFieldsTransformerEditor.tsx | 3 +- .../components/AnnotationQueryEditor.tsx | 3 +- .../components/Experimental/Aggregation.tsx | 3 +- .../components/Experimental/AliasBy.tsx | 3 +- .../components/Experimental/Alignment.tsx | 2 +- .../components/Experimental/GraphPeriod.tsx | 3 +- .../components/Experimental/GroupBy.tsx | 3 +- .../components/Experimental/LabelFilter.tsx | 3 +- .../Experimental/MetricQueryEditor.tsx | 2 +- .../components/Experimental/Metrics.tsx | 3 +- .../components/Experimental/Preprocessor.tsx | 3 +- .../components/Experimental/Project.tsx | 3 +- .../components/Experimental/QueryHeader.tsx | 3 +- .../components/Experimental/SLO.tsx | 3 +- .../Experimental/SLOQueryEditor.tsx | 2 +- .../components/Experimental/Selector.tsx | 3 +- .../components/Experimental/Service.tsx | 3 +- .../components/QueryEditor.tsx | 3 +- .../components/AnnotationQueryEditor.tsx | 3 +- .../components/Dimensions/Dimensions.tsx | 2 +- .../components/Dimensions/FilterItem.tsx | 3 +- .../MetricStatEditor/MetricStatEditor.tsx | 3 +- .../MetricsQueryEditor/MetricsQueryEditor.tsx | 3 +- .../MetricsQueryEditor/MetricsQueryHeader.tsx | 3 +- .../cloudwatch/components/QueryHeader.tsx | 2 +- .../SQLBuilderEditor/SQLBuilderEditor.tsx | 3 +- .../SQLBuilderEditor/SQLBuilderSelectRow.tsx | 3 +- .../components/SQLBuilderEditor/SQLFilter.tsx | 3 +- .../SQLBuilderEditor/SQLGroupBy.tsx | 3 +- .../SQLBuilderEditor/SQLOrderByGroup.tsx | 3 +- .../VariableQueryEditor/MultiFilter.tsx | 2 +- .../VariableQueryEditor/MultiFilterItem.tsx | 3 +- .../CompletionItemProvider.test.ts | 2 +- .../QueryEditor/AnnotationQueryEditor.tsx | 3 +- .../ArgQueryEditor/ArgQueryEditor.tsx | 2 +- .../components/Field.tsx | 3 +- .../LogsQueryEditor/LogsQueryEditor.tsx | 3 +- .../MetricsQueryEditor/DimensionFields.tsx | 3 +- .../MetricsQueryEditor/MetricsQueryEditor.tsx | 2 +- .../components/QueryHeader.tsx | 2 +- .../components/AnnotationsQueryEditor.tsx | 3 +- .../components/LokiQueryBuilder.tsx | 2 +- .../components/LokiQueryBuilderExplained.tsx | 2 +- .../components/LokiQueryBuilderOptions.tsx | 3 +- .../components/LokiQueryEditorSelector.tsx | 3 +- .../querybuilder/components/NestedQuery.tsx | 3 +- .../components/NestedQueryList.tsx | 2 +- .../querybuilder/components/QueryPreview.tsx | 2 +- .../plugins/datasource/mssql/datasource.ts | 9 +- .../datasource/mssql/sqlCompletionProvider.ts | 9 +- .../datasource/mysql/MySqlDatasource.ts | 9 +- .../datasource/mysql/sqlCompletionProvider.ts | 13 +- .../components/AnnotationQueryEditor.tsx | 3 +- .../querybuilder/components/MetricSelect.tsx | 3 +- .../querybuilder/components/NestedQuery.tsx | 3 +- .../components/NestedQueryList.tsx | 2 +- .../components/PromQueryBuilder.tsx | 2 +- .../components/PromQueryBuilderExplained.tsx | 2 +- .../components/PromQueryBuilderOptions.tsx | 3 +- .../components/PromQueryEditorSelector.tsx | 3 +- .../components/PromQueryLegendEditor.tsx | 3 +- .../querybuilder/components/QueryPreview.tsx | 2 +- .../querybuilder/shared/FeedbackLink.tsx | 3 +- .../querybuilder/shared/LabelFilterItem.tsx | 3 +- .../querybuilder/shared/LabelFilters.tsx | 2 +- .../querybuilder/shared/OperationEditor.tsx | 3 +- .../querybuilder/shared/OperationHeader.tsx | 3 +- .../shared/OperationInfoButton.tsx | 3 +- .../querybuilder/shared/OperationList.tsx | 3 +- .../shared/OperationsEditorRow.tsx | 3 +- .../querybuilder/shared/QueryHeaderSwitch.tsx | 3 +- .../querybuilder/shared/QueryOptionGroup.tsx | 3 +- yarn.lock | 22 - 157 files changed, 6644 insertions(+), 210 deletions(-) create mode 100644 packages/grafana-ui/src/components/QueryEditor/AccessoryButton.tsx create mode 100644 packages/grafana-ui/src/components/QueryEditor/EditorField.tsx create mode 100644 packages/grafana-ui/src/components/QueryEditor/EditorFieldGroup.tsx create mode 100644 packages/grafana-ui/src/components/QueryEditor/EditorHeader.tsx create mode 100644 packages/grafana-ui/src/components/QueryEditor/EditorList.tsx create mode 100644 packages/grafana-ui/src/components/QueryEditor/EditorRow.tsx create mode 100644 packages/grafana-ui/src/components/QueryEditor/EditorRows.tsx create mode 100644 packages/grafana-ui/src/components/QueryEditor/EditorSwitch.tsx create mode 100644 packages/grafana-ui/src/components/QueryEditor/FlexItem.tsx create mode 100644 packages/grafana-ui/src/components/QueryEditor/InlineSelect.tsx create mode 100644 packages/grafana-ui/src/components/QueryEditor/InputGroup.tsx create mode 100644 packages/grafana-ui/src/components/QueryEditor/Space.tsx create mode 100644 packages/grafana-ui/src/components/QueryEditor/Stack.tsx create mode 100644 packages/grafana-ui/src/components/QueryEditor/index.ts create mode 100644 public/app/features/plugins/sql/components/index.ts create mode 100644 public/app/features/plugins/sql/components/query-editor-raw/README.md create mode 100644 public/app/features/plugins/sql/components/query-editor-raw/SQLEditor.tsx create mode 100644 public/app/features/plugins/sql/components/query-editor-raw/index.ts create mode 100644 public/app/features/plugins/sql/components/visual-query-builder/index.ts create mode 100644 public/app/features/plugins/sql/index.ts create mode 100644 public/app/features/plugins/sql/mocks/Monaco.ts create mode 100644 public/app/features/plugins/sql/mocks/TextModel.ts create mode 100644 public/app/features/plugins/sql/mocks/queries/multiLineFullQuery.ts create mode 100644 public/app/features/plugins/sql/mocks/queries/multiLineFullQueryWithAggregation.ts create mode 100644 public/app/features/plugins/sql/mocks/queries/multiLineMultipleColumns.ts create mode 100644 public/app/features/plugins/sql/mocks/queries/singleLineEmptyQuery.ts create mode 100644 public/app/features/plugins/sql/mocks/queries/singleLineFullQuery.ts create mode 100644 public/app/features/plugins/sql/mocks/queries/singleLineFullQueryWithAggregation.ts create mode 100644 public/app/features/plugins/sql/mocks/queries/singleLineMultipleColumns.ts create mode 100644 public/app/features/plugins/sql/mocks/queries/singleLineTwoQueries.ts create mode 100644 public/app/features/plugins/sql/mocks/queries/singleLineTwoQueriesWithAggregation.ts create mode 100644 public/app/features/plugins/sql/mocks/testData.ts create mode 100644 public/app/features/plugins/sql/standardSql/definition.ts create mode 100644 public/app/features/plugins/sql/standardSql/getStandardSuggestions.test.ts create mode 100644 public/app/features/plugins/sql/standardSql/getStandardSuggestions.ts create mode 100644 public/app/features/plugins/sql/standardSql/getStatementPosition.test.ts create mode 100644 public/app/features/plugins/sql/standardSql/getStatementPosition.ts create mode 100644 public/app/features/plugins/sql/standardSql/language.ts create mode 100644 public/app/features/plugins/sql/standardSql/macros.ts create mode 100644 public/app/features/plugins/sql/standardSql/standardSuggestionsRegistry.ts create mode 100644 public/app/features/plugins/sql/standardSql/statementPositionResolversRegistry.ts create mode 100644 public/app/features/plugins/sql/standardSql/suggestionsKindRegistry.ts create mode 100644 public/app/features/plugins/sql/standardSql/types.ts create mode 100644 public/app/features/plugins/sql/test-utils/index.ts create mode 100644 public/app/features/plugins/sql/test-utils/statementPosition.ts create mode 100644 public/app/features/plugins/sql/test-utils/testQueries.txt create mode 100644 public/app/features/plugins/sql/test-utils/types.ts create mode 100644 public/app/features/plugins/sql/utils/LinkedToken.ts create mode 100644 public/app/features/plugins/sql/utils/commands.ts create mode 100644 public/app/features/plugins/sql/utils/debugger.ts create mode 100644 public/app/features/plugins/sql/utils/getSuggestionKind.test.ts create mode 100644 public/app/features/plugins/sql/utils/getSuggestionKind.ts create mode 100644 public/app/features/plugins/sql/utils/linkedTokenBuilder.test.ts create mode 100644 public/app/features/plugins/sql/utils/linkedTokenBuilder.ts create mode 100644 public/app/features/plugins/sql/utils/toCompletionItem.ts create mode 100644 public/app/features/plugins/sql/utils/tokenUtils.ts create mode 100644 public/app/features/plugins/sql/utils/types.ts diff --git a/.betterer.results b/.betterer.results index c2bd381ecad..7f8ff5acfac 100644 --- a/.betterer.results +++ b/.betterer.results @@ -5362,15 +5362,7 @@ exports[`better eslint`] = { [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"] - ], - "public/app/features/playlist/PlaylistNewPage.test.tsx: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.", "3"] ], "public/app/features/playlist/PlaylistSrv.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -5530,11 +5522,39 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "7"], [0, 0, 0, "Do not use any type assertions.", "8"] ], + "public/app/features/plugins/sql/components/query-editor-raw/SQLEditor.tsx:5381": [ + [0, 0, 0, "Unexpected any. Specify a different type.", "0"], + [0, 0, 0, "Do not use any type assertions.", "1"], + [0, 0, 0, "Do not use any type assertions.", "2"], + [0, 0, 0, "Do not use any type assertions.", "3"], + [0, 0, 0, "Do not use any type assertions.", "4"], + [0, 0, 0, "Do not use any type assertions.", "5"] + ], "public/app/features/plugins/sql/components/visual-query-builder/AwesomeQueryBuilder.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], + "public/app/features/plugins/sql/mocks/Monaco.ts:5381": [ + [0, 0, 0, "Unexpected any. Specify a different type.", "0"] + ], + "public/app/features/plugins/sql/mocks/queries/singleLineFullQuery.ts:5381": [ + [0, 0, 0, "Do not use any type assertions.", "0"] + ], + "public/app/features/plugins/sql/standardSql/definition.ts:5381": [ + [0, 0, 0, "Unexpected any. Specify a different type.", "0"] + ], + "public/app/features/plugins/sql/test-utils/statementPosition.ts:5381": [ + [0, 0, 0, "Unexpected any. Specify a different type.", "0"], + [0, 0, 0, "Do not use any type assertions.", "1"], + [0, 0, 0, "Unexpected any. Specify a different type.", "2"], + [0, 0, 0, "Do not use any type assertions.", "3"] + ], + "public/app/features/plugins/sql/utils/debugger.ts:5381": [ + [0, 0, 0, "Unexpected any. Specify a different type.", "0"], + [0, 0, 0, "Do not use any type assertions.", "1"], + [0, 0, 0, "Unexpected any. Specify a different type.", "2"] + ], "public/app/features/plugins/tests/datasource_srv.test.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 7e9819bb609..eb292f01c43 100644 --- a/package.json +++ b/package.json @@ -254,7 +254,6 @@ "@grafana/aws-sdk": "0.0.37", "@grafana/data": "workspace:*", "@grafana/e2e-selectors": "workspace:*", - "@grafana/experimental": "^0.0.2-canary.32", "@grafana/google-sdk": "0.0.3", "@grafana/lezer-logql": "^0.0.14", "@grafana/runtime": "workspace:*", diff --git a/packages/grafana-ui/src/components/QueryEditor/AccessoryButton.tsx b/packages/grafana-ui/src/components/QueryEditor/AccessoryButton.tsx new file mode 100644 index 00000000000..07f8c2c8a53 --- /dev/null +++ b/packages/grafana-ui/src/components/QueryEditor/AccessoryButton.tsx @@ -0,0 +1,23 @@ +import { css, cx } from '@emotion/css'; +import React from 'react'; + +import { GrafanaTheme2 } from '@grafana/data'; + +import { useTheme2, stylesFactory } from '../../themes'; +import { Button, ButtonProps } from '../Button'; + +interface AccessoryButtonProps extends ButtonProps {} + +export const AccessoryButton: React.FC = ({ className, ...props }) => { + const theme = useTheme2(); + const styles = getButtonStyles(theme); + + return