diff --git a/web/ui/react-app/src/pages/graph/ExpressionInput.test.tsx b/web/ui/react-app/src/pages/graph/ExpressionInput.test.tsx
index 4b058416e..8dc20be61 100644
--- a/web/ui/react-app/src/pages/graph/ExpressionInput.test.tsx
+++ b/web/ui/react-app/src/pages/graph/ExpressionInput.test.tsx
@@ -30,6 +30,7 @@ describe('ExpressionInput', () => {
// Do nothing.
},
loading: false,
+ enableMetricAutocomplete: true,
};
let expressionInput: ReactWrapper;
@@ -174,8 +175,27 @@ describe('ExpressionInput', () => {
instance.createAutocompleteSection({ closeMenu: spyCloseMenu });
setTimeout(() => expect(spyCloseMenu).toHaveBeenCalled());
});
+ it('should not render list if enableMetricAutocomplete is false', () => {
+ const input = mount(
+
+ );
+ const instance: any = input.instance();
+ const spyCloseMenu = jest.fn();
+ instance.createAutocompleteSection({ closeMenu: spyCloseMenu });
+ setTimeout(() => expect(spyCloseMenu).toHaveBeenCalled());
+ });
it('should render autosuggest-dropdown', () => {
- const input = mount();
+ const input = mount(
+
+ );
const instance: any = input.instance();
const spyGetMenuProps = jest.fn();
const sections = instance.createAutocompleteSection({
diff --git a/web/ui/react-app/src/pages/graph/ExpressionInput.tsx b/web/ui/react-app/src/pages/graph/ExpressionInput.tsx
index 7d2622abb..3a5d10e30 100644
--- a/web/ui/react-app/src/pages/graph/ExpressionInput.tsx
+++ b/web/ui/react-app/src/pages/graph/ExpressionInput.tsx
@@ -14,6 +14,7 @@ interface ExpressionInputProps {
autocompleteSections: { [key: string]: string[] };
executeQuery: () => void;
loading: boolean;
+ enableMetricAutocomplete: boolean;
}
interface ExpressionInputState {
@@ -76,38 +77,39 @@ class ExpressionInput extends Component {
- const matches = this.getSearchMatches(inputValue!, items);
- return !matches.length
- ? acc
- : [
- ...acc,
-
- - {title}
- {matches
- .slice(0, 100) // Limit DOM rendering to 100 results, as DOM rendering is sloooow.
- .map(({ original, string: text }) => {
- const itemProps = downshift.getItemProps({
- key: original,
- index,
- item: original,
- style: {
- backgroundColor: highlightedIndex === index++ ? 'lightgray' : 'white',
- },
- });
- return (
-
- );
- })}
-
,
- ];
- }, [] as JSX.Element[])
- : [];
+ const sections =
+ inputValue!.length && this.props.enableMetricAutocomplete
+ ? Object.entries(autocompleteSections).reduce((acc, [title, items]) => {
+ const matches = this.getSearchMatches(inputValue!, items);
+ return !matches.length
+ ? acc
+ : [
+ ...acc,
+
+ - {title}
+ {matches
+ .slice(0, 100) // Limit DOM rendering to 100 results, as DOM rendering is sloooow.
+ .map(({ original, string: text }) => {
+ const itemProps = downshift.getItemProps({
+ key: original,
+ index,
+ item: original,
+ style: {
+ backgroundColor: highlightedIndex === index++ ? 'lightgray' : 'white',
+ },
+ });
+ return (
+
+ );
+ })}
+
,
+ ];
+ }, [] as JSX.Element[])
+ : [];
if (!sections.length) {
// This is ugly but is needed in order to sync state updates.
diff --git a/web/ui/react-app/src/pages/graph/Panel.test.tsx b/web/ui/react-app/src/pages/graph/Panel.test.tsx
index 3fc207272..a0b78d51d 100644
--- a/web/ui/react-app/src/pages/graph/Panel.test.tsx
+++ b/web/ui/react-app/src/pages/graph/Panel.test.tsx
@@ -32,6 +32,7 @@ const defaultProps = {
onExecuteQuery: (): void => {
// Do nothing.
},
+ enableMetricAutocomplete: true,
};
describe('Panel', () => {
diff --git a/web/ui/react-app/src/pages/graph/Panel.tsx b/web/ui/react-app/src/pages/graph/Panel.tsx
index bd103de4d..2da5c7051 100644
--- a/web/ui/react-app/src/pages/graph/Panel.tsx
+++ b/web/ui/react-app/src/pages/graph/Panel.tsx
@@ -22,6 +22,7 @@ interface PanelProps {
removePanel: () => void;
onExecuteQuery: (query: string) => void;
pathPrefix: string;
+ enableMetricAutocomplete: boolean;
}
interface PanelState {
@@ -233,6 +234,7 @@ class Panel extends Component {
onExpressionChange={this.handleExpressionChange}
executeQuery={this.executeQuery}
loading={this.state.loading}
+ enableMetricAutocomplete={this.props.enableMetricAutocomplete}
autocompleteSections={{
'Query History': pastQueries,
'Metric Names': metricNames,
diff --git a/web/ui/react-app/src/pages/graph/PanelList.tsx b/web/ui/react-app/src/pages/graph/PanelList.tsx
index b8e29bcb0..c299ccef8 100644
--- a/web/ui/react-app/src/pages/graph/PanelList.tsx
+++ b/web/ui/react-app/src/pages/graph/PanelList.tsx
@@ -22,9 +22,16 @@ interface PanelListProps extends RouteComponentProps {
metrics: string[];
useLocalTime: boolean;
queryHistoryEnabled: boolean;
+ enableMetricAutocomplete: boolean;
}
-export const PanelListContent: FC = ({ metrics = [], useLocalTime, queryHistoryEnabled, ...rest }) => {
+export const PanelListContent: FC = ({
+ metrics = [],
+ useLocalTime,
+ queryHistoryEnabled,
+ enableMetricAutocomplete,
+ ...rest
+}) => {
const [panels, setPanels] = useState(rest.panels);
const [historyItems, setLocalStorageHistoryItems] = useLocalStorage('history', []);
@@ -95,6 +102,7 @@ export const PanelListContent: FC = ({ metrics = [], useLocalTim
useLocalTime={useLocalTime}
metricNames={metrics}
pastQueries={queryHistoryEnabled ? historyItems : []}
+ enableMetricAutocomplete={enableMetricAutocomplete}
/>
))}