Skip to content

Commit

Permalink
feat: Add export functionality for dev tool queries
Browse files Browse the repository at this point in the history
Signed-off-by: kishor82 <[email protected]>
  • Loading branch information
kishor82 committed Apr 11, 2023
1 parent be47d9a commit 2dd8b46
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ interface Props {
onClickHistory: () => void;
onClickSettings: () => void;
onClickHelp: () => void;
onClickExport: () => void;
}

export function getTopNavConfig({ onClickHistory, onClickSettings, onClickHelp }: Props) {
export function getTopNavConfig({
onClickHistory,
onClickSettings,
onClickHelp,
onClickExport,
}: Props) {
return [
{
id: 'history',
Expand Down Expand Up @@ -77,5 +83,18 @@ export function getTopNavConfig({ onClickHistory, onClickSettings, onClickHelp }
},
testId: 'consoleHelpButton',
},
{
id: 'export',
label: i18n.translate('console.topNav.exportTabLabel', {
defaultMessage: 'Export',
}),
description: i18n.translate('console.topNav.exportTabDescription', {
defaultMessage: 'Export',
}),
onClick: () => {
onClickExport();
},
testId: 'consoleExportButton',
},
];
}
14 changes: 12 additions & 2 deletions src/plugins/console/public/application/containers/main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
* under the License.
*/

import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';
import { i18n } from '@osd/i18n';
// @ts-expect-error
import { saveAs } from '@elastic/filesaver';
import { EuiFlexGroup, EuiFlexItem, EuiTitle, EuiPageContent } from '@elastic/eui';
import { ConsoleHistory } from '../console_history';
import { Editor } from '../editor';
Expand All @@ -54,7 +56,7 @@ interface MainProps {

export function Main({ dataSourceId }: MainProps) {
const {
services: { storage },
services: { storage, objectStorageClient },
} = useServicesContext();

const { ready: editorsReady } = useEditorReadContext();
Expand All @@ -72,6 +74,13 @@ export function Main({ dataSourceId }: MainProps) {
const [showSettings, setShowSettings] = useState(false);
const [showHelp, setShowHelp] = useState(false);

const onExport = async () => {
const results = await objectStorageClient.text.findAll();
const senseData = results.sort((a, b) => a.createdAt - b.createdAt)[0];
const blob = new Blob([JSON.stringify(senseData || {})], { type: 'application/json' });
saveAs(blob, 'sense.json');
};

const renderConsoleHistory = () => {
return editorsReady ? <ConsoleHistory close={() => setShowHistory(false)} /> : null;
};
Expand Down Expand Up @@ -111,6 +120,7 @@ export function Main({ dataSourceId }: MainProps) {
onClickHistory: () => setShowHistory(!showingHistory),
onClickSettings: () => setShowSettings(true),
onClickHelp: () => setShowHelp(!showHelp),
onClickExport: () => onExport(),
})}
/>
</EuiFlexItem>
Expand Down

0 comments on commit 2dd8b46

Please sign in to comment.