Skip to content

Commit f62ef9b

Browse files
committed
feat: Add the requested the changes from the PR review
- **SQLDatasourceEditor**: Removed `useWatch` from react-hook-form; `driver` is now derived directly from `config.driver` (already present in `value.proxy.spec`). - **SQLTimeSeriesQueryEditor**: Replaced the manual `string → DatasourceSelector` conversion with the `isVariableDatasource` guard pattern used across other query editors, so variable datasources (e.g. `$ds`) are passed through as-is. - **package.json**: Added `"license": "Apache-2.0"` field. - **jest.config.ts**: Replaced `module.exports` + manual settings with the shared `jest.shared` config (matching `clickhouse/jest.config.ts`). - **test-setup.sh** (all three DB checks): Replaced `|| echo` with `|| { ...; exit 1; }` so a failed query exits the script rather than silently continuing to print "Test data verified". - **Makefile**: Fixed the Adminer port from `8080` to `8081` to match `docker-compose.test.yaml`. Signed-off-by: Pascal Zimmermann <pascal.zimmermann@theiotstudio.com>
1 parent 5696640 commit f62ef9b

6 files changed

Lines changed: 33 additions & 37 deletions

File tree

sql/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ db-up: ## Start all test databases
1818
@echo "PostgreSQL: localhost:5432"
1919
@echo "MySQL: localhost:3306"
2020
@echo "MariaDB: localhost:3307"
21-
@echo "Adminer UI: http://localhost:8080"
21+
@echo "Adminer UI: http://localhost:8081"
2222

2323
db-down: ## Stop all test databases
2424
docker-compose -f docker-compose.test.yaml down

sql/jest.config.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,13 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
const path = require('path');
15-
const fs = require('fs');
14+
import type { Config } from '@jest/types';
15+
import shared from '../jest.shared';
1616

17-
const swcrcPath = path.join(__dirname, '..', '.cjs.swcrc');
18-
const swcrc = JSON.parse(fs.readFileSync(swcrcPath, 'utf-8'));
17+
const jestConfig: Config.InitialOptions = {
18+
...shared,
1919

20-
module.exports = {
21-
testEnvironment: 'jsdom',
22-
roots: ['<rootDir>/src'],
23-
moduleNameMapper: {
24-
'^echarts/(.*)$': 'echarts',
25-
'^use-resize-observer$': 'use-resize-observer/polyfilled',
26-
'\\.(css|less)$': '<rootDir>/../stylesMock.js',
27-
},
28-
transformIgnorePatterns: ['node_modules/(?!(lodash-es|yaml|@perses-dev))'],
29-
transform: {
30-
'^.+\\.(ts|tsx|js|jsx)$': ['@swc/jest', { ...swcrc, exclude: [], swcrc: false }],
31-
},
32-
setupFilesAfterEnv: ['<rootDir>/src/setup-tests.ts'],
20+
setupFilesAfterEnv: [...(shared.setupFilesAfterEnv ?? []), '<rootDir>/src/setup-tests.ts'],
3321
};
22+
23+
export default jestConfig;

sql/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@perses-dev/sql-plugin",
33
"version": "0.1.0-rc.0",
44
"description": "Generic SQL datasource plugin for Perses (supports PostgreSQL, MySQL, MariaDB)",
5+
"license": "Apache-2.0",
56
"homepage": "https://github.com/perses/plugins/blob/main/README.md",
67
"repository": {
78
"type": "git",

sql/src/datasources/sql-datasource/SQLDatasourceEditor.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// limitations under the License.
1313

1414
import { Stack, TextField, MenuItem, Select, FormControl, InputLabel, FormHelperText } from '@mui/material';
15-
import { useWatch } from 'react-hook-form';
1615
import { OptionsEditorProps } from '@perses-dev/plugin-system';
1716
import { SQLDatasourceSpec, SQLProxySpec, SQLDriver, SSLMode } from './sql-datasource-types';
1817

@@ -32,11 +31,9 @@ const SSL_MODES: Array<{ value: SSLMode; label: string }> = [
3231
export function SQLDatasourceEditor(props: OptionsEditorProps<SQLDatasourceSpec>) {
3332
const { value, onChange } = props;
3433

35-
// Access the actual config through proxy.spec
3634
const config = value?.proxy?.spec || ({} as SQLProxySpec);
3735

38-
// Use useWatch to watch the driver field
39-
const driver = useWatch({ name: 'proxy.spec.driver', defaultValue: config.driver || 'postgres' });
36+
const driver = config.driver || 'postgres';
4037

4138
const handleChange = (field: keyof SQLProxySpec, fieldValue: unknown) => {
4239
onChange({

sql/src/queries/sql-time-series-query/SQLTimeSeriesQueryEditor.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,34 @@
1212
// limitations under the License.
1313

1414
import { Stack, TextField } from '@mui/material';
15-
import { OptionsEditorProps, DatasourceSelect } from '@perses-dev/plugin-system';
16-
import { DatasourceSelector } from '@perses-dev/spec';
15+
import {
16+
DatasourceSelect,
17+
DatasourceSelectProps,
18+
isVariableDatasource,
19+
OptionsEditorProps,
20+
} from '@perses-dev/plugin-system';
1721
import { SQLTimeSeriesQuerySpec } from './sql-time-series-query-types';
1822

19-
export function SQLTimeSeriesQueryEditor({ value, onChange }: OptionsEditorProps<SQLTimeSeriesQuerySpec>) {
20-
const handleDatasourceChange = (newDatasource: DatasourceSelector | string | undefined) => {
21-
// Convert string to DatasourceSelector if needed
22-
const datasourceValue: DatasourceSelector | undefined =
23-
typeof newDatasource === 'string'
24-
? { kind: 'SQLDatasource', name: newDatasource }
25-
: (newDatasource as DatasourceSelector | undefined);
23+
const DATASOURCE_KIND = 'SQLDatasource';
2624

27-
onChange({ ...value, datasource: datasourceValue });
25+
export function SQLTimeSeriesQueryEditor({ value, onChange }: OptionsEditorProps<SQLTimeSeriesQuerySpec>) {
26+
const handleDatasourceChange: DatasourceSelectProps['onChange'] = (newDatasource) => {
27+
if (isVariableDatasource(newDatasource)) {
28+
onChange({ ...value, datasource: newDatasource });
29+
return;
30+
}
31+
if (newDatasource.kind === DATASOURCE_KIND) {
32+
onChange({ ...value, datasource: newDatasource });
33+
return;
34+
}
35+
throw new Error('Got unexpected non SQLDatasource selection');
2836
};
2937

3038
return (
3139
<Stack spacing={2}>
3240
<DatasourceSelect
33-
datasourcePluginKind="SQLDatasource"
34-
value={value?.datasource || { kind: 'SQLDatasource' }}
41+
datasourcePluginKind={DATASOURCE_KIND}
42+
value={value?.datasource ?? { kind: DATASOURCE_KIND }}
3543
onChange={handleDatasourceChange}
3644
/>
3745

sql/test-setup.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ verify_data() {
7474
UNION ALL SELECT 'sensor_readings', COUNT(*) FROM sensor_readings \
7575
UNION ALL SELECT 'http_requests', COUNT(*) FROM http_requests \
7676
UNION ALL SELECT 'transactions', COUNT(*) FROM transactions \
77-
) t;" 2>/dev/null || echo -e "${RED} Failed to query PostgreSQL${NC}"
77+
) t;" || { echo -e "${RED} Failed to query PostgreSQL${NC}"; exit 1; }
7878

7979
# MySQL
8080
echo -e "${YELLOW}MySQL:${NC}"
@@ -84,7 +84,7 @@ verify_data() {
8484
UNION ALL SELECT 'sensor_readings', COUNT(*) FROM sensor_readings \
8585
UNION ALL SELECT 'http_requests', COUNT(*) FROM http_requests \
8686
UNION ALL SELECT 'transactions', COUNT(*) FROM transactions \
87-
) t;" 2>/dev/null || echo -e "${RED} Failed to query MySQL${NC}"
87+
) t;" || { echo -e "${RED} Failed to query MySQL${NC}"; exit 1; }
8888

8989
# MariaDB
9090
echo -e "${YELLOW}MariaDB:${NC}"
@@ -94,7 +94,7 @@ verify_data() {
9494
UNION ALL SELECT 'sensor_readings', COUNT(*) FROM sensor_readings \
9595
UNION ALL SELECT 'http_requests', COUNT(*) FROM http_requests \
9696
UNION ALL SELECT 'transactions', COUNT(*) FROM transactions \
97-
) t;" 2>/dev/null || echo -e "${RED} Failed to query MariaDB${NC}"
97+
) t;" || { echo -e "${RED} Failed to query MariaDB${NC}"; exit 1; }
9898

9999
echo -e "${GREEN}${NC} Test data verified"
100100
}

0 commit comments

Comments
 (0)