From d4036d7ceb3652be3eac15821dde436f871ad593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Jamr=C3=B3z?= Date: Fri, 13 Aug 2021 09:52:02 +0200 Subject: [PATCH] Remove redundant variable --- .../graphite/components/SeriesSection.tsx | 2 +- .../datasource/graphite/components/TagsSection.tsx | 8 ++------ .../plugins/datasource/graphite/specs/store.test.ts | 4 ---- .../plugins/datasource/graphite/state/helpers.ts | 13 ------------- .../app/plugins/datasource/graphite/state/store.ts | 7 ------- 5 files changed, 3 insertions(+), 31 deletions(-) diff --git a/public/app/plugins/datasource/graphite/components/SeriesSection.tsx b/public/app/plugins/datasource/graphite/components/SeriesSection.tsx index 3908cf905bc..8e40026ebcc 100644 --- a/public/app/plugins/datasource/graphite/components/SeriesSection.tsx +++ b/public/app/plugins/datasource/graphite/components/SeriesSection.tsx @@ -10,7 +10,7 @@ type Props = { export function SeriesSection({ state }: Props) { const sectionContent = state.queryModel?.seriesByTagUsed ? ( - + ) : ( ); diff --git a/public/app/plugins/datasource/graphite/components/TagsSection.tsx b/public/app/plugins/datasource/graphite/components/TagsSection.tsx index 01c76735639..d2f6e2a8987 100644 --- a/public/app/plugins/datasource/graphite/components/TagsSection.tsx +++ b/public/app/plugins/datasource/graphite/components/TagsSection.tsx @@ -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 ; })} - {newTagsOptions.length && ( + {tags.length && ( inputMinWidth={150} onChange={(value) => { diff --git a/public/app/plugins/datasource/graphite/specs/store.test.ts b/public/app/plugins/datasource/graphite/specs/store.test.ts index d1b8b02867c..0b361161b28 100644 --- a/public/app/plugins/datasource/graphite/specs/store.test.ts +++ b/public/app/plugins/datasource/graphite/specs/store.test.ts @@ -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', () => { diff --git a/public/app/plugins/datasource/graphite/state/helpers.ts b/public/app/plugins/datasource/graphite/state/helpers.ts index d65305c002e..70816a726a0 100644 --- a/public/app/plugins/datasource/graphite/state/helpers.ts +++ b/public/app/plugins/datasource/graphite/state/helpers.ts @@ -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. diff --git a/public/app/plugins/datasource/graphite/state/store.ts b/public/app/plugins/datasource/graphite/state/store.ts index 91699735ce4..394ef6a5bb5 100644 --- a/public/app/plugins/datasource/graphite/state/store.ts +++ b/public/app/plugins/datasource/graphite/state/store.ts @@ -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;