From 31bb3522c895e8c1e0aabecba0af34de6d13ff7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Jamr=C3=B3z?= Date: Wed, 11 Aug 2021 09:13:55 +0200 Subject: [PATCH] Graphite: Migrate to React (part 3: migrate segments) (#37309) * 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 * Update public/app/plugins/datasource/graphite/state/helpers.ts Co-authored-by: Giordano Ricci * Update public/app/plugins/datasource/graphite/state/helpers.ts Co-authored-by: Giordano Ricci * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci * 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 * 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 * Use block docs for better doc generation * Handle undefined values provided for autocomplete Co-authored-by: Giordano Ricci --- .../src/components/Segment/SegmentAsync.tsx | 9 +- .../src/components/Segment/SegmentSelect.tsx | 19 +++- public/app/core/angular_wrappers.ts | 2 + .../graphite/components/MetricSegment.tsx | 59 ++++++++++++ .../graphite/components/MetricsSection.tsx | 34 +++++++ .../graphite/components/SeriesSection.tsx | 23 +++++ .../graphite/components/TagEditor.tsx | 91 +++++++++++++++++++ .../graphite/components/TagsSection.tsx | 75 +++++++++++++++ .../datasource/graphite/components/helpers.ts | 15 +++ .../datasource/graphite/graphite_query.ts | 8 +- .../graphite/partials/query.editor.html | 41 +-------- .../plugins/datasource/graphite/query_ctrl.ts | 38 ++++---- .../graphite/specs/query_ctrl.test.ts | 54 ++++++----- .../datasource/graphite/state/actions.ts | 2 +- .../datasource/graphite/state/helpers.ts | 17 +--- .../datasource/graphite/state/providers.ts | 69 +++++++++----- .../datasource/graphite/state/store.ts | 25 ++++- .../app/plugins/datasource/graphite/types.ts | 1 - 18 files changed, 448 insertions(+), 134 deletions(-) create mode 100644 public/app/plugins/datasource/graphite/components/MetricSegment.tsx create mode 100644 public/app/plugins/datasource/graphite/components/MetricsSection.tsx create mode 100644 public/app/plugins/datasource/graphite/components/SeriesSection.tsx create mode 100644 public/app/plugins/datasource/graphite/components/TagEditor.tsx create mode 100644 public/app/plugins/datasource/graphite/components/TagsSection.tsx diff --git a/packages/grafana-ui/src/components/Segment/SegmentAsync.tsx b/packages/grafana-ui/src/components/Segment/SegmentAsync.tsx index ffe4a60d2d8..b952c38367e 100644 --- a/packages/grafana-ui/src/components/Segment/SegmentAsync.tsx +++ b/packages/grafana-ui/src/components/Segment/SegmentAsync.tsx @@ -13,6 +13,11 @@ import { useStyles } from '../../themes'; export interface SegmentAsyncProps extends SegmentProps, Omit, 'value' | 'onChange'> { value?: T | SelectableValue; loadOptions: (query?: string) => Promise>>; + /** + * If true options will be reloaded when user changes the value in the input, + * otherwise, options will be loaded when the segment is clicked + */ + reloadOptionsOnChange?: boolean; onChange: (item: SelectableValue) => void; noOptionMessageHandler?: (state: AsyncState>>) => string; inputMinWidth?: number; @@ -22,6 +27,7 @@ export function SegmentAsync({ value, onChange, loadOptions, + reloadOptionsOnChange = false, Component, className, allowCustomValue, @@ -45,7 +51,7 @@ export function SegmentAsync({ return (