Skip to content

Commit

Permalink
fix undefined doc links
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Apr 28, 2021
1 parent d345106 commit 8837958
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
EuiTitle,
} from '@elastic/eui';

import { getAutoFollowPatternUrl } from '../services/documentation_links';
import { documentationLinks } from '../services/documentation_links';

export const AutoFollowPatternPageTitle = ({ title }) => (
<Fragment>
Expand All @@ -36,7 +36,7 @@ export const AutoFollowPatternPageTitle = ({ title }) => (
<EuiButtonEmpty
size="s"
flush="right"
href={getAutoFollowPatternUrl()}
href={documentationLinks.apis.createAutoFollowPattern}
target="_blank"
iconType="help"
data-test-subj="docsButton"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { getByteUnitsUrl, getTimeUnitsUrl } from '../../services/documentation_links';
import { getSettingDefault } from '../../services/follower_index_default_settings';

const byteUnitsHelpText = (
const getByteUnitsHelpText = (documentationLinks) => (
<FormattedMessage
id="xpack.crossClusterReplication.followerIndexForm.advancedSettings.byteUnitsHelpText"
defaultMessage="Example values: 10b, 1024kb, 1mb, 5gb, 2tb, 1pb. {link}"
values={{
link: (
<a href={getByteUnitsUrl()} target="_blank">
<a href={documentationLinks.apis.byteSizeUnits} target="_blank">
<FormattedMessage
id="xpack.crossClusterReplication.followerIndexForm.advancedSettings.byteUnitsHelpTextLinkMessage"
defaultMessage="Learn more"
Expand All @@ -28,13 +27,13 @@ const byteUnitsHelpText = (
/>
);

const timeUnitsHelpText = (
const getTimeUnitsHelpText = (documentationLinks) => (
<FormattedMessage
id="xpack.crossClusterReplication.followerIndexForm.advancedSettings.timeUnitsHelpText"
defaultMessage="Example values: 2d, 24h, 20m, 30s, 500ms, 10000micros, 80000nanos. {link}"
values={{
link: (
<a href={getTimeUnitsUrl()} target="_blank">
<a href={documentationLinks.apis.timeUnits} target="_blank">
<FormattedMessage
id="xpack.crossClusterReplication.followerIndexForm.advancedSettings.timeUnitsHelpTextLinkMessage"
defaultMessage="Learn more"
Expand All @@ -45,7 +44,7 @@ const timeUnitsHelpText = (
/>
);

export const advancedSettingsFields = [
export const getAdvancedSettingsFields = (documentationLinks) => [
{
field: 'maxReadRequestOperationCount',
testSubject: 'maxReadRequestOperationCountInput',
Expand Down Expand Up @@ -118,7 +117,7 @@ export const advancedSettingsFields = [
}
),
defaultValue: getSettingDefault('maxReadRequestSize'),
helpText: byteUnitsHelpText,
helpText: getByteUnitsHelpText(documentationLinks),
},
{
field: 'maxWriteRequestOperationCount',
Expand Down Expand Up @@ -168,7 +167,7 @@ export const advancedSettingsFields = [
}
),
defaultValue: getSettingDefault('maxWriteRequestSize'),
helpText: byteUnitsHelpText,
helpText: getByteUnitsHelpText(documentationLinks),
},
{
field: 'maxOutstandingWriteRequests',
Expand Down Expand Up @@ -246,7 +245,7 @@ export const advancedSettingsFields = [
}
),
defaultValue: getSettingDefault('maxWriteBufferSize'),
helpText: byteUnitsHelpText,
helpText: getByteUnitsHelpText(documentationLinks),
},
{
field: 'maxRetryDelay',
Expand All @@ -272,7 +271,7 @@ export const advancedSettingsFields = [
}
),
defaultValue: getSettingDefault('maxRetryDelay'),
helpText: timeUnitsHelpText,
helpText: getTimeUnitsHelpText(documentationLinks),
},
{
field: 'readPollTimeout',
Expand Down Expand Up @@ -300,18 +299,19 @@ export const advancedSettingsFields = [
}
),
defaultValue: getSettingDefault('readPollTimeout'),
helpText: timeUnitsHelpText,
helpText: getTimeUnitsHelpText(documentationLinks),
},
];

export const emptyAdvancedSettings = advancedSettingsFields.reduce((obj, advancedSetting) => {
const { field, defaultValue } = advancedSetting;
return { ...obj, [field]: defaultValue };
}, {});
export const getEmptyAdvancedSettings = (documentationLinks) =>
getAdvancedSettingsFields(documentationLinks).reduce((obj, advancedSetting) => {
const { field, defaultValue } = advancedSetting;
return { ...obj, [field]: defaultValue };
}, {});

export function areAdvancedSettingsEdited(followerIndex) {
return advancedSettingsFields.some((advancedSetting) => {
export function areAdvancedSettingsEdited(followerIndex, documentationLinks) {
return getAdvancedSettingsFields(documentationLinks).some((advancedSetting) => {
const { field } = advancedSetting;
return followerIndex[field] !== emptyAdvancedSettings[field];
return followerIndex[field] !== getEmptyAdvancedSettings(documentationLinks)[field];
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,40 @@ import { indexNameValidator, leaderIndexValidator } from '../../services/input_v
import { routing } from '../../services/routing';
import { getFatalErrors } from '../../services/notifications';
import { loadIndices } from '../../services/api';
import { documentationLinks } from '../../services/documentation_links';
import { API_STATUS } from '../../constants';
import { getRemoteClusterName } from '../../services/get_remote_cluster_name';
import { RemoteClustersFormField } from '../remote_clusters_form_field';
import { SectionError } from '../section_error';
import { FormEntryRow } from '../form_entry_row';
import {
advancedSettingsFields,
emptyAdvancedSettings,
getAdvancedSettingsFields,
getEmptyAdvancedSettings,
areAdvancedSettingsEdited,
} from './advanced_settings_fields';

import { FollowerIndexRequestFlyout } from './follower_index_request_flyout';

const indexNameIllegalCharacters = indices.INDEX_ILLEGAL_CHARACTERS_VISIBLE.join(' ');

const fieldToValidatorMap = advancedSettingsFields.reduce(
(map, advancedSetting) => {
const { field, validator } = advancedSetting;
map[field] = validator;
return map;
},
{
name: indexNameValidator,
leaderIndex: leaderIndexValidator,
}
);
const getFieldToValidatorMap = (advancedSettingsFields) =>
advancedSettingsFields.reduce(
(map, advancedSetting) => {
const { field, validator } = advancedSetting;
map[field] = validator;
return map;
},
{
name: indexNameValidator,
leaderIndex: leaderIndexValidator,
}
);

const getEmptyFollowerIndex = (remoteClusterName = '') => ({
name: '',
remoteCluster: remoteClusterName,
leaderIndex: '',
...emptyAdvancedSettings,
...getEmptyAdvancedSettings(documentationLinks),
});

/**
Expand Down Expand Up @@ -121,7 +123,7 @@ export class FollowerIndexForm extends PureComponent {
// eslint-disable-next-line no-nested-ternary
const areAdvancedSettingsVisible = isNew
? false
: areAdvancedSettingsEdited(followerIndex)
: areAdvancedSettingsEdited(followerIndex, documentationLinks)
? true
: false;

Expand Down Expand Up @@ -164,7 +166,8 @@ export class FollowerIndexForm extends PureComponent {

getFieldsErrors = (newFields) => {
return Object.keys(newFields).reduce((errors, field) => {
const validator = fieldToValidatorMap[field];
const advancedSettings = getAdvancedSettingsFields(documentationLinks);
const validator = getFieldToValidatorMap(advancedSettings)[field];
const value = newFields[field];

if (validator) {
Expand Down Expand Up @@ -278,17 +281,20 @@ export class FollowerIndexForm extends PureComponent {
}

// Clear the advanced settings form.
this.onFieldsChange(emptyAdvancedSettings);
this.onFieldsChange(getEmptyAdvancedSettings(documentationLinks));

// Save a cache of the advanced settings.
const fields = this.getFields();
this.cachedAdvancedSettings = advancedSettingsFields.reduce((cache, { field }) => {
const value = fields[field];
if (value !== '') {
cache[field] = value;
}
return cache;
}, {});
this.cachedAdvancedSettings = getAdvancedSettingsFields(documentationLinks).reduce(
(cache, { field }) => {
const value = fields[field];
if (value !== '') {
cache[field] = value;
}
return cache;
},
{}
);

// Hide the advanced settings.
this.setState({
Expand Down Expand Up @@ -614,7 +620,7 @@ export class FollowerIndexForm extends PureComponent {
{areAdvancedSettingsVisible && (
<Fragment>
<EuiSpacer size="s" />
{advancedSettingsFields.map((advancedSetting) => {
{getAdvancedSettingsFields(documentationLinks).map((advancedSetting) => {
const {
field,
testSubject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
EuiTitle,
} from '@elastic/eui';

import { getFollowerIndexUrl } from '../services/documentation_links';
import { documentationLinks } from '../services/documentation_links';

export const FollowerIndexPageTitle = ({ title }) => (
<Fragment>
Expand All @@ -36,7 +36,7 @@ export const FollowerIndexPageTitle = ({ title }) => (
<EuiButtonEmpty
size="s"
flush="right"
href={getFollowerIndexUrl()}
href={documentationLinks.apis.createFollower}
target="_blank"
iconType="help"
data-test-subj="docsButton"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,8 @@

import type { DocLinksStart } from 'src/core/public';

let autoFollowPatternUrl: string;
let followerIndexUrl: string;
let byteUnitsUrl: string;
let timeUnitsUrl: string;
export let documentationLinks: DocLinksStart['links'];

export const init = (docLinks: DocLinksStart) => {
autoFollowPatternUrl = `${docLinks.links.apis.createAutoFollowPattern}`;
followerIndexUrl = `${docLinks.links.apis.createFollower}`;
byteUnitsUrl = `${docLinks.links.apis.byteSizeUnits}`;
timeUnitsUrl = `${docLinks.links.apis.timeUnits}`;
documentationLinks = docLinks.links;
};

export const getAutoFollowPatternUrl = (): string => autoFollowPatternUrl;
export const getFollowerIndexUrl = (): string => followerIndexUrl;
export const getByteUnitsUrl = (): string => byteUnitsUrl;
export const getTimeUnitsUrl = (): string => timeUnitsUrl;

0 comments on commit 8837958

Please sign in to comment.