selectors.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {
  2. AdHocVariableEditorState,
  3. DataSourceVariableEditorState,
  4. QueryVariableEditorState,
  5. VariableEditorState,
  6. } from './reducer';
  7. /**
  8. * Narrows generic variable editor state down to specific Adhoc variable extended editor state
  9. */
  10. export function getAdhocVariableEditorState(editorState: VariableEditorState): AdHocVariableEditorState | null {
  11. if (editorState.extended && 'dataSources' in editorState.extended) {
  12. return editorState.extended;
  13. }
  14. return null;
  15. }
  16. /**
  17. * Narrows generic variable editor state down to specific Datasource variable extended editor state
  18. */
  19. export function getDatasourceVariableEditorState(
  20. editorState: VariableEditorState
  21. ): DataSourceVariableEditorState | null {
  22. if (editorState.extended && 'dataSourceTypes' in editorState.extended) {
  23. return editorState.extended;
  24. }
  25. return null;
  26. }
  27. /**
  28. * Narrows generic variable editor state down to specific Query variable extended editor state
  29. */
  30. export function getQueryVariableEditorState(editorState: VariableEditorState): QueryVariableEditorState | null {
  31. if (editorState.extended && 'dataSource' in editorState.extended) {
  32. return editorState.extended;
  33. }
  34. return null;
  35. }