mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 02:23:31 -06:00
Primarily- moving majority of the types and utils from @grafana/ui to @grafana/data * Move types from grafana-ui to grafana-data * Move valueFormats to grafana-data * Move utils from grafana-ui to grafana-data * Update imports in grafana-ui * revert data's tsconfig change * Update imports in grafana-runtime * Fix import paths in grafana-ui * Move rxjs to devDeps * Core import updates batch 1 * Import updates batch 2 * Imports fix batch 3 * Imports fixes batch i don't know * Fix imorts in grafana-toolkit * Fix imports after master merge
97 lines
2.6 KiB
TypeScript
97 lines
2.6 KiB
TypeScript
// Libraries
|
|
import React, { PureComponent } from 'react';
|
|
|
|
// @ts-ignore ignoring this for now, otherwise we would have to extend _ interface with move
|
|
import _ from 'lodash';
|
|
|
|
// Types
|
|
import { PanelModel } from '../state/PanelModel';
|
|
import { DataQuery, PanelData, DataSourceSelectItem } from '@grafana/data';
|
|
import { DashboardModel } from '../state/DashboardModel';
|
|
import { QueryEditorRow } from './QueryEditorRow';
|
|
import { addQuery } from 'app/core/utils/query';
|
|
|
|
interface Props {
|
|
// The query configuration
|
|
queries: DataQuery[];
|
|
datasource: DataSourceSelectItem;
|
|
|
|
// Query editing
|
|
onChangeQueries: (queries: DataQuery[]) => void;
|
|
onScrollBottom: () => void;
|
|
|
|
// Dashboard Configs
|
|
panel: PanelModel;
|
|
dashboard: DashboardModel;
|
|
|
|
// Query Response Data
|
|
data: PanelData;
|
|
}
|
|
|
|
export class QueryEditorRows extends PureComponent<Props> {
|
|
onAddQuery = (query?: Partial<DataQuery>) => {
|
|
const { queries, onChangeQueries } = this.props;
|
|
onChangeQueries(addQuery(queries, query));
|
|
this.props.onScrollBottom();
|
|
};
|
|
|
|
onRemoveQuery = (query: DataQuery) => {
|
|
const { queries, onChangeQueries, panel } = this.props;
|
|
const removed = queries.filter(q => {
|
|
return q !== query;
|
|
});
|
|
onChangeQueries(removed);
|
|
panel.refresh();
|
|
};
|
|
|
|
onMoveQuery = (query: DataQuery, direction: number) => {
|
|
const { queries, onChangeQueries, panel } = this.props;
|
|
|
|
const index = _.indexOf(queries, query);
|
|
// @ts-ignore
|
|
_.move(queries, index, index + direction);
|
|
onChangeQueries(queries);
|
|
panel.refresh();
|
|
};
|
|
|
|
onChangeQuery(query: DataQuery, index: number) {
|
|
const { queries, onChangeQueries } = this.props;
|
|
|
|
// ensure refId is maintained
|
|
query.refId = queries[index].refId;
|
|
|
|
// update query in array
|
|
onChangeQueries(
|
|
queries.map((item, itemIndex) => {
|
|
if (itemIndex === index) {
|
|
return query;
|
|
}
|
|
return item;
|
|
})
|
|
);
|
|
}
|
|
|
|
render() {
|
|
const { props } = this;
|
|
return (
|
|
<div className="query-editor-rows">
|
|
{props.queries.map((query, index) => (
|
|
<QueryEditorRow
|
|
dataSourceValue={query.datasource || props.datasource.value}
|
|
key={query.refId}
|
|
panel={props.panel}
|
|
dashboard={props.dashboard}
|
|
data={props.data}
|
|
query={query}
|
|
onChange={query => this.onChangeQuery(query, index)}
|
|
onRemoveQuery={this.onRemoveQuery}
|
|
onAddQuery={this.onAddQuery}
|
|
onMoveQuery={this.onMoveQuery}
|
|
inMixedMode={props.datasource.meta.mixed}
|
|
/>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
}
|