LokiQueryField.tsx 1.1 KB

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