[Canvas] i18n for all known canvas errors (#46945)

* i18n for all known canvas errors

* Removing error message not seen by users
This commit is contained in:
Poff Poffenberger 2019-10-10 09:28:30 -05:00 committed by GitHub
parent 8dc80a2d31
commit 3632bd62f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 21 deletions

View file

@ -8,6 +8,53 @@ import { i18n } from '@kbn/i18n';
import { CANVAS, JSON } from './constants';
export const ErrorStrings = {
actionsElements: {
getInvalidArgIndexErrorMessage: (index: string) =>
i18n.translate('xpack.canvas.error.actionsElements.invaludArgIndexErrorMessage', {
defaultMessage: 'Invalid argument index: {index}',
values: {
index,
},
}),
},
downloadWorkpad: {
getDownloadFailureErrorMessage: () =>
i18n.translate('xpack.canvas.error.downloadWorkpad.downloadFailureErrorMessage', {
defaultMessage: "Couldn't download workpad",
}),
},
esPersist: {
getSaveFailureTitle: () =>
i18n.translate('xpack.canvas.error.esPersist.saveFailureTitle', {
defaultMessage: "Couldn't save your changes to Elasticsearch",
}),
getTooLargeErrorMessage: () =>
i18n.translate('xpack.canvas.error.esPersist.tooLargeErrorMessage', {
defaultMessage:
'The server gave a response that the workpad data was too large. This usually means uploaded image assets that are too large for Kibana or a proxy. Try removing some assets in the asset manager.',
}),
getUpdateFailureTitle: () =>
i18n.translate('xpack.canvas.error.esPersist.updateFailureTitle', {
defaultMessage: "Couldn't update workpad",
}),
},
esService: {
getDefaultIndexFetchErrorMessage: () =>
i18n.translate('xpack.canvas.error.esService.defaultIndexFetchErrorMessage', {
defaultMessage: "Couldn't fetch default index",
}),
getFieldsFetchErrorMessage: (index: string) =>
i18n.translate('xpack.canvas.error.esService.fieldsFetchErrorMessage', {
defaultMessage: "Couldn't fetch Elasticsearch fields for '{index}'",
values: {
index,
},
}),
getIndicesFetchErrorMessage: () =>
i18n.translate('xpack.canvas.error.esService.indicesFetchErrorMessage', {
defaultMessage: "Couldn't fetch Elasticsearch indices",
}),
},
WorkpadFileUpload: {
getAcceptJSONOnlyErrorMessage: () =>
i18n.translate('xpack.canvas.error.workpadUpload.acceptJSONOnlyErrorMessage', {
@ -58,4 +105,14 @@ export const ErrorStrings = {
defaultMessage: `Couldn't upload workpad`,
}),
},
workpadRoutes: {
getCreateFailureErrorMessage: () =>
i18n.translate('xpack.canvas.error.workpadRoutes.createFailureErrorMessage', {
defaultMessage: "Couldn't create workpad",
}),
getLoadFailureErrorMessage: () =>
i18n.translate('xpack.canvas.error.workpadRoutes.loadFailureErrorMessage', {
defaultMessage: "Couldn't load workpad with ID",
}),
},
};

View file

@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { ErrorStrings } from '../../../i18n';
import * as workpadService from '../../lib/workpad_service';
import { notify } from '../../lib/notify';
import { getBaseBreadcrumb, getWorkpadBreadcrumb, setBreadcrumb } from '../../lib/breadcrumbs';
@ -15,6 +16,8 @@ import { getWorkpad } from '../../state/selectors/workpad';
import { setZoomScale } from '../../state/actions/transient';
import { WorkpadApp } from './workpad_app';
const { workpadRoutes: strings } = ErrorStrings;
export const routes = [
{
path: '/workpad',
@ -30,7 +33,7 @@ export const routes = [
dispatch(resetAssets());
router.redirectTo('loadWorkpad', { id: newWorkpad.id, page: 1 });
} catch (err) {
notify.error(err, { title: `Couldn't create workpad` });
notify.error(err, { title: strings.getCreateFailureErrorMessage() });
router.redirectTo('home');
}
},
@ -56,7 +59,7 @@ export const routes = [
// reset transient properties when changing workpads
dispatch(setZoomScale(1));
} catch (err) {
notify.error(err, { title: `Couldn't load workpad with ID` });
notify.error(err, { title: strings.getLoadFailureErrorMessage() });
return router.redirectTo('home');
}
}

View file

@ -4,15 +4,20 @@
* you may not use this file except in compliance with the Elastic License.
*/
import fileSaver from 'file-saver';
import { ErrorStrings } from '../../i18n';
// @ts-ignore untyped local
import { notify } from './notify';
// @ts-ignore untyped local
import * as workpadService from './workpad_service';
export const downloadWorkpad = async workpadId => {
const { downloadWorkpad: strings } = ErrorStrings;
export const downloadWorkpad = async (workpadId: string) => {
try {
const workpad = await workpadService.get(workpadId);
const jsonBlob = new Blob([JSON.stringify(workpad)], { type: 'application/json' });
fileSaver.saveAs(jsonBlob, `canvas-workpad-${workpad.name}-${workpad.id}.json`);
} catch (err) {
notify.error(err, { title: `Couldn't download workpad` });
notify.error(err, { title: strings.getDownloadFailureErrorMessage() });
}
};

View file

@ -6,9 +6,14 @@
import chrome from 'ui/chrome';
import { API_ROUTE } from '../../common/lib/constants';
// @ts-ignore untyped local
import { fetch } from '../../common/lib/fetch';
import { ErrorStrings } from '../../i18n';
// @ts-ignore untyped local
import { notify } from './notify';
const { esService: strings } = ErrorStrings;
const basePath = chrome.getBasePath();
const apiPath = basePath + API_ROUTE;
const savedObjectsClient = chrome.getSavedObjectsClient();
@ -17,13 +22,15 @@ const AdvancedSettings = chrome.getUiSettingsClient();
export const getFields = (index = '_all') => {
return fetch
.get(`${apiPath}/es_fields?index=${index}`)
.then(({ data: mapping }) =>
.then(({ data: mapping }: { data: object }) =>
Object.keys(mapping)
.filter(field => !field.startsWith('_')) // filters out meta fields
.sort()
)
.catch(err =>
notify.error(err, { title: `Couldn't fetch Elasticsearch fields for '${index}'` })
.catch((err: Error) =>
notify.error(err, {
title: strings.getFieldsFetchErrorMessage(index),
})
);
};
@ -32,7 +39,7 @@ export const getIndices = () =>
.find({
type: 'index-pattern',
fields: ['title'],
search_fields: ['title'],
searchFields: ['title'],
perPage: 1000,
})
.then(resp => {
@ -40,7 +47,7 @@ export const getIndices = () =>
return savedObject.attributes.title;
});
})
.catch(err => notify.error(err, { title: `Couldn't fetch Elasticsearch indices` }));
.catch((err: Error) => notify.error(err, { title: strings.getIndicesFetchErrorMessage() }));
export const getDefaultIndex = () => {
const defaultIndexId = AdvancedSettings.get('defaultIndex');
@ -49,6 +56,6 @@ export const getDefaultIndex = () => {
? savedObjectsClient
.get('index-pattern', defaultIndexId)
.then(defaultIndex => defaultIndex.attributes.title)
.catch(err => notify.error(err, { title: `Couldn't fetch default index` }))
.catch(err => notify.error(err, { title: strings.getDefaultIndexFetchErrorMessage() }))
: Promise.resolve('');
};

View file

@ -13,12 +13,15 @@ import { interpretAst } from 'plugins/interpreter/interpreter';
import { getPages, getNodeById, getNodes, getSelectedPageIndex } from '../selectors/workpad';
import { getValue as getResolvedArgsValue } from '../selectors/resolved_args';
import { getDefaultElement } from '../defaults';
import { ErrorStrings } from '../../../i18n';
import { notify } from '../../lib/notify';
import { runInterpreter } from '../../lib/run_interpreter';
import { subMultitree } from '../../lib/aeroelastic/functional';
import { selectToplevelNodes } from './transient';
import * as args from './resolved_args';
const { actionsElements: strings } = ErrorStrings;
const { set, del } = immutable;
export function getSiblingContext(state, elementId, checkIndex) {
@ -67,7 +70,7 @@ export const fetchContext = createThunk(
const invalidIndex = chain ? index >= chain.length : true;
if (!element || !chain || invalidIndex) {
throw new Error(`Invalid argument index: ${index}`);
throw new Error(strings.getInvalidArgIndexErrorMessage(index));
}
// cache context as the previous index

View file

@ -5,6 +5,7 @@
*/
import { isEqual } from 'lodash';
import { ErrorStrings } from '../../../i18n';
import { getWorkpad, getFullWorkpadPersisted, getWorkpadPersisted } from '../selectors/workpad';
import { getAssetIds } from '../selectors/assets';
import { appReady } from '../actions/app';
@ -16,6 +17,8 @@ import { update, updateAssets, updateWorkpad } from '../../lib/workpad_service';
import { notify } from '../../lib/notify';
import { canUserWrite } from '../selectors/app';
const { esPersist: strings } = ErrorStrings;
const workpadChanged = (before, after) => {
const workpad = getWorkpad(before);
return getWorkpad(after) !== workpad;
@ -60,20 +63,15 @@ export const esPersistMiddleware = ({ getState }) => {
switch (statusCode) {
case 400:
return notify.error(err.response, {
title: `Couldn't save your changes to Elasticsearch`,
title: strings.getSaveFailureTitle(),
});
case 413:
return notify.error(
`The server gave a response that the workpad data was too large. This
usually means uploaded image assets that are too large for Kibana or
a proxy. Try removing some assets in the asset manager.`,
{
title: `Couldn't save your changes to Elasticsearch`,
}
);
return notify.error(strings.getTooLargeErrorMessage(), {
title: strings.getSaveFailureTitle(),
});
default:
return notify.error(err, {
title: `Couldn't update workpad`,
title: strings.getUpdateFailureTitle(),
});
}
};