From 2b379ba7eaf5e3fcf327471fdd2a06d67d943830 Mon Sep 17 00:00:00 2001 From: Joao Silva <100691367+JoaoSilvaGrafana@users.noreply.github.com> Date: Tue, 11 Jul 2023 15:48:23 +0100 Subject: [PATCH] Forms: Remove usage of sass styles in Group By and Reduce Transformations (#71223) --- .../RichHistory/RichHistoryQueriesTab.tsx | 7 -- .../RichHistory/RichHistoryStarredTab.tsx | 6 -- .../editors/GroupByTransformerEditor.tsx | 68 +++++---------- .../editors/ReduceTransformerEditor.tsx | 85 +++++++------------ 4 files changed, 55 insertions(+), 111 deletions(-) diff --git a/public/app/features/explore/RichHistory/RichHistoryQueriesTab.tsx b/public/app/features/explore/RichHistory/RichHistoryQueriesTab.tsx index 8b5d2ed0cdb..a9dd7a0bdbf 100644 --- a/public/app/features/explore/RichHistory/RichHistoryQueriesTab.tsx +++ b/public/app/features/explore/RichHistory/RichHistoryQueriesTab.tsx @@ -32,8 +32,6 @@ export interface RichHistoryQueriesTabProps { } const getStyles = (theme: GrafanaTheme2, height: number) => { - const bgColor = theme.isLight ? theme.v1.palette.gray5 : theme.v1.palette.dark4; - return { container: css` display: flex; @@ -76,11 +74,6 @@ const getStyles = (theme: GrafanaTheme2, height: number) => { multiselect: css` width: 100%; margin-bottom: ${theme.spacing(1)}; - .gf-form-select-box__multi-value { - background-color: ${bgColor}; - padding: ${theme.spacing(0.25, 0.5, 0.25, 1)}; - border-radius: ${theme.shape.borderRadius(1)}; - } `, sort: css` width: 170px; diff --git a/public/app/features/explore/RichHistory/RichHistoryStarredTab.tsx b/public/app/features/explore/RichHistory/RichHistoryStarredTab.tsx index b492c8f838c..1cd19952e34 100644 --- a/public/app/features/explore/RichHistory/RichHistoryStarredTab.tsx +++ b/public/app/features/explore/RichHistory/RichHistoryStarredTab.tsx @@ -29,7 +29,6 @@ export interface RichHistoryStarredTabProps { } const getStyles = (theme: GrafanaTheme2) => { - const bgColor = theme.isLight ? theme.v1.palette.gray5 : theme.v1.palette.dark4; return { container: css` display: flex; @@ -45,11 +44,6 @@ const getStyles = (theme: GrafanaTheme2) => { multiselect: css` width: 100%; margin-bottom: ${theme.spacing(1)}; - .gf-form-select-box__multi-value { - background-color: ${bgColor}; - padding: ${theme.spacing(0.25, 0.5, 0.25, 1)}; - border-radius: ${theme.shape.borderRadius(1)}; - } `, filterInput: css` margin-bottom: ${theme.spacing(1)}; diff --git a/public/app/features/transformers/editors/GroupByTransformerEditor.tsx b/public/app/features/transformers/editors/GroupByTransformerEditor.tsx index 54242338d65..c2e80529653 100644 --- a/public/app/features/transformers/editors/GroupByTransformerEditor.tsx +++ b/public/app/features/transformers/editors/GroupByTransformerEditor.tsx @@ -1,4 +1,4 @@ -import { css, cx } from '@emotion/css'; +import { css } from '@emotion/css'; import React, { useCallback } from 'react'; import { @@ -9,13 +9,15 @@ import { TransformerRegistryItem, TransformerUIProps, TransformerCategory, + GrafanaTheme2, } from '@grafana/data'; import { GroupByFieldOptions, GroupByOperationID, GroupByTransformerOptions, } from '@grafana/data/src/transformations/transformers/groupBy'; -import { Select, StatsPicker, stylesFactory } from '@grafana/ui'; +import { Stack } from '@grafana/experimental'; +import { useTheme2, Select, StatsPicker, InlineField } from '@grafana/ui'; import { useAllFieldNamesFromDataFrames } from '../utils'; @@ -67,7 +69,8 @@ const options = [ ]; export const GroupByFieldConfiguration = ({ fieldName, config, onConfigChange }: FieldProps) => { - const styles = getStyling(); + const theme = useTheme2(); + const styles = getStyles(theme); const onChange = useCallback( (value: SelectableValue) => { @@ -80,28 +83,15 @@ export const GroupByFieldConfiguration = ({ fieldName, config, onConfigChange }: ); return ( -
-
-
{fieldName}
-
- -
-
-
-
- {config?.operation === GroupByOperationID.aggregate && ( -
+ {config?.operation === GroupByOperationID.aggregate && ( -
- )} -
+ )} + + ); }; -const getStyling = stylesFactory(() => { - const cell = css` - display: table-cell; - `; - +const getStyles = (theme: GrafanaTheme2) => { return { - row: css` - display: table-row; + operation: css` + flex-shrink: 0; + height: 100%; + width: ${theme.spacing(24)}; `, - cell: cell, - rowSpacing: css` - margin-bottom: 4px; - `, - fieldName: css` - ${cell} - min-width: 250px; - white-space: nowrap; - `, - calculations: css` - ${cell} - width: 99%; + aggregations: css` + flex-grow: 1; `, }; -}); +}; export const groupByTransformRegistryItem: TransformerRegistryItem = { id: DataTransformerID.groupBy, diff --git a/public/app/features/transformers/editors/ReduceTransformerEditor.tsx b/public/app/features/transformers/editors/ReduceTransformerEditor.tsx index 049538cae92..f7623ac5a75 100644 --- a/public/app/features/transformers/editors/ReduceTransformerEditor.tsx +++ b/public/app/features/transformers/editors/ReduceTransformerEditor.tsx @@ -11,7 +11,7 @@ import { } from '@grafana/data'; import { ReduceTransformerMode, ReduceTransformerOptions } from '@grafana/data/src/transformations/transformers/reduce'; import { selectors } from '@grafana/e2e-selectors'; -import { LegacyForms, Select, StatsPicker } from '@grafana/ui'; +import { InlineField, Select, StatsPicker, InlineSwitch } from '@grafana/ui'; // TODO: Minimal implementation, needs some <3 export const ReduceTransformerEditor = ({ options, onChange }: TransformerUIProps) => { @@ -56,61 +56,40 @@ export const ReduceTransformerEditor = ({ options, onChange }: TransformerUIProp return ( <> -
-
-
- Mode -
- v.value === options.mode) || modes[0]} + onChange={onSelectMode} + /> + + + { + onChange({ + ...options, + reducers: stats as ReducerID[], + }); + }} + /> + {options.mode === ReduceTransformerMode.ReduceFields && ( -
-
- -
-
+ + + )} {options.mode !== ReduceTransformerMode.ReduceFields && ( -
-
- -
-
+ + + )} );