Dashboard: Schema V2 - remove code in sharing export (#97164)
Dashboard: Schema V2 - remove code in sharing export related to schema v2 POC
This commit is contained in:
@@ -2,7 +2,6 @@ import saveAs from 'file-saver';
|
||||
import { useAsync } from 'react-use';
|
||||
import AutoSizer from 'react-virtualized-auto-sizer';
|
||||
|
||||
import { config } from '@grafana/runtime';
|
||||
import { SceneComponentProps, SceneObjectBase } from '@grafana/scenes';
|
||||
import { Button, ClipboardButton, CodeEditor, Field, Modal, Stack, Switch } from '@grafana/ui';
|
||||
import { t, Trans } from 'app/core/internationalization';
|
||||
@@ -11,7 +10,6 @@ import { shareDashboardType } from 'app/features/dashboard/components/ShareModal
|
||||
import { DashboardModel } from 'app/features/dashboard/state';
|
||||
|
||||
import { transformSceneToSaveModel } from '../serialization/transformSceneToSaveModel';
|
||||
import { transformSceneToSaveModelSchemaV2 } from '../serialization/transformSceneToSaveModelSchemaV2';
|
||||
import { getVariablesCompatibility } from '../utils/getVariablesCompatibility';
|
||||
import { DashboardInteractions } from '../utils/interactions';
|
||||
import { getDashboardSceneFor } from '../utils/utils';
|
||||
@@ -21,7 +19,6 @@ import { SceneShareTabState, ShareView } from './types';
|
||||
export interface ShareExportTabState extends SceneShareTabState {
|
||||
isSharingExternally?: boolean;
|
||||
isViewingJSON?: boolean;
|
||||
isViewingJSONSchemaV2?: boolean;
|
||||
}
|
||||
|
||||
export class ShareExportTab extends SceneObjectBase<ShareExportTabState> implements ShareView {
|
||||
@@ -54,12 +51,6 @@ export class ShareExportTab extends SceneObjectBase<ShareExportTabState> impleme
|
||||
});
|
||||
};
|
||||
|
||||
public onViewJSONSchemaV2 = () => {
|
||||
this.setState({
|
||||
isViewingJSONSchemaV2: !this.state.isViewingJSONSchemaV2,
|
||||
});
|
||||
};
|
||||
|
||||
public getClipboardText() {
|
||||
return;
|
||||
}
|
||||
@@ -81,23 +72,6 @@ export class ShareExportTab extends SceneObjectBase<ShareExportTabState> impleme
|
||||
return exportable;
|
||||
};
|
||||
|
||||
public getExportableDashboardJsonSchemaV2 = async () => {
|
||||
// const { isSharingExternally } = this.state;
|
||||
const saveModel = transformSceneToSaveModelSchemaV2(getDashboardSceneFor(this));
|
||||
|
||||
// const exportable = isSharingExternally
|
||||
// ? await this._exporter.makeExportable(
|
||||
// new DashboardModel(saveModel, undefined, {
|
||||
// getVariablesFromState: () => {
|
||||
// return getVariablesCompatibility(window.__grafanaSceneContext);
|
||||
// },
|
||||
// })
|
||||
// )
|
||||
// : saveModel;
|
||||
|
||||
return saveModel;
|
||||
};
|
||||
|
||||
public onSaveAsFile = async () => {
|
||||
const dashboardJson = await this.getExportableDashboardJson();
|
||||
const dashboardJsonPretty = JSON.stringify(dashboardJson, null, 2);
|
||||
@@ -120,9 +94,7 @@ export class ShareExportTab extends SceneObjectBase<ShareExportTabState> impleme
|
||||
}
|
||||
|
||||
function ShareExportTabRenderer({ model }: SceneComponentProps<ShareExportTab>) {
|
||||
const { isSharingExternally, isViewingJSON, modalRef, isViewingJSONSchemaV2 } = model.useState();
|
||||
// use dashboardSchemaV2 to show new button, this is for internal testing
|
||||
const shouldShowNewSchemaV2Button = config.featureToggles.dashboardSchemaV2 ?? false;
|
||||
const { isSharingExternally, isViewingJSON, modalRef } = model.useState();
|
||||
const dashboardJson = useAsync(async () => {
|
||||
if (isViewingJSON) {
|
||||
const json = await model.getExportableDashboardJson();
|
||||
@@ -132,20 +104,11 @@ function ShareExportTabRenderer({ model }: SceneComponentProps<ShareExportTab>)
|
||||
return '';
|
||||
}, [isViewingJSON]);
|
||||
|
||||
const dashboardJsonSchemaV2 = useAsync(async () => {
|
||||
if (isViewingJSONSchemaV2) {
|
||||
const json = await model.getExportableDashboardJsonSchemaV2();
|
||||
console.log('json v2', json);
|
||||
return JSON.stringify(json, null, 2);
|
||||
}
|
||||
return '';
|
||||
}, [isViewingJSONSchemaV2]);
|
||||
|
||||
const exportExternallyTranslation = t('share-modal.export.share-externally-label', `Export for sharing externally`);
|
||||
|
||||
return (
|
||||
<>
|
||||
{!isViewingJSON && !isViewingJSONSchemaV2 && (
|
||||
{!isViewingJSON && (
|
||||
<>
|
||||
<p>
|
||||
<Trans i18nKey="share-modal.export.info-text">Export this dashboard.</Trans>
|
||||
@@ -173,11 +136,6 @@ function ShareExportTabRenderer({ model }: SceneComponentProps<ShareExportTab>)
|
||||
<Button variant="secondary" icon="brackets-curly" onClick={model.onViewJSON}>
|
||||
<Trans i18nKey="share-modal.export.view-button">View JSON</Trans>
|
||||
</Button>
|
||||
{shouldShowNewSchemaV2Button && (
|
||||
<Button variant="secondary" icon="brackets-curly" onClick={model.onViewJSONSchemaV2}>
|
||||
<Trans i18nKey="share-modal.export.view-button-schemav2">View JSON SchemaV2</Trans>
|
||||
</Button>
|
||||
)}
|
||||
<Button variant="primary" icon="save" onClick={() => model.onSaveAsFile()}>
|
||||
<Trans i18nKey="share-modal.export.save-button">Save to file</Trans>
|
||||
</Button>
|
||||
@@ -231,52 +189,6 @@ function ShareExportTabRenderer({ model }: SceneComponentProps<ShareExportTab>)
|
||||
</Modal.ButtonRow>
|
||||
</>
|
||||
)}
|
||||
{isViewingJSONSchemaV2 && (
|
||||
<>
|
||||
<AutoSizer disableHeight>
|
||||
{({ width }) => {
|
||||
if (dashboardJsonSchemaV2.value) {
|
||||
return (
|
||||
<CodeEditor
|
||||
value={dashboardJsonSchemaV2.value ?? ''}
|
||||
language="json"
|
||||
showMiniMap={false}
|
||||
height="500px"
|
||||
width={width}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (dashboardJsonSchemaV2.loading) {
|
||||
return (
|
||||
<div>
|
||||
<Trans i18nKey="share-modal.export.loading">Loading...</Trans>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}}
|
||||
</AutoSizer>
|
||||
|
||||
<Modal.ButtonRow>
|
||||
<Button variant="secondary" fill="outline" onClick={model.onViewJSONSchemaV2} icon="arrow-left">
|
||||
<Trans i18nKey="share-modal.export.back-button">Back to export config</Trans>
|
||||
</Button>
|
||||
<ClipboardButton
|
||||
variant="secondary"
|
||||
icon="copy"
|
||||
disabled={dashboardJson.loading}
|
||||
getText={() => dashboardJson.value ?? ''}
|
||||
>
|
||||
<Trans i18nKey="share-modal.view-json.copy-button">Copy to Clipboard</Trans>
|
||||
</ClipboardButton>
|
||||
<Button variant="primary" icon="save" disabled={dashboardJson.loading} onClick={() => model.onSaveAsFile()}>
|
||||
<Trans i18nKey="share-modal.export.save-button">Save to file</Trans>
|
||||
</Button>
|
||||
</Modal.ButtonRow>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2937,8 +2937,7 @@
|
||||
"loading": "Loading...",
|
||||
"save-button": "Save to file",
|
||||
"share-externally-label": "Export for sharing externally",
|
||||
"view-button": "View JSON",
|
||||
"view-button-schemav2": "View JSON SchemaV2"
|
||||
"view-button": "View JSON"
|
||||
},
|
||||
"library": {
|
||||
"info": "Create library panel."
|
||||
|
||||
@@ -2937,8 +2937,7 @@
|
||||
"loading": "Ŀőäđįʼnģ...",
|
||||
"save-button": "Ŝävę ŧő ƒįľę",
|
||||
"share-externally-label": "Ēχpőřŧ ƒőř şĥäřįʼnģ ęχŧęřʼnäľľy",
|
||||
"view-button": "Vįęŵ ĴŜØŃ",
|
||||
"view-button-schemav2": "Vįęŵ ĴŜØŃ ŜčĥęmäV2"
|
||||
"view-button": "Vįęŵ ĴŜØŃ"
|
||||
},
|
||||
"library": {
|
||||
"info": "Cřęäŧę ľįþřäřy päʼnęľ."
|
||||
|
||||
Reference in New Issue
Block a user