grafana/public/app/features/scenes/editor/SceneEditManager.tsx
Torkel Ödegaard 8c585a4ebf
Scene: Variables interpolation formats and multi value handling (#58591)
* Component that can cache and extract variable dependencies

* Component that can cache and extract variable dependencies

* Updates

* Refactoring

* Lots of refactoring and iterations of supporting both re-rendering and query re-execution

* Updated SceneCanvasText

* Updated name of file

* Updated

* Refactoring a bit

* Added back getName

* Added comment

* minor fix

* Minor fix

* Merge fixes

* Scene variable interpolation progress

* Merge fixes

* Added all format registeries

* Progress on multi value support

* Progress on multi value support

* Updates

* Progress on scoped vars

* Fixed circular dependency

* Updates

* Some review fixes

* Updated comment

* Added forceRender function

* Add back fail on console log

* Update public/app/features/scenes/variables/interpolation/sceneInterpolator.test.ts

* Moving functions from SceneObjectBase

* fixing tests

* Fixed e2e

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
2022-11-16 11:36:30 +01:00

76 lines
2.1 KiB
TypeScript

import { css } from '@emotion/css';
import React from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { useStyles2 } from '@grafana/ui';
import { SceneObjectBase } from '../core/SceneObjectBase';
import { SceneEditorState, SceneEditor, SceneObject, SceneComponentProps, SceneComponent } from '../core/types';
import { SceneComponentEditWrapper } from './SceneComponentEditWrapper';
import { SceneObjectEditor } from './SceneObjectEditor';
import { SceneObjectTree } from './SceneObjectTree';
export class SceneEditManager extends SceneObjectBase<SceneEditorState> implements SceneEditor {
public static Component = SceneEditorRenderer;
public get Component(): SceneComponent<this> {
return SceneEditorRenderer;
}
public onMouseEnterObject(model: SceneObject) {
this.setState({ hoverObject: { ref: model } });
}
public onMouseLeaveObject(model: SceneObject) {
if (model.parent) {
this.setState({ hoverObject: { ref: model.parent } });
} else {
this.setState({ hoverObject: undefined });
}
}
public onSelectObject(model: SceneObject) {
this.setState({ selectedObject: { ref: model } });
}
public getEditComponentWrapper() {
return SceneComponentEditWrapper;
}
}
function SceneEditorRenderer({ model, isEditing }: SceneComponentProps<SceneEditManager>) {
const { selectedObject } = model.useState();
const styles = useStyles2(getStyles);
if (!isEditing) {
return null;
}
return (
<div className={styles.container}>
<div className={styles.tree}>
<SceneObjectTree node={model.parent!} selectedObject={selectedObject?.ref} />
</div>
{selectedObject && <SceneObjectEditor model={selectedObject.ref} />}
</div>
);
}
const getStyles = (theme: GrafanaTheme2) => {
return {
container: css({
display: 'flex',
flexGrow: 0,
border: `1px solid ${theme.colors.border.weak}`,
background: theme.colors.background.primary,
width: theme.spacing(40),
cursor: 'pointer',
flexDirection: 'column',
}),
tree: css({
padding: theme.spacing(0.25, 1),
}),
};
};