Skip to content

Commit

Permalink
Transformations: Move debug to drawer (grafana#76281)
Browse files Browse the repository at this point in the history
* Move debug to drawer
* Prettier
* Remove render actions arg
* Remove unused import
  • Loading branch information
codeincarnate authored and ssama88 committed Oct 31, 2023
1 parent bd3193c commit f908058
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@grafana/data';
import { selectors } from '@grafana/e2e-selectors';
import { getTemplateSrv } from '@grafana/runtime';
import { Icon, JSONFormatter, useStyles2 } from '@grafana/ui';
import { Icon, JSONFormatter, useStyles2, Drawer } from '@grafana/ui';

import { TransformationsEditorTransformation } from './types';

Expand All @@ -24,6 +24,7 @@ interface TransformationEditorProps {
uiConfig: TransformerRegistryItem<any>;
configs: TransformationsEditorTransformation[];
onChange: (index: number, config: DataTransformerConfig) => void;
toggleShowDebug: () => void;
}

export const TransformationEditor = ({
Expand All @@ -33,6 +34,7 @@ export const TransformationEditor = ({
uiConfig,
configs,
onChange,
toggleShowDebug,
}: TransformationEditorProps) => {
const styles = useStyles2(getStyles);
const [input, setInput] = useState<DataFrame[]>([]);
Expand Down Expand Up @@ -84,32 +86,32 @@ export const TransformationEditor = ({
<div className={styles.editor} data-testid={selectors.components.TransformTab.transformationEditor(uiConfig.name)}>
{editor}
{debugMode && (
<div
className={styles.debugWrapper}
data-testid={selectors.components.TransformTab.transformationEditorDebugger(uiConfig.name)}
>
<div className={styles.debug}>
<div className={styles.debugTitle}>Transformation input data</div>
<div className={styles.debugJson}>
<JSONFormatter json={input} />
<Drawer title="Debug transformation" subtitle={uiConfig.name} onClose={toggleShowDebug}>
<div
className={styles.debugWrapper}
data-testid={selectors.components.TransformTab.transformationEditorDebugger(uiConfig.name)}
>
<div className={styles.debug}>
<div className={styles.debugTitle}>Input data</div>
<div className={styles.debugJson}>
<JSONFormatter json={input} />
</div>
</div>
<div className={styles.debugSeparator}>
<Icon name="arrow-right" />
</div>
<div className={styles.debug}>
<div className={styles.debugTitle}>Output data</div>
<div className={styles.debugJson}>{output && <JSONFormatter json={output} />}</div>
</div>
</div>
<div className={styles.debugSeparator}>
<Icon name="arrow-right" />
</div>
<div className={styles.debug}>
<div className={styles.debugTitle}>Transformation output data</div>
<div className={styles.debugJson}>{output && <JSONFormatter json={output} />}</div>
</div>
</div>
</Drawer>
)}
</div>
);
};

const getStyles = (theme: GrafanaTheme2) => {
const debugBorder = theme.isLight ? theme.v1.palette.gray85 : theme.v1.palette.gray15;

return {
title: css`
display: flex;
Expand Down Expand Up @@ -159,15 +161,15 @@ const getStyles = (theme: GrafanaTheme2) => {
font-family: ${theme.typography.fontFamilyMonospace};
font-size: ${theme.typography.bodySmall.fontSize};
color: ${theme.colors.text};
border-bottom: 1px solid ${debugBorder};
border-bottom: 1px solid ${theme.colors.border.weak};
flex-grow: 0;
flex-shrink: 1;
`,

debug: css`
margin-top: ${theme.spacing(1)};
padding: 0 ${theme.spacing(1, 1, 1)};
border: 1px solid ${debugBorder};
border: 1px solid ${theme.colors.border.weak};
background: ${theme.isLight ? theme.v1.palette.white : theme.v1.palette.gray05};
border-radius: ${theme.shape.radius.default};
width: 100%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import {
QueryOperationAction,
QueryOperationToggleAction,
} from 'app/core/components/QueryOperationRow/QueryOperationAction';
import {
QueryOperationRow,
QueryOperationRowRenderProps,
} from 'app/core/components/QueryOperationRow/QueryOperationRow';
import { QueryOperationRow } from 'app/core/components/QueryOperationRow/QueryOperationRow';
import config from 'app/core/config';
import { PluginStateInfo } from 'app/features/plugins/components/PluginStateInfo';

Expand Down Expand Up @@ -101,7 +98,7 @@ export const TransformationOperationRow = ({
[configs, index]
);

const renderActions = ({ isOpen }: QueryOperationRowRenderProps) => {
const renderActions = () => {
return (
<>
{uiConfig.state && <PluginStateInfo state={uiConfig.state} />}
Expand All @@ -122,7 +119,6 @@ export const TransformationOperationRow = ({
)}
<QueryOperationToggleAction
title="Debug"
disabled={!isOpen}
icon="bug"
onClick={instrumentToggleCallback(toggleShowDebug, 'debug', showDebug)}
active={showDebug}
Expand Down Expand Up @@ -183,6 +179,7 @@ export const TransformationOperationRow = ({
configs={configs}
uiConfig={uiConfig}
onChange={onChange}
toggleShowDebug={toggleShowDebug}
/>
</QueryOperationRow>
);
Expand Down

0 comments on commit f908058

Please sign in to comment.