Skip to content

Commit

Permalink
Merge branch 'master' into release-0.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Nils Hirsekorn authored and Nils Hirsekorn committed Jan 10, 2021
2 parents 396facd + 8a624a8 commit 11407e8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 69 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meteostat-grafama",
"version": "0.1.4",
"name": "meteostat-grafana",
"version": "0.1.5",
"description": "Access historic weather data using the meteostat API",
"scripts": {
"build": "grafana-toolkit plugin:build && cp DOC.md dist/README.md",
Expand Down
104 changes: 38 additions & 66 deletions src/QueryEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import defaults from 'lodash/defaults';

import React, { ChangeEvent, PureComponent } from 'react';
import { AsyncSelect, Button, LegacyForms } from '@grafana/ui';
import { MultiSelect, InlineFieldRow, InlineField, AsyncSelect, Input } from '@grafana/ui';
import { QueryEditorProps, SelectableValue } from '@grafana/data';
import { DataSource } from './DataSource';
import { defaultQuery, MyDataSourceOptions, MyQuery, PropertiesMap } from './types';

const { FormField, Select } = LegacyForms;
// This is a temporary work-around for a styling issue related to the new Input component.
// For more information, refer to https://github.com/grafana/grafana/issues/26512.
import {} from '@emotion/core';

type Props = QueryEditorProps<DataSource, MyQuery, MyDataSourceOptions>;

Expand Down Expand Up @@ -48,81 +50,51 @@ export class QueryEditor extends PureComponent<Props> {
onRunQuery();
};

onPropertyChange = (event: SelectableValue, index: number) => {
onPropertiesChange = (v: Array<SelectableValue<string>>) => {
const { onChange, query, onRunQuery } = this.props;
const properties = JSON.parse(JSON.stringify(query.properties));
properties[index] = event.value;
onChange({ ...query, properties });
onRunQuery();
};

onPropertyRemoved = (index: number) => {
const { onChange, query, onRunQuery } = this.props;
const propertiesBefore = query.properties.slice(0, index);
const propertiesAfter = query.properties.slice(index + 1);
onChange({ ...query, properties: [...propertiesBefore, ...propertiesAfter] });
onRunQuery();
};

onAddProperty = () => {
const { onChange, query, onRunQuery } = this.props;
onChange({ ...query, properties: [...query.properties, ''] });
onChange({ ...query, properties: v.map(_ => _.value!) ?? [] });
onRunQuery();
};

render() {
const query = defaults(this.props.query, defaultQuery);
const { station, latitude, longitude, properties } = query;

const renderProperties = properties.map((property, index) => {
return (
<div className="gf-form-inline">
<Select
width={10}
value={PropertiesMap[property]}
onChange={event => this.onPropertyChange(event, index)}
placeholder="Property"
options={Object.values(PropertiesMap)}
/>
<Button onClick={() => this.onPropertyRemoved(index)}>-</Button>
</div>
);
});

return (
<div className="gf-form">
<div className="gf-form-group">
<AsyncSelect
width={30}
isClearable
value={station}
isLoading={this.state.isLoadingStations}
loadOptions={this.searchStations}
noOptionsMessage="No stations found"
onChange={this.onSearchStationSelected}
placeholder="Weather Station"
/>
<div className="gf-form-inline">
<FormField
labelWidth={10}
value={latitude || ''}
onChange={this.onLatitudeChange}
label="Latitude"
placeholder="Latitude"
<>
<InlineFieldRow>
<InlineField label="Weather station" labelWidth={15}>
<AsyncSelect
width={30}
isClearable
value={station}
isLoading={this.state.isLoadingStations}
loadOptions={this.searchStations}
noOptionsMessage="No stations found"
onChange={this.onSearchStationSelected}
/>
<FormField
labelWidth={10}
value={longitude || ''}
onChange={this.onLongitudeChange}
label="Longitude"
placeholder="Longitude"
</InlineField>
</InlineFieldRow>
<InlineFieldRow>
<InlineField label="Latitude" labelWidth={10}>
<Input width={30} value={latitude || ''} onChange={this.onLatitudeChange} />
</InlineField>
<InlineField label="Longitude" labelWidth={10}>
<Input width={30} value={longitude || ''} onChange={this.onLongitudeChange} />
</InlineField>
</InlineFieldRow>
<InlineFieldRow>
<InlineField label="Properties" labelWidth={10}>
<MultiSelect
width={71}
value={properties}
onChange={v => this.onPropertiesChange(v)}
placeholder="Property"
options={Object.values(PropertiesMap)}
/>
</div>
Properties
{renderProperties}
<Button onClick={this.onAddProperty}>+</Button>
</div>
</div>
</InlineField>
</InlineFieldRow>
</>
);
}
}
2 changes: 1 addition & 1 deletion src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"updated": "%TODAY%"
},
"dependencies": {
"grafanaDependency": "6.5.x",
"grafanaDependency": "7.3.x",
"plugins": []
},
"routes": [
Expand Down

0 comments on commit 11407e8

Please sign in to comment.