mirror of https://github.com/grafana/grafana
Scenes: Show transformations when editing scene dashboard (#80372)
* Make dashboard data source query actually use DashboardDataSource
* remove commented out bit
* Always wrap SceneQueryRunner with SceneDataTransformer
* Update Dashboard model compat wrapper tests
* DashboardQueryEditor test
* VizPanelManager tests update
* transform save model to scene tests update
* Betterer
* PanelMenuBehavior test update
* Few more bits
* Prettier
* Show transformations when editing scene dashboard
* remove and edit transformations works
* add add and remove buttons
* Change styles to object to fix betterer issue
* Revert "Change styles to object to fix betterer issue"
This reverts commit 8627b9162c
.
* Fix the correct file...
* Some refactoring
* remove unneessary if statement
* panel data not present on first render
* move transformation tabs out of folder
* fix tests
* add lint exception
* refactor tab component
* Fix merge issue
* reorder components
---------
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
pull/80667/head
parent
dbae7ccd3f
commit
14c82c2725
@ -0,0 +1,37 @@ |
||||
import React from 'react'; |
||||
|
||||
import { selectors } from '@grafana/e2e-selectors'; |
||||
import { Box, Button, Stack, Text } from '@grafana/ui'; |
||||
import { Trans } from 'app/core/internationalization'; |
||||
|
||||
interface EmptyTransformationsProps { |
||||
onShowPicker: () => void; |
||||
} |
||||
export function EmptyTransformationsMessage(props: EmptyTransformationsProps) { |
||||
return ( |
||||
<Box alignItems="center" padding={4}> |
||||
<Stack direction="column" alignItems="center" gap={2}> |
||||
<Text element="h3" textAlignment="center"> |
||||
<Trans key="transformations.empty.add-transformation-header">Start transforming data</Trans> |
||||
</Text> |
||||
<Text element="p" textAlignment="center" data-testid={selectors.components.Transforms.noTransformationsMessage}> |
||||
<Trans key="transformations.empty.add-transformation-body"> |
||||
Transformations allow data to be changed in various ways before your visualization is shown. |
||||
<br /> |
||||
This includes joining data together, renaming fields, making calculations, formatting data for display, and |
||||
more. |
||||
</Trans> |
||||
</Text> |
||||
<Button |
||||
icon="plus" |
||||
variant="primary" |
||||
size="md" |
||||
onClick={props.onShowPicker} |
||||
data-testid={selectors.components.Transforms.addTransformationButton} |
||||
> |
||||
Add transformation |
||||
</Button> |
||||
</Stack> |
||||
</Box> |
||||
); |
||||
} |
@ -0,0 +1,54 @@ |
||||
import { render, screen } from '@testing-library/react'; |
||||
import React from 'react'; |
||||
|
||||
import { FieldType, LoadingState, TimeRange, standardTransformersRegistry, toDataFrame } from '@grafana/data'; |
||||
import { selectors } from '@grafana/e2e-selectors'; |
||||
import { SceneDataTransformer } from '@grafana/scenes'; |
||||
import { getStandardTransformers } from 'app/features/transformers/standardTransformers'; |
||||
|
||||
import { PanelDataTransformationsTab, PanelDataTransformationsTabRendered } from './PanelDataTransformationsTab'; |
||||
|
||||
function createPanelManagerMock(sceneDataTransformer: SceneDataTransformer) { |
||||
return { |
||||
getDataTransformer: () => sceneDataTransformer, |
||||
} as unknown as PanelDataTransformationsTab; |
||||
} |
||||
|
||||
describe('PanelDataTransformationsTab', () => { |
||||
it('renders empty message when there are no transformations', async () => { |
||||
const modelMock = createPanelManagerMock(new SceneDataTransformer({ transformations: [] })); |
||||
render(<PanelDataTransformationsTabRendered model={modelMock}></PanelDataTransformationsTabRendered>); |
||||
|
||||
await screen.findByTestId(selectors.components.Transforms.noTransformationsMessage); |
||||
}); |
||||
|
||||
it('renders transformations when there are transformations', async () => { |
||||
standardTransformersRegistry.setInit(getStandardTransformers); |
||||
const modelMock = createPanelManagerMock( |
||||
new SceneDataTransformer({ |
||||
data: { |
||||
timeRange: {} as unknown as TimeRange, |
||||
state: {} as unknown as LoadingState, |
||||
series: [ |
||||
toDataFrame({ |
||||
name: 'A', |
||||
fields: [ |
||||
{ name: 'time', type: FieldType.time, values: [100, 200, 300] }, |
||||
{ name: 'values', type: FieldType.number, values: [1, 2, 3] }, |
||||
], |
||||
}), |
||||
], |
||||
}, |
||||
transformations: [ |
||||
{ |
||||
id: 'calculateField', |
||||
options: {}, |
||||
}, |
||||
], |
||||
}) |
||||
); |
||||
render(<PanelDataTransformationsTabRendered model={modelMock}></PanelDataTransformationsTabRendered>); |
||||
|
||||
await screen.findByText('1 - Add field from calculation'); |
||||
}); |
||||
}); |
Loading…
Reference in new issue