Skip to content

Commit

Permalink
Add i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
scottybollinger committed Dec 2, 2020
1 parent 67fb7b1 commit d3af644
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { i18n } from '@kbn/i18n';

export const SCHEMA_ERRORS_HEADING = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.errors.heading',
{
defaultMessage: 'Schema Change Errors',
}
);

export const SCHEMA_ERRORS_TABLE_FIELD_NAME_HEADER = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.errors.header.fieldName',
{
defaultMessage: 'Field Name',
}
);

export const SCHEMA_ERRORS_TABLE_DATA_TYPE_HEADER = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.errors.header.dataType',
{
defaultMessage: 'Data Type',
}
);

export const SCHEMA_FIELD_ERRORS_ERROR_MESSAGE = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.errors.message',
{
defaultMessage: 'Oops, we were not able to find any errors for this Schema.',
}
);

export const SCHEMA_FIELD_ADDED_MESSAGE = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.fieldAdded.message',
{
defaultMessage: 'New field added.',
}
);

export const SCHEMA_UPDATED_MESSAGE = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.updated.message',
{
defaultMessage: 'Schema updated.',
}
);

export const SCHEMA_ADD_FIELD_BUTTON = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.addField.button',
{
defaultMessage: 'Add field',
}
);

export const SCHEMA_MANAGE_SCHEMA_TITLE = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.manage.title',
{
defaultMessage: 'Manage source schema',
}
);

export const SCHEMA_MANAGE_SCHEMA_DESCRIPTION = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.manage.description',
{
defaultMessage: 'Add new fields or change the types of existing ones',
}
);

export const SCHEMA_FILTER_PLACEHOLDER = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.filter.placeholder',
{
defaultMessage: 'Filter schema fields...',
}
);

export const SCHEMA_UPDATING = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.updating',
{
defaultMessage: 'Updating schema...',
}
);

export const SCHEMA_SAVE_BUTTON = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.save.button',
{
defaultMessage: 'Save schema',
}
);

export const SCHEMA_EMPTY_SCHEMA_TITLE = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.empty.title',
{
defaultMessage: 'Content source does not have a schema',
}
);

export const SCHEMA_EMPTY_SCHEMA_DESCRIPTION = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.empty.description',
{
defaultMessage:
'A schema is created for you once you index some documents. Click below to create schema fields in advance.',
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ import { IndexingStatus } from '../../../../../shared/indexing_status';
import { SchemaFieldsTable } from './schema_fields_table';
import { SchemaLogic } from './schema_logic';

import {
SCHEMA_ADD_FIELD_BUTTON,
SCHEMA_MANAGE_SCHEMA_TITLE,
SCHEMA_MANAGE_SCHEMA_DESCRIPTION,
SCHEMA_FILTER_PLACEHOLDER,
SCHEMA_UPDATING,
SCHEMA_SAVE_BUTTON,
SCHEMA_EMPTY_SCHEMA_TITLE,
SCHEMA_EMPTY_SCHEMA_DESCRIPTION,
} from './constants';

export const Schema: React.FC = () => {
const {
initializeSchema,
Expand Down Expand Up @@ -66,7 +77,7 @@ export const Schema: React.FC = () => {

const addFieldButton = (
<EuiButtonEmpty color="primary" data-test-subj="AddFieldButton" onClick={openAddFieldModal}>
Add Field
{SCHEMA_ADD_FIELD_BUTTON}
</EuiButtonEmpty>
);
const statusPath = isOrganization
Expand All @@ -76,8 +87,8 @@ export const Schema: React.FC = () => {
return (
<>
<ViewContentHeader
title="Manage source schema"
description="Add new fields or change the types of existing ones"
title={SCHEMA_MANAGE_SCHEMA_TITLE}
description={SCHEMA_MANAGE_SCHEMA_DESCRIPTION}
/>
<div>
{(isActive || hasErrors) && (
Expand All @@ -101,7 +112,7 @@ export const Schema: React.FC = () => {
<EuiFieldSearch
value={filterValue}
data-test-subj="FilterSchemaInput"
placeholder="Filter schema fields..."
placeholder={SCHEMA_FILTER_PLACEHOLDER}
onChange={(e) => setFilterValue(e.target.value)}
/>
</EuiFlexItem>
Expand All @@ -111,7 +122,7 @@ export const Schema: React.FC = () => {
<EuiFlexItem grow={false}>
{percentageComplete < 100 ? (
<EuiButton isLoading={true} fill={true}>
Updating schema...
{SCHEMA_UPDATING}
</EuiButton>
) : (
<EuiButton
Expand All @@ -120,7 +131,7 @@ export const Schema: React.FC = () => {
onClick={updateFields}
fill={true}
>
Save Schema
{SCHEMA_SAVE_BUTTON}
</EuiButton>
)}
</EuiFlexItem>
Expand All @@ -134,13 +145,8 @@ export const Schema: React.FC = () => {
<EuiPanel className="euiPanel--inset">
<EuiEmptyPrompt
iconType="managementApp"
title={<h2>Content source does not have a schema</h2>}
body={
<p>
A schema is created for you once you index some documents. Click below to create
schema fields in advance.
</p>
}
title={<h2>{SCHEMA_EMPTY_SCHEMA_TITLE}</h2>}
body={<p>{SCHEMA_EMPTY_SCHEMA_DESCRIPTION}</p>}
actions={addFieldButton}
/>
</EuiPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { EuiSpacer } from '@elastic/eui';
import { SchemaErrorsAccordion } from '../../../../../shared/schema/schema_errors_accordion';
import { ViewContentHeader } from '../../../../components/shared/view_content_header';
import { SchemaLogic } from './schema_logic';
import { SCHEMA_ERRORS_HEADING } from './constants';

export const SchemaChangeErrors: React.FC = () => {
const { activeReindexJobId, sourceId } = useParams() as {
Expand All @@ -30,7 +31,7 @@ export const SchemaChangeErrors: React.FC = () => {

return (
<div>
<ViewContentHeader title="Schema Change Errors" />
<ViewContentHeader title={SCHEMA_ERRORS_HEADING} />
<EuiSpacer size="xl" />
<main>
<SchemaErrorsAccordion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import React from 'react';

import { useActions, useValues } from 'kea';

import { i18n } from '@kbn/i18n';

import {
EuiFlexGroup,
EuiFlexItem,
Expand All @@ -21,6 +23,10 @@ import {

import { SchemaExistingField } from '../../../../../shared/schema/schema_existing_field';
import { SchemaLogic } from './schema_logic';
import {
SCHEMA_ERRORS_TABLE_FIELD_NAME_HEADER,
SCHEMA_ERRORS_TABLE_DATA_TYPE_HEADER,
} from './constants';

export const SchemaFieldsTable: React.FC = () => {
const { updateExistingFieldType } = useActions(SchemaLogic);
Expand All @@ -30,8 +36,8 @@ export const SchemaFieldsTable: React.FC = () => {
return Object.keys(filteredSchemaFields).length > 0 ? (
<EuiTable>
<EuiTableHeader>
<EuiTableHeaderCell>Field Name</EuiTableHeaderCell>
<EuiTableHeaderCell>Data Type</EuiTableHeaderCell>
<EuiTableHeaderCell>{SCHEMA_ERRORS_TABLE_FIELD_NAME_HEADER}</EuiTableHeaderCell>
<EuiTableHeaderCell>{SCHEMA_ERRORS_TABLE_DATA_TYPE_HEADER}</EuiTableHeaderCell>
</EuiTableHeader>
<EuiTableBody>
{Object.keys(filteredSchemaFields).map((fieldName) => (
Expand All @@ -58,6 +64,14 @@ export const SchemaFieldsTable: React.FC = () => {
</EuiTableBody>
</EuiTable>
) : (
<p>No results found for &apos;{filterValue}&apos;.</p>
<p>
{i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.errors.header.dataType',
{
defaultMessage: 'No results found for "{filterValue}".',
values: { filterValue },
}
)}
</p>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import {
import { AppLogic } from '../../../../app_logic';
import { SourceLogic } from '../../source_logic';

import {
SCHEMA_FIELD_ERRORS_ERROR_MESSAGE,
SCHEMA_FIELD_ADDED_MESSAGE,
SCHEMA_UPDATED_MESSAGE,
} from './constants';

interface SchemaActions {
onInitializeSchema(schemaProps: SchemaInitialData): SchemaInitialData;
onInitializeSchemaFieldErrors(
Expand Down Expand Up @@ -112,8 +118,6 @@ const dataTypeOptions = [
{ value: 'geolocation', text: 'Geo Location' },
];

const FIELD_ERRORS_ERROR = 'Oops, we were not able to find any errors for this Schema';

export const SchemaLogic = kea<MakeLogicType<SchemaValues, SchemaActions>>({
actions: {
onInitializeSchema: (schemaProps: SchemaInitialData) => schemaProps,
Expand Down Expand Up @@ -295,7 +299,7 @@ export const SchemaLogic = kea<MakeLogicType<SchemaValues, SchemaActions>>({
fieldCoercionErrors: response.fieldCoercionErrors,
});
} catch (e) {
flashAPIErrors({ ...e, message: FIELD_ERRORS_ERROR });
flashAPIErrors({ ...e, message: SCHEMA_FIELD_ERRORS_ERROR_MESSAGE });
}
},
addNewField: ({ fieldName, newFieldType }) => {
Expand All @@ -314,7 +318,7 @@ export const SchemaLogic = kea<MakeLogicType<SchemaValues, SchemaActions>>({
const { http } = HttpLogic.values;
const isAdding = operation === ADD;
const { sourceId } = values;
const successMessage = isAdding ? 'New field added.' : 'Schema updated.';
const successMessage = isAdding ? SCHEMA_FIELD_ADDED_MESSAGE : SCHEMA_UPDATED_MESSAGE;
const route = isOrganization
? `/api/workplace_search/org/sources/${sourceId}/schemas`
: `/api/workplace_search/account/sources/${sourceId}/schemas`;
Expand Down

0 comments on commit d3af644

Please sign in to comment.