LokiQueryField.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  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. );
  13. return (
  14. <LokiQueryFieldForm
  15. datasource={datasource}
  16. datasourceStatus={datasourceStatus}
  17. syntaxLoaded={isSyntaxReady}
  18. /**
  19. * setActiveOption name is intentional. Because of the way rc-cascader requests additional data
  20. * https://github.com/react-component/cascader/blob/master/src/Cascader.jsx#L165
  21. * we are notyfing useLokiSyntax hook, what the active option is, and then it's up to the hook logic
  22. * to fetch data of options that aren't fetched yet
  23. */
  24. onLoadOptions={setActiveOption}
  25. onLabelsRefresh={refreshLabels}
  26. {...syntaxProps}
  27. {...otherProps}
  28. />
  29. );
  30. };
  31. export default LokiQueryField;