diff --git a/.betterer.results b/.betterer.results index fe2cc870b0c..ce4bc3b1eaf 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1133,9 +1133,6 @@ exports[`better eslint`] = { "packages/grafana-ui/src/utils/useAsyncDependency.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "plugins-bundled/internal/input-datasource/src/InputDatasource.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/core/TableModel.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -6293,9 +6290,6 @@ exports[`no gf-form usage`] = { [0, 0, 0, "gf-form usage has been deprecated. Use a component from @grafana/ui or custom CSS instead.", "5381"], [0, 0, 0, "gf-form usage has been deprecated. Use a component from @grafana/ui or custom CSS instead.", "5381"] ], - "plugins-bundled/internal/input-datasource/src/InputConfigEditor.tsx:5381": [ - [0, 0, 0, "gf-form usage has been deprecated. Use a component from @grafana/ui or custom CSS instead.", "5381"] - ], "public/app/angular/components/code_editor/code_editor.ts:5381": [ [0, 0, 0, "gf-form usage has been deprecated. Use a component from @grafana/ui or custom CSS instead.", "5381"] ], diff --git a/plugins-bundled/internal/input-datasource/.gitignore b/plugins-bundled/internal/input-datasource/.gitignore deleted file mode 100644 index 61c3bc75a05..00000000000 --- a/plugins-bundled/internal/input-datasource/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.yarn diff --git a/plugins-bundled/internal/input-datasource/README.md b/plugins-bundled/internal/input-datasource/README.md deleted file mode 100644 index 00761696d6a..00000000000 --- a/plugins-bundled/internal/input-datasource/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Direct Input Data Source - Bundled Plugin - -This data source lets you define results directly in CSV. The values are stored either in a shared data source, or directly in panels. diff --git a/plugins-bundled/internal/input-datasource/__mocks__/d3-interpolate.ts b/plugins-bundled/internal/input-datasource/__mocks__/d3-interpolate.ts deleted file mode 100644 index f053ebf7976..00000000000 --- a/plugins-bundled/internal/input-datasource/__mocks__/d3-interpolate.ts +++ /dev/null @@ -1 +0,0 @@ -module.exports = {}; diff --git a/plugins-bundled/internal/input-datasource/jest.config.js b/plugins-bundled/internal/input-datasource/jest.config.js deleted file mode 100644 index 88c2dfafc09..00000000000 --- a/plugins-bundled/internal/input-datasource/jest.config.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - testEnvironment: 'jest-environment-jsdom', - preset: 'ts-jest', - extensionsToTreatAsEsm: ['.ts'], - transform: { - '^.+\\.(t|j)sx?$': [ - 'ts-jest', - { - useESM: true, - isolatedModules: true, - allowJs: true, - }, - ], - }, - moduleNameMapper: { - '^d3-interpolate$': '/__mocks__/d3-interpolate.ts', - }, -}; diff --git a/plugins-bundled/internal/input-datasource/package.json b/plugins-bundled/internal/input-datasource/package.json deleted file mode 100644 index d893ab319d4..00000000000 --- a/plugins-bundled/internal/input-datasource/package.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "@grafana-plugins/input-datasource", - "version": "11.0.0-pre", - "description": "Input Datasource", - "private": true, - "repository": { - "type": "git", - "url": "http://github.com/grafana/grafana.git" - }, - "scripts": { - "build": "yarn test && webpack -c webpack.config.ts --env production", - "dev": "webpack -w -c webpack.config.ts --env development", - "test": "jest -c jest.config.js" - }, - "author": "Grafana Labs", - "devDependencies": { - "@grafana/tsconfig": "^1.3.0-rc1", - "@types/jest": "26.0.15", - "@types/react": "18.0.28", - "copy-webpack-plugin": "11.0.0", - "eslint-webpack-plugin": "4.0.0", - "fork-ts-checker-webpack-plugin": "8.0.0", - "jest": "29.3.1", - "jest-environment-jsdom": "29.3.1", - "swc-loader": "0.2.3", - "ts-jest": "29.0.5", - "ts-node": "10.9.2", - "webpack": "5.76.0" - }, - "dependencies": { - "@grafana/data": "11.0.0-pre", - "@grafana/ui": "11.0.0-pre", - "react": "18.2.0", - "tslib": "2.5.0" - } -} diff --git a/plugins-bundled/internal/input-datasource/src/InputConfigEditor.tsx b/plugins-bundled/internal/input-datasource/src/InputConfigEditor.tsx deleted file mode 100644 index e79558da14c..00000000000 --- a/plugins-bundled/internal/input-datasource/src/InputConfigEditor.tsx +++ /dev/null @@ -1,69 +0,0 @@ -// Libraries -import React, { PureComponent } from 'react'; - -// Types -import { DataSourcePluginOptionsEditorProps, DataFrame, MutableDataFrame } from '@grafana/data'; -import { TableInputCSV } from '@grafana/ui'; - -import { InputOptions } from './types'; -import { dataFrameToCSV } from './utils'; - -interface Props extends DataSourcePluginOptionsEditorProps {} - -interface State { - text: string; -} - -export class InputConfigEditor extends PureComponent { - state = { - text: '', - }; - - componentDidMount() { - const { options } = this.props; - if (options.jsonData.data) { - const text = dataFrameToCSV(options.jsonData.data); - this.setState({ text }); - } - } - - onSeriesParsed = (data: DataFrame[], text: string) => { - const { options, onOptionsChange } = this.props; - if (!data) { - data = [new MutableDataFrame()]; - } - // data is a property on 'jsonData' - const jsonData = { - ...options.jsonData, - data, - }; - - onOptionsChange({ - ...options, - jsonData, - }); - this.setState({ text }); - }; - - render() { - const { text } = this.state; - return ( -
-
-

Shared Data:

- Enter CSV - -
- -
- This data is stored in the datasource json and is returned to every user in the initial request for any - datasource. This is an appropriate place to enter a few values. Large datasets will perform better in other - datasources. -
-
- NOTE: Changes to this data will only be reflected after a browser refresh. -
-
- ); - } -} diff --git a/plugins-bundled/internal/input-datasource/src/InputDatasource.test.ts b/plugins-bundled/internal/input-datasource/src/InputDatasource.test.ts deleted file mode 100644 index e28de87908d..00000000000 --- a/plugins-bundled/internal/input-datasource/src/InputDatasource.test.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { - DataFrame, - DataFrameDTO, - DataSourceInstanceSettings, - MutableDataFrame, - PluginMeta, - readCSV, -} from '@grafana/data'; - -import InputDatasource, { describeDataFrame } from './InputDatasource'; -import { getQueryOptions } from './testHelpers'; -import { InputOptions, InputQuery } from './types'; - -describe('InputDatasource', () => { - const data = readCSV('a,b,c\n1,2,3\n4,5,6'); - const instanceSettings: DataSourceInstanceSettings = { - id: 1, - uid: 'xxx', - type: 'x', - name: 'xxx', - meta: {} as PluginMeta, - access: 'proxy', - readOnly: false, - jsonData: { - data, - }, - }; - - describe('when querying', () => { - test('should return the saved data with a query', () => { - const ds = new InputDatasource(instanceSettings); - const options = getQueryOptions({ - targets: [{ refId: 'Z' }], - }); - - return ds.query(options).then((rsp) => { - expect(rsp.data.length).toBe(1); - - const series: DataFrame = rsp.data[0]; - expect(series.refId).toBe('Z'); - expect(series.fields[0].values).toEqual(data[0].fields[0].values); - }); - }); - }); - - test('DataFrame descriptions', () => { - expect(describeDataFrame([])).toEqual(''); - expect(describeDataFrame(null as unknown as Array)).toEqual(''); - expect( - describeDataFrame([ - new MutableDataFrame({ - name: 'x', - fields: [{ name: 'a' }], - }), - ]) - ).toEqual('1 Fields, 0 Rows'); - }); -}); diff --git a/plugins-bundled/internal/input-datasource/src/InputDatasource.ts b/plugins-bundled/internal/input-datasource/src/InputDatasource.ts deleted file mode 100644 index 455452693ee..00000000000 --- a/plugins-bundled/internal/input-datasource/src/InputDatasource.ts +++ /dev/null @@ -1,124 +0,0 @@ -// Types -import { - DataQueryRequest, - DataQueryResponse, - TestDataSourceResponse, - DataSourceApi, - DataSourceInstanceSettings, - MetricFindValue, - DataFrame, - DataFrameDTO, - toDataFrame, -} from '@grafana/data'; - -import { InputQuery, InputOptions } from './types'; - -export class InputDatasource extends DataSourceApi { - data: DataFrame[] = []; - - constructor(instanceSettings: DataSourceInstanceSettings) { - super(instanceSettings); - - if (instanceSettings.jsonData.data) { - this.data = instanceSettings.jsonData.data.map((v) => toDataFrame(v)); - } - } - - /** - * Convert a query to a simple text string - */ - getQueryDisplayText(query: InputQuery): string { - if (query.data) { - return 'Panel Data: ' + describeDataFrame(query.data); - } - return `Shared Data From: ${this.name} (${describeDataFrame(this.data)})`; - } - - metricFindQuery(query: string, options?: any): Promise { - return new Promise((resolve, reject) => { - const names = []; - for (const series of this.data) { - for (const field of series.fields) { - // TODO, match query/options? - names.push({ - text: field.name, - }); - } - } - resolve(names); - }); - } - - query(options: DataQueryRequest): Promise { - const results: DataFrame[] = []; - for (const query of options.targets) { - if (query.hide) { - continue; - } - let data = this.data; - if (query.data) { - data = query.data.map((v) => toDataFrame(v)); - } - for (let i = 0; i < data.length; i++) { - results.push({ - ...data[i], - refId: query.refId, - }); - } - } - return Promise.resolve({ data: results }); - } - - testDatasource(): Promise { - return new Promise((resolve, reject) => { - let rowCount = 0; - let info = `${this.data.length} Series:`; - for (const series of this.data) { - const length = series.length; - info += ` [${series.fields.length} Fields, ${length} Rows]`; - rowCount += length; - } - - if (rowCount > 0) { - resolve({ - status: 'success', - message: info, - }); - } - reject({ - status: 'error', - message: 'No Data Entered', - }); - }); - } -} - -function getLength(data?: DataFrameDTO | DataFrame) { - if (!data || !data.fields || !data.fields.length) { - return 0; - } - if ('length' in data) { - return data.length; - } - return data.fields[0].values!.length; -} - -export function describeDataFrame(data: Array): string { - if (!data || !data.length) { - return ''; - } - if (data.length > 1) { - const count = data.reduce((acc, series) => { - return acc + getLength(series); - }, 0); - return `${data.length} Series, ${count} Rows`; - } - const series = data[0]; - if (!series.fields) { - return 'Missing Fields'; - } - const length = getLength(series); - return `${series.fields.length} Fields, ${length} Rows`; -} - -export default InputDatasource; diff --git a/plugins-bundled/internal/input-datasource/src/InputQueryEditor.tsx b/plugins-bundled/internal/input-datasource/src/InputQueryEditor.tsx deleted file mode 100644 index b20520629f6..00000000000 --- a/plugins-bundled/internal/input-datasource/src/InputQueryEditor.tsx +++ /dev/null @@ -1,86 +0,0 @@ -// Libraries -import React, { PureComponent } from 'react'; - -// Types -import { DataFrame, toCSV, SelectableValue, MutableDataFrame, QueryEditorProps } from '@grafana/data'; -import { Select, TableInputCSV, LinkButton, Icon, InlineField } from '@grafana/ui'; - -import { InputDatasource, describeDataFrame } from './InputDatasource'; -import { InputQuery, InputOptions } from './types'; -import { dataFrameToCSV } from './utils'; - -type Props = QueryEditorProps; - -const options = [ - { value: 'panel', label: 'Panel', description: 'Save data in the panel configuration.' }, - { value: 'shared', label: 'Shared', description: 'Save data in the shared datasource object.' }, -]; - -interface State { - text: string; -} - -export class InputQueryEditor extends PureComponent { - state = { - text: '', - }; - - onComponentDidMount() { - const { query } = this.props; - const text = dataFrameToCSV(query.data); - this.setState({ text }); - } - - onSourceChange = (item: SelectableValue) => { - const { datasource, query, onChange, onRunQuery } = this.props; - let data: DataFrame[] | undefined = undefined; - if (item.value === 'panel') { - if (query.data) { - return; - } - data = [...datasource.data]; - if (!data) { - data = [new MutableDataFrame()]; - } - this.setState({ text: toCSV(data) }); - } - onChange({ ...query, data }); - onRunQuery(); - }; - - onSeriesParsed = (data: DataFrame[], text: string) => { - const { query, onChange, onRunQuery } = this.props; - this.setState({ text }); - if (!data) { - data = [new MutableDataFrame()]; - } - onChange({ ...query, data }); - onRunQuery(); - }; - - render() { - const { datasource, query } = this.props; - const { uid, name } = datasource; - const { text } = this.state; - - const selected = query.data ? options[0] : options[1]; - return ( -
- - <> -