Skip to content

Commit

Permalink
update: removed legacy variable export.
Browse files Browse the repository at this point in the history
Signed-off-by: kishor82 <kishorrathva8298@gmail.com>
  • Loading branch information
kishor82 committed Jul 14, 2023
1 parent 660b8c2 commit c7c0284
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
29 changes: 17 additions & 12 deletions src/plugins/console/public/application/components/import_flyout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { i18n } from '@osd/i18n';
import { FormattedMessage } from '@osd/i18n/react';
import React, { Fragment, useState } from 'react';
import { ImportMode, ImportModeControl } from './import_mode_control';
import { useEditorReadContext, useServicesContext } from '../contexts';
import { useServicesContext } from '../contexts';
import { TextObject } from '../../../common/text_object';
import { OverwriteModal } from './overwrite_modal';

Expand All @@ -37,9 +37,14 @@ interface ImportFlyoutProps {
refresh: () => void;
}

const getErrorMessage = () => {
const getErrorMessage = (e: any) => {
const errorMessage =
e.body?.error && e.body?.message ? `${e.body.error}: ${e.body.message}` : e.message;
return i18n.translate('console.ImportFlyout.importFileErrorMessage', {
defaultMessage: 'The file could not be processed due to error.',
defaultMessage: 'The file could not be processed due to error: "{error}"',
values: {
error: errorMessage,
},
});
};

Expand All @@ -61,7 +66,6 @@ export const ImportFlyout = ({ close, refresh }: ImportFlyoutProps) => {
notifications: { toasts },
},
} = useServicesContext();
const { currentTextObject } = useEditorReadContext();

const dateFormat = uiSettings.get<string>('dateFormat');

Expand Down Expand Up @@ -161,6 +165,8 @@ export const ImportFlyout = ({ close, refresh }: ImportFlyoutProps) => {
setStatus('loading');
setError(undefined);
try {
const results = await objectStorageClient.text.findAll();
const currentText = results.sort((a, b) => a.createdAt - b.createdAt)[0];
if (jsonData && jsonData.text) {
if (importMode.overwrite) {
if (!isOverwriteConfirmed) {
Expand All @@ -173,9 +179,9 @@ export const ImportFlyout = ({ close, refresh }: ImportFlyoutProps) => {
updatedAt: Date.now(),
text: jsonData.text,
};
if (currentTextObject) {
if (results.length) {
await objectStorageClient.text.update({
...currentTextObject,
...currentText,
...newObject,
});
} else {
Expand All @@ -187,13 +193,13 @@ export const ImportFlyout = ({ close, refresh }: ImportFlyoutProps) => {
toasts.addSuccess('Queries overwritten.');
} else {
setLoadingMessage('Importing queries and merging with existing ones...');
if (currentTextObject) {
if (results.length) {
await objectStorageClient.text.update({
...currentTextObject,
...currentText,
createdAt: Date.now(),
updatedAt: Date.now(),
text: currentTextObject.text.concat(
`\n#Imported on ${moment(Date.now()).format(dateFormat)}\n\n${jsonData.text}`
text: currentText.text.concat(
`\n\n#Imported on ${moment(Date.now()).format(dateFormat)}\n\n${jsonData.text}`
),
});
toasts.addSuccess('Queries merged.');
Expand All @@ -214,8 +220,7 @@ export const ImportFlyout = ({ close, refresh }: ImportFlyoutProps) => {
}
} catch (e) {
setStatus('error');
setError(getErrorMessage());
return;
setError(getErrorMessage(e));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const abs: CSSProperties = {
right: '0',
};

export const DEFAULT_INPUT_VALUE = `GET _search
const DEFAULT_INPUT_VALUE = `GET _search
{
"query": {
"match_all": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
import { useCallback, useEffect, useState } from 'react';
import { migrateToTextObjects } from './data_migration';
import { useEditorActionContext, useServicesContext } from '../../contexts';
import { DEFAULT_INPUT_VALUE } from '../../containers/editor/legacy/console_editor/editor';

const DEFAULT_INPUT_VALUE = `GET _search
{
"query": {
"match_all": {}
}
}`;

export const useDataInit = () => {
const [error, setError] = useState<Error | null>(null);
Expand Down

0 comments on commit c7c0284

Please sign in to comment.