LokiQueryField.tsx 1.0 KB

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