From 988242c1c1fcfddfb7fb7942a5ace025ce4e9dae Mon Sep 17 00:00:00 2001 From: sebelga Date: Fri, 22 Mar 2019 07:41:53 +0100 Subject: [PATCH 1/8] Move app dependencies to its own context provider --- .../app/components/repository_type_name.tsx | 12 ++--- .../snapshot_restore/public/app/index.tsx | 49 ++++++++++--------- .../public/app/sections/home/home.tsx | 13 +++-- .../repository_details/repository_details.tsx | 15 +++--- .../type_details/azure_details.tsx | 16 +++--- .../type_details/default_details.tsx | 12 ++--- .../type_details/fs_details.tsx | 13 +++-- .../type_details/gcs_details.tsx | 13 +++-- .../type_details/hdfs_details.tsx | 13 +++-- .../type_details/readonly_details.tsx | 12 ++--- .../type_details/s3_details.tsx | 13 +++-- .../home/repository_list/repository_list.tsx | 12 ++--- .../repository_table/repository_table.tsx | 10 ++-- .../public/app/services/app_context.ts | 19 ------- .../public/app/services/app_state.ts | 23 +++++++++ .../public/app/services/use_request.ts | 10 ++-- .../snapshot_restore/public/app/types/app.ts | 48 ++++++++++++++++++ .../public/app/types/index.ts | 7 +++ .../plugins/snapshot_restore/public/shim.ts | 29 +---------- 19 files changed, 176 insertions(+), 163 deletions(-) delete mode 100644 x-pack/plugins/snapshot_restore/public/app/services/app_context.ts create mode 100644 x-pack/plugins/snapshot_restore/public/app/services/app_state.ts create mode 100644 x-pack/plugins/snapshot_restore/public/app/types/app.ts create mode 100644 x-pack/plugins/snapshot_restore/public/app/types/index.ts diff --git a/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx b/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx index 0ddc7718b4320..8c6217acc4eb0 100644 --- a/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx @@ -6,7 +6,7 @@ import React, { Fragment } from 'react'; import { RepositoryType, RepositoryTypes } from '../../../common/types/repository_types'; -import { AppStateInterface, useAppState } from '../services/app_context'; +import { useAppDependencies } from '../index'; interface Props { type: RepositoryType; @@ -14,13 +14,11 @@ interface Props { } export const RepositoryTypeName = ({ type, delegateType }: Props) => { - const [ - { - core: { - i18n: { FormattedMessage }, - }, + const { + core: { + i18n: { FormattedMessage }, }, - ] = useAppState() as [AppStateInterface]; + } = useAppDependencies(); const typeNameMap: { [key in RepositoryType]: JSX.Element } = { [RepositoryTypes.fs]: ( diff --git a/x-pack/plugins/snapshot_restore/public/app/index.tsx b/x-pack/plugins/snapshot_restore/public/app/index.tsx index 6d46af98e6f07..102c20abf66a7 100644 --- a/x-pack/plugins/snapshot_restore/public/app/index.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/index.tsx @@ -3,34 +3,43 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import React, { useReducer } from 'react'; +import React, { createContext, useContext, useReducer } from 'react'; import { render } from 'react-dom'; import { HashRouter } from 'react-router-dom'; -import { AppCore, AppPlugins } from '../shim'; import { App } from './app'; -import { AppStateInterface, AppStateProvider } from './services/app_context'; +import { AppStateProvider, initialState, reducer } from './services/app_state'; +import { AppCore, AppDependencies, AppPlugins } from './types'; export { BASE_PATH as CLIENT_BASE_PATH } from './constants'; -// Placeholder reducer in case we need it for any app state data -const appStateReducer = (state: any, action: any) => { - switch (action.type) { - default: - return state; - } -}; +/** + * App dependencies + */ +let DependenciesContext: React.Context; -const ReactApp = ({ appState }: { appState: AppStateInterface }) => { +export const useAppDependencies = () => useContext(DependenciesContext); + +const ReactApp: React.FunctionComponent = ({ core, plugins }) => { const { i18n: { Context: I18nContext }, - } = appState.core; + } = core; + + const appDependencies: AppDependencies = { + core, + plugins, + }; + + DependenciesContext = createContext(appDependencies); + return ( - - - + + + + + ); @@ -41,13 +50,5 @@ export const renderReact = async ( core: AppCore, plugins: AppPlugins ): Promise => { - render( - , - elem - ); + render(, elem); }; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/home.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/home.tsx index 072e9e6b80eb5..11483173cd93d 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/home.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/home.tsx @@ -10,7 +10,7 @@ import { Route, RouteComponentProps, Switch } from 'react-router-dom'; import { EuiPageBody, EuiPageContent, EuiSpacer, EuiTab, EuiTabs, EuiTitle } from '@elastic/eui'; import { BASE_PATH, Section } from '../../constants'; -import { AppStateInterface, useAppState } from '../../services/app_context'; +import { useAppDependencies } from '../../index'; import { RepositoryList } from './repository_list'; import { SnapshotList } from './snapshot_list'; @@ -29,12 +29,11 @@ export const SnapshotRestoreHome = ({ }: Props) => { const [activeSection, setActiveSection] = useState
(section); - const [ - { - core: { i18n, chrome }, - plugins: { management }, - }, - ] = useAppState() as [AppStateInterface]; + const { + core: { i18n, chrome }, + plugins: { management }, + } = useAppDependencies(); + const { FormattedMessage } = i18n; const tabs = [ diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx index 8ae6d80b764f5..8e80022271ef9 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx @@ -5,7 +5,7 @@ */ import React, { Fragment } from 'react'; -import { AppStateInterface, useAppState } from '../../../../services/app_context'; +import { useAppDependencies } from '../../../../index'; import { getRepositoryTypeDocUrl } from '../../../../services/documentation_links'; import { useRequest } from '../../../../services/use_request'; @@ -37,14 +37,13 @@ interface Props { } export const RepositoryDetails = ({ repositoryName, onClose }: Props) => { - const [ - { - core: { - i18n, - documentation: { esDocBasePath, esPluginDocBasePath }, - }, + const { + core: { + i18n, + documentation: { esDocBasePath, esPluginDocBasePath }, }, - ] = useAppState() as [AppStateInterface]; + } = useAppDependencies(); + const { FormattedMessage } = i18n; const { error, loading, data: repository } = useRequest({ path: `repositories/${repositoryName}`, diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/azure_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/azure_details.tsx index bcab9cc876a84..1fd5b4534501f 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/azure_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/azure_details.tsx @@ -6,23 +6,21 @@ import React, { Fragment } from 'react'; -import { AzureRepository } from '../../../../../../../common/types/repository_types'; -import { AppStateInterface, useAppState } from '../../../../../services/app_context'; - import { EuiDescriptionList, EuiSpacer, EuiTitle } from '@elastic/eui'; +import { AzureRepository } from '../../../../../../../common/types/repository_types'; +import { useAppDependencies } from '../../../../../index'; interface Props { repository: AzureRepository; } export const AzureDetails = ({ repository }: Props) => { - const [ - { - core: { - i18n: { FormattedMessage }, - }, + const { + core: { + i18n: { FormattedMessage }, }, - ] = useAppState() as [AppStateInterface]; + } = useAppDependencies(); + const { settings: { client, container, base_path, compress, chunk_size, readonly, location_mode }, } = repository; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/default_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/default_details.tsx index 539ce2842f60f..80dad3df26a08 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/default_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/default_details.tsx @@ -12,7 +12,7 @@ declare module '@elastic/eui' { import React, { Fragment } from 'react'; import { Repository } from '../../../../../../../common/types/repository_types'; -import { AppStateInterface, useAppState } from '../../../../../services/app_context'; +import { useAppDependencies } from '../../../../../index'; import 'brace/theme/textmate'; @@ -23,13 +23,11 @@ interface Props { } export const DefaultDetails = ({ repository: { name, settings } }: Props) => { - const [ - { - core: { - i18n: { FormattedMessage }, - }, + const { + core: { + i18n: { FormattedMessage }, }, - ] = useAppState() as [AppStateInterface]; + } = useAppDependencies(); return ( diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/fs_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/fs_details.tsx index 64586461b270a..f53f9ef36ce26 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/fs_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/fs_details.tsx @@ -7,7 +7,7 @@ import React, { Fragment } from 'react'; import { FSRepository } from '../../../../../../../common/types/repository_types'; -import { AppStateInterface, useAppState } from '../../../../../services/app_context'; +import { useAppDependencies } from '../../../../../index'; import { EuiDescriptionList, EuiSpacer, EuiTitle } from '@elastic/eui'; @@ -16,13 +16,12 @@ interface Props { } export const FSDetails = ({ repository }: Props) => { - const [ - { - core: { - i18n: { FormattedMessage }, - }, + const { + core: { + i18n: { FormattedMessage }, }, - ] = useAppState() as [AppStateInterface]; + } = useAppDependencies(); + const { settings: { location, diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/gcs_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/gcs_details.tsx index a934da36d0850..9768c6dac2c37 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/gcs_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/gcs_details.tsx @@ -7,7 +7,7 @@ import React, { Fragment } from 'react'; import { GCSRepository } from '../../../../../../../common/types/repository_types'; -import { AppStateInterface, useAppState } from '../../../../../services/app_context'; +import { useAppDependencies } from '../../../../../index'; import { EuiDescriptionList, EuiSpacer, EuiTitle } from '@elastic/eui'; @@ -16,13 +16,12 @@ interface Props { } export const GCSDetails = ({ repository }: Props) => { - const [ - { - core: { - i18n: { FormattedMessage }, - }, + const { + core: { + i18n: { FormattedMessage }, }, - ] = useAppState() as [AppStateInterface]; + } = useAppDependencies(); + const { settings: { bucket, client, base_path, compress, chunk_size }, } = repository; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/hdfs_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/hdfs_details.tsx index da1a6c98a11c5..32950e53d53bd 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/hdfs_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/hdfs_details.tsx @@ -7,7 +7,7 @@ import React, { Fragment } from 'react'; import { HDFSRepository } from '../../../../../../../common/types/repository_types'; -import { AppStateInterface, useAppState } from '../../../../../services/app_context'; +import { useAppDependencies } from '../../../../../index'; import { EuiDescriptionList, EuiSpacer, EuiTitle } from '@elastic/eui'; @@ -16,13 +16,12 @@ interface Props { } export const HDFSDetails = ({ repository }: Props) => { - const [ - { - core: { - i18n: { FormattedMessage }, - }, + const { + core: { + i18n: { FormattedMessage }, }, - ] = useAppState() as [AppStateInterface]; + } = useAppDependencies(); + const { settings } = repository; const { uri, diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/readonly_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/readonly_details.tsx index 9301d5994c303..d60a7c281c84a 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/readonly_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/readonly_details.tsx @@ -7,7 +7,7 @@ import React, { Fragment } from 'react'; import { ReadonlyRepository } from '../../../../../../../common/types/repository_types'; -import { AppStateInterface, useAppState } from '../../../../../services/app_context'; +import { useAppDependencies } from '../../../../../index'; import { EuiDescriptionList, EuiSpacer, EuiTitle } from '@elastic/eui'; @@ -16,13 +16,11 @@ interface Props { } export const ReadonlyDetails = ({ repository }: Props) => { - const [ - { - core: { - i18n: { FormattedMessage }, - }, + const { + core: { + i18n: { FormattedMessage }, }, - ] = useAppState() as [AppStateInterface]; + } = useAppDependencies(); const { settings: { url }, } = repository; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/s3_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/s3_details.tsx index 7f3f2d1a0ff17..49caf38f5e67d 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/s3_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/s3_details.tsx @@ -7,7 +7,7 @@ import React, { Fragment } from 'react'; import { S3Repository } from '../../../../../../../common/types/repository_types'; -import { AppStateInterface, useAppState } from '../../../../../services/app_context'; +import { useAppDependencies } from '../../../../../index'; import { EuiDescriptionList, EuiSpacer, EuiTitle } from '@elastic/eui'; @@ -16,13 +16,12 @@ interface Props { } export const S3Details = ({ repository }: Props) => { - const [ - { - core: { - i18n: { FormattedMessage }, - }, + const { + core: { + i18n: { FormattedMessage }, }, - ] = useAppState() as [AppStateInterface]; + } = useAppDependencies(); + const { settings: { bucket, diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx index 5e67dc22cf48c..20b14b9d103d0 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx @@ -9,7 +9,7 @@ import { RouteComponentProps } from 'react-router-dom'; import { Repository } from '../../../../../common/types/repository_types'; import { BASE_PATH, Section } from '../../../constants'; -import { AppStateInterface, useAppState } from '../../../services/app_context'; +import { useAppDependencies } from '../../../index'; import { useRequest } from '../../../services/use_request'; import { SectionError, SectionLoading } from '../../../components'; @@ -30,13 +30,11 @@ export const RepositoryList = ({ history, }: Props) => { const section = 'repositories' as Section; - const [ - { - core: { - i18n: { FormattedMessage }, - }, + const { + core: { + i18n: { FormattedMessage }, }, - ] = useAppState() as [AppStateInterface]; + } = useAppDependencies(); const { error, loading, data: repositories, request: reload } = useRequest({ path: 'repositories', method: 'get', diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx index ecf65ca73eaa8..3835ef4b2f77d 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx @@ -11,7 +11,7 @@ import { RepositoryTypes, } from '../../../../../../common/types/repository_types'; import { RepositoryDeleteProvider, RepositoryTypeName } from '../../../../components'; -import { AppStateInterface, useAppState } from '../../../../services/app_context'; +import { useAppDependencies } from '../../../../index'; interface Props { repositories: Repository[]; @@ -20,11 +20,9 @@ interface Props { } export const RepositoryTable = ({ repositories, reload, openRepositoryDetails }: Props) => { - const [ - { - core: { i18n }, - }, - ] = useAppState() as [AppStateInterface]; + const { + core: { i18n }, + } = useAppDependencies(); const { FormattedMessage } = i18n; const [selectedItems, setSelectedItems] = useState([]); diff --git a/x-pack/plugins/snapshot_restore/public/app/services/app_context.ts b/x-pack/plugins/snapshot_restore/public/app/services/app_context.ts deleted file mode 100644 index 1be52a8c69050..0000000000000 --- a/x-pack/plugins/snapshot_restore/public/app/services/app_context.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 { createContext, useContext } from 'react'; -import { AppCore, AppPlugins } from '../../shim'; - -export interface AppStateInterface { - core: AppCore; - plugins: AppPlugins; -} - -const AppState = createContext({}); - -export const AppStateProvider = AppState.Provider; - -export const useAppState = () => useContext(AppState); diff --git a/x-pack/plugins/snapshot_restore/public/app/services/app_state.ts b/x-pack/plugins/snapshot_restore/public/app/services/app_state.ts new file mode 100644 index 0000000000000..9ed91d6fed264 --- /dev/null +++ b/x-pack/plugins/snapshot_restore/public/app/services/app_state.ts @@ -0,0 +1,23 @@ +/* + * 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 { createContext, useContext } from 'react'; +import { AppState } from '../types'; + +const StateContext = createContext({}); + +export const initialState = {}; + +export const reducer = (state: any, action: { type: string }) => { + switch (action.type) { + default: + return state; + } +}; + +export const AppStateProvider = StateContext.Provider; + +export const useAppState = () => useContext(StateContext); diff --git a/x-pack/plugins/snapshot_restore/public/app/services/use_request.ts b/x-pack/plugins/snapshot_restore/public/app/services/use_request.ts index fbc05d2b8e267..16021ee9864ab 100644 --- a/x-pack/plugins/snapshot_restore/public/app/services/use_request.ts +++ b/x-pack/plugins/snapshot_restore/public/app/services/use_request.ts @@ -5,7 +5,7 @@ */ import { useEffect, useState } from 'react'; import { API_BASE_PATH } from '../../../common/constants'; -import { AppStateInterface, useAppState } from './app_context'; +import { useAppDependencies } from '../index'; export const useRequest = ({ path, @@ -18,11 +18,9 @@ export const useRequest = ({ body?: any; interval?: number; }) => { - const [ - { - core: { http, chrome }, - }, - ] = useAppState() as [AppStateInterface]; + const { + core: { http, chrome }, + } = useAppDependencies(); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); diff --git a/x-pack/plugins/snapshot_restore/public/app/types/app.ts b/x-pack/plugins/snapshot_restore/public/app/types/app.ts new file mode 100644 index 0000000000000..debfb04a22b48 --- /dev/null +++ b/x-pack/plugins/snapshot_restore/public/app/types/app.ts @@ -0,0 +1,48 @@ +/* + * 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 { FormattedMessage } from '@kbn/i18n/react'; +import chrome from 'ui/chrome'; +import { I18nContext } from 'ui/i18n'; +import { management, MANAGEMENT_BREADCRUMB } from 'ui/management'; +import { fatalError } from 'ui/notify'; + +export interface AppCore { + i18n: { + [i18nPackage: string]: any; + Context: typeof I18nContext; + FormattedMessage: typeof FormattedMessage; + }; + chrome: typeof chrome; + notification: { + fatalError: typeof fatalError; + }; + http: { + getClient(): any; + setClient(client: any): void; + }; + documentation: { + esDocBasePath: string; + esPluginDocBasePath: string; + }; +} + +export interface AppPlugins { + management: { + sections: typeof management; + constants: { + BREADCRUMB: typeof MANAGEMENT_BREADCRUMB; + }; + }; +} + +export interface AppDependencies { + core: AppCore; + plugins: AppPlugins; +} + +export interface AppState { + [key: string]: any; +} diff --git a/x-pack/plugins/snapshot_restore/public/app/types/index.ts b/x-pack/plugins/snapshot_restore/public/app/types/index.ts new file mode 100644 index 0000000000000..1460fdfef37e6 --- /dev/null +++ b/x-pack/plugins/snapshot_restore/public/app/types/index.ts @@ -0,0 +1,7 @@ +/* + * 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. + */ + +export * from './app'; diff --git a/x-pack/plugins/snapshot_restore/public/shim.ts b/x-pack/plugins/snapshot_restore/public/shim.ts index 5389b26939399..92c6f89ba23c5 100644 --- a/x-pack/plugins/snapshot_restore/public/shim.ts +++ b/x-pack/plugins/snapshot_restore/public/shim.ts @@ -15,34 +15,7 @@ import routes from 'ui/routes'; import { HashRouter } from 'react-router-dom'; -export interface AppCore { - i18n: { - [i18nPackage: string]: any; - Context: typeof I18nContext; - FormattedMessage: typeof FormattedMessage; - }; - chrome: typeof chrome; - notification: { - fatalError: typeof fatalError; - }; - http: { - getClient(): any; - setClient(client: any): void; - }; - documentation: { - esDocBasePath: string; - esPluginDocBasePath: string; - }; -} - -export interface AppPlugins { - management: { - sections: typeof management; - constants: { - BREADCRUMB: typeof MANAGEMENT_BREADCRUMB; - }; - }; -} +import { AppCore, AppPlugins } from './app/types'; export interface Core extends AppCore { routing: { From dd39f8939e36a8a368feece3664ae01721c4317a Mon Sep 17 00:00:00 2001 From: sebelga Date: Fri, 22 Mar 2019 07:55:04 +0100 Subject: [PATCH 2/8] Add index.ts barrel file for common types --- x-pack/plugins/snapshot_restore/common/types/index.ts | 7 +++++++ .../common/types/{repository_types.ts => repository.ts} | 0 .../public/app/components/repository_delete_provider.tsx | 2 +- .../public/app/components/repository_type_name.tsx | 2 +- .../repository_details/repository_details.tsx | 2 +- .../repository_details/type_details/azure_details.tsx | 2 +- .../repository_details/type_details/default_details.tsx | 2 +- .../repository_details/type_details/fs_details.tsx | 2 +- .../repository_details/type_details/gcs_details.tsx | 2 +- .../repository_details/type_details/hdfs_details.tsx | 2 +- .../repository_details/type_details/index.tsx | 2 +- .../repository_details/type_details/readonly_details.tsx | 2 +- .../repository_details/type_details/s3_details.tsx | 2 +- .../app/sections/home/repository_list/repository_list.tsx | 2 +- .../repository_list/repository_table/repository_table.tsx | 6 +----- .../public/app/services/documentation_links.ts | 6 +----- 16 files changed, 21 insertions(+), 22 deletions(-) create mode 100644 x-pack/plugins/snapshot_restore/common/types/index.ts rename x-pack/plugins/snapshot_restore/common/types/{repository_types.ts => repository.ts} (100%) diff --git a/x-pack/plugins/snapshot_restore/common/types/index.ts b/x-pack/plugins/snapshot_restore/common/types/index.ts new file mode 100644 index 0000000000000..1553d27e441ea --- /dev/null +++ b/x-pack/plugins/snapshot_restore/common/types/index.ts @@ -0,0 +1,7 @@ +/* + * 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. + */ + +export * from './repository'; diff --git a/x-pack/plugins/snapshot_restore/common/types/repository_types.ts b/x-pack/plugins/snapshot_restore/common/types/repository.ts similarity index 100% rename from x-pack/plugins/snapshot_restore/common/types/repository_types.ts rename to x-pack/plugins/snapshot_restore/common/types/repository.ts diff --git a/x-pack/plugins/snapshot_restore/public/app/components/repository_delete_provider.tsx b/x-pack/plugins/snapshot_restore/public/app/components/repository_delete_provider.tsx index a3f549446be3b..d401892d1c20a 100644 --- a/x-pack/plugins/snapshot_restore/public/app/components/repository_delete_provider.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/components/repository_delete_provider.tsx @@ -5,7 +5,7 @@ */ import React, { Fragment, useState } from 'react'; -import { Repository } from '../../../common/types/repository_types'; +import { Repository } from '../../../common/types'; interface Props { children: (deleteRepository: DeleteRepository) => React.ReactNode; diff --git a/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx b/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx index 8c6217acc4eb0..a96690e7243b0 100644 --- a/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx @@ -5,7 +5,7 @@ */ import React, { Fragment } from 'react'; -import { RepositoryType, RepositoryTypes } from '../../../common/types/repository_types'; +import { RepositoryType, RepositoryTypes } from '../../../common/types'; import { useAppDependencies } from '../index'; interface Props { diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx index 8e80022271ef9..96cd3dc3c40d6 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx @@ -9,7 +9,7 @@ import { useAppDependencies } from '../../../../index'; import { getRepositoryTypeDocUrl } from '../../../../services/documentation_links'; import { useRequest } from '../../../../services/use_request'; -import { Repository, RepositoryTypes } from '../../../../../../common/types/repository_types'; +import { Repository, RepositoryTypes } from '../../../../../../common/types'; import { RepositoryDeleteProvider, RepositoryTypeName, diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/azure_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/azure_details.tsx index 1fd5b4534501f..e012bc0b28ead 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/azure_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/azure_details.tsx @@ -7,7 +7,7 @@ import React, { Fragment } from 'react'; import { EuiDescriptionList, EuiSpacer, EuiTitle } from '@elastic/eui'; -import { AzureRepository } from '../../../../../../../common/types/repository_types'; +import { AzureRepository } from '../../../../../../../common/types'; import { useAppDependencies } from '../../../../../index'; interface Props { diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/default_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/default_details.tsx index 80dad3df26a08..1acaf89c53129 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/default_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/default_details.tsx @@ -11,7 +11,7 @@ declare module '@elastic/eui' { import React, { Fragment } from 'react'; -import { Repository } from '../../../../../../../common/types/repository_types'; +import { Repository } from '../../../../../../../common/types'; import { useAppDependencies } from '../../../../../index'; import 'brace/theme/textmate'; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/fs_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/fs_details.tsx index f53f9ef36ce26..0007b76b0908f 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/fs_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/fs_details.tsx @@ -6,7 +6,7 @@ import React, { Fragment } from 'react'; -import { FSRepository } from '../../../../../../../common/types/repository_types'; +import { FSRepository } from '../../../../../../../common/types'; import { useAppDependencies } from '../../../../../index'; import { EuiDescriptionList, EuiSpacer, EuiTitle } from '@elastic/eui'; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/gcs_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/gcs_details.tsx index 9768c6dac2c37..63f5ab6bc4961 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/gcs_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/gcs_details.tsx @@ -6,7 +6,7 @@ import React, { Fragment } from 'react'; -import { GCSRepository } from '../../../../../../../common/types/repository_types'; +import { GCSRepository } from '../../../../../../../common/types'; import { useAppDependencies } from '../../../../../index'; import { EuiDescriptionList, EuiSpacer, EuiTitle } from '@elastic/eui'; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/hdfs_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/hdfs_details.tsx index 32950e53d53bd..08fee4284b9f9 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/hdfs_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/hdfs_details.tsx @@ -6,7 +6,7 @@ import React, { Fragment } from 'react'; -import { HDFSRepository } from '../../../../../../../common/types/repository_types'; +import { HDFSRepository } from '../../../../../../../common/types'; import { useAppDependencies } from '../../../../../index'; import { EuiDescriptionList, EuiSpacer, EuiTitle } from '@elastic/eui'; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/index.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/index.tsx index 5eaf6dd32f92c..7c776b72e9f8e 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/index.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/index.tsx @@ -13,7 +13,7 @@ import { Repository, RepositoryTypes, S3Repository, -} from '../../../../../../../common/types/repository_types'; +} from '../../../../../../../common/types'; import { AzureDetails } from './azure_details'; import { DefaultDetails } from './default_details'; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/readonly_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/readonly_details.tsx index d60a7c281c84a..1d81a9c9a6dff 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/readonly_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/readonly_details.tsx @@ -6,7 +6,7 @@ import React, { Fragment } from 'react'; -import { ReadonlyRepository } from '../../../../../../../common/types/repository_types'; +import { ReadonlyRepository } from '../../../../../../../common/types'; import { useAppDependencies } from '../../../../../index'; import { EuiDescriptionList, EuiSpacer, EuiTitle } from '@elastic/eui'; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/s3_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/s3_details.tsx index 49caf38f5e67d..4c819575a1a0c 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/s3_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/s3_details.tsx @@ -6,7 +6,7 @@ import React, { Fragment } from 'react'; -import { S3Repository } from '../../../../../../../common/types/repository_types'; +import { S3Repository } from '../../../../../../../common/types'; import { useAppDependencies } from '../../../../../index'; import { EuiDescriptionList, EuiSpacer, EuiTitle } from '@elastic/eui'; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx index 20b14b9d103d0..f51324ba15622 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx @@ -7,7 +7,7 @@ import React, { Fragment, useEffect, useState } from 'react'; import { RouteComponentProps } from 'react-router-dom'; -import { Repository } from '../../../../../common/types/repository_types'; +import { Repository } from '../../../../../common/types'; import { BASE_PATH, Section } from '../../../constants'; import { useAppDependencies } from '../../../index'; import { useRequest } from '../../../services/use_request'; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx index 3835ef4b2f77d..023ef8c8b036d 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx @@ -5,11 +5,7 @@ */ import { EuiButton, EuiButtonIcon, EuiInMemoryTable, EuiLink } from '@elastic/eui'; import React, { useState } from 'react'; -import { - Repository, - RepositoryType, - RepositoryTypes, -} from '../../../../../../common/types/repository_types'; +import { Repository, RepositoryType, RepositoryTypes } from '../../../../../../common/types'; import { RepositoryDeleteProvider, RepositoryTypeName } from '../../../../components'; import { useAppDependencies } from '../../../../index'; diff --git a/x-pack/plugins/snapshot_restore/public/app/services/documentation_links.ts b/x-pack/plugins/snapshot_restore/public/app/services/documentation_links.ts index 17e4c9c331981..ef7b670da99aa 100644 --- a/x-pack/plugins/snapshot_restore/public/app/services/documentation_links.ts +++ b/x-pack/plugins/snapshot_restore/public/app/services/documentation_links.ts @@ -3,11 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { - RepositoryDocPaths, - RepositoryType, - RepositoryTypes, -} from '../../../common/types/repository_types'; +import { RepositoryDocPaths, RepositoryType, RepositoryTypes } from '../../../common/types'; export const getRepositoryTypeDocUrl = ( type: RepositoryType, From e10563431d3e2b7dbdc6b177c8180c8da418f11b Mon Sep 17 00:00:00 2001 From: sebelga Date: Fri, 22 Mar 2019 08:02:19 +0100 Subject: [PATCH 3/8] Move Enums to constants.ts file --- .../snapshot_restore/common/constants.ts | 21 ++++++++++++ .../common/types/repository.ts | 21 ------------ .../app/components/repository_type_name.tsx | 19 ++++++----- .../repository_details/repository_details.tsx | 5 +-- .../repository_details/type_details/index.tsx | 17 +++++----- .../repository_table/repository_table.tsx | 6 ++-- .../app/services/documentation_links.ts | 33 ++++++++++--------- 7 files changed, 64 insertions(+), 58 deletions(-) diff --git a/x-pack/plugins/snapshot_restore/common/constants.ts b/x-pack/plugins/snapshot_restore/common/constants.ts index a13c57da16932..459a8b7d534f2 100644 --- a/x-pack/plugins/snapshot_restore/common/constants.ts +++ b/x-pack/plugins/snapshot_restore/common/constants.ts @@ -19,3 +19,24 @@ export const PLUGIN = { }; export const API_BASE_PATH = '/api/snapshot_restore/'; + +export enum REPOSITORY_TYPES { + fs = 'fs', + url = 'url', + source = 'source', + s3 = 's3', + hdfs = 'hdfs', + azure = 'azure', + gcs = 'gcs', +} + +export enum REPOSITORY_DOC_PATHS { + default = 'modules-snapshots.html', + fs = 'modules-snapshots.html#_shared_file_system_repository', + url = 'modules-snapshots.html#_read_only_url_repository', + source = 'modules-snapshots.html#_source_only_repository', + s3 = 'repository-s3.html', + hdfs = 'repository-hdfs.html', + azure = 'repository-azure.html', + gcs = 'repository-gcs.html', +} diff --git a/x-pack/plugins/snapshot_restore/common/types/repository.ts b/x-pack/plugins/snapshot_restore/common/types/repository.ts index 2eefe2fd67c85..15095b378eb3d 100644 --- a/x-pack/plugins/snapshot_restore/common/types/repository.ts +++ b/x-pack/plugins/snapshot_restore/common/types/repository.ts @@ -12,16 +12,6 @@ export type HDFSRepositoryType = 'hdfs'; export type AzureRepositoryType = 'azure'; export type GCSRepositoryType = 'gcs'; -export enum RepositoryTypes { - fs = 'fs', - url = 'url', - source = 'source', - s3 = 's3', - hdfs = 'hdfs', - azure = 'azure', - gcs = 'gcs', -} - export type RepositoryType = | FSRepositoryType | ReadonlyRepositoryType @@ -31,17 +21,6 @@ export type RepositoryType = | AzureRepositoryType | GCSRepositoryType; -export enum RepositoryDocPaths { - default = 'modules-snapshots.html', - fs = 'modules-snapshots.html#_shared_file_system_repository', - url = 'modules-snapshots.html#_read_only_url_repository', - source = 'modules-snapshots.html#_source_only_repository', - s3 = 'repository-s3.html', - hdfs = 'repository-hdfs.html', - azure = 'repository-azure.html', - gcs = 'repository-gcs.html', -} - export interface FSRepository { name: string; type: FSRepositoryType; diff --git a/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx b/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx index a96690e7243b0..a5e11907c0427 100644 --- a/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx @@ -5,7 +5,8 @@ */ import React, { Fragment } from 'react'; -import { RepositoryType, RepositoryTypes } from '../../../common/types'; +import { REPOSITORY_TYPES } from '../../../common/constants'; +import { RepositoryType } from '../../../common/types'; import { useAppDependencies } from '../index'; interface Props { @@ -21,43 +22,43 @@ export const RepositoryTypeName = ({ type, delegateType }: Props) => { } = useAppDependencies(); const typeNameMap: { [key in RepositoryType]: JSX.Element } = { - [RepositoryTypes.fs]: ( + [REPOSITORY_TYPES.fs]: ( ), - [RepositoryTypes.url]: ( + [REPOSITORY_TYPES.url]: ( ), - [RepositoryTypes.s3]: ( + [REPOSITORY_TYPES.s3]: ( ), - [RepositoryTypes.hdfs]: ( + [REPOSITORY_TYPES.hdfs]: ( ), - [RepositoryTypes.azure]: ( + [REPOSITORY_TYPES.azure]: ( ), - [RepositoryTypes.gcs]: ( + [REPOSITORY_TYPES.gcs]: ( ), - [RepositoryTypes.source]: ( + [REPOSITORY_TYPES.source]: ( { return typeNameMap[repositoryType] || {type}; }; - if (type === RepositoryTypes.source && delegateType) { + if (type === REPOSITORY_TYPES.source && delegateType) { return ( { - {type === RepositoryTypes.source ? ( + {type === REPOSITORY_TYPES.source ? ( ) : ( diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/index.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/index.tsx index 7c776b72e9f8e..a7dbe290f455e 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/index.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/index.tsx @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ import React from 'react'; + +import { REPOSITORY_TYPES } from '../../../../../../../common/constants'; import { AzureRepository, FSRepository, @@ -11,7 +13,6 @@ import { HDFSRepository, ReadonlyRepository, Repository, - RepositoryTypes, S3Repository, } from '../../../../../../../common/types'; @@ -30,13 +31,13 @@ interface Props { export const TypeDetails = ({ repository }: Props) => { const { type, settings } = repository; switch (type) { - case RepositoryTypes.fs: + case REPOSITORY_TYPES.fs: return ; break; - case RepositoryTypes.url: + case REPOSITORY_TYPES.url: return ; break; - case RepositoryTypes.source: + case REPOSITORY_TYPES.source: const { delegate_type } = settings; const delegatedRepository = { ...repository, @@ -44,16 +45,16 @@ export const TypeDetails = ({ repository }: Props) => { }; return ; break; - case RepositoryTypes.azure: + case REPOSITORY_TYPES.azure: return ; break; - case RepositoryTypes.gcs: + case REPOSITORY_TYPES.gcs: return ; break; - case RepositoryTypes.hdfs: + case REPOSITORY_TYPES.hdfs: return ; break; - case RepositoryTypes.s3: + case REPOSITORY_TYPES.s3: return ; break; default: diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx index 023ef8c8b036d..0615b89ccc1e8 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx @@ -5,7 +5,9 @@ */ import { EuiButton, EuiButtonIcon, EuiInMemoryTable, EuiLink } from '@elastic/eui'; import React, { useState } from 'react'; -import { Repository, RepositoryType, RepositoryTypes } from '../../../../../../common/types'; + +import { REPOSITORY_TYPES } from '../../../../../../common/constants'; +import { Repository, RepositoryType } from '../../../../../../common/types'; import { RepositoryDeleteProvider, RepositoryTypeName } from '../../../../components'; import { useAppDependencies } from '../../../../index'; @@ -42,7 +44,7 @@ export const RepositoryTable = ({ repositories, reload, openRepositoryDetails }: truncateText: true, sortable: true, render: (type: RepositoryType, repository: Repository) => { - if (type === RepositoryTypes.source) { + if (type === REPOSITORY_TYPES.source) { return ( ); diff --git a/x-pack/plugins/snapshot_restore/public/app/services/documentation_links.ts b/x-pack/plugins/snapshot_restore/public/app/services/documentation_links.ts index ef7b670da99aa..f59de63fdc1df 100644 --- a/x-pack/plugins/snapshot_restore/public/app/services/documentation_links.ts +++ b/x-pack/plugins/snapshot_restore/public/app/services/documentation_links.ts @@ -3,7 +3,8 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { RepositoryDocPaths, RepositoryType, RepositoryTypes } from '../../../common/types'; +import { REPOSITORY_DOC_PATHS, REPOSITORY_TYPES } from '../../../common/constants'; +import { RepositoryType } from '../../../common/types'; export const getRepositoryTypeDocUrl = ( type: RepositoryType, @@ -11,21 +12,21 @@ export const getRepositoryTypeDocUrl = ( esPluginDocBasePath: string ): string => { switch (type) { - case RepositoryTypes.fs: - return `${esDocBasePath}${RepositoryDocPaths.fs}`; - case RepositoryTypes.url: - return `${esDocBasePath}${RepositoryDocPaths.url}`; - case RepositoryTypes.source: - return `${esDocBasePath}${RepositoryDocPaths.source}`; - case RepositoryTypes.s3: - return `${esPluginDocBasePath}${RepositoryDocPaths.s3}`; - case RepositoryTypes.hdfs: - return `${esPluginDocBasePath}${RepositoryDocPaths.hdfs}`; - case RepositoryTypes.azure: - return `${esPluginDocBasePath}${RepositoryDocPaths.azure}`; - case RepositoryTypes.gcs: - return `${esPluginDocBasePath}${RepositoryDocPaths.gcs}`; + case REPOSITORY_TYPES.fs: + return `${esDocBasePath}${REPOSITORY_DOC_PATHS.fs}`; + case REPOSITORY_TYPES.url: + return `${esDocBasePath}${REPOSITORY_DOC_PATHS.url}`; + case REPOSITORY_TYPES.source: + return `${esDocBasePath}${REPOSITORY_DOC_PATHS.source}`; + case REPOSITORY_TYPES.s3: + return `${esPluginDocBasePath}${REPOSITORY_DOC_PATHS.s3}`; + case REPOSITORY_TYPES.hdfs: + return `${esPluginDocBasePath}${REPOSITORY_DOC_PATHS.hdfs}`; + case REPOSITORY_TYPES.azure: + return `${esPluginDocBasePath}${REPOSITORY_DOC_PATHS.azure}`; + case REPOSITORY_TYPES.gcs: + return `${esPluginDocBasePath}${REPOSITORY_DOC_PATHS.gcs}`; default: - return `${esDocBasePath}${RepositoryDocPaths.default}`; + return `${esDocBasePath}${REPOSITORY_DOC_PATHS.default}`; } }; From b35bdd313abba76c1585224e2ce01bfb255d7fcd Mon Sep 17 00:00:00 2001 From: sebelga Date: Fri, 22 Mar 2019 08:17:21 +0100 Subject: [PATCH 4/8] Refactor function component using `React.FunctionComponent` --- .../public/app/components/repository_delete_provider.tsx | 8 ++++---- .../public/app/components/repository_type_name.tsx | 2 +- .../public/app/components/section_error.tsx | 4 ++-- .../public/app/components/section_loading.tsx | 4 ++-- .../snapshot_restore/public/app/sections/home/home.tsx | 4 ++-- .../repository_details/repository_details.tsx | 2 +- .../repository_details/type_details/azure_details.tsx | 2 +- .../repository_details/type_details/default_details.tsx | 4 +++- .../repository_details/type_details/fs_details.tsx | 2 +- .../repository_details/type_details/gcs_details.tsx | 2 +- .../repository_details/type_details/hdfs_details.tsx | 2 +- .../repository_details/type_details/index.tsx | 2 +- .../repository_details/type_details/readonly_details.tsx | 2 +- .../repository_details/type_details/s3_details.tsx | 2 +- .../app/sections/home/repository_list/repository_list.tsx | 4 ++-- .../repository_list/repository_table/repository_table.tsx | 6 +++++- .../app/sections/home/snapshot_list/snapshot_list.tsx | 2 +- 17 files changed, 30 insertions(+), 24 deletions(-) diff --git a/x-pack/plugins/snapshot_restore/public/app/components/repository_delete_provider.tsx b/x-pack/plugins/snapshot_restore/public/app/components/repository_delete_provider.tsx index d401892d1c20a..6ef5bf4f57b81 100644 --- a/x-pack/plugins/snapshot_restore/public/app/components/repository_delete_provider.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/components/repository_delete_provider.tsx @@ -4,16 +4,16 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { Fragment, useState } from 'react'; +import React, { useState } from 'react'; import { Repository } from '../../../common/types'; interface Props { - children: (deleteRepository: DeleteRepository) => React.ReactNode; + children: (deleteRepository: DeleteRepository) => React.ReactElement; } type DeleteRepository = (names: Array) => void; -export const RepositoryDeleteProvider = ({ children }: Props) => { +export const RepositoryDeleteProvider: React.FunctionComponent = ({ children }) => { const [repositoryNames, setRepositoryNames] = useState>([]); const [isModalOpen, setIsModalOpen] = useState(false); const deleteRepository: DeleteRepository = names => { @@ -25,5 +25,5 @@ export const RepositoryDeleteProvider = ({ children }: Props) => { /* placeholder */ } - return {children(deleteRepository)}; + return children(deleteRepository); }; diff --git a/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx b/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx index a5e11907c0427..355da4ac9a25e 100644 --- a/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/components/repository_type_name.tsx @@ -14,7 +14,7 @@ interface Props { delegateType?: RepositoryType; } -export const RepositoryTypeName = ({ type, delegateType }: Props) => { +export const RepositoryTypeName: React.FunctionComponent = ({ type, delegateType }) => { const { core: { i18n: { FormattedMessage }, diff --git a/x-pack/plugins/snapshot_restore/public/app/components/section_error.tsx b/x-pack/plugins/snapshot_restore/public/app/components/section_error.tsx index 89d4215dafbcd..d04e2cf3911b2 100644 --- a/x-pack/plugins/snapshot_restore/public/app/components/section_error.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/components/section_error.tsx @@ -18,7 +18,7 @@ interface Props { }; } -export function SectionError({ title, error }: Props) { +export const SectionError: React.FunctionComponent = ({ title, error }) => { const { error: errorString, cause, // wrapEsError() on the server adds a "cause" array @@ -40,4 +40,4 @@ export function SectionError({ title, error }: Props) { )} ); -} +}; diff --git a/x-pack/plugins/snapshot_restore/public/app/components/section_loading.tsx b/x-pack/plugins/snapshot_restore/public/app/components/section_loading.tsx index d07a8c6836fad..7732a045e81e2 100644 --- a/x-pack/plugins/snapshot_restore/public/app/components/section_loading.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/components/section_loading.tsx @@ -12,7 +12,7 @@ interface Props { children: React.ReactNode; } -export function SectionLoading({ children }: Props) { +export const SectionLoading: React.FunctionComponent = ({ children }) => { return ( @@ -26,4 +26,4 @@ export function SectionLoading({ children }: Props) { ); -} +}; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/home.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/home.tsx index 11483173cd93d..5448f9303037e 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/home.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/home.tsx @@ -21,12 +21,12 @@ interface MatchParams { interface Props extends RouteComponentProps {} -export const SnapshotRestoreHome = ({ +export const SnapshotRestoreHome: React.FunctionComponent = ({ match: { params: { section }, }, history, -}: Props) => { +}) => { const [activeSection, setActiveSection] = useState
(section); const { diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx index 8cb5e60c65736..dce4105cceff9 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx @@ -37,7 +37,7 @@ interface Props { onClose: () => void; } -export const RepositoryDetails = ({ repositoryName, onClose }: Props) => { +export const RepositoryDetails: React.FunctionComponent = ({ repositoryName, onClose }) => { const { core: { i18n, diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/azure_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/azure_details.tsx index e012bc0b28ead..fa9f997fac4b0 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/azure_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/azure_details.tsx @@ -14,7 +14,7 @@ interface Props { repository: AzureRepository; } -export const AzureDetails = ({ repository }: Props) => { +export const AzureDetails: React.FunctionComponent = ({ repository }) => { const { core: { i18n: { FormattedMessage }, diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/default_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/default_details.tsx index 1acaf89c53129..43006618ccd6e 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/default_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/default_details.tsx @@ -22,7 +22,9 @@ interface Props { repository: Repository; } -export const DefaultDetails = ({ repository: { name, settings } }: Props) => { +export const DefaultDetails: React.FunctionComponent = ({ + repository: { name, settings }, +}) => { const { core: { i18n: { FormattedMessage }, diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/fs_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/fs_details.tsx index 0007b76b0908f..a8d29087b04d7 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/fs_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/fs_details.tsx @@ -15,7 +15,7 @@ interface Props { repository: FSRepository; } -export const FSDetails = ({ repository }: Props) => { +export const FSDetails: React.FunctionComponent = ({ repository }) => { const { core: { i18n: { FormattedMessage }, diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/gcs_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/gcs_details.tsx index 63f5ab6bc4961..42331dfc1d551 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/gcs_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/gcs_details.tsx @@ -15,7 +15,7 @@ interface Props { repository: GCSRepository; } -export const GCSDetails = ({ repository }: Props) => { +export const GCSDetails: React.FunctionComponent = ({ repository }) => { const { core: { i18n: { FormattedMessage }, diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/hdfs_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/hdfs_details.tsx index 08fee4284b9f9..1adb673401b27 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/hdfs_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/hdfs_details.tsx @@ -15,7 +15,7 @@ interface Props { repository: HDFSRepository; } -export const HDFSDetails = ({ repository }: Props) => { +export const HDFSDetails: React.FunctionComponent = ({ repository }) => { const { core: { i18n: { FormattedMessage }, diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/index.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/index.tsx index a7dbe290f455e..78aac947b3cdb 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/index.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/index.tsx @@ -28,7 +28,7 @@ interface Props { repository: Repository; } -export const TypeDetails = ({ repository }: Props) => { +export const TypeDetails: React.FunctionComponent = ({ repository }) => { const { type, settings } = repository; switch (type) { case REPOSITORY_TYPES.fs: diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/readonly_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/readonly_details.tsx index 1d81a9c9a6dff..746e2f726c9dc 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/readonly_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/readonly_details.tsx @@ -15,7 +15,7 @@ interface Props { repository: ReadonlyRepository; } -export const ReadonlyDetails = ({ repository }: Props) => { +export const ReadonlyDetails: React.FunctionComponent = ({ repository }) => { const { core: { i18n: { FormattedMessage }, diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/s3_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/s3_details.tsx index 4c819575a1a0c..88f9ab56421d0 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/s3_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/type_details/s3_details.tsx @@ -15,7 +15,7 @@ interface Props { repository: S3Repository; } -export const S3Details = ({ repository }: Props) => { +export const S3Details: React.FunctionComponent = ({ repository }) => { const { core: { i18n: { FormattedMessage }, diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx index f51324ba15622..a6efceaf83a17 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx @@ -23,12 +23,12 @@ interface MatchParams { } interface Props extends RouteComponentProps {} -export const RepositoryList = ({ +export const RepositoryList: React.FunctionComponent = ({ match: { params: { name }, }, history, -}: Props) => { +}) => { const section = 'repositories' as Section; const { core: { diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx index 0615b89ccc1e8..620028ee081d9 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_table/repository_table.tsx @@ -17,7 +17,11 @@ interface Props { openRepositoryDetails: (name: Repository['name']) => void; } -export const RepositoryTable = ({ repositories, reload, openRepositoryDetails }: Props) => { +export const RepositoryTable: React.FunctionComponent = ({ + repositories, + reload, + openRepositoryDetails, +}) => { const { core: { i18n }, } = useAppDependencies(); diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_list.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_list.tsx index b485207e8edc3..a45ef4fbb27f6 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_list.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/snapshot_list/snapshot_list.tsx @@ -6,6 +6,6 @@ import React from 'react'; -export const SnapshotList = () => { +export const SnapshotList: React.FunctionComponent = () => { return
List of snapshots
; }; From 2ed8bf72b26786defe5236877f16f01e17228688 Mon Sep 17 00:00:00 2001 From: sebelga Date: Fri, 22 Mar 2019 08:24:25 +0100 Subject: [PATCH 5/8] Refactor service folder structure --- x-pack/plugins/snapshot_restore/public/app/index.tsx | 2 +- .../repository_details/repository_details.tsx | 4 ++-- .../app/sections/home/repository_list/repository_list.tsx | 2 +- .../services/{ => documentation}/documentation_links.ts | 4 ++-- .../public/app/services/documentation/index.ts | 7 +++++++ .../snapshot_restore/public/app/services/http/index.ts | 7 +++++++ .../public/app/services/{ => http}/use_request.ts | 4 ++-- .../public/app/services/{ => state}/app_state.ts | 2 +- .../snapshot_restore/public/app/services/state/index.ts | 7 +++++++ 9 files changed, 30 insertions(+), 9 deletions(-) rename x-pack/plugins/snapshot_restore/public/app/services/{ => documentation}/documentation_links.ts (93%) create mode 100644 x-pack/plugins/snapshot_restore/public/app/services/documentation/index.ts create mode 100644 x-pack/plugins/snapshot_restore/public/app/services/http/index.ts rename x-pack/plugins/snapshot_restore/public/app/services/{ => http}/use_request.ts (92%) rename x-pack/plugins/snapshot_restore/public/app/services/{ => state}/app_state.ts (94%) create mode 100644 x-pack/plugins/snapshot_restore/public/app/services/state/index.ts diff --git a/x-pack/plugins/snapshot_restore/public/app/index.tsx b/x-pack/plugins/snapshot_restore/public/app/index.tsx index 102c20abf66a7..b94a1ca27e2b9 100644 --- a/x-pack/plugins/snapshot_restore/public/app/index.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/index.tsx @@ -8,7 +8,7 @@ import { render } from 'react-dom'; import { HashRouter } from 'react-router-dom'; import { App } from './app'; -import { AppStateProvider, initialState, reducer } from './services/app_state'; +import { AppStateProvider, initialState, reducer } from './services/state'; import { AppCore, AppDependencies, AppPlugins } from './types'; export { BASE_PATH as CLIENT_BASE_PATH } from './constants'; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx index dce4105cceff9..4230bb073a619 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_details/repository_details.tsx @@ -6,8 +6,8 @@ import React, { Fragment } from 'react'; import { useAppDependencies } from '../../../../index'; -import { getRepositoryTypeDocUrl } from '../../../../services/documentation_links'; -import { useRequest } from '../../../../services/use_request'; +import { getRepositoryTypeDocUrl } from '../../../../services/documentation'; +import { useRequest } from '../../../../services/http'; import { REPOSITORY_TYPES } from '../../../../../../common/constants'; import { Repository } from '../../../../../../common/types'; diff --git a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx index a6efceaf83a17..934adf50835cc 100644 --- a/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx +++ b/x-pack/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx @@ -10,7 +10,7 @@ import { RouteComponentProps } from 'react-router-dom'; import { Repository } from '../../../../../common/types'; import { BASE_PATH, Section } from '../../../constants'; import { useAppDependencies } from '../../../index'; -import { useRequest } from '../../../services/use_request'; +import { useRequest } from '../../../services/http'; import { SectionError, SectionLoading } from '../../../components'; import { RepositoryDetails } from './repository_details'; diff --git a/x-pack/plugins/snapshot_restore/public/app/services/documentation_links.ts b/x-pack/plugins/snapshot_restore/public/app/services/documentation/documentation_links.ts similarity index 93% rename from x-pack/plugins/snapshot_restore/public/app/services/documentation_links.ts rename to x-pack/plugins/snapshot_restore/public/app/services/documentation/documentation_links.ts index f59de63fdc1df..93a3ed2fd0cd2 100644 --- a/x-pack/plugins/snapshot_restore/public/app/services/documentation_links.ts +++ b/x-pack/plugins/snapshot_restore/public/app/services/documentation/documentation_links.ts @@ -3,8 +3,8 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { REPOSITORY_DOC_PATHS, REPOSITORY_TYPES } from '../../../common/constants'; -import { RepositoryType } from '../../../common/types'; +import { REPOSITORY_DOC_PATHS, REPOSITORY_TYPES } from '../../../../common/constants'; +import { RepositoryType } from '../../../../common/types'; export const getRepositoryTypeDocUrl = ( type: RepositoryType, diff --git a/x-pack/plugins/snapshot_restore/public/app/services/documentation/index.ts b/x-pack/plugins/snapshot_restore/public/app/services/documentation/index.ts new file mode 100644 index 0000000000000..9d72acfe2d14e --- /dev/null +++ b/x-pack/plugins/snapshot_restore/public/app/services/documentation/index.ts @@ -0,0 +1,7 @@ +/* + * 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. + */ + +export { getRepositoryTypeDocUrl } from './documentation_links'; diff --git a/x-pack/plugins/snapshot_restore/public/app/services/http/index.ts b/x-pack/plugins/snapshot_restore/public/app/services/http/index.ts new file mode 100644 index 0000000000000..56a211119ed5c --- /dev/null +++ b/x-pack/plugins/snapshot_restore/public/app/services/http/index.ts @@ -0,0 +1,7 @@ +/* + * 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. + */ + +export { useRequest } from './use_request'; diff --git a/x-pack/plugins/snapshot_restore/public/app/services/use_request.ts b/x-pack/plugins/snapshot_restore/public/app/services/http/use_request.ts similarity index 92% rename from x-pack/plugins/snapshot_restore/public/app/services/use_request.ts rename to x-pack/plugins/snapshot_restore/public/app/services/http/use_request.ts index 16021ee9864ab..7c14b7d011ee1 100644 --- a/x-pack/plugins/snapshot_restore/public/app/services/use_request.ts +++ b/x-pack/plugins/snapshot_restore/public/app/services/http/use_request.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ import { useEffect, useState } from 'react'; -import { API_BASE_PATH } from '../../../common/constants'; -import { useAppDependencies } from '../index'; +import { API_BASE_PATH } from '../../../../common/constants'; +import { useAppDependencies } from '../../index'; export const useRequest = ({ path, diff --git a/x-pack/plugins/snapshot_restore/public/app/services/app_state.ts b/x-pack/plugins/snapshot_restore/public/app/services/state/app_state.ts similarity index 94% rename from x-pack/plugins/snapshot_restore/public/app/services/app_state.ts rename to x-pack/plugins/snapshot_restore/public/app/services/state/app_state.ts index 9ed91d6fed264..e50e01add7867 100644 --- a/x-pack/plugins/snapshot_restore/public/app/services/app_state.ts +++ b/x-pack/plugins/snapshot_restore/public/app/services/state/app_state.ts @@ -5,7 +5,7 @@ */ import { createContext, useContext } from 'react'; -import { AppState } from '../types'; +import { AppState } from '../../types'; const StateContext = createContext({}); diff --git a/x-pack/plugins/snapshot_restore/public/app/services/state/index.ts b/x-pack/plugins/snapshot_restore/public/app/services/state/index.ts new file mode 100644 index 0000000000000..e0c4ee23cb18a --- /dev/null +++ b/x-pack/plugins/snapshot_restore/public/app/services/state/index.ts @@ -0,0 +1,7 @@ +/* + * 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. + */ + +export { initialState, reducer, AppStateProvider, useAppState } from './app_state'; From 824647172da000bc4962c514a2a314fe605d714a Mon Sep 17 00:00:00 2001 From: sebelga Date: Fri, 22 Mar 2019 13:48:58 +0100 Subject: [PATCH 6/8] Fix type import --- x-pack/plugins/snapshot_restore/public/plugin.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/snapshot_restore/public/plugin.ts b/x-pack/plugins/snapshot_restore/public/plugin.ts index cc0f006603a9c..4f7d2c3ae7828 100644 --- a/x-pack/plugins/snapshot_restore/public/plugin.ts +++ b/x-pack/plugins/snapshot_restore/public/plugin.ts @@ -7,7 +7,8 @@ import { unmountComponentAtNode } from 'react-dom'; import { PLUGIN } from '../common/constants'; import { CLIENT_BASE_PATH, renderReact } from './app'; -import { AppCore, AppPlugins, Core, Plugins } from './shim'; +import { AppCore, AppPlugins } from './app/types'; +import { Core, Plugins } from './shim'; import template from './index.html'; From 64f3363d833bdfbf30376f6c034c42040dda111e Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Fri, 22 Mar 2019 15:49:00 -0700 Subject: [PATCH 7/8] Move REPOSITORY_DOC_PATHS from common to public constants --- x-pack/plugins/snapshot_restore/common/constants.ts | 11 ----------- .../snapshot_restore/public/app/constants/index.ts | 11 +++++++++++ .../app/services/documentation/documentation_links.ts | 3 ++- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/snapshot_restore/common/constants.ts b/x-pack/plugins/snapshot_restore/common/constants.ts index 459a8b7d534f2..57540c9b87545 100644 --- a/x-pack/plugins/snapshot_restore/common/constants.ts +++ b/x-pack/plugins/snapshot_restore/common/constants.ts @@ -29,14 +29,3 @@ export enum REPOSITORY_TYPES { azure = 'azure', gcs = 'gcs', } - -export enum REPOSITORY_DOC_PATHS { - default = 'modules-snapshots.html', - fs = 'modules-snapshots.html#_shared_file_system_repository', - url = 'modules-snapshots.html#_read_only_url_repository', - source = 'modules-snapshots.html#_source_only_repository', - s3 = 'repository-s3.html', - hdfs = 'repository-hdfs.html', - azure = 'repository-azure.html', - gcs = 'repository-gcs.html', -} diff --git a/x-pack/plugins/snapshot_restore/public/app/constants/index.ts b/x-pack/plugins/snapshot_restore/public/app/constants/index.ts index c993c76b4b639..ba885dd3da7df 100644 --- a/x-pack/plugins/snapshot_restore/public/app/constants/index.ts +++ b/x-pack/plugins/snapshot_restore/public/app/constants/index.ts @@ -6,3 +6,14 @@ export const BASE_PATH = '/management/elasticsearch/snapshot_restore'; export type Section = 'repositories' | 'snapshots'; + +export enum REPOSITORY_DOC_PATHS { + default = 'modules-snapshots.html', + fs = 'modules-snapshots.html#_shared_file_system_repository', + url = 'modules-snapshots.html#_read_only_url_repository', + source = 'modules-snapshots.html#_source_only_repository', + s3 = 'repository-s3.html', + hdfs = 'repository-hdfs.html', + azure = 'repository-azure.html', + gcs = 'repository-gcs.html', +} diff --git a/x-pack/plugins/snapshot_restore/public/app/services/documentation/documentation_links.ts b/x-pack/plugins/snapshot_restore/public/app/services/documentation/documentation_links.ts index 93a3ed2fd0cd2..cca151aa6b583 100644 --- a/x-pack/plugins/snapshot_restore/public/app/services/documentation/documentation_links.ts +++ b/x-pack/plugins/snapshot_restore/public/app/services/documentation/documentation_links.ts @@ -3,8 +3,9 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { REPOSITORY_DOC_PATHS, REPOSITORY_TYPES } from '../../../../common/constants'; +import { REPOSITORY_TYPES } from '../../../../common/constants'; import { RepositoryType } from '../../../../common/types'; +import { REPOSITORY_DOC_PATHS } from '../../constants'; export const getRepositoryTypeDocUrl = ( type: RepositoryType, From e54ed20ceb36ebbf7208c65c4a0999e79808e446 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Fri, 22 Mar 2019 15:52:29 -0700 Subject: [PATCH 8/8] Move AppCore and AppPlugins interfaces back to shim and re-export them from app types --- .../snapshot_restore/public/app/types/app.ts | 36 ++----------------- .../plugins/snapshot_restore/public/shim.ts | 29 ++++++++++++++- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/x-pack/plugins/snapshot_restore/public/app/types/app.ts b/x-pack/plugins/snapshot_restore/public/app/types/app.ts index debfb04a22b48..28d83e3e4bb24 100644 --- a/x-pack/plugins/snapshot_restore/public/app/types/app.ts +++ b/x-pack/plugins/snapshot_restore/public/app/types/app.ts @@ -3,40 +3,8 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { FormattedMessage } from '@kbn/i18n/react'; -import chrome from 'ui/chrome'; -import { I18nContext } from 'ui/i18n'; -import { management, MANAGEMENT_BREADCRUMB } from 'ui/management'; -import { fatalError } from 'ui/notify'; - -export interface AppCore { - i18n: { - [i18nPackage: string]: any; - Context: typeof I18nContext; - FormattedMessage: typeof FormattedMessage; - }; - chrome: typeof chrome; - notification: { - fatalError: typeof fatalError; - }; - http: { - getClient(): any; - setClient(client: any): void; - }; - documentation: { - esDocBasePath: string; - esPluginDocBasePath: string; - }; -} - -export interface AppPlugins { - management: { - sections: typeof management; - constants: { - BREADCRUMB: typeof MANAGEMENT_BREADCRUMB; - }; - }; -} +import { AppCore, AppPlugins } from '../../shim'; +export { AppCore, AppPlugins } from '../../shim'; export interface AppDependencies { core: AppCore; diff --git a/x-pack/plugins/snapshot_restore/public/shim.ts b/x-pack/plugins/snapshot_restore/public/shim.ts index 92c6f89ba23c5..5389b26939399 100644 --- a/x-pack/plugins/snapshot_restore/public/shim.ts +++ b/x-pack/plugins/snapshot_restore/public/shim.ts @@ -15,7 +15,34 @@ import routes from 'ui/routes'; import { HashRouter } from 'react-router-dom'; -import { AppCore, AppPlugins } from './app/types'; +export interface AppCore { + i18n: { + [i18nPackage: string]: any; + Context: typeof I18nContext; + FormattedMessage: typeof FormattedMessage; + }; + chrome: typeof chrome; + notification: { + fatalError: typeof fatalError; + }; + http: { + getClient(): any; + setClient(client: any): void; + }; + documentation: { + esDocBasePath: string; + esPluginDocBasePath: string; + }; +} + +export interface AppPlugins { + management: { + sections: typeof management; + constants: { + BREADCRUMB: typeof MANAGEMENT_BREADCRUMB; + }; + }; +} export interface Core extends AppCore { routing: {