|
|
@ -1,9 +1,9 @@ |
|
|
|
import React, { PureComponent } from 'react'; |
|
|
|
import React, { PureComponent } from 'react'; |
|
|
|
import { chain } from 'lodash'; |
|
|
|
import { chain } from 'lodash'; |
|
|
|
import { AppEvents, PanelData, SelectableValue } from '@grafana/data'; |
|
|
|
import { AppEvents, PanelData, SelectableValue } from '@grafana/data'; |
|
|
|
import { Button, ClipboardButton, Field, JSONFormatter, Select, TextArea } from '@grafana/ui'; |
|
|
|
import { Button, CodeEditor, Field, Select } from '@grafana/ui'; |
|
|
|
|
|
|
|
import AutoSizer from 'react-virtualized-auto-sizer'; |
|
|
|
import { selectors } from '@grafana/e2e-selectors'; |
|
|
|
import { selectors } from '@grafana/e2e-selectors'; |
|
|
|
|
|
|
|
|
|
|
|
import { appEvents } from 'app/core/core'; |
|
|
|
import { appEvents } from 'app/core/core'; |
|
|
|
import { DashboardModel, PanelModel } from '../../state'; |
|
|
|
import { DashboardModel, PanelModel } from '../../state'; |
|
|
|
import { getPanelInspectorStyles } from './styles'; |
|
|
|
import { getPanelInspectorStyles } from './styles'; |
|
|
@ -49,20 +49,18 @@ export class InspectJSONTab extends PureComponent<Props, State> { |
|
|
|
super(props); |
|
|
|
super(props); |
|
|
|
this.state = { |
|
|
|
this.state = { |
|
|
|
show: ShowContent.PanelJSON, |
|
|
|
show: ShowContent.PanelJSON, |
|
|
|
text: getSaveModelJSON(props.panel), |
|
|
|
text: getPrettyJSON(props.panel.getSaveModel()), |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onSelectChanged = (item: SelectableValue<ShowContent>) => { |
|
|
|
onSelectChanged = (item: SelectableValue<ShowContent>) => { |
|
|
|
let text = ''; |
|
|
|
const show = this.getJSONObject(item.value); |
|
|
|
if (item.value === ShowContent.PanelJSON) { |
|
|
|
const text = getPrettyJSON(show); |
|
|
|
text = getSaveModelJSON(this.props.panel); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.setState({ text, show: item.value }); |
|
|
|
this.setState({ text, show: item.value }); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
onTextChanged = (e: React.FormEvent<HTMLTextAreaElement>) => { |
|
|
|
// Called onBlur
|
|
|
|
const text = e.currentTarget.value; |
|
|
|
onTextChanged = (text: string) => { |
|
|
|
this.setState({ text }); |
|
|
|
this.setState({ text }); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -93,17 +91,7 @@ export class InspectJSONTab extends PureComponent<Props, State> { |
|
|
|
return this.props.panel.getSaveModel(); |
|
|
|
return this.props.panel.getSaveModel(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { note: 'Unknown Object', show }; |
|
|
|
return { note: `Unknown Object: ${show}` }; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getClipboardText = () => { |
|
|
|
|
|
|
|
const { show } = this.state; |
|
|
|
|
|
|
|
const obj = this.getJSONObject(show); |
|
|
|
|
|
|
|
return JSON.stringify(obj, null, 2); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onClipboardCopied = () => { |
|
|
|
|
|
|
|
appEvents.emit(AppEvents.alertSuccess, ['Content copied to clipboard']); |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
onApplyPanelModel = () => { |
|
|
|
onApplyPanelModel = () => { |
|
|
@ -126,12 +114,6 @@ export class InspectJSONTab extends PureComponent<Props, State> { |
|
|
|
onClose(); |
|
|
|
onClose(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
renderPanelJSON(styles: any) { |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<TextArea spellCheck={false} value={this.state.text} onChange={this.onTextChanged} className={styles.editor} /> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
render() { |
|
|
|
const { dashboard } = this.props; |
|
|
|
const { dashboard } = this.props; |
|
|
|
const { show } = this.state; |
|
|
|
const { show } = this.state; |
|
|
@ -146,14 +128,6 @@ export class InspectJSONTab extends PureComponent<Props, State> { |
|
|
|
<Field label="Select source" className="flex-grow-1"> |
|
|
|
<Field label="Select source" className="flex-grow-1"> |
|
|
|
<Select options={options} value={selected} onChange={this.onSelectChanged} /> |
|
|
|
<Select options={options} value={selected} onChange={this.onSelectChanged} /> |
|
|
|
</Field> |
|
|
|
</Field> |
|
|
|
<ClipboardButton |
|
|
|
|
|
|
|
variant="secondary" |
|
|
|
|
|
|
|
className={styles.toolbarItem} |
|
|
|
|
|
|
|
getText={this.getClipboardText} |
|
|
|
|
|
|
|
onClipboardCopy={this.onClipboardCopied} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
Copy to clipboard |
|
|
|
|
|
|
|
</ClipboardButton> |
|
|
|
|
|
|
|
{isPanelJSON && canEdit && ( |
|
|
|
{isPanelJSON && canEdit && ( |
|
|
|
<Button className={styles.toolbarItem} onClick={this.onApplyPanelModel}> |
|
|
|
<Button className={styles.toolbarItem} onClick={this.onApplyPanelModel}> |
|
|
|
Apply |
|
|
|
Apply |
|
|
@ -161,19 +135,24 @@ export class InspectJSONTab extends PureComponent<Props, State> { |
|
|
|
)} |
|
|
|
)} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div className={styles.content}> |
|
|
|
<div className={styles.content}> |
|
|
|
{isPanelJSON ? ( |
|
|
|
<AutoSizer disableWidth> |
|
|
|
this.renderPanelJSON(styles) |
|
|
|
{({ height }) => ( |
|
|
|
) : ( |
|
|
|
<CodeEditor |
|
|
|
<div className={styles.viewer}> |
|
|
|
width="100%" |
|
|
|
<JSONFormatter json={this.getJSONObject(show)} /> |
|
|
|
height={height} |
|
|
|
</div> |
|
|
|
language="json" |
|
|
|
)} |
|
|
|
value={this.state.text} |
|
|
|
|
|
|
|
readOnly={!isPanelJSON} |
|
|
|
|
|
|
|
onBlur={this.onTextChanged} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
</AutoSizer> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</> |
|
|
|
</> |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getSaveModelJSON(panel: PanelModel): string { |
|
|
|
function getPrettyJSON(obj: any): string { |
|
|
|
return JSON.stringify(panel.getSaveModel(), null, 2); |
|
|
|
return JSON.stringify(obj, null, 2); |
|
|
|
} |
|
|
|
} |
|
|
|