index.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import React from 'react';
  2. import { config, featureEnabled } from '@grafana/runtime';
  3. import { isExpressionReference } from '@grafana/runtime/src/utils/DataSourceWithBackend';
  4. import { GroupActionComponents, RowActionComponents } from 'app/features/query/components/QueryActionComponent';
  5. import { store, dispatch } from 'app/store/store';
  6. import { EnterpriseStoreState } from '../types';
  7. import { RecordedQueryAddModal } from './RecordedQueryAddModal';
  8. import { CreateRecordedQuery } from './RecordedQueryCreateModal';
  9. import { getPrometheusWriteTarget } from './state/actions';
  10. const hasWriteTarget = (): boolean => {
  11. const state = store.getState() as EnterpriseStoreState;
  12. const target = state.recordedQueries.prometheusWriteTarget;
  13. return Boolean(target?.data_source_uid) && Boolean(target?.remote_write_path);
  14. };
  15. export function initRecordedQueries() {
  16. const showRecordQuery = featureEnabled('recordedqueries') && config?.recordedQueries?.enabled;
  17. if (!showRecordQuery) {
  18. return;
  19. }
  20. dispatch(getPrometheusWriteTarget());
  21. RowActionComponents.addExtraRenderAction((props) =>
  22. hasWriteTarget() && (props.dataSource?.meta.backend || isExpressionReference(props.dataSource)) ? (
  23. <CreateRecordedQuery {...props} />
  24. ) : null
  25. );
  26. GroupActionComponents.addExtraRenderAction((props) =>
  27. hasWriteTarget() ? <RecordedQueryAddModal {...props} /> : null
  28. );
  29. }