mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* Add UMLs * Add rendered diagrams * Move QueryCtrl to flux * Remove redundant param in the reducer * Use named imports for lodash and fix typing for GraphiteTagOperator * Add missing async/await * Extract providers to a separate file * Clean up async await * Rename controller functions back to main * Simplify creating actions * Re-order controller functions * Separate helpers from actions * Rename vars * Simplify helpers * Move controller methods to state reducers * Remove docs (they are added in design doc) * Move actions.ts to state folder * Add docs * Add old methods stubs for easier review * Check how state dependencies will be mapped * Rename state to store * Rename state to store * Rewrite spec tests for Graphite Query Controller * Update docs * Update docs * Add GraphiteTextEditor * Add play button * Add AddGraphiteFunction * Use Segment to simplify AddGraphiteFunction * Memoize function defs * Fix useCallback deps * Update public/app/plugins/datasource/graphite/state/helpers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/helpers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/helpers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Add more type definitions * Remove submitOnClickAwayOption This behavior is actually needed to remove parameters in functions * Load function definitions before parsing the target on initial load * Add button padding * Fix loading function definitions * Change targetChanged to updateQuery to avoid mutating state directly It's also needed for extra refresh/runQuery execution as handleTargetChanged doesn't handle changing the raw query * Fix updating query after adding a function * Simplify updating function params * Migrate function editor to react * Simplify setting Segment Select min width * Remove unnecessary changes to SegmentInput * Extract view logic to a helper and update types definitions * Clean up types * Update FuncDef types and add tests * Show red border for unknown functions * Autofocus on new params * Extract params mapping to a helper * Split code between params and function editor * Focus on the first param when a function is added even if it's an optional argument * Add function editor tests * Remove todo marker * Fix adding new functions * Allow empty value in selects for removing function params * Add placeholders and fix styling * Add more docs * Create basic implementation for metrics and tags * Post merge fixes These files are not .ts * Remove mapping to Angular dropdowns * Simplify mapping tag names, values and operators * Simplify mapping metrics * Fix removing tags and autocomplete * Simplify debouncing providers * Ensure options are loaded twice and segment is opened * Remove focusing new segments logic (not supported by React's segment) * Clean up * Move debouncing to components * Simplify mapping to selectable options * Add docs * Group all components * Remove unused controller methods * Create Dispatch context * Group Series and Tags Sections * Create Functions section * Create Section component * use getStyles * remove redundant async/await * Remove * remove redundant async/await * Remove console.log and silent test console output * Do not display the name of the selected dropdown option * Move Section to grafana-ui * Update storybook * Simplify SectionLabel * Fix Influx tests * Fix API Extractor warnings * Fix API Extractor warnings * Do not show hidden functions * Use block docs for better doc generation * Handle undefined values provided for autocomplete * Section -> SegmentSection * Simplify section styling * Remove redundant div * Simplify SegmentSection component * Use theme.spacing * Use empty label instead of a single space label Co-authored-by: Giordano Ricci <me@giordanoricci.com>
82 lines
3.3 KiB
TypeScript
82 lines
3.3 KiB
TypeScript
import GraphiteQuery from './graphite_query';
|
|
import { QueryCtrl } from 'app/plugins/sdk';
|
|
import { auto } from 'angular';
|
|
import { TemplateSrv } from '@grafana/runtime';
|
|
import { actions } from './state/actions';
|
|
import { createStore, GraphiteQueryEditorState } from './state/store';
|
|
import { GraphiteActionDispatcher, GraphiteQueryEditorAngularDependencies } from './types';
|
|
|
|
/**
|
|
* @deprecated Moved to state/store
|
|
*
|
|
* Note: methods marked with WIP are kept for easier diffing with previous changes. They will be removed when
|
|
* GraphiteQueryCtrl is replaced with a react component.
|
|
*/
|
|
export class GraphiteQueryCtrl extends QueryCtrl {
|
|
static templateUrl = 'partials/query.editor.html';
|
|
|
|
declare queryModel: GraphiteQuery;
|
|
segments: any[] = [];
|
|
addTagSegments: any[] = [];
|
|
declare removeTagValue: string;
|
|
supportsTags = false;
|
|
paused = false;
|
|
|
|
state: GraphiteQueryEditorState;
|
|
readonly dispatch: GraphiteActionDispatcher;
|
|
|
|
/** @ngInject */
|
|
constructor(
|
|
$scope: any,
|
|
$injector: auto.IInjectorService,
|
|
private uiSegmentSrv: any,
|
|
private templateSrv: TemplateSrv
|
|
) {
|
|
super($scope, $injector);
|
|
|
|
// This controller will be removed once it's root partial (query.editor.html) renders only React components.
|
|
// All component will be wrapped in ReactQueryEditor receiving DataSourceApi in QueryRow.renderQueryEditor
|
|
// The init() action will be removed and the store will be created in ReactQueryEditor. Note that properties
|
|
// passed to React component in QueryRow.renderQueryEditor are different than properties passed to Angular editor
|
|
// and will be mapped/provided in a way described below:
|
|
const deps = {
|
|
// WIP: to be removed. It's not passed to ReactQueryEditor but it's used only to:
|
|
// - get refId of the query (refId be passed in query property),
|
|
// - and to refresh changes (this will be handled by onChange passed to ReactQueryEditor)
|
|
// - it's needed to get other targets to interpolate the query (this will be added in QueryRow)
|
|
panelCtrl: this.panelCtrl,
|
|
|
|
// WIP: to be replaced with query property passed to ReactQueryEditor
|
|
target: this.target,
|
|
|
|
// WIP: same object will be passed to ReactQueryEditor
|
|
datasource: this.datasource,
|
|
|
|
// This is used to create view models for Angular <metric-segment> component (view models are MetricSegment objects)
|
|
// It will be simplified to produce data needed by React <SegmentAsync/> component
|
|
uiSegmentSrv: this.uiSegmentSrv,
|
|
|
|
// WIP: will be replaced with:
|
|
// import { getTemplateSrv } from 'app/features/templating/template_srv';
|
|
templateSrv: this.templateSrv,
|
|
};
|
|
|
|
const [dispatch, state] = createStore((state) => {
|
|
this.state = state;
|
|
// HACK: inefficient but not invoked frequently. It's needed to inform angular watcher about state changes
|
|
// for state shared between React/AngularJS. Actions invoked from React component will not mark the scope
|
|
// as dirty and the view won't be updated. It has to happen manually on each state change.
|
|
this.$scope.$digest();
|
|
});
|
|
|
|
this.state = state;
|
|
this.dispatch = dispatch;
|
|
|
|
this.dispatch(actions.init(deps as GraphiteQueryEditorAngularDependencies));
|
|
}
|
|
|
|
async toggleEditorMode() {
|
|
await this.dispatch(actions.toggleEditorMode());
|
|
}
|
|
}
|