diff --git a/src/plugins/es_ui_shared/public/request/index.ts b/src/plugins/es_ui_shared/public/request/index.ts index a19005c0191a..f942a9cc3932 100644 --- a/src/plugins/es_ui_shared/public/request/index.ts +++ b/src/plugins/es_ui_shared/public/request/index.ts @@ -21,6 +21,7 @@ export { SendRequestConfig, SendRequestResponse, UseRequestConfig, + UseRequestResponse, sendRequest, useRequest, } from './request'; diff --git a/src/plugins/es_ui_shared/public/request/request.ts b/src/plugins/es_ui_shared/public/request/request.ts index 3abadf27047e..fd6980367136 100644 --- a/src/plugins/es_ui_shared/public/request/request.ts +++ b/src/plugins/es_ui_shared/public/request/request.ts @@ -27,7 +27,7 @@ export interface SendRequestConfig { export interface SendRequestResponse { data: any; - error: Error; + error: Error | null; } export interface UseRequestConfig extends SendRequestConfig { @@ -36,10 +36,18 @@ export interface UseRequestConfig extends SendRequestConfig { deserializer?: (data: any) => any; } +export interface UseRequestResponse { + isInitialRequest: boolean; + isLoading: boolean; + error: null | unknown; + data: any; + sendRequest: (...args: any[]) => Promise; +} + export const sendRequest = async ( httpClient: ng.IHttpService, { path, method, body }: SendRequestConfig -): Promise> => { +): Promise => { try { const response = await (httpClient as any)[method](path, body); @@ -47,9 +55,10 @@ export const sendRequest = async ( throw new Error(response.statusText); } - return { data: response.data }; + return { data: response.data, error: null }; } catch (e) { return { + data: null, error: e.response ? e.response : e, }; } @@ -65,7 +74,7 @@ export const useRequest = ( initialData, deserializer = (data: any): any => data, }: UseRequestConfig -) => { +): UseRequestResponse => { // Main states for tracking request status and data const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(true); @@ -112,7 +121,7 @@ export const useRequest = ( // If an outdated request has resolved, DON'T update state, but DO allow the processData handler // to execute side effects like update telemetry. if (isOutdatedRequest) { - return; + return { data: null, error: null }; } setError(responseError); @@ -123,6 +132,8 @@ export const useRequest = ( // If we're on an interval, we need to schedule the next request. This also allows us to reset // the interval if the user has manually requested the data, to avoid doubled-up requests. scheduleRequest(); + + return { data: serializedResponseData, error: responseError }; }; useEffect(() => { diff --git a/src/plugins/es_ui_shared/static/forms/components/fields/index.ts b/src/plugins/es_ui_shared/static/forms/components/fields/index.ts index 154c07aa05b7..4e9d3c562422 100644 --- a/src/plugins/es_ui_shared/static/forms/components/fields/index.ts +++ b/src/plugins/es_ui_shared/static/forms/components/fields/index.ts @@ -24,3 +24,4 @@ export * from './combobox_field'; export * from './multi_select_field'; export * from './select_field'; export * from './toggle_field'; +export * from './text_area_field'; diff --git a/src/plugins/es_ui_shared/static/forms/components/fields/text_area_field.tsx b/src/plugins/es_ui_shared/static/forms/components/fields/text_area_field.tsx new file mode 100644 index 000000000000..6916f224f8bd --- /dev/null +++ b/src/plugins/es_ui_shared/static/forms/components/fields/text_area_field.tsx @@ -0,0 +1,56 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import React from 'react'; +import { EuiFormRow, EuiTextArea } from '@elastic/eui'; + +import { FieldHook } from '../../hook_form_lib'; +import { getFieldValidityAndErrorMessage } from '../helpers'; + +interface Props { + field: FieldHook; + euiFieldProps?: Record; + idAria?: string; + [key: string]: any; +} + +export const TextAreaField = ({ field, euiFieldProps = {}, ...rest }: Props) => { + const { isInvalid, errorMessage } = getFieldValidityAndErrorMessage(field); + + return ( + + + + ); +}; diff --git a/tsconfig.json b/tsconfig.json index 39009cfb543a..a2da9c127e7b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,7 @@ ], "test_utils/*": [ "src/test_utils/public/*" - ], + ] }, // Support .tsx files and transform JSX into calls to React.createElement "jsx": "react", diff --git a/x-pack/legacy/plugins/index_management/public/components/index.ts b/x-pack/legacy/plugins/index_management/public/components/index.ts index be64f5756c56..473f685dbb2f 100644 --- a/x-pack/legacy/plugins/index_management/public/components/index.ts +++ b/x-pack/legacy/plugins/index_management/public/components/index.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -export { SectionError } from './section_error'; +export { SectionError, Error } from './section_error'; export { SectionLoading } from './section_loading'; export { NoMatch } from './no_match'; export { PageErrorForbidden } from './page_error'; diff --git a/x-pack/legacy/plugins/index_management/public/components/section_error.tsx b/x-pack/legacy/plugins/index_management/public/components/section_error.tsx index 6d65addeb4cb..c6fdc9f0d843 100644 --- a/x-pack/legacy/plugins/index_management/public/components/section_error.tsx +++ b/x-pack/legacy/plugins/index_management/public/components/section_error.tsx @@ -7,15 +7,17 @@ import { EuiCallOut, EuiSpacer } from '@elastic/eui'; import React, { Fragment } from 'react'; +export interface Error { + data: { + error: string; + cause?: string[]; + message?: string; + }; +} + interface Props { title: React.ReactNode; - error: { - data: { - error: string; - cause?: string[]; - message?: string; - }; - }; + error: Error; } export const SectionError: React.FunctionComponent = ({ title, error, ...rest }) => { diff --git a/x-pack/legacy/plugins/index_management/public/sections/home/template_list/template_details/template_details.tsx b/x-pack/legacy/plugins/index_management/public/sections/home/template_list/template_details/template_details.tsx index 0ce74ce3ea45..29b8f469631c 100644 --- a/x-pack/legacy/plugins/index_management/public/sections/home/template_list/template_details/template_details.tsx +++ b/x-pack/legacy/plugins/index_management/public/sections/home/template_list/template_details/template_details.tsx @@ -31,10 +31,11 @@ import { UIM_TEMPLATE_DETAIL_PANEL_ALIASES_TAB, } from '../../../../../common/constants'; import { Template } from '../../../../../common/types'; -import { TemplateDeleteModal, SectionLoading, SectionError } from '../../../../components'; +import { TemplateDeleteModal, SectionLoading, SectionError, Error } from '../../../../components'; import { loadIndexTemplate } from '../../../../services/api'; import { decodePath } from '../../../../services/routing'; import { trackUiMetric, METRIC_TYPE } from '../../../../services/track_ui_metric'; +import { SendRequestResponse } from '../../../../shared_imports'; import { TabSummary, TabMappings, TabSettings, TabAliases } from './tabs'; interface Props { @@ -42,7 +43,7 @@ interface Props { onClose: () => void; editTemplate: (templateName: Template['name']) => void; cloneTemplate: (templateName: Template['name']) => void; - reload: () => Promise; + reload: () => Promise; } const SUMMARY_TAB_ID = 'summary'; @@ -128,7 +129,7 @@ export const TemplateDetails: React.FunctionComponent = ({ defaultMessage="Error loading template" /> } - error={error} + error={error as Error} data-test-subj="sectionError" /> ); diff --git a/x-pack/legacy/plugins/index_management/public/sections/home/template_list/template_list.tsx b/x-pack/legacy/plugins/index_management/public/sections/home/template_list/template_list.tsx index a4281ab203c3..b9276afe42fa 100644 --- a/x-pack/legacy/plugins/index_management/public/sections/home/template_list/template_list.tsx +++ b/x-pack/legacy/plugins/index_management/public/sections/home/template_list/template_list.tsx @@ -16,7 +16,7 @@ import { EuiFlexItem, EuiFlexGroup, } from '@elastic/eui'; -import { SectionError, SectionLoading } from '../../../components'; +import { SectionError, SectionLoading, Error } from '../../../components'; import { TemplateTable } from './template_table'; import { loadIndexTemplates } from '../../../services/api'; import { Template } from '../../../../common/types'; @@ -87,7 +87,7 @@ export const TemplateList: React.FunctionComponent } - error={error} + error={error as Error} /> ); } else if (Array.isArray(templates) && templates.length === 0) { diff --git a/x-pack/legacy/plugins/index_management/public/sections/home/template_list/template_table/template_table.tsx b/x-pack/legacy/plugins/index_management/public/sections/home/template_list/template_table/template_table.tsx index 754da6f8fec0..52207cfa46e7 100644 --- a/x-pack/legacy/plugins/index_management/public/sections/home/template_list/template_table/template_table.tsx +++ b/x-pack/legacy/plugins/index_management/public/sections/home/template_list/template_table/template_table.tsx @@ -13,10 +13,11 @@ import { BASE_PATH, UIM_TEMPLATE_SHOW_DETAILS_CLICK } from '../../../../../commo import { TemplateDeleteModal } from '../../../../components'; import { trackUiMetric, METRIC_TYPE } from '../../../../services/track_ui_metric'; import { getTemplateDetailsLink } from '../../../../services/routing'; +import { SendRequestResponse } from '../../../../shared_imports'; interface Props { templates: TemplateListItem[]; - reload: () => Promise; + reload: () => Promise; editTemplate: (name: Template['name']) => void; cloneTemplate: (name: Template['name']) => void; } diff --git a/x-pack/legacy/plugins/index_management/public/sections/template_clone/template_clone.tsx b/x-pack/legacy/plugins/index_management/public/sections/template_clone/template_clone.tsx index 52b95acdd38f..1d0d8bf15902 100644 --- a/x-pack/legacy/plugins/index_management/public/sections/template_clone/template_clone.tsx +++ b/x-pack/legacy/plugins/index_management/public/sections/template_clone/template_clone.tsx @@ -7,7 +7,7 @@ import React, { useEffect, useState } from 'react'; import { RouteComponentProps } from 'react-router-dom'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiPageBody, EuiPageContent, EuiSpacer, EuiTitle } from '@elastic/eui'; -import { TemplateForm, SectionLoading, SectionError } from '../../components'; +import { TemplateForm, SectionLoading, SectionError, Error } from '../../components'; import { setBreadcrumbs } from '../../services/set_breadcrumbs'; import { decodePath, getTemplateDetailsLink } from '../../services/routing'; import { Template } from '../../../common/types'; @@ -77,7 +77,7 @@ export const TemplateClone: React.FunctionComponent } - error={templateToCloneError} + error={templateToCloneError as Error} data-test-subj="sectionError" /> ); diff --git a/x-pack/legacy/plugins/index_management/public/sections/template_edit/template_edit.tsx b/x-pack/legacy/plugins/index_management/public/sections/template_edit/template_edit.tsx index f14a975cc804..bed9c85cca18 100644 --- a/x-pack/legacy/plugins/index_management/public/sections/template_edit/template_edit.tsx +++ b/x-pack/legacy/plugins/index_management/public/sections/template_edit/template_edit.tsx @@ -10,7 +10,7 @@ import { EuiPageBody, EuiPageContent, EuiTitle, EuiSpacer, EuiCallOut } from '@e import { setBreadcrumbs } from '../../services/set_breadcrumbs'; import { loadIndexTemplate, updateTemplate } from '../../services/api'; import { decodePath, getTemplateDetailsLink } from '../../services/routing'; -import { SectionLoading, SectionError, TemplateForm } from '../../components'; +import { SectionLoading, SectionError, TemplateForm, Error } from '../../components'; import { Template } from '../../../common/types'; interface MatchParams { @@ -73,7 +73,7 @@ export const TemplateEdit: React.FunctionComponent } - error={error} + error={error as Error} data-test-subj="sectionError" /> ); diff --git a/x-pack/legacy/plugins/index_management/public/services/use_request.ts b/x-pack/legacy/plugins/index_management/public/services/use_request.ts index cb50ea3e9f13..4788b655d9e8 100644 --- a/x-pack/legacy/plugins/index_management/public/services/use_request.ts +++ b/x-pack/legacy/plugins/index_management/public/services/use_request.ts @@ -13,7 +13,7 @@ import { } from '../shared_imports'; import { getHttpClient } from './api'; -export const sendRequest = (config: SendRequestConfig): Promise> => { +export const sendRequest = (config: SendRequestConfig): Promise => { return _sendRequest(getHttpClient(), config); }; diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/components/index.ts b/x-pack/legacy/plugins/snapshot_restore/public/app/components/index.ts index 8b0912b09343..32b45c05d5cb 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/components/index.ts +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/components/index.ts @@ -10,7 +10,7 @@ export { RepositoryDeleteProvider } from './repository_delete_provider'; export { RepositoryForm } from './repository_form'; export { RepositoryVerificationBadge } from './repository_verification_badge'; export { RepositoryTypeLogo } from './repository_type_logo'; -export { SectionError } from './section_error'; +export { SectionError, Error } from './section_error'; export { SectionLoading } from './section_loading'; export { SnapshotDeleteProvider } from './snapshot_delete_provider'; export { RestoreSnapshotForm } from './restore_snapshot_form'; diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/components/repository_form/step_one.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/components/repository_form/step_one.tsx index fe76d06b9c4b..8f6b465b2fe5 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/components/repository_form/step_one.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/components/repository_form/step_one.tsx @@ -30,7 +30,7 @@ import { documentationLinksService } from '../../services/documentation'; import { useLoadRepositoryTypes } from '../../services/http'; import { textService } from '../../services/text'; import { RepositoryValidation } from '../../services/validation'; -import { SectionError, SectionLoading, RepositoryTypeLogo } from '../'; +import { SectionError, SectionLoading, RepositoryTypeLogo, Error } from '../'; interface Props { repository: Repository | EmptyRepository; @@ -177,7 +177,7 @@ export const RepositoryFormStepOne: React.FunctionComponent = ({ defaultMessage="Error loading repository types" /> } - error={repositoryTypesError} + error={repositoryTypesError as Error} /> ); } diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/components/section_error.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/components/section_error.tsx index 2ad6f0870c14..cffc9ed0989f 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/components/section_error.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/components/section_error.tsx @@ -7,15 +7,17 @@ import { EuiCallOut, EuiSpacer } from '@elastic/eui'; import React, { Fragment } from 'react'; +export interface Error { + data: { + error: string; + cause?: string[]; + message?: string; + }; +} + interface Props { title: React.ReactNode; - error: { - data: { - error: string; - cause?: string[]; - message?: string; - }; - }; + error: Error; actions?: JSX.Element; } diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/lib/authorization/components/authorization_provider.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/lib/authorization/components/authorization_provider.tsx index 9a219b225c63..6aa3484645b3 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/lib/authorization/components/authorization_provider.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/lib/authorization/components/authorization_provider.tsx @@ -54,7 +54,7 @@ export const AuthorizationProvider = ({ privilegesEndpoint, children }: Props) = isLoading, privileges: isLoading ? { hasAllPrivileges: true, missingPrivileges: {} } : privilegesData, apiError: error ? error : null, - }; + } as Authorization; return {children}; }; diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/policy_list/policy_details/policy_details.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/policy_list/policy_details/policy_details.tsx index e4b6ad28e324..dfc19069b17a 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/policy_list/policy_details/policy_details.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/policy_list/policy_details/policy_details.tsx @@ -37,6 +37,7 @@ import { SectionLoading, PolicyExecuteProvider, PolicyDeleteProvider, + Error, } from '../../../../components'; import { TabSummary, TabHistory } from './tabs'; @@ -144,7 +145,7 @@ export const PolicyDetails: React.FunctionComponent = ({ }; const renderError = () => { - const notFound = error.status === 404; + const notFound = (error as any).status === 404; const errorObject = notFound ? { data: { @@ -168,7 +169,7 @@ export const PolicyDetails: React.FunctionComponent = ({ defaultMessage="Error loading policy" /> } - error={errorObject} + error={errorObject as Error} /> ); }; diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/policy_list/policy_list.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/policy_list/policy_list.tsx index e46bf1ce384b..dfcf75b5b89a 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/policy_list/policy_list.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/policy_list/policy_list.tsx @@ -10,7 +10,7 @@ import { RouteComponentProps } from 'react-router-dom'; import { EuiEmptyPrompt, EuiButton, EuiCallOut, EuiSpacer } from '@elastic/eui'; import { SlmPolicy } from '../../../../../common/types'; import { APP_SLM_CLUSTER_PRIVILEGES } from '../../../../../common/constants'; -import { SectionError, SectionLoading } from '../../../components'; +import { SectionError, SectionLoading, Error } from '../../../components'; import { BASE_PATH, UIM_POLICY_LIST_LOAD } from '../../../constants'; import { useAppDependencies } from '../../../index'; import { useLoadPolicies, useLoadRetentionSettings } from '../../../services/http'; @@ -102,7 +102,7 @@ export const PolicyList: React.FunctionComponent } - error={error} + error={error as Error} /> ); } else if (policies && policies.length === 0) { diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/policy_list/policy_table/policy_table.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/policy_list/policy_table/policy_table.tsx index bbab68a03881..b544666b6715 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/policy_list/policy_table/policy_table.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/policy_list/policy_table/policy_table.tsx @@ -28,10 +28,11 @@ import { } from '../../../../components'; import { uiMetricService } from '../../../../services/ui_metric'; import { linkToAddPolicy, linkToEditPolicy } from '../../../../services/navigation'; +import { SendRequestResponse } from '../../../../../shared_imports'; interface Props { policies: SlmPolicy[]; - reload: () => Promise; + reload: () => Promise; openPolicyDetailsUrl: (name: SlmPolicy['name']) => string; onPolicyDeleted: (policiesDeleted: Array) => void; onPolicyExecuted: () => void; diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx index 35eaf331b4f0..c03162bae8bd 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx @@ -39,6 +39,7 @@ import { SectionError, SectionLoading, RepositoryVerificationBadge, + Error, } from '../../../../components'; import { TypeDetails } from './type_details'; @@ -98,7 +99,7 @@ export const RepositoryDetails: React.FunctionComponent = ({ }; const renderError = () => { - const notFound = error.status === 404; + const notFound = (error as any).status === 404; const errorObject = notFound ? { data: { @@ -122,7 +123,7 @@ export const RepositoryDetails: React.FunctionComponent = ({ defaultMessage="Error loading repository" /> } - error={errorObject} + error={errorObject as Error} /> ); }; diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx index 975d42a1d1e8..5e3250f082fc 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx @@ -9,7 +9,7 @@ import { RouteComponentProps } from 'react-router-dom'; import { EuiButton, EuiEmptyPrompt } from '@elastic/eui'; import { Repository } from '../../../../../common/types'; -import { SectionError, SectionLoading } from '../../../components'; +import { SectionError, SectionLoading, Error } from '../../../components'; import { BASE_PATH, UIM_REPOSITORY_LIST_LOAD } from '../../../constants'; import { useAppDependencies } from '../../../index'; import { useLoadRepositories } from '../../../services/http'; @@ -88,7 +88,7 @@ export const RepositoryList: React.FunctionComponent } - error={error} + error={error as Error} /> ); } else if (repositories && repositories.length === 0) { diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx index 29affbf5c3cb..119733d891ab 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx @@ -24,11 +24,12 @@ import { useAppDependencies } from '../../../../index'; import { textService } from '../../../../services/text'; import { uiMetricService } from '../../../../services/ui_metric'; import { linkToEditRepository, linkToAddRepository } from '../../../../services/navigation'; +import { SendRequestResponse } from '../../../../../shared_imports'; interface Props { repositories: Repository[]; managedRepository?: string; - reload: () => Promise; + reload: () => Promise; openRepositoryDetailsUrl: (name: Repository['name']) => string; onRepositoryDeleted: (repositoriesDeleted: Array) => void; } diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/restore_list/restore_list.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/restore_list/restore_list.tsx index d43c83519287..ec4b8d9f19fb 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/restore_list/restore_list.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/restore_list/restore_list.tsx @@ -18,7 +18,7 @@ import { EuiLink, } from '@elastic/eui'; import { APP_RESTORE_INDEX_PRIVILEGES } from '../../../../../common/constants'; -import { SectionError, SectionLoading } from '../../../components'; +import { SectionError, SectionLoading, Error } from '../../../components'; import { UIM_RESTORE_LIST_LOAD } from '../../../constants'; import { useAppDependencies } from '../../../index'; import { useLoadRestores } from '../../../services/http'; @@ -85,7 +85,7 @@ export const RestoreList: React.FunctionComponent = () => { defaultMessage="Error loading restores" /> } - error={error} + error={error as Error} /> ); } diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_details/snapshot_details.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_details/snapshot_details.tsx index e3534e3c8945..e9ce9cbe0ac7 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_details/snapshot_details.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_details/snapshot_details.tsx @@ -23,7 +23,12 @@ import { import React, { Fragment, useState, useEffect } from 'react'; import { SnapshotDetails as ISnapshotDetails } from '../../../../../../common/types'; -import { SectionError, SectionLoading, SnapshotDeleteProvider } from '../../../../components'; +import { + SectionError, + SectionLoading, + SnapshotDeleteProvider, + Error, +} from '../../../../components'; import { useAppDependencies } from '../../../../index'; import { UIM_SNAPSHOT_DETAIL_PANEL_SUMMARY_TAB, @@ -125,7 +130,7 @@ export const SnapshotDetails: React.FunctionComponent = ({ content = ; } } else if (error) { - const notFound = error.status === 404; + const notFound = (error as any).status === 404; const errorObject = notFound ? { data: { @@ -148,7 +153,7 @@ export const SnapshotDetails: React.FunctionComponent = ({ defaultMessage="Error loading repository" /> } - error={errorObject} + error={errorObject as Error} /> ); } else { diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_list.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_list.tsx index b5554bde2d32..642a12411e6f 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_list.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_list.tsx @@ -10,7 +10,7 @@ import { parse } from 'querystring'; import { EuiButton, EuiCallOut, EuiLink, EuiEmptyPrompt, EuiSpacer, EuiIcon } from '@elastic/eui'; import { APP_SLM_CLUSTER_PRIVILEGES } from '../../../../../common/constants'; -import { SectionError, SectionLoading } from '../../../components'; +import { SectionError, SectionLoading, Error } from '../../../components'; import { BASE_PATH, UIM_SNAPSHOT_LIST_LOAD } from '../../../constants'; import { WithPrivileges } from '../../../lib/authorization'; import { useAppDependencies } from '../../../index'; @@ -125,7 +125,7 @@ export const SnapshotList: React.FunctionComponent } - error={error} + error={error as Error} /> ); } else if (Object.keys(errors).length && repositories.length === 0) { diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_table/snapshot_table.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_table/snapshot_table.tsx index e3493e506d23..dbf584acd547 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_table/snapshot_table.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_table/snapshot_table.tsx @@ -21,11 +21,12 @@ import { useAppDependencies } from '../../../../index'; import { linkToRepository, linkToRestoreSnapshot } from '../../../../services/navigation'; import { uiMetricService } from '../../../../services/ui_metric'; import { DataPlaceholder, FormattedDateTime, SnapshotDeleteProvider } from '../../../../components'; +import { SendRequestResponse } from '../../../../../shared_imports'; interface Props { snapshots: SnapshotDetails[]; repositories: string[]; - reload: () => Promise; + reload: () => Promise; openSnapshotDetailsUrl: (repositoryName: string, snapshotId: string) => string; repositoryFilter?: string; policyFilter?: string; diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/policy_add/policy_add.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/policy_add/policy_add.tsx index 0547e811d461..191d31cfba62 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/policy_add/policy_add.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/policy_add/policy_add.tsx @@ -10,7 +10,7 @@ import { EuiPageBody, EuiPageContent, EuiSpacer, EuiTitle } from '@elastic/eui'; import { SlmPolicyPayload } from '../../../../common/types'; import { TIME_UNITS } from '../../../../common/constants'; -import { PolicyForm, SectionError, SectionLoading } from '../../components'; +import { PolicyForm, SectionError, SectionLoading, Error } from '../../components'; import { useAppDependencies } from '../../index'; import { BASE_PATH, DEFAULT_POLICY_SCHEDULE } from '../../constants'; import { breadcrumbService, docTitleService } from '../../services/navigation'; @@ -119,7 +119,7 @@ export const PolicyAdd: React.FunctionComponent = ({ defaultMessage="Error loading available indices" /> } - error={errorLoadingIndices} + error={errorLoadingIndices as Error} /> ) : ( { if (errorLoadingPolicy) { - const notFound = errorLoadingPolicy.status === 404; + const notFound = (errorLoadingPolicy as any).status === 404; const errorObject = notFound ? { data: { @@ -135,7 +135,7 @@ export const PolicyEdit: React.FunctionComponent } - error={errorObject} + error={errorObject as Error} /> ); } @@ -149,7 +149,7 @@ export const PolicyEdit: React.FunctionComponent } - error={errorLoadingIndices} + error={errorLoadingIndices as Error} /> ); } diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/repository_edit/repository_edit.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/repository_edit/repository_edit.tsx index 8544ea8f5ef1..9e8a06863254 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/repository_edit/repository_edit.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/repository_edit/repository_edit.tsx @@ -9,7 +9,7 @@ import { RouteComponentProps } from 'react-router-dom'; import { EuiCallOut, EuiPageBody, EuiPageContent, EuiSpacer, EuiTitle } from '@elastic/eui'; import { Repository, EmptyRepository } from '../../../../common/types'; -import { RepositoryForm, SectionError, SectionLoading } from '../../components'; +import { RepositoryForm, SectionError, SectionLoading, Error } from '../../components'; import { BASE_PATH, Section } from '../../constants'; import { useAppDependencies } from '../../index'; import { breadcrumbService, docTitleService } from '../../services/navigation'; @@ -87,7 +87,7 @@ export const RepositoryEdit: React.FunctionComponent { - const notFound = repositoryError.status === 404; + const notFound = (repositoryError as any).status === 404; const errorObject = notFound ? { data: { @@ -111,7 +111,7 @@ export const RepositoryEdit: React.FunctionComponent } - error={errorObject} + error={errorObject as Error} /> ); }; diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/restore_snapshot/restore_snapshot.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/restore_snapshot/restore_snapshot.tsx index 53956cd00763..3205624775bd 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/restore_snapshot/restore_snapshot.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/restore_snapshot/restore_snapshot.tsx @@ -9,7 +9,7 @@ import { EuiPageBody, EuiPageContent, EuiSpacer, EuiTitle } from '@elastic/eui'; import { SnapshotDetails, RestoreSettings } from '../../../../common/types'; import { BASE_PATH } from '../../constants'; -import { SectionError, SectionLoading, RestoreSnapshotForm } from '../../components'; +import { SectionError, SectionLoading, RestoreSnapshotForm, Error } from '../../components'; import { useAppDependencies } from '../../index'; import { breadcrumbService, docTitleService } from '../../services/navigation'; import { useLoadSnapshot, executeRestore } from '../../services/http'; @@ -86,7 +86,7 @@ export const RestoreSnapshot: React.FunctionComponent { - const notFound = snapshotError.status === 404; + const notFound = (snapshotError as any).status === 404; const errorObject = notFound ? { data: { @@ -111,7 +111,7 @@ export const RestoreSnapshot: React.FunctionComponent } - error={errorObject} + error={errorObject as Error} /> ); }; diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/services/http/use_request.ts b/x-pack/legacy/plugins/snapshot_restore/public/app/services/http/use_request.ts index dc5f3d9b990a..51b1d49c98d4 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/services/http/use_request.ts +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/services/http/use_request.ts @@ -13,7 +13,7 @@ import { } from '../../../shared_imports'; import { httpService } from './index'; -export const sendRequest = (config: SendRequestConfig): Promise> => { +export const sendRequest = (config: SendRequestConfig): Promise => { return _sendRequest(httpService.httpClient, config); }; diff --git a/x-pack/legacy/plugins/watcher/public/components/index.ts b/x-pack/legacy/plugins/watcher/public/components/index.ts index 8217950a7597..f703bb586489 100644 --- a/x-pack/legacy/plugins/watcher/public/components/index.ts +++ b/x-pack/legacy/plugins/watcher/public/components/index.ts @@ -10,4 +10,4 @@ export { DeleteWatchesModal } from './delete_watches_modal'; export { ErrableFormRow } from './form_errors'; export { WatchStatus } from './watch_status'; export { SectionLoading } from './section_loading'; -export { SectionError } from './section_error'; +export { SectionError, Error } from './section_error'; diff --git a/x-pack/legacy/plugins/watcher/public/components/section_error.tsx b/x-pack/legacy/plugins/watcher/public/components/section_error.tsx index fea655107731..8951b95b7507 100644 --- a/x-pack/legacy/plugins/watcher/public/components/section_error.tsx +++ b/x-pack/legacy/plugins/watcher/public/components/section_error.tsx @@ -7,15 +7,17 @@ import { EuiCallOut, EuiSpacer } from '@elastic/eui'; import React, { Fragment } from 'react'; +export interface Error { + data: { + error: string; + cause?: string[]; + message?: string; + }; +} + interface Props { title: React.ReactNode; - error: { - data: { - error: string; - cause?: string[]; - message?: string; - }; - }; + error: Error; } export const SectionError: React.FunctionComponent = ({ title, error, ...rest }) => { diff --git a/x-pack/legacy/plugins/watcher/public/lib/use_request.ts b/x-pack/legacy/plugins/watcher/public/lib/use_request.ts index cb50ea3e9f13..4788b655d9e8 100644 --- a/x-pack/legacy/plugins/watcher/public/lib/use_request.ts +++ b/x-pack/legacy/plugins/watcher/public/lib/use_request.ts @@ -13,7 +13,7 @@ import { } from '../shared_imports'; import { getHttpClient } from './api'; -export const sendRequest = (config: SendRequestConfig): Promise> => { +export const sendRequest = (config: SendRequestConfig): Promise => { return _sendRequest(getHttpClient(), config); }; diff --git a/x-pack/legacy/plugins/watcher/public/sections/watch_edit/components/threshold_watch_edit/watch_visualization.tsx b/x-pack/legacy/plugins/watcher/public/sections/watch_edit/components/threshold_watch_edit/watch_visualization.tsx index 3f38e4983c74..772f3cc024fe 100644 --- a/x-pack/legacy/plugins/watcher/public/sections/watch_edit/components/threshold_watch_edit/watch_visualization.tsx +++ b/x-pack/legacy/plugins/watcher/public/sections/watch_edit/components/threshold_watch_edit/watch_visualization.tsx @@ -31,7 +31,7 @@ import { getWatchVisualizationData } from '../../../../lib/api'; import { WatchContext } from '../../watch_context'; import { aggTypes } from '../../../../models/watch/agg_types'; import { comparators } from '../../../../models/watch/comparators'; -import { SectionError } from '../../../../components'; +import { SectionError, Error } from '../../../../components'; const customTheme = () => { return { @@ -181,7 +181,7 @@ export const WatchVisualization = () => { defaultMessage="Cannot load watch visualization" /> } - error={error} + error={error as Error} /> diff --git a/x-pack/legacy/plugins/watcher/public/sections/watch_list/components/watch_list.tsx b/x-pack/legacy/plugins/watcher/public/sections/watch_list/components/watch_list.tsx index 6bcb7568eae3..d5191c56643c 100644 --- a/x-pack/legacy/plugins/watcher/public/sections/watch_list/components/watch_list.tsx +++ b/x-pack/legacy/plugins/watcher/public/sections/watch_list/components/watch_list.tsx @@ -39,6 +39,7 @@ import { WatchStatus, SectionError, SectionLoading, + Error, } from '../../../components'; import { loadWatches } from '../../../lib/api'; import { watcherGettingStartedUrl } from '../../../lib/documentation_links'; @@ -223,7 +224,7 @@ export const WatchList = () => { defaultMessage="Error loading watches" /> } - error={error} + error={error as Error} /> ); } else if (availableWatches) { diff --git a/x-pack/legacy/plugins/watcher/public/sections/watch_status/components/watch_history.tsx b/x-pack/legacy/plugins/watcher/public/sections/watch_status/components/watch_history.tsx index c65d6b12e2e6..bf6ca0c6c43a 100644 --- a/x-pack/legacy/plugins/watcher/public/sections/watch_status/components/watch_history.tsx +++ b/x-pack/legacy/plugins/watcher/public/sections/watch_status/components/watch_history.tsx @@ -24,7 +24,7 @@ import { } from '@elastic/eui'; import { PAGINATION } from '../../../../common/constants'; -import { WatchStatus, SectionError } from '../../../components'; +import { WatchStatus, SectionError, Error } from '../../../components'; import { loadWatchHistory, loadWatchHistoryDetail } from '../../../lib/api'; import { WatchDetailsContext } from '../watch_details_context'; @@ -107,7 +107,7 @@ export const WatchHistory = () => { defaultMessage="Error loading execution history" /> } - error={historyError} + error={historyError as Error} /> ); @@ -186,7 +186,7 @@ export const WatchHistory = () => { defaultMessage="Error loading execution details" /> } - error={watchHistoryDetailsError} + error={watchHistoryDetailsError as Error} data-test-subj="errorMessage" /> diff --git a/x-pack/legacy/server/lib/check_license/check_license.js b/x-pack/legacy/server/lib/check_license/check_license.js index 12e92c74e22d..530b76f2ab1e 100644 --- a/x-pack/legacy/server/lib/check_license/check_license.js +++ b/x-pack/legacy/server/lib/check_license/check_license.js @@ -14,6 +14,10 @@ import { } from '../../../common/constants'; export function checkLicense(pluginName, minimumLicenseRequired, xpackLicenseInfo) { + if (!minimumLicenseRequired) { + throw new Error(`Error checking license for plugin "${pluginName}". The minimum license required has not been provided.`); + } + if(!RANKED_LICENSE_TYPES.includes(minimumLicenseRequired)) { throw new Error(`Invalid license type supplied to checkLicense: ${minimumLicenseRequired}`); } diff --git a/x-pack/legacy/server/lib/create_router/index.js b/x-pack/legacy/server/lib/create_router/index.js index f8d47f8c1884..69697775e80c 100644 --- a/x-pack/legacy/server/lib/create_router/index.js +++ b/x-pack/legacy/server/lib/create_router/index.js @@ -48,7 +48,7 @@ export const createRouter = (server, pluginId, apiBasePath = '', config) => { return (['get', 'post', 'put', 'delete', 'patch'].reduce((router, methodName) => { router[methodName] = (subPath, handler) => { const method = methodName.toUpperCase(); - const path = `${apiBasePath}${subPath}`; + const path = apiBasePath + subPath; server.route({ path, method,