Skip to content

Commit

Permalink
Use documentation link service for snapshot restore (elastic#91596)
Browse files Browse the repository at this point in the history
Co-authored-by: Alison Goryachev <[email protected]>
  • Loading branch information
lcawl and alisonelizabeth authored Feb 19, 2021
1 parent fc77586 commit a6a567f
Show file tree
Hide file tree
Showing 22 changed files with 117 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ readonly links: {
};
readonly date: {
readonly dateMath: string;
readonly dateMathIndexNames: string;
};
readonly management: Record<string, string>;
readonly ml: Record<string, string>;
Expand All @@ -130,13 +131,15 @@ readonly links: {
createApiKey: string;
createPipeline: string;
createTransformRequest: string;
cronExpressions: string;
executeWatchActionModes: string;
indexExists: string;
openIndex: string;
putComponentTemplate: string;
painlessExecute: string;
painlessExecuteAPIContexts: string;
putComponentTemplateMetadata: string;
putSnapshotLifecyclePolicy: string;
putWatch: string;
updateTransform: string;
}>;
Expand All @@ -158,5 +161,7 @@ readonly links: {
}>;
readonly watcher: Record<string, string>;
readonly ccs: Record<string, string>;
readonly plugins: Record<string, string>;
readonly snapshotRestore: Record<string, string>;
};
```

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class DocLinksService {
const DOC_LINK_VERSION = injectedMetadata.getKibanaBranch();
const ELASTIC_WEBSITE_URL = 'https://www.elastic.co/';
const ELASTICSEARCH_DOCS = `${ELASTIC_WEBSITE_URL}guide/en/elasticsearch/reference/${DOC_LINK_VERSION}/`;
const PLUGIN_DOCS = `${ELASTIC_WEBSITE_URL}guide/en/elasticsearch/plugins/${DOC_LINK_VERSION}/`;

return deepFreeze({
DOC_LINK_VERSION,
Expand Down Expand Up @@ -126,6 +127,7 @@ export class DocLinksService {
addData: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/connect-to-elasticsearch.html`,
kibana: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/index.html`,
elasticsearch: {
indexModules: `${ELASTICSEARCH_DOCS}index-modules.html`,
mapping: `${ELASTICSEARCH_DOCS}mapping.html`,
remoteClusters: `${ELASTICSEARCH_DOCS}modules-remote-clusters.html`,
remoteClustersProxy: `${ELASTICSEARCH_DOCS}modules-remote-clusters.html#proxy-mode`,
Expand All @@ -145,6 +147,7 @@ export class DocLinksService {
},
date: {
dateMath: `${ELASTICSEARCH_DOCS}common-options.html#date-math`,
dateMathIndexNames: `${ELASTICSEARCH_DOCS}date-math-index-names.html`,
},
management: {
kibanaSearchSettings: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/advanced-options.html#kibana-search-settings`,
Expand Down Expand Up @@ -239,16 +242,34 @@ export class DocLinksService {
createApiKey: `${ELASTICSEARCH_DOCS}security-api-create-api-key.html`,
createPipeline: `${ELASTICSEARCH_DOCS}put-pipeline-api.html`,
createTransformRequest: `${ELASTICSEARCH_DOCS}put-transform.html#put-transform-request-body`,
cronExpressions: `${ELASTICSEARCH_DOCS}cron-expressions.html`,
executeWatchActionModes: `${ELASTICSEARCH_DOCS}watcher-api-execute-watch.html#watcher-api-execute-watch-action-mode`,
indexExists: `${ELASTICSEARCH_DOCS}indices-exists.html`,
openIndex: `${ELASTICSEARCH_DOCS}indices-open-close.html`,
putComponentTemplate: `${ELASTICSEARCH_DOCS}indices-component-template.html`,
painlessExecute: `${ELASTIC_WEBSITE_URL}guide/en/elasticsearch/painless/${DOC_LINK_VERSION}/painless-execute-api.html`,
painlessExecuteAPIContexts: `${ELASTIC_WEBSITE_URL}guide/en/elasticsearch/painless/${DOC_LINK_VERSION}/painless-execute-api.html#_contexts`,
putComponentTemplateMetadata: `${ELASTICSEARCH_DOCS}indices-component-template.html#component-templates-metadata`,
putSnapshotLifecyclePolicy: `${ELASTICSEARCH_DOCS}slm-api-put-policy.html`,
putWatch: `${ELASTICSEARCH_DOCS}/watcher-api-put-watch.html`,
updateTransform: `${ELASTICSEARCH_DOCS}update-transform.html`,
},
plugins: {
azureRepo: `${PLUGIN_DOCS}repository-azure.html`,
gcsRepo: `${PLUGIN_DOCS}repository-gcs.html`,
hdfsRepo: `${PLUGIN_DOCS}repository-hdfs.html`,
s3Repo: `${PLUGIN_DOCS}repository-s3.html`,
snapshotRestoreRepos: `${PLUGIN_DOCS}repository.html`,
},
snapshotRestore: {
guide: `${ELASTICSEARCH_DOCS}snapshot-restore.html`,
changeIndexSettings: `${ELASTICSEARCH_DOCS}snapshots-restore-snapshot.html#change-index-settings-during-restore`,
createSnapshot: `${ELASTICSEARCH_DOCS}snapshots-take-snapshot.html`,
registerSharedFileSystem: `${ELASTICSEARCH_DOCS}snapshots-register-repository.html#snapshots-filesystem-repository`,
registerSourceOnly: `${ELASTICSEARCH_DOCS}snapshots-register-repository.html#snapshots-source-only-repository`,
registerUrl: `${ELASTICSEARCH_DOCS}snapshots-register-repository.html#snapshots-read-only-repository`,
restoreSnapshot: `${ELASTICSEARCH_DOCS}snapshots-restore-snapshot.html`,
},
},
});
}
Expand Down Expand Up @@ -368,6 +389,7 @@ export interface DocLinksStart {
};
readonly date: {
readonly dateMath: string;
readonly dateMathIndexNames: string;
};
readonly management: Record<string, string>;
readonly ml: Record<string, string>;
Expand All @@ -381,13 +403,15 @@ export interface DocLinksStart {
createApiKey: string;
createPipeline: string;
createTransformRequest: string;
cronExpressions: string;
executeWatchActionModes: string;
indexExists: string;
openIndex: string;
putComponentTemplate: string;
painlessExecute: string;
painlessExecuteAPIContexts: string;
putComponentTemplateMetadata: string;
putSnapshotLifecyclePolicy: string;
putWatch: string;
updateTransform: string;
}>;
Expand All @@ -409,5 +433,7 @@ export interface DocLinksStart {
}>;
readonly watcher: Record<string, string>;
readonly ccs: Record<string, string>;
readonly plugins: Record<string, string>;
readonly snapshotRestore: Record<string, string>;
};
}
5 changes: 5 additions & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ export interface DocLinksStart {
};
readonly date: {
readonly dateMath: string;
readonly dateMathIndexNames: string;
};
readonly management: Record<string, string>;
readonly ml: Record<string, string>;
Expand All @@ -600,13 +601,15 @@ export interface DocLinksStart {
createApiKey: string;
createPipeline: string;
createTransformRequest: string;
cronExpressions: string;
executeWatchActionModes: string;
indexExists: string;
openIndex: string;
putComponentTemplate: string;
painlessExecute: string;
painlessExecuteAPIContexts: string;
putComponentTemplateMetadata: string;
putSnapshotLifecyclePolicy: string;
putWatch: string;
updateTransform: string;
}>;
Expand All @@ -628,6 +631,8 @@ export interface DocLinksStart {
}>;
readonly watcher: Record<string, string>;
readonly ccs: Record<string, string>;
readonly plugins: Record<string, string>;
readonly snapshotRestore: Record<string, string>;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { AppContextProvider } from '../../../public/application/app_context';
import { textService } from '../../../public/application/services/text';
import { init as initHttpRequests } from './http_requests';
import { UiMetricService } from '../../../public/application/services';
import { documentationLinksService } from '../../../public/application/services/documentation';

const mockHttpClient = axios.create({ adapter: axiosXhrAdapter });

Expand All @@ -40,7 +39,7 @@ export const services = {
setUiMetricService(services.uiMetricService);

const appDependencies = {
core: coreMock.createSetup(),
core: coreMock.createStart(),
services,
config: {
slm_ui: { enabled: true },
Expand All @@ -53,7 +52,6 @@ export const setupEnvironment = () => {
httpService.setup(mockHttpClient);
breadcrumbService.setup(() => undefined);
textService.setup(i18n);
documentationLinksService.setup({} as any);
docTitleService.setup(() => undefined);

const { server, httpRequestsMockHelpers } = initHttpRequests();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ import {

import { Repository } from '../../../../../common/types';
import { Frequency, CronEditor, SectionError } from '../../../../shared_imports';
import { useServices } from '../../../app_context';
import { useCore, useServices } from '../../../app_context';
import { DEFAULT_POLICY_SCHEDULE, DEFAULT_POLICY_FREQUENCY } from '../../../constants';
import { useLoadRepositories } from '../../../services/http';
import { linkToAddRepository } from '../../../services/navigation';
import { documentationLinksService } from '../../../services/documentation';
import { SectionLoading } from '../../';
import { StepProps } from './';

Expand All @@ -57,6 +56,7 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({
} = useLoadRepositories();

const { i18n, history } = useServices();
const { docLinks } = useCore();

const [showRepositoryNotFoundWarning, setShowRepositoryNotFoundWarning] = useState<boolean>(
false
Expand Down Expand Up @@ -338,10 +338,7 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({
defaultMessage="Supports date math expressions. {docLink}"
values={{
docLink: (
<EuiLink
href={documentationLinksService.getDateMathIndexNamesUrl()}
target="_blank"
>
<EuiLink href={docLinks.links.date.dateMathIndexNames} target="_blank">
<FormattedMessage
id="xpack.snapshotRestore.policyForm.stepLogistics.policySnapshotNameHelpTextDocLink"
defaultMessage="Learn more."
Expand Down Expand Up @@ -420,7 +417,7 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({
defaultMessage="Use cron expression. {docLink}"
values={{
docLink: (
<EuiLink href={documentationLinksService.getCronUrl()} target="_blank">
<EuiLink href={docLinks.links.apis.cronExpressions} target="_blank">
<FormattedMessage
id="xpack.snapshotRestore.policyForm.stepLogistics.policyScheduleHelpTextDocLink"
defaultMessage="Learn more."
Expand Down Expand Up @@ -548,7 +545,7 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({
<EuiButtonEmpty
size="s"
flush="right"
href={documentationLinksService.getSlmUrl()}
href={docLinks.links.apis.putSnapshotLifecyclePolicy}
target="_blank"
iconType="help"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import {

import { SlmPolicyPayload } from '../../../../../common/types';
import { TIME_UNITS } from '../../../../../common/constants';
import { documentationLinksService } from '../../../services/documentation';
import { StepProps } from './';
import { textService } from '../../../services/text';
import { useCore } from '../../../app_context';

const getExpirationTimeOptions = (unitSize = '0') =>
Object.entries(TIME_UNITS).map(([_key, value]) => ({
Expand All @@ -37,6 +37,7 @@ export const PolicyStepRetention: React.FunctionComponent<StepProps> = ({
errors,
}) => {
const { retention = {} } = policy;
const { docLinks } = useCore();

const updatePolicyRetention = (
updatedFields: Partial<SlmPolicyPayload['retention']>,
Expand Down Expand Up @@ -224,7 +225,7 @@ export const PolicyStepRetention: React.FunctionComponent<StepProps> = ({
<EuiButtonEmpty
size="s"
flush="right"
href={documentationLinksService.getSlmUrl()}
href={docLinks.links.apis.putSnapshotLifecyclePolicy}
target="_blank"
iconType="help"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
} from '@elastic/eui';

import { SlmPolicyPayload } from '../../../../../../common/types';
import { documentationLinksService } from '../../../../services/documentation';
import { StepProps } from '../';

import { IndicesAndDataStreamsField } from './fields';
import { useCore } from '../../../../app_context';

export const PolicyStepSettings: React.FunctionComponent<StepProps> = ({
policy,
Expand All @@ -31,6 +31,7 @@ export const PolicyStepSettings: React.FunctionComponent<StepProps> = ({
updatePolicy,
errors,
}) => {
const { docLinks } = useCore();
const { config = {}, isManagedPolicy } = policy;

const updatePolicyConfig = (
Expand Down Expand Up @@ -184,7 +185,7 @@ export const PolicyStepSettings: React.FunctionComponent<StepProps> = ({
<EuiButtonEmpty
size="s"
flush="right"
href={documentationLinksService.getSnapshotDocUrl()}
href={docLinks.links.snapshotRestore.createSnapshot}
target="_blank"
iconType="help"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ import { Repository, RepositoryType, EmptyRepository } from '../../../../common/
import { REPOSITORY_TYPES } from '../../../../common';
import { SectionError, Error } from '../../../shared_imports';

import { documentationLinksService } from '../../services/documentation';
import { useLoadRepositoryTypes } from '../../services/http';
import { textService } from '../../services/text';
import { RepositoryValidation } from '../../services/validation';
import { SectionLoading, RepositoryTypeLogo } from '../';
import { useCore } from '../../app_context';
import { getRepositoryTypeDocUrl } from '../../lib/type_to_doc_url';

interface Props {
repository: Repository | EmptyRepository;
Expand All @@ -54,6 +55,8 @@ export const RepositoryFormStepOne: React.FunctionComponent<Props> = ({
data: repositoryTypes = [],
} = useLoadRepositoryTypes();

const { docLinks } = useCore();

const hasValidationErrors: boolean = !validation.isValid;

const onTypeChange = (newType: RepositoryType) => {
Expand All @@ -72,7 +75,7 @@ export const RepositoryFormStepOne: React.FunctionComponent<Props> = ({
};

const pluginDocLink = (
<EuiLink href={documentationLinksService.getRepositoryPluginDocUrl()} target="_blank">
<EuiLink href={docLinks.links.plugins.snapshotRestoreRepos} target="_blank">
<FormattedMessage
id="xpack.snapshotRestore.repositoryForm.fields.typePluginsDocLinkText"
defaultMessage="Learn more about plugins."
Expand Down Expand Up @@ -140,7 +143,7 @@ export const RepositoryFormStepOne: React.FunctionComponent<Props> = ({
description={<Fragment />} /* EuiCard requires `description` */
footer={
<EuiButtonEmpty
href={documentationLinksService.getRepositoryTypeDocUrl(type)}
href={getRepositoryTypeDocUrl(docLinks, type)}
target="_blank"
size="xs"
iconType="iInCircle"
Expand Down Expand Up @@ -284,7 +287,7 @@ export const RepositoryFormStepOne: React.FunctionComponent<Props> = ({
values={{
docLink: (
<EuiLink
href={documentationLinksService.getRepositoryTypeDocUrl(REPOSITORY_TYPES.source)}
href={getRepositoryTypeDocUrl(docLinks, REPOSITORY_TYPES.source)}
target="_blank"
>
<FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import {
import { Repository } from '../../../../common/types';
import { REPOSITORY_TYPES } from '../../../../common/constants';
import { RepositoryValidation } from '../../services/validation';
import { documentationLinksService } from '../../services/documentation';
import { TypeSettings } from './type_settings';
import { textService } from '../../services/text';
import { useCore } from '../../app_context';
import { getRepositoryTypeDocUrl } from '../../lib/type_to_doc_url';

interface Props {
repository: Repository;
Expand All @@ -47,6 +48,7 @@ export const RepositoryFormStepTwo: React.FunctionComponent<Props> = ({
saveError,
onBack,
}) => {
const { docLinks } = useCore();
const hasValidationErrors: boolean = !validation.isValid;
const {
name,
Expand Down Expand Up @@ -76,7 +78,7 @@ export const RepositoryFormStepTwo: React.FunctionComponent<Props> = ({
<EuiButtonEmpty
size="s"
flush="right"
href={documentationLinksService.getRepositoryTypeDocUrl(typeForDocs)}
href={getRepositoryTypeDocUrl(docLinks, typeForDocs)}
target="_blank"
iconType="help"
>
Expand Down
Loading

0 comments on commit a6a567f

Please sign in to comment.