Remove redundant variable

This commit is contained in:
Piotr Jamróz
2021-08-13 09:52:02 +02:00
parent 5d72b0c2c6
commit d4036d7ceb
5 changed files with 3 additions and 31 deletions
@@ -10,7 +10,7 @@ type Props = {
export function SeriesSection({ state }: Props) {
const sectionContent = state.queryModel?.seriesByTagUsed ? (
<TagsSection tags={state.queryModel?.tags} addTagSegments={state.addTagSegments} state={state} />
<TagsSection tags={state.queryModel?.tags} state={state} />
) : (
<MetricsSection segments={state.segments} state={state} />
);
@@ -7,7 +7,6 @@ import { Button, SegmentAsync, useStyles2 } from '@grafana/ui';
import { actions } from '../state/actions';
import { GrafanaTheme2 } from '@grafana/data';
import { css } from '@emotion/css';
import { mapSegmentsToSelectables } from './helpers';
import { TagEditor } from './TagEditor';
import { debounce } from 'lodash';
import { useDispatch } from '../state/context';
@@ -15,7 +14,6 @@ import { PlayButton } from './PlayButton';
type Props = {
tags: GraphiteTag[];
addTagSegments: GraphiteSegment[];
state: GraphiteQueryEditorState;
};
@@ -25,12 +23,10 @@ type Props = {
* Options for tag names are reloaded while user is typing with backend taking care of auto-complete
* (auto-complete cannot be implemented in front-end because backend returns only limited number of entries)
*/
export function TagsSection({ tags, state, addTagSegments }: Props) {
export function TagsSection({ tags, state }: Props) {
const dispatch = useDispatch();
const styles = useStyles2(getStyles);
const newTagsOptions = mapSegmentsToSelectables(addTagSegments || []);
// Options are reloaded while user is typing with backend taking care of auto-complete (auto-complete cannot be
// implemented in front-end because backend returns only limited number of entries)
const getTagsAsSegmentsOptions = useCallback(
@@ -48,7 +44,7 @@ export function TagsSection({ tags, state, addTagSegments }: Props) {
{tags.map((tag, index) => {
return <TagEditor key={index} tagIndex={index} tag={tag} state={state} />;
})}
{newTagsOptions.length && (
{tags.length && (
<SegmentAsync<GraphiteSegment>
inputMinWidth={150}
onChange={(value) => {
@@ -349,10 +349,6 @@ describe('Graphite actions', async () => {
];
expect(ctx.state.queryModel.tags).toEqual(expected);
});
it('should add plus button', () => {
expect(ctx.state.addTagSegments.length).toBe(1);
});
});
describe('when tag added', () => {
@@ -37,10 +37,6 @@ export async function buildSegments(state: GraphiteQueryEditorState, modifyLastS
const checkOtherSegmentsIndex = state.queryModel.checkOtherSegmentsIndex || 0;
await checkOtherSegments(state, checkOtherSegmentsIndex, modifyLastSegment);
if (state.queryModel.seriesByTagUsed) {
fixTagSegments(state);
}
}
/**
@@ -138,15 +134,6 @@ export function smartlyHandleNewAliasByNode(state: GraphiteQueryEditorState, fun
}
}
/**
* Add "+" button for adding tags once at least one tag is selected
*/
export function fixTagSegments(state: GraphiteQueryEditorState): void {
// Adding tag with the same name as just removed works incorrectly if single segment is used (instead of array)
// TODO: The segment data is not being used.
state.addTagSegments = [{ value: '+', fake: true }];
}
/**
* Pauses running the query to allow selecting tag value. This is to prevent getting errors if the query is run
* for a tag with no selected value.
@@ -9,7 +9,6 @@ import {
buildSegments,
checkOtherSegments,
emptySegments,
fixTagSegments,
handleTargetChanged,
parseTarget,
pause,
@@ -23,11 +22,6 @@ import { AnyAction } from '@reduxjs/toolkit';
import { TimeRange } from '@grafana/data';
export type GraphiteQueryEditorState = {
/**
* Extra segment with plus button when tags are rendered
*/
addTagSegments: GraphiteSegment[];
supportsTags: boolean;
paused: boolean;
removeTagValue: string;
@@ -130,7 +124,6 @@ const reducer = async (action: Action, state: GraphiteQueryEditorState): Promise
const newTag = { key: newTagKey, operator: '=' as GraphiteTagOperator, value: '' };
state.queryModel.addTag(newTag);
handleTargetChanged(state);
fixTagSegments(state);
}
if (actions.unpause.match(action)) {
state.paused = false;