LokiQueryField.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import React, { FunctionComponent } from 'react';
  2. import { LokiQueryFieldForm, LokiQueryFieldFormProps } from './LokiQueryFieldForm';
  3. import { useLokiSyntax } from './useLokiSyntax';
  4. import LokiLanguageProvider from '../language_provider';
  5. export const LokiQueryField: FunctionComponent<LokiQueryFieldFormProps> = ({
  6. datasource,
  7. datasourceStatus,
  8. ...otherProps
  9. }) => {
  10. const { isSyntaxReady, setActiveOption, refreshLabels, ...syntaxProps } = useLokiSyntax(
  11. datasource.languageProvider as LokiLanguageProvider,
  12. datasourceStatus,
  13. otherProps.absoluteRange
  14. );
  15. return (
  16. <LokiQueryFieldForm
  17. datasource={datasource}
  18. datasourceStatus={datasourceStatus}
  19. syntaxLoaded={isSyntaxReady}
  20. /**
  21. * setActiveOption name is intentional. Because of the way rc-cascader requests additional data
  22. * https://github.com/react-component/cascader/blob/master/src/Cascader.jsx#L165
  23. * we are notyfing useLokiSyntax hook, what the active option is, and then it's up to the hook logic
  24. * to fetch data of options that aren't fetched yet
  25. */
  26. onLoadOptions={setActiveOption}
  27. onLabelsRefresh={refreshLabels}
  28. {...syntaxProps}
  29. {...otherProps}
  30. />
  31. );
  32. };
  33. export default LokiQueryField;