Skip to content

Commit 48c774d

Browse files
authored
Add precommit hook (#112)
1 parent e365ca7 commit 48c774d

15 files changed

+198
-113
lines changed

.drone.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,3 @@ steps:
4141
---
4242
kind: signature
4343
hmac: a2e180c09fe108e09838e4c44aa5648124fff138cb0372080677dcdd14e49f9f
44-
45-
...

.github/issue_commands.json

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
[
2-
{
3-
"type": "label",
4-
"name": "grafana-aws-sdk-react",
5-
"action": "addToProject",
6-
"addToProject": {
7-
"url": "https://github.com/orgs/grafana/projects/97"
8-
}
9-
},
10-
{
11-
"type": "label",
12-
"name": "grafana-aws-sdk-react",
13-
"action": "removeFromProject",
14-
"removeFromProject": {
15-
"url": "https://github.com/orgs/grafana/projects/97"
16-
}
17-
},
18-
{
19-
"type": "label",
20-
"name": "type/docs",
21-
"action": "addToProject",
22-
"addToProject": {
23-
"url": "https://github.com/orgs/grafana/projects/69"
24-
}
25-
},
26-
{
27-
"type": "label",
28-
"name": "type/docs",
29-
"action": "removeFromProject",
30-
"removeFromProject": {
31-
"url": "https://github.com/orgs/grafana/projects/69"
32-
}
1+
[
2+
{
3+
"type": "label",
4+
"name": "grafana-aws-sdk-react",
5+
"action": "addToProject",
6+
"addToProject": {
7+
"url": "https://github.com/orgs/grafana/projects/97"
338
}
34-
]
9+
},
10+
{
11+
"type": "label",
12+
"name": "grafana-aws-sdk-react",
13+
"action": "removeFromProject",
14+
"removeFromProject": {
15+
"url": "https://github.com/orgs/grafana/projects/97"
16+
}
17+
},
18+
{
19+
"type": "label",
20+
"name": "type/docs",
21+
"action": "addToProject",
22+
"addToProject": {
23+
"url": "https://github.com/orgs/grafana/projects/69"
24+
}
25+
},
26+
{
27+
"type": "label",
28+
"name": "type/docs",
29+
"action": "removeFromProject",
30+
"removeFromProject": {
31+
"url": "https://github.com/orgs/grafana/projects/69"
32+
}
33+
}
34+
]

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ cypress/screenshots/actual
66
cypress/videos/
77
dist/
88
compiled/
9+
910
yarn-error.log
1011
.idea/
1112
.DS_Store
13+
14+
.eslintcache

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export DRONE_TOKEN=<Your DRONE_TOKEN>
2626

2727
drone --server https://drone.grafana.net sign --save grafana/grafana-aws-sdk-react
2828
```
29+
2930
### Local Development
3031

31-
For local development instructions, please see the [contributing guide](https://github.com/grafana/grafana-aws-sdk-react/blob/main/CONTRIBUTING.md).
32+
For local development instructions, please see the [contributing guide](https://github.com/grafana/grafana-aws-sdk-react/blob/main/CONTRIBUTING.md).

cspell.config.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
2-
"ignorePaths": [
3-
".github/**",
4-
"node_modules/**",
5-
"dist/**",
6-
"yarn.lock"
7-
],
2+
"ignorePaths": [".github/**", "node_modules/**", "dist/**", "yarn.lock"],
83
"words": [
94
"SIGV",
105
"isob",
116
"Creds",
127
"CREDS",
13-
"opensearch",
8+
"opensearch",
149
"esbuild",
1510
"testid",
1611
"Datasources",
1712
"Datasource",
1813
"typecheck",
19-
"tibdex"
14+
"tibdex",
15+
"eslintcache",
16+
"lefthook",
17+
"gofmt",
18+
"hmac",
19+
"grabpl"
2020
]
2121
}

lefthook.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pre-commit:
2+
parallel: true
3+
commands:
4+
frontend-lint:
5+
glob: '*.{js,ts,tsx}'
6+
run: |
7+
yarn lint {staged_files}
8+
yarn prettier --write {staged_files}
9+
stage_fixed: true
10+
spellcheck:
11+
run: yarn spellcheck {staged_files}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464
"identity-obj-proxy": "^3.0.0",
6565
"jest": "29.7.0",
6666
"jest-environment-jsdom": "^29.7.0",
67+
"lefthook": "^1.9.2",
6768
"node-notifier": "^10.0.1",
69+
"prettier": "^3.4.2",
6870
"react": "18.3.1",
6971
"react-dom": "18.3.1",
7072
"react-router-dom": "^6.27.0",

src/components/SIGV4ConnectionConfig.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ import React from 'react';
33
import { fireEvent, render, screen } from '@testing-library/react';
44
import { AwsAuthType } from '../types';
55
import { SIGV4ConnectionConfig } from './SIGV4ConnectionConfig';
6-
import {config} from '@grafana/runtime'
6+
import { config } from '@grafana/runtime';
77

88
jest.mock('@grafana/runtime', () => ({
99
...jest.requireActual('@grafana/runtime'),
1010
config: {
1111
awsAllowedAuthProviders: [AwsAuthType.Credentials, AwsAuthType.Keys],
1212
awsAssumeRoleEnabled: true,
1313
featureToggles: {
14-
awsDatasourcesTempCredentials: false
15-
}
14+
awsDatasourcesTempCredentials: false,
15+
},
1616
},
1717
}));
1818

1919
describe('SIGV4ConnectionConfig', () => {
2020
beforeEach(() => {
2121
config.awsAllowedAuthProviders = [AwsAuthType.Credentials, AwsAuthType.Keys];
2222
config.awsAssumeRoleEnabled = true;
23-
config.featureToggles.awsDatasourcesTempCredentials = false
23+
config.featureToggles.awsDatasourcesTempCredentials = false;
2424
});
2525
const setup = (onOptionsChange?: () => {}) => {
2626
const props: DataSourcePluginOptionsEditorProps<any, any> = {

src/components/SIGV4ConnectionConfig.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import { AwsAuthDataSourceSecureJsonData, AwsAuthDataSourceJsonData, ConnectionC
66

77
export interface SIGV4ConnectionConfigProps extends DataSourcePluginOptionsEditorProps<any, any> {
88
inExperimentalAuthComponent?: boolean;
9-
};
9+
}
1010

11-
export const SIGV4ConnectionConfig: React.FC<SIGV4ConnectionConfigProps> = (
12-
props: SIGV4ConnectionConfigProps
13-
) => {
11+
export const SIGV4ConnectionConfig: React.FC<SIGV4ConnectionConfigProps> = (props: SIGV4ConnectionConfigProps) => {
1412
const { onOptionsChange, options } = props;
1513

1614
// Map HttpSettings props to ConnectionConfigProps

src/sql/ConfigEditor/ConfigSelect.test.tsx

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,38 @@ const props: ConfigSelectProps = {
1616
};
1717

1818
describe('ConfigSelect', () => {
19-
it('should call onChange with the new value', async () => {
20-
const fetch = jest.fn().mockResolvedValue(['bar']);
21-
const onChange = jest.fn();
22-
const label = 'foo-id';
23-
render(<ConfigSelect {...props} label={label} fetch={fetch} onChange={onChange} />);
24-
25-
const selectEl = screen.getByLabelText(label);
26-
expect(selectEl).toBeInTheDocument();
27-
expect(selectEl).not.toBeDisabled();
28-
await select(selectEl, 'bar', { container: document.body });
29-
expect(fetch).toHaveBeenCalled();
30-
expect(onChange).toHaveBeenCalledWith({ label: 'bar', value: 'bar' });
31-
});
32-
33-
it('should show disabled select if passed disabled as prop', () => {
34-
const label = 'foo-id';
35-
render(<ConfigSelect {...props} disabled={true} label={label} />);
36-
const selectEl = screen.getByLabelText(label);
37-
38-
expect(selectEl).toBeDisabled();
39-
});
40-
41-
it('should show disabled select if passed disabled=false as prop but jsonData.defaultRegion is not set', () => {
42-
const propsWithoutDefaultRegion = {
43-
...props,
44-
options: { ...props.options, jsonData: { ...props.options.jsonData } },
45-
};
46-
propsWithoutDefaultRegion.options.jsonData = {};
47-
const label = 'foo-id';
48-
render(<ConfigSelect {...propsWithoutDefaultRegion} disabled={false} label={label} />);
49-
const selectEl = screen.getByLabelText(label);
50-
51-
expect(selectEl).toBeDisabled();
52-
});
19+
it('should call onChange with the new value', async () => {
20+
const fetch = jest.fn().mockResolvedValue(['bar']);
21+
const onChange = jest.fn();
22+
const label = 'foo-id';
23+
render(<ConfigSelect {...props} label={label} fetch={fetch} onChange={onChange} />);
24+
25+
const selectEl = screen.getByLabelText(label);
26+
expect(selectEl).toBeInTheDocument();
27+
expect(selectEl).not.toBeDisabled();
28+
await select(selectEl, 'bar', { container: document.body });
29+
expect(fetch).toHaveBeenCalled();
30+
expect(onChange).toHaveBeenCalledWith({ label: 'bar', value: 'bar' });
31+
});
32+
33+
it('should show disabled select if passed disabled as prop', () => {
34+
const label = 'foo-id';
35+
render(<ConfigSelect {...props} disabled={true} label={label} />);
36+
const selectEl = screen.getByLabelText(label);
37+
38+
expect(selectEl).toBeDisabled();
39+
});
40+
41+
it('should show disabled select if passed disabled=false as prop but jsonData.defaultRegion is not set', () => {
42+
const propsWithoutDefaultRegion = {
43+
...props,
44+
options: { ...props.options, jsonData: { ...props.options.jsonData } },
45+
};
46+
propsWithoutDefaultRegion.options.jsonData = {};
47+
const label = 'foo-id';
48+
render(<ConfigSelect {...propsWithoutDefaultRegion} disabled={false} label={label} />);
49+
const selectEl = screen.getByLabelText(label);
50+
51+
expect(selectEl).toBeDisabled();
52+
});
5353
});

0 commit comments

Comments
 (0)