Canvas: Inline element settings (#52771)

This commit is contained in:
Nathan Marrs 2022-08-01 11:22:13 -06:00 committed by GitHub
parent eab6365cf7
commit 7b249d19b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 13 deletions

View File

@ -3905,12 +3905,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"] [0, 0, 0, "Unexpected any. Specify a different type.", "1"]
], ],
"public/app/features/canvas/runtime/ables.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
],
"public/app/features/canvas/runtime/element.tsx:5381": [ "public/app/features/canvas/runtime/element.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"], [0, 0, 0, "Do not use any type assertions.", "1"],

View File

@ -4,11 +4,52 @@ import { HorizontalConstraint, VerticalConstraint } from '../types';
import { Scene } from './scene'; import { Scene } from './scene';
export const settingsViewable = (scene: Scene) => ({
name: 'settingsViewable',
props: {},
events: {},
render(moveable: MoveableManagerInterface<unknown, unknown>, React: Renderer) {
// If selection is more than 1 element don't display settings button
if (scene.selecto?.getSelectedTargets() && scene.selecto?.getSelectedTargets().length > 1) {
return;
}
const rect = moveable.getRect();
return (
<div
key={'settings-viewable'}
className={'moveable-settings'}
style={{
position: 'absolute',
left: `${rect.width + 18}px`,
top: '0px',
color: 'white',
fontSize: '18px',
cursor: 'pointer',
userSelect: 'none',
willChange: 'transform',
transform: 'translate(-50%, 0px)',
zIndex: 100,
}}
onClick={(event) => {
const container = moveable.getContainer();
const evt = new PointerEvent('contextmenu', { clientX: event.clientX, clientY: event.clientY });
container.dispatchEvent(evt);
}}
>
{``}
{``}
</div>
);
},
});
export const dimensionViewable = { export const dimensionViewable = {
name: 'dimensionViewable', name: 'dimensionViewable',
props: {}, props: {},
events: {}, events: {},
render(moveable: MoveableManagerInterface<any, any>, React: Renderer) { render(moveable: MoveableManagerInterface<unknown, unknown>, React: Renderer) {
const rect = moveable.getRect(); const rect = moveable.getRect();
return ( return (
<div <div
@ -40,9 +81,9 @@ export const constraintViewable = (scene: Scene) => ({
name: 'constraintViewable', name: 'constraintViewable',
props: {}, props: {},
events: {}, events: {},
render(moveable: MoveableManagerInterface<any, any>, React: Renderer) { render(moveable: MoveableManagerInterface<unknown, unknown>, React: Renderer) {
const rect = moveable.getRect(); const rect = moveable.getRect();
const targetElement = scene.findElementByTarget(moveable.state.target); const targetElement = scene.findElementByTarget(moveable.state.target!);
// If selection is more than 1 element don't display constraint visualizations // If selection is more than 1 element don't display constraint visualizations
if (scene.selecto?.getSelectedTargets() && scene.selecto?.getSelectedTargets().length > 1) { if (scene.selecto?.getSelectedTargets() && scene.selecto?.getSelectedTargets().length > 1) {

View File

@ -30,7 +30,7 @@ import { LayerActionID } from 'app/plugins/panel/canvas/types';
import { HorizontalConstraint, Placement, VerticalConstraint } from '../types'; import { HorizontalConstraint, Placement, VerticalConstraint } from '../types';
import { constraintViewable, dimensionViewable } from './ables'; import { constraintViewable, dimensionViewable, settingsViewable } from './ables';
import { ElementState } from './element'; import { ElementState } from './element';
import { FrameState } from './frame'; import { FrameState } from './frame';
import { RootElement } from './root'; import { RootElement } from './root';
@ -334,10 +334,11 @@ export class Scene {
this.moveable = new Moveable(this.div!, { this.moveable = new Moveable(this.div!, {
draggable: allowChanges, draggable: allowChanges,
resizable: allowChanges, resizable: allowChanges,
ables: [dimensionViewable, constraintViewable(this)], ables: [dimensionViewable, constraintViewable(this), settingsViewable(this)],
props: { props: {
dimensionViewable: allowChanges, dimensionViewable: allowChanges,
constraintViewable: allowChanges, constraintViewable: allowChanges,
settingsViewable: allowChanges,
}, },
origin: false, origin: false,
className: this.styles.selected, className: this.styles.selected,

View File

@ -4,8 +4,7 @@ import { useObservable } from 'react-use';
import { first } from 'rxjs/operators'; import { first } from 'rxjs/operators';
import { ContextMenu, MenuItem } from '@grafana/ui'; import { ContextMenu, MenuItem } from '@grafana/ui';
import { Scene } from 'app/features/canvas/runtime/scene';
import { Scene } from '../../../features/canvas/runtime/scene';
import { activePanelSubject } from './CanvasPanel'; import { activePanelSubject } from './CanvasPanel';
import { LayerActionID } from './types'; import { LayerActionID } from './types';

View File

@ -194,6 +194,7 @@ export class CanvasPanel extends Component<Props, State> {
renderInlineEdit = () => { renderInlineEdit = () => {
return <InlineEdit onClose={() => this.closeInlineEdit()} id={this.props.id} scene={activeCanvasPanel!.scene} />; return <InlineEdit onClose={() => this.closeInlineEdit()} id={this.props.id} scene={activeCanvasPanel!.scene} />;
}; };
render() { render() {
return ( return (
<> <>