actions.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { createAction } from '@reduxjs/toolkit';
  2. import { TimeRange } from '@grafana/data';
  3. import { FuncInstance } from '../gfunc';
  4. import { GraphiteQuery, GraphiteQueryEditorDependencies, GraphiteSegment, GraphiteTag } from '../types';
  5. /**
  6. * List of possible actions changing the state of QueryEditor
  7. */
  8. const init = createAction<GraphiteQueryEditorDependencies>('init');
  9. /**
  10. * Synchronise editor dependencies with internal state.
  11. */
  12. const timeRangeChanged = createAction<TimeRange | undefined>('time-range-changed');
  13. const queriesChanged = createAction<GraphiteQuery[] | undefined>('queries-changed');
  14. const queryChanged = createAction<GraphiteQuery>('query-changed');
  15. // Metrics & Tags
  16. const segmentValueChanged = createAction<{ segment: GraphiteSegment | string; index: number }>('segment-value-changed');
  17. // Tags
  18. const addNewTag = createAction<{ segment: GraphiteSegment }>('add-new-tag');
  19. const tagChanged = createAction<{ tag: GraphiteTag; index: number }>('tag-changed');
  20. const unpause = createAction('unpause');
  21. // Functions
  22. const addFunction = createAction<{ name: string }>('add-function');
  23. const removeFunction = createAction<{ func: FuncInstance }>('remove-function');
  24. const moveFunction = createAction<{ func: FuncInstance; offset: number }>('move-function');
  25. const updateFunctionParam = createAction<{ func: FuncInstance; index: number; value: string }>('change-function-param');
  26. // Text editor
  27. const updateQuery = createAction<{ query: string }>('update-query');
  28. const runQuery = createAction('run-current-query');
  29. const toggleEditorMode = createAction('toggle-editor');
  30. export const actions = {
  31. init,
  32. timeRangeChanged,
  33. queriesChanged,
  34. queryChanged,
  35. segmentValueChanged,
  36. tagChanged,
  37. addNewTag,
  38. unpause,
  39. addFunction,
  40. removeFunction,
  41. moveFunction,
  42. updateFunctionParam,
  43. updateQuery,
  44. runQuery,
  45. toggleEditorMode,
  46. };