Skip to content

Commit 3b3ce7d

Browse files
authored
variable fixes, toolkit migration and docs website update (#729)
1 parent c6ee6bf commit 3b3ce7d

File tree

166 files changed

+6216
-18025
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+6216
-18025
lines changed

.config/.cprc.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "2.10.1"
3+
}

.config/.eslintrc

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in
5+
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-eslint-config
6+
*/
7+
{
8+
"extends": ["@grafana/eslint-config"],
9+
"root": true,
10+
"rules": {
11+
"react/prop-types": "off"
12+
},
13+
"overrides": [
14+
{
15+
"plugins": ["deprecation"],
16+
"files": ["src/**/*.{ts,tsx}"],
17+
"rules": {
18+
"deprecation/deprecation": "warn"
19+
},
20+
"parserOptions": {
21+
"project": "./tsconfig.json"
22+
}
23+
}
24+
]
25+
}

.config/.prettierrc.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in .config/README.md
5+
*/
6+
7+
module.exports = {
8+
endOfLine: 'auto',
9+
printWidth: 120,
10+
trailingComma: 'es5',
11+
semi: true,
12+
jsxSingleQuote: false,
13+
singleQuote: true,
14+
useTabs: false,
15+
tabWidth: 2,
16+
};

.config/Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ARG grafana_version=latest
2+
ARG grafana_image=grafana-enterprise
3+
4+
FROM grafana/${grafana_image}:${grafana_version}
5+
6+
# Make it as simple as possible to access the grafana instance for development purposes
7+
# Do NOT enable these settings in a public facing / production grafana instance
8+
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
9+
ENV GF_AUTH_ANONYMOUS_ENABLED "true"
10+
ENV GF_AUTH_BASIC_ENABLED "false"
11+
# Set development mode so plugins can be loaded without the need to sign
12+
ENV GF_DEFAULT_APP_MODE "development"
13+
14+
# Inject livereload script into grafana index.html
15+
USER root
16+
RUN sed -i 's/<\/body><\/html>/<script src=\"http:\/\/localhost:35729\/livereload.js\"><\/script><\/body><\/html>/g' /usr/share/grafana/public/views/index.html

.config/README.md

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Default build configuration by Grafana
2+
3+
**This is an auto-generated directory and is not intended to be changed! ⚠️**
4+
5+
The `.config/` directory holds basic configuration for the different tools
6+
that are used to develop, test and build the project. In order to make it updates easier we ask you to
7+
not edit files in this folder to extend configuration.
8+
9+
## How to extend the basic configs?
10+
11+
Bear in mind that you are doing it at your own risk, and that extending any of the basic configuration can lead
12+
to issues around working with the project.
13+
14+
### Extending the ESLint config
15+
16+
Edit the `.eslintrc` file in the project root in order to extend the ESLint configuration.
17+
18+
**Example:**
19+
20+
```json
21+
{
22+
"extends": "./.config/.eslintrc",
23+
"rules": {
24+
"react/prop-types": "off"
25+
}
26+
}
27+
```
28+
29+
---
30+
31+
### Extending the Prettier config
32+
33+
Edit the `.prettierrc.js` file in the project root in order to extend the Prettier configuration.
34+
35+
**Example:**
36+
37+
```javascript
38+
module.exports = {
39+
// Prettier configuration provided by Grafana scaffolding
40+
...require('./.config/.prettierrc.js'),
41+
42+
semi: false,
43+
};
44+
```
45+
46+
---
47+
48+
### Extending the Jest config
49+
50+
There are two configuration in the project root that belong to Jest: `jest-setup.js` and `jest.config.js`.
51+
52+
**`jest-setup.js`:** A file that is run before each test file in the suite is executed. We are using it to
53+
set up the Jest DOM for the testing library and to apply some polyfills. ([link to Jest docs](https://jestjs.io/docs/configuration#setupfilesafterenv-array))
54+
55+
**`jest.config.js`:** The main Jest configuration file that extends the Grafana recommended setup. ([link to Jest docs](https://jestjs.io/docs/configuration))
56+
57+
#### ESM errors with Jest
58+
59+
A common issue with the current jest config involves importing an npm package that only offers an ESM build. These packages cause jest to error with `SyntaxError: Cannot use import statement outside a module`. To work around this, we provide a list of known packages to pass to the `[transformIgnorePatterns](https://jestjs.io/docs/configuration#transformignorepatterns-arraystring)` jest configuration property. If need be, this can be extended in the following way:
60+
61+
```javascript
62+
process.env.TZ = 'UTC';
63+
const { grafanaESModules, nodeModulesToTransform } = require('./config/jest/utils');
64+
65+
module.exports = {
66+
// Jest configuration provided by Grafana
67+
...require('./.config/jest.config'),
68+
// Inform jest to only transform specific node_module packages.
69+
transformIgnorePatterns: [nodeModulesToTransform([...grafanaESModules, 'packageName'])],
70+
};
71+
```
72+
73+
---
74+
75+
### Extending the TypeScript config
76+
77+
Edit the `tsconfig.json` file in the project root in order to extend the TypeScript configuration.
78+
79+
**Example:**
80+
81+
```json
82+
{
83+
"extends": "./.config/tsconfig.json",
84+
"compilerOptions": {
85+
"preserveConstEnums": true
86+
}
87+
}
88+
```
89+
90+
---
91+
92+
### Extending the Webpack config
93+
94+
Follow these steps to extend the basic Webpack configuration that lives under `.config/`:
95+
96+
#### 1. Create a new Webpack configuration file
97+
98+
Create a new config file that is going to extend the basic one provided by Grafana.
99+
It can live in the project root, e.g. `webpack.config.ts`.
100+
101+
#### 2. Merge the basic config provided by Grafana and your custom setup
102+
103+
We are going to use [`webpack-merge`](https://github.com/survivejs/webpack-merge) for this.
104+
105+
```typescript
106+
// webpack.config.ts
107+
import type { Configuration } from 'webpack';
108+
import { merge } from 'webpack-merge';
109+
import grafanaConfig from './.config/webpack/webpack.config';
110+
111+
const config = async (env): Promise<Configuration> => {
112+
const baseConfig = await grafanaConfig(env);
113+
114+
return merge(baseConfig, {
115+
// Add custom config here...
116+
output: {
117+
asyncChunks: true,
118+
},
119+
});
120+
};
121+
122+
export default config;
123+
```
124+
125+
#### 3. Update the `package.json` to use the new Webpack config
126+
127+
We need to update the `scripts` in the `package.json` to use the extended Webpack configuration.
128+
129+
**Update for `build`:**
130+
131+
```diff
132+
-"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
133+
+"build": "webpack -c ./webpack.config.ts --env production",
134+
```
135+
136+
**Update for `dev`:**
137+
138+
```diff
139+
-"dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development",
140+
+"dev": "webpack -w -c ./webpack.config.ts --env development",
141+
```
142+
143+
### Configure grafana image to use when running docker
144+
145+
By default, `grafana-enterprise` will be used as the docker image for all docker related commands. If you want to override this behavior, simply alter the `docker-compose.yaml` by adding the following build arg `grafana_image`.
146+
147+
**Example:**
148+
149+
```yaml
150+
version: '3.7'
151+
152+
services:
153+
grafana:
154+
container_name: 'myorg-basic-app'
155+
build:
156+
context: ./.config
157+
args:
158+
grafana_version: ${GRAFANA_VERSION:-9.1.2}
159+
grafana_image: ${GRAFANA_IMAGE:-grafana}
160+
```
161+
162+
In this example, we assign the environment variable `GRAFANA_IMAGE` to the build arg `grafana_image` with a default value of `grafana`. This will allow you to set the value while running the docker-compose commands, which might be convenient in some scenarios.
163+
164+
---

.config/jest-setup.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in
5+
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-jest-config
6+
*/
7+
8+
import '@testing-library/jest-dom';
9+
10+
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
11+
Object.defineProperty(global, 'matchMedia', {
12+
writable: true,
13+
value: jest.fn().mockImplementation((query) => ({
14+
matches: false,
15+
media: query,
16+
onchange: null,
17+
addListener: jest.fn(), // deprecated
18+
removeListener: jest.fn(), // deprecated
19+
addEventListener: jest.fn(),
20+
removeEventListener: jest.fn(),
21+
dispatchEvent: jest.fn(),
22+
})),
23+
});
24+
25+
HTMLCanvasElement.prototype.getContext = () => {};

.config/jest.config.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in
5+
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-jest-config
6+
*/
7+
8+
const path = require('path');
9+
const { grafanaESModules, nodeModulesToTransform } = require('./jest/utils');
10+
11+
module.exports = {
12+
moduleNameMapper: {
13+
'\\.(css|scss|sass)$': 'identity-obj-proxy',
14+
'react-inlinesvg': path.resolve(__dirname, 'jest', 'mocks', 'react-inlinesvg.tsx'),
15+
},
16+
modulePaths: ['<rootDir>/src'],
17+
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
18+
testEnvironment: 'jest-environment-jsdom',
19+
testMatch: [
20+
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
21+
'<rootDir>/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}',
22+
'<rootDir>/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}',
23+
],
24+
transform: {
25+
'^.+\\.(t|j)sx?$': [
26+
'@swc/jest',
27+
{
28+
sourceMaps: 'inline',
29+
jsc: {
30+
parser: {
31+
syntax: 'typescript',
32+
tsx: true,
33+
decorators: false,
34+
dynamicImport: true,
35+
},
36+
},
37+
},
38+
],
39+
},
40+
// Jest will throw `Cannot use import statement outside module` if it tries to load an
41+
// ES module without it being transformed first. ./config/README.md#esm-errors-with-jest
42+
transformIgnorePatterns: [nodeModulesToTransform(grafanaESModules)],
43+
};
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Due to the grafana/ui Icon component making fetch requests to
2+
// `/public/img/icon/<icon_name>.svg` we need to mock react-inlinesvg to prevent
3+
// the failed fetch requests from displaying errors in console.
4+
5+
import React from 'react';
6+
7+
type Callback = (...args: any[]) => void;
8+
9+
export interface StorageItem {
10+
content: string;
11+
queue: Callback[];
12+
status: string;
13+
}
14+
15+
export const cacheStore: { [key: string]: StorageItem } = Object.create(null);
16+
17+
const SVG_FILE_NAME_REGEX = /(.+)\/(.+)\.svg$/;
18+
19+
const InlineSVG = ({ src }: { src: string }) => {
20+
// testId will be the file name without extension (e.g. `public/img/icons/angle-double-down.svg` -> `angle-double-down`)
21+
const testId = src.replace(SVG_FILE_NAME_REGEX, '$2');
22+
return <svg xmlns="http://www.w3.org/2000/svg" data-testid={testId} viewBox="0 0 24 24" />;
23+
};
24+
25+
export default InlineSVG;

.config/jest/utils.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in .config/README.md
5+
*/
6+
7+
/*
8+
* This utility function is useful in combination with jest `transformIgnorePatterns` config
9+
* to transform specific packages (e.g.ES modules) in a projects node_modules folder.
10+
*/
11+
const nodeModulesToTransform = (moduleNames) => `node_modules\/(?!.*(${moduleNames.join('|')})\/.*)`;
12+
13+
// Array of known nested grafana package dependencies that only bundle an ESM version
14+
const grafanaESModules = [
15+
'.pnpm', // Support using pnpm symlinked packages
16+
'@grafana/schema',
17+
'd3',
18+
'd3-color',
19+
'd3-force',
20+
'd3-interpolate',
21+
'd3-scale-chromatic',
22+
'ol',
23+
'react-colorful',
24+
'rxjs',
25+
'uuid',
26+
];
27+
28+
module.exports = {
29+
nodeModulesToTransform,
30+
grafanaESModules,
31+
};

.config/tsconfig.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in
5+
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-typescript-config
6+
*/
7+
{
8+
"compilerOptions": {
9+
"alwaysStrict": true,
10+
"declaration": false,
11+
"rootDir": "../src",
12+
"baseUrl": "../src",
13+
"typeRoots": ["../node_modules/@types"],
14+
"resolveJsonModule": true
15+
},
16+
"ts-node": {
17+
"compilerOptions": {
18+
"module": "commonjs",
19+
"target": "es5",
20+
"esModuleInterop": true
21+
},
22+
"transpileOnly": true
23+
},
24+
"include": ["../src", "./types"],
25+
"extends": "@grafana/tsconfig"
26+
}

0 commit comments

Comments
 (0)