From 24692f702d22d929d784eea352b4db7351dd5402 Mon Sep 17 00:00:00 2001 From: leoswing <1160922634@qq.com> Date: Wed, 20 Nov 2024 17:51:17 +0800 Subject: [PATCH] fix: fix style in queryEditor --- src/components/QueryEditor.tsx | 205 ++++++++++++++++----------------- 1 file changed, 100 insertions(+), 105 deletions(-) diff --git a/src/components/QueryEditor.tsx b/src/components/QueryEditor.tsx index d6b8805..57afc55 100644 --- a/src/components/QueryEditor.tsx +++ b/src/components/QueryEditor.tsx @@ -1,8 +1,9 @@ import React, { ChangeEvent, useRef, FormEventHandler } from 'react'; import _ from 'lodash'; import defaults from 'lodash/defaults'; -import { InlineField, InlineFieldRow, HorizontalGroup, InlineSwitch, Input, Select } from '@grafana/ui'; -import { QueryEditorProps } from '@grafana/data'; +import { InlineField, InlineSwitch, Input, Select, Button, Icon, useStyles2 } from '@grafana/ui'; +import { QueryEditorProps, GrafanaTheme2 } from '@grafana/data'; +import { css } from '@emotion/css'; import { DataSource } from '../datasource'; import { TIMESHIFT_FORMAT_REG, TIMESHIFT_VAR_FORMAT_REG } from '../config'; import { CompareQueriesOptions, CompareQueriesQuery, defaultQuery } from '../types'; @@ -21,6 +22,15 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) { const aliasTypes = ['suffix', 'prefix', 'absolute']; let target: Record = defaults(query, defaultQuery); + const getStyles = (theme: GrafanaTheme2) => ({ + root: css({ + display: 'flex', + }), + addButton: css({ + padding: '0px 10px', + }), + }); + // Query refId change event const onQueryRefChange = (event: ChangeEvent) => { target.query = event.target.value; @@ -154,117 +164,102 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) { return !TIMESHIFT_FORMAT_REG.test(amountValue) && !TIMESHIFT_VAR_FORMAT_REG.test(amountValue) }; + const styles = useStyles2(getStyles); + return (
-
- -
- - - - - - - - -
-
+
+ + + + + + +
- - - { - target.timeShifts?.map((timeShift: any) => { - return ( -
- - - - Time shift - - - - - - - - - - - + - { - target.timeShifts.length > 1 && () - } -
) - }) - } -
- -
- - + + + + + + + + { + target.timeShifts.length > 1 && () + } +
) + }) + } +
+ ); }