AdvancedOptions.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { css } from '@emotion/css';
  2. import React, { useState } from 'react';
  3. import { CSSTransition } from 'react-transition-group';
  4. import { GrafanaTheme } from '@grafana/data';
  5. import { Icon, InlineField, InlineFieldRow, InlineLabel, Input, useStyles } from '@grafana/ui';
  6. import { JaegerQuery } from '../types';
  7. const durationPlaceholder = 'e.g. 1.2s, 100ms, 500us';
  8. type Props = {
  9. query: JaegerQuery;
  10. onChange: (value: JaegerQuery) => void;
  11. };
  12. export function AdvancedOptions({ query, onChange }: Props) {
  13. const [showAdvancedOptions, setShowAdvancedOptions] = useState(false);
  14. const styles = useStyles(getStyles);
  15. return (
  16. <div>
  17. <InlineFieldRow>
  18. <div className={styles.advancedOptionsContainer} onClick={() => setShowAdvancedOptions(!showAdvancedOptions)}>
  19. <InlineLabel as="div">
  20. Advanced options{' '}
  21. <Icon className={showAdvancedOptions ? styles.angleUp : styles.angleDown} name="angle-down" />
  22. </InlineLabel>
  23. </div>
  24. </InlineFieldRow>
  25. <CSSTransition
  26. in={showAdvancedOptions}
  27. mountOnEnter={true}
  28. unmountOnExit={true}
  29. timeout={300}
  30. classNames={styles}
  31. >
  32. <div>
  33. <InlineFieldRow>
  34. <InlineField label="Min Duration" labelWidth={21} grow>
  35. <Input
  36. id="minDuration"
  37. name="minDuration"
  38. value={query.minDuration || ''}
  39. placeholder={durationPlaceholder}
  40. onChange={(v) =>
  41. onChange({
  42. ...query,
  43. minDuration: v.currentTarget.value,
  44. })
  45. }
  46. />
  47. </InlineField>
  48. </InlineFieldRow>
  49. <InlineFieldRow>
  50. <InlineField label="Max Duration" labelWidth={21} grow>
  51. <Input
  52. id="maxDuration"
  53. name="maxDuration"
  54. value={query.maxDuration || ''}
  55. placeholder={durationPlaceholder}
  56. onChange={(v) =>
  57. onChange({
  58. ...query,
  59. maxDuration: v.currentTarget.value,
  60. })
  61. }
  62. />
  63. </InlineField>
  64. </InlineFieldRow>
  65. <InlineFieldRow>
  66. <InlineField label="Limit" labelWidth={21} grow tooltip="Maximum numbers of returned results">
  67. <Input
  68. id="limit"
  69. name="limit"
  70. value={query.limit || ''}
  71. type="number"
  72. onChange={(v) =>
  73. onChange({
  74. ...query,
  75. limit: v.currentTarget.value ? parseInt(v.currentTarget.value, 10) : undefined,
  76. })
  77. }
  78. />
  79. </InlineField>
  80. </InlineFieldRow>
  81. </div>
  82. </CSSTransition>
  83. </div>
  84. );
  85. }
  86. function getStyles(theme: GrafanaTheme) {
  87. return {
  88. advancedOptionsContainer: css`
  89. margin: 0 ${theme.spacing.xs} ${theme.spacing.xs} 0;
  90. width: 100%;
  91. cursor: pointer;
  92. `,
  93. enter: css`
  94. label: enter;
  95. height: 0;
  96. opacity: 0;
  97. `,
  98. enterActive: css`
  99. label: enterActive;
  100. height: 108px;
  101. opacity: 1;
  102. transition: height 300ms ease, opacity 300ms ease;
  103. `,
  104. exit: css`
  105. label: exit;
  106. height: 108px;
  107. opacity: 1;
  108. `,
  109. exitActive: css`
  110. label: exitActive;
  111. height: 0;
  112. opacity: 0;
  113. transition: height 300ms ease, opacity 300ms ease;
  114. `,
  115. angleUp: css`
  116. transform: rotate(-180deg);
  117. transition: transform 300ms;
  118. `,
  119. angleDown: css`
  120. transform: rotate(0deg);
  121. transition: transform 300ms;
  122. `,
  123. };
  124. }