mirror of https://github.com/prometheus/prometheus
React UI: Change "metrics autocomplete" with "autocomplete" (#8174)
- First, it is currently not only removing "metric" autocomplete, but also "query history autocomplete", so the checkbox is confusing. - Then, in the future, we will want also "functions" autocomplete. Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>pull/8181/head
parent
cda52234eb
commit
f97fba7cc9
|
@ -30,7 +30,7 @@ describe('ExpressionInput', () => {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
},
|
},
|
||||||
loading: false,
|
loading: false,
|
||||||
enableMetricAutocomplete: true,
|
enableAutocomplete: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
let expressionInput: ReactWrapper;
|
let expressionInput: ReactWrapper;
|
||||||
|
@ -175,12 +175,12 @@ describe('ExpressionInput', () => {
|
||||||
instance.createAutocompleteSection({ closeMenu: spyCloseMenu });
|
instance.createAutocompleteSection({ closeMenu: spyCloseMenu });
|
||||||
setTimeout(() => expect(spyCloseMenu).toHaveBeenCalled());
|
setTimeout(() => expect(spyCloseMenu).toHaveBeenCalled());
|
||||||
});
|
});
|
||||||
it('should not render list if enableMetricAutocomplete is false', () => {
|
it('should not render list if enableAutocomplete is false', () => {
|
||||||
const input = mount(
|
const input = mount(
|
||||||
<ExpressionInput
|
<ExpressionInput
|
||||||
autocompleteSections={{ title: ['foo', 'bar', 'baz'] }}
|
autocompleteSections={{ title: ['foo', 'bar', 'baz'] }}
|
||||||
{...({} as any)}
|
{...({} as any)}
|
||||||
enableMetricAutocomplete={false}
|
enableAutocomplete={false}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
const instance: any = input.instance();
|
const instance: any = input.instance();
|
||||||
|
@ -193,7 +193,7 @@ describe('ExpressionInput', () => {
|
||||||
<ExpressionInput
|
<ExpressionInput
|
||||||
autocompleteSections={{ title: ['foo', 'bar', 'baz'] }}
|
autocompleteSections={{ title: ['foo', 'bar', 'baz'] }}
|
||||||
{...({} as any)}
|
{...({} as any)}
|
||||||
enableMetricAutocomplete={true}
|
enableAutocomplete={true}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
const instance: any = input.instance();
|
const instance: any = input.instance();
|
||||||
|
|
|
@ -14,7 +14,7 @@ interface ExpressionInputProps {
|
||||||
autocompleteSections: { [key: string]: string[] };
|
autocompleteSections: { [key: string]: string[] };
|
||||||
executeQuery: () => void;
|
executeQuery: () => void;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
enableMetricAutocomplete: boolean;
|
enableAutocomplete: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ExpressionInputState {
|
interface ExpressionInputState {
|
||||||
|
@ -78,7 +78,7 @@ class ExpressionInput extends Component<ExpressionInputProps, ExpressionInputSta
|
||||||
const { autocompleteSections } = this.props;
|
const { autocompleteSections } = this.props;
|
||||||
let index = 0;
|
let index = 0;
|
||||||
const sections =
|
const sections =
|
||||||
inputValue!.length && this.props.enableMetricAutocomplete
|
inputValue!.length && this.props.enableAutocomplete
|
||||||
? Object.entries(autocompleteSections).reduce((acc, [title, items]) => {
|
? Object.entries(autocompleteSections).reduce((acc, [title, items]) => {
|
||||||
const matches = this.getSearchMatches(inputValue!, items);
|
const matches = this.getSearchMatches(inputValue!, items);
|
||||||
return !matches.length
|
return !matches.length
|
||||||
|
|
|
@ -32,7 +32,7 @@ const defaultProps = {
|
||||||
onExecuteQuery: (): void => {
|
onExecuteQuery: (): void => {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
},
|
},
|
||||||
enableMetricAutocomplete: true,
|
enableAutocomplete: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('Panel', () => {
|
describe('Panel', () => {
|
||||||
|
|
|
@ -22,7 +22,7 @@ interface PanelProps {
|
||||||
removePanel: () => void;
|
removePanel: () => void;
|
||||||
onExecuteQuery: (query: string) => void;
|
onExecuteQuery: (query: string) => void;
|
||||||
pathPrefix: string;
|
pathPrefix: string;
|
||||||
enableMetricAutocomplete: boolean;
|
enableAutocomplete: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PanelState {
|
interface PanelState {
|
||||||
|
@ -234,7 +234,7 @@ class Panel extends Component<PanelProps, PanelState> {
|
||||||
onExpressionChange={this.handleExpressionChange}
|
onExpressionChange={this.handleExpressionChange}
|
||||||
executeQuery={this.executeQuery}
|
executeQuery={this.executeQuery}
|
||||||
loading={this.state.loading}
|
loading={this.state.loading}
|
||||||
enableMetricAutocomplete={this.props.enableMetricAutocomplete}
|
enableAutocomplete={this.props.enableAutocomplete}
|
||||||
autocompleteSections={{
|
autocompleteSections={{
|
||||||
'Query History': pastQueries,
|
'Query History': pastQueries,
|
||||||
'Metric Names': metricNames,
|
'Metric Names': metricNames,
|
||||||
|
|
|
@ -22,14 +22,14 @@ interface PanelListProps extends RouteComponentProps {
|
||||||
metrics: string[];
|
metrics: string[];
|
||||||
useLocalTime: boolean;
|
useLocalTime: boolean;
|
||||||
queryHistoryEnabled: boolean;
|
queryHistoryEnabled: boolean;
|
||||||
enableMetricAutocomplete: boolean;
|
enableAutocomplete: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PanelListContent: FC<PanelListProps> = ({
|
export const PanelListContent: FC<PanelListProps> = ({
|
||||||
metrics = [],
|
metrics = [],
|
||||||
useLocalTime,
|
useLocalTime,
|
||||||
queryHistoryEnabled,
|
queryHistoryEnabled,
|
||||||
enableMetricAutocomplete,
|
enableAutocomplete,
|
||||||
...rest
|
...rest
|
||||||
}) => {
|
}) => {
|
||||||
const [panels, setPanels] = useState(rest.panels);
|
const [panels, setPanels] = useState(rest.panels);
|
||||||
|
@ -102,7 +102,7 @@ export const PanelListContent: FC<PanelListProps> = ({
|
||||||
useLocalTime={useLocalTime}
|
useLocalTime={useLocalTime}
|
||||||
metricNames={metrics}
|
metricNames={metrics}
|
||||||
pastQueries={queryHistoryEnabled ? historyItems : []}
|
pastQueries={queryHistoryEnabled ? historyItems : []}
|
||||||
enableMetricAutocomplete={enableMetricAutocomplete}
|
enableAutocomplete={enableAutocomplete}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<Button className="d-block mb-3" color="primary" onClick={addPanel}>
|
<Button className="d-block mb-3" color="primary" onClick={addPanel}>
|
||||||
|
@ -116,7 +116,7 @@ const PanelList: FC<RouteComponentProps> = () => {
|
||||||
const [delta, setDelta] = useState(0);
|
const [delta, setDelta] = useState(0);
|
||||||
const [useLocalTime, setUseLocalTime] = useLocalStorage('use-local-time', false);
|
const [useLocalTime, setUseLocalTime] = useLocalStorage('use-local-time', false);
|
||||||
const [enableQueryHistory, setEnableQueryHistory] = useLocalStorage('enable-query-history', false);
|
const [enableQueryHistory, setEnableQueryHistory] = useLocalStorage('enable-query-history', false);
|
||||||
const [enableMetricAutocomplete, setEnableMetricAutocomplete] = useLocalStorage('enable-metric-autocomplete', true);
|
const [enableAutocomplete, setEnableAutocomplete] = useLocalStorage('enable-metric-autocomplete', true);
|
||||||
|
|
||||||
const pathPrefix = usePathPrefix();
|
const pathPrefix = usePathPrefix();
|
||||||
const { response: metricsRes, error: metricsErr } = useFetch<string[]>(`${pathPrefix}/${API_PATH}/label/__name__/values`);
|
const { response: metricsRes, error: metricsErr } = useFetch<string[]>(`${pathPrefix}/${API_PATH}/label/__name__/values`);
|
||||||
|
@ -159,11 +159,11 @@ const PanelList: FC<RouteComponentProps> = () => {
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
wrapperStyles={{ marginLeft: 20, display: 'inline-block' }}
|
wrapperStyles={{ marginLeft: 20, display: 'inline-block' }}
|
||||||
id="metric-autocomplete"
|
id="autocomplete"
|
||||||
onChange={({ target }) => setEnableMetricAutocomplete(target.checked)}
|
onChange={({ target }) => setEnableAutocomplete(target.checked)}
|
||||||
defaultChecked={enableMetricAutocomplete}
|
defaultChecked={enableAutocomplete}
|
||||||
>
|
>
|
||||||
Enable metric autocomplete
|
Enable autocomplete
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
{(delta > 30 || timeErr) && (
|
{(delta > 30 || timeErr) && (
|
||||||
<Alert color="danger">
|
<Alert color="danger">
|
||||||
|
@ -184,7 +184,7 @@ const PanelList: FC<RouteComponentProps> = () => {
|
||||||
useLocalTime={useLocalTime}
|
useLocalTime={useLocalTime}
|
||||||
metrics={metricsRes.data}
|
metrics={metricsRes.data}
|
||||||
queryHistoryEnabled={enableQueryHistory}
|
queryHistoryEnabled={enableQueryHistory}
|
||||||
enableMetricAutocomplete={enableMetricAutocomplete}
|
enableAutocomplete={enableAutocomplete}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue