[SR] support setting for disabling slm ui (#46050) (#46144)

This commit is contained in:
Alison Goryachev 2019-09-19 12:48:47 -04:00 committed by GitHub
parent fb1d1fab75
commit 290ebda828
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 65 additions and 15 deletions

View file

@ -19,6 +19,21 @@ export function snapshotRestore(kibana: any) {
uiExports: {
styleSheetPaths: resolve(__dirname, 'public/app/index.scss'),
managementSections: ['plugins/snapshot_restore'],
injectDefaultVars(server: Legacy.Server) {
const config = server.config();
return {
slmUiEnabled: config.get('xpack.snapshot_restore.slm_ui.enabled'),
};
},
},
config(Joi: any) {
return Joi.object({
slm_ui: Joi.object({
enabled: Joi.boolean().default(true),
}).default(),
enabled: Joi.boolean().default(true),
}).default();
},
init(server: Legacy.Server) {
const { core, plugins } = createShim(server, PLUGIN.ID);

View file

@ -26,11 +26,19 @@ export const App: React.FunctionComponent = () => {
const {
core: {
i18n: { FormattedMessage },
chrome,
},
} = useAppDependencies();
const { apiError } = useContext(AuthorizationContext);
const sections: Section[] = ['repositories', 'snapshots', 'restore_status', 'policies'];
const slmUiEnabled = chrome.getInjected('slmUiEnabled');
const sections: Section[] = ['repositories', 'snapshots', 'restore_status'];
if (slmUiEnabled) {
sections.push('policies' as Section);
}
const sectionsRegex = sections.join('|');
return apiError ? (
@ -77,8 +85,12 @@ export const App: React.FunctionComponent = () => {
path={`${BASE_PATH}/restore/:repositoryName/:snapshotId*`}
component={RestoreSnapshot}
/>
<Route exact path={`${BASE_PATH}/add_policy`} component={PolicyAdd} />
<Route exact path={`${BASE_PATH}/edit_policy/:name*`} component={PolicyEdit} />
{slmUiEnabled && (
<Route exact path={`${BASE_PATH}/add_policy`} component={PolicyAdd} />
)}
{slmUiEnabled && (
<Route exact path={`${BASE_PATH}/edit_policy/:name*`} component={PolicyEdit} />
)}
<Redirect from={`${BASE_PATH}`} to={`${BASE_PATH}/${DEFAULT_SECTION}`} />
</Switch>
</div>

View file

@ -43,9 +43,12 @@ export const SnapshotRestoreHome: React.FunctionComponent<RouteComponentProps<Ma
const {
core: {
i18n: { FormattedMessage },
chrome,
},
} = useAppDependencies();
const slmUiEnabled = chrome.getInjected('slmUiEnabled');
const tabs: Array<{
id: Section;
name: React.ReactNode;
@ -68,15 +71,6 @@ export const SnapshotRestoreHome: React.FunctionComponent<RouteComponentProps<Ma
/>
),
},
{
id: 'policies',
name: (
<FormattedMessage
id="xpack.snapshotRestore.home.policiesTabTitle"
defaultMessage="Policies"
/>
),
},
{
id: 'restore_status',
name: (
@ -88,6 +82,18 @@ export const SnapshotRestoreHome: React.FunctionComponent<RouteComponentProps<Ma
},
];
if (slmUiEnabled) {
tabs.splice(2, 0, {
id: 'policies',
name: (
<FormattedMessage
id="xpack.snapshotRestore.home.policiesTabTitle"
defaultMessage="Policies"
/>
),
});
}
const onSectionChange = (newSection: Section) => {
history.push(`${BASE_PATH}/${newSection}`);
};

View file

@ -90,7 +90,7 @@ export class Plugin {
if (elem) {
renderReact(
elem,
{ i18n, notification } as AppCore,
{ i18n, notification, chrome } as AppCore,
{ management: { sections: management.sections } } as AppPlugins
);
}

View file

@ -31,6 +31,7 @@ export interface AppCore {
fatalError: typeof fatalError;
toastNotifications: typeof toastNotifications;
};
chrome: typeof chrome;
}
export interface AppPlugins {
@ -40,7 +41,6 @@ export interface AppPlugins {
}
export interface Core extends AppCore {
chrome: typeof chrome;
http: {
getClient(): any;
setClient(client: any): void;

View file

@ -12,9 +12,14 @@ import { registerRestoreRoutes } from './restore';
import { registerPolicyRoutes } from './policy';
export const registerRoutes = (router: Router, plugins: Plugins): void => {
const isSlmEnabled = plugins.settings.config.isSlmEnabled;
registerAppRoutes(router, plugins);
registerRepositoriesRoutes(router, plugins);
registerSnapshotsRoutes(router, plugins);
registerRestoreRoutes(router);
registerPolicyRoutes(router);
if (isSlmEnabled) {
registerPolicyRoutes(router);
}
};

View file

@ -29,6 +29,11 @@ export interface Plugins {
isCloudEnabled: boolean;
};
};
settings: {
config: {
isSlmEnabled: boolean;
};
};
xpack_main: any;
elasticsearch: any;
}
@ -56,6 +61,13 @@ export function createShim(
isCloudEnabled: get(server.plugins, 'cloud.config.isCloudEnabled', false),
},
},
settings: {
config: {
isSlmEnabled: server.config()
? server.config().get('xpack.snapshot_restore.slm_ui.enabled')
: true,
},
},
xpack_main: server.plugins.xpack_main,
elasticsearch: server.plugins.elasticsearch,
},