Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Apr 19, 2020
1 parent 7372af1 commit 961e157
Show file tree
Hide file tree
Showing 54 changed files with 58 additions and 87 deletions.
1 change: 0 additions & 1 deletion src/plugins/management/public/management_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export class ManagementService {
);

register({ id: 'kibana', title: 'Kibana', order: 30, euiIconType: 'logoKibana' });
register({ id: 'logstash', title: 'Logstash', order: 30, euiIconType: 'logoLogstash' });
register({
id: 'elasticsearch',
title: 'Elasticsearch',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'brace/mode/plain_text';
import 'brace/theme/github';

import { isEmpty } from 'lodash';
import { TOOLTIPS } from '../../../common/constants/tooltips';
import { TOOLTIPS } from '../../../../common/constants/tooltips';
import {
EuiButton,
EuiButtonEmpty,
Expand All @@ -40,7 +40,6 @@ class PipelineEditorUi extends React.Component {

const {
pipeline: { id, description, pipeline, settings },
username,
} = this.props;

const pipelineWorkersSet = typeof settings['pipeline.workers'] === 'number';
Expand All @@ -60,7 +59,6 @@ class PipelineEditorUi extends React.Component {
'queue.max_bytes': settings['queue.max_bytes.number'] + settings['queue.max_bytes.units'],
'queue.type': settings['queue.type'],
},
username,
},
pipelineIdErrors: [],
pipelineIdPattern: /^[A-Za-z\_][A-Za-z0-9\-\_]*$/,
Expand Down Expand Up @@ -526,7 +524,6 @@ PipelineEditorUi.propTypes = {
addSuccess: PropTypes.func.isRequired,
addError: PropTypes.func.isRequired,
}).isRequired,
username: PropTypes.string,
};

export const PipelineEditor = injectI18n(PipelineEditorUi);
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,19 @@ import {
// @ts-ignore
} from '../services';
// @ts-ignore
import { PipelineList } from '../components/pipeline_list';
import { PipelineList } from './components/pipeline_list';
import { PipelineEditView } from './pipeline_edit_view';
// @ts-ignore
import { Pipeline } from '../models/pipeline';
import { SecurityPluginSetup } from '../../../security/public';
// @ts-ignore
import * as Breadcrumbs from './breadcrumbs';

export const renderApp = async (
core: CoreStart,
{ basePath, element, setBreadcrumbs }: ManagementAppMountParams,
license$: Observable<any>,
security?: SecurityPluginSetup
licenseService$: Observable<any>
) => {
const logstashLicenseService = await license$.pipe(first()).toPromise();
const logstashLicenseService = await licenseService$.pipe(first()).toPromise();
const clusterService = new ClusterService(core.http);
const monitoringService = new MonitoringService(
core.http,
Expand Down Expand Up @@ -82,7 +80,6 @@ export const renderApp = async (
setBreadcrumbs={setBreadcrumbs}
logstashLicenseService={logstashLicenseService}
pipelineService={pipelineService}
security={security}
toasts={core.notifications.toasts}
upgradeService={upgradeService}
/>
Expand All @@ -102,7 +99,6 @@ export const renderApp = async (
setBreadcrumbs={setBreadcrumbs}
logstashLicenseService={logstashLicenseService}
pipelineService={pipelineService}
security={security}
toasts={core.notifications.toasts}
upgradeService={upgradeService}
id={match.params.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import { i18n } from '@kbn/i18n';
import { ToastsStart } from 'src/core/public';

// @ts-ignore
import { UpgradeFailure } from '../components/upgrade_failure';
import { UpgradeFailure } from './components/upgrade_failure';
// @ts-ignore
import { PipelineEditor } from '../components/pipeline_editor';
import { PipelineEditor } from './components/pipeline_editor';
// @ts-ignore
import { Pipeline } from '../models/pipeline';
import { SecurityPluginSetup, AuthenticatedUser } from '../../../security/public';
import { ManagementAppMountParams } from '../../../../../src/plugins/management/public';
// @ts-ignore
import * as Breadcrumbs from './breadcrumbs';
Expand All @@ -26,7 +25,7 @@ const usePipeline = (
pipelineService: any,
logstashLicenseService: any,
toasts: ToastsStart,
clone: boolean,
shouldClone: boolean,
id?: string
) => {
const mounted = usePromise();
Expand All @@ -40,7 +39,7 @@ const usePipeline = (

try {
const result = await mounted(pipelineService.loadPipeline(id) as Promise<any>);
setPipeline(clone ? result.clone : result);
setPipeline(shouldClone ? result.clone : result);
} catch (e) {
await logstashLicenseService.checkValidity();
if (e.status !== 403) {
Expand All @@ -55,7 +54,7 @@ const usePipeline = (
}
}
})();
}, [pipelineService, id, mounted, clone, logstashLicenseService, toasts]);
}, [pipelineService, id, mounted, shouldClone, logstashLicenseService, toasts]);

return pipeline;
};
Expand All @@ -73,24 +72,10 @@ const useIsUpgraded = (upgradeService: any) => {
return isUpgraded;
};

const useCurrentUser = (security?: SecurityPluginSetup) => {
const [currentUser, setCurrentUser] = useState<null | AuthenticatedUser>(null);
const mounted = usePromise();

useLayoutEffect(() => {
if (security) {
mounted(security.authc.getCurrentUser()).then(result => setCurrentUser(result));
}
}, [mounted, security]);

return currentUser;
};

interface EditProps {
pipelineService: any;
logstashLicenseService: any;
upgradeService: any;
security?: SecurityPluginSetup;
toasts: ToastsStart;
history: History;
setBreadcrumbs: ManagementAppMountParams['setBreadcrumbs'];
Expand All @@ -103,19 +88,17 @@ export const PipelineEditView: React.FC<EditProps> = ({
pipelineService,
logstashLicenseService,
upgradeService,
security,
toasts,
history,
setBreadcrumbs,
id,
}) => {
const params = new URLSearchParams(history.location.search);
const retry = params.get('retry') === 'true';
const clone = params.get('clone') === '';
const shouldRetry = params.get('retry') === 'true';
const shouldClone = params.get('clone') === '';

const pipeline = usePipeline(pipelineService, logstashLicenseService, toasts, clone, id);
const pipeline = usePipeline(pipelineService, logstashLicenseService, toasts, shouldClone, id);
const isUpgraded = useIsUpgraded(upgradeService);
const currentUser = useCurrentUser(security);

const onRetry = useCallback(() => {
const newParams = new URLSearchParams(history.location.search);
Expand Down Expand Up @@ -147,7 +130,7 @@ export const PipelineEditView: React.FC<EditProps> = ({
return (
<UpgradeFailure
isNewPipeline={isNewPipeline}
isManualUpgrade={!!retry}
isManualUpgrade={!!shouldRetry}
onRetry={onRetry}
onClose={close}
/>
Expand All @@ -157,11 +140,10 @@ export const PipelineEditView: React.FC<EditProps> = ({
return (
<PipelineEditor
id={id}
clone={clone}
clone={shouldClone}
close={close}
open={open}
isNewPipeline={isNewPipeline}
username={currentUser ? currentUser.username : null}
pipeline={pipeline}
pipelineService={pipelineService}
toastNotifications={toasts}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class PipelineListItem {
this.username = props.username;

if (props.lastModified) {
this.lastModified = getMoment(props.lastModified);
this.lastModified = getMomentDate(props.lastModified);
this.lastModifiedHumanized = capitalize(this.lastModified.fromNow());
}
}
Expand All @@ -52,7 +52,7 @@ export class PipelineListItem {
}
}

function getMoment(date) {
function getMomentDate(date) {
if (!date) {
return null;
}
Expand Down
86 changes: 42 additions & 44 deletions x-pack/plugins/logstash/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/

import { i18n } from '@kbn/i18n';
import { first, map } from 'rxjs/operators';
import { Subscription } from 'rxjs';
import { map } from 'rxjs/operators';
import { once } from 'lodash';

import { CoreSetup, CoreStart, Plugin } from 'src/core/public';
Expand All @@ -18,30 +19,29 @@ import { ManagementSetup } from '../../../../src/plugins/management/public';

// @ts-ignore
import { PLUGIN } from '../common/constants';
import {
LogstashLicenseService,
// @ts-ignore
} from './services';
// @ts-ignore
import { registerEditSection } from './sections/pipeline_edit';
// @ts-ignore
import { registerListSection } from './sections/pipeline_list';
import { SecurityPluginSetup } from '../../security/public';
import { LogstashLicenseService } from './services';

interface SetupDeps {
licensing: LicensingPluginSetup;
management: ManagementSetup;

home?: HomePublicPluginSetup;
security?: SecurityPluginSetup;
}

export class LogstashPlugin implements Plugin<void, void, SetupDeps> {
private licenseSubscription?: Subscription;

public setup(core: CoreSetup, plugins: SetupDeps) {
const logstashLicense$ = plugins.licensing.license$.pipe(
map(license => new LogstashLicenseService(license))
);
const section = plugins.management.sections.getSection('logstash')!;
const section = plugins.management.sections.register({
id: 'logstash',
title: 'Logstash',
order: 30,
euiIconType: 'logoLogstash',
});
const managementApp = section.registerApp({
id: 'pipelines',
title: i18n.translate('xpack.logstash.managementSection.pipelinesTitle', {
Expand All @@ -50,47 +50,45 @@ export class LogstashPlugin implements Plugin<void, void, SetupDeps> {
order: 10,
mount: async params => {
const [coreStart] = await core.getStartServices();
const { renderApp } = await import('./sections');
const { renderApp } = await import('./application');

return renderApp(coreStart, params, logstashLicense$, plugins.security);
return renderApp(coreStart, params, logstashLicense$);
},
});

logstashLicense$
.pipe(first())
.toPromise()
.then((license: any) => {
if (license.enableLinks) {
managementApp.enable();
} else {
managementApp.disable();
}
this.licenseSubscription = logstashLicense$.subscribe((license: any) => {
if (license.enableLinks) {
managementApp.enable();
} else {
managementApp.disable();
}

if (plugins.home && license.enableLinks) {
// Ensure that we don't register the feature more than once
once(() => {
plugins.home!.featureCatalogue.register({
id: 'management_logstash',
title: i18n.translate('xpack.logstash.homeFeature.logstashPipelinesTitle', {
defaultMessage: 'Logstash Pipelines',
}),
description: i18n.translate(
'xpack.logstash.homeFeature.logstashPipelinesDescription',
{
defaultMessage: 'Create, delete, update, and clone data ingestion pipelines.',
}
),
icon: 'pipelineApp',
path: '/app/kibana#/management/logstash/pipelines',
showOnHomePage: true,
category: FeatureCatalogueCategory.ADMIN,
});
if (plugins.home && license.enableLinks) {
// Ensure that we don't register the feature more than once
once(() => {
plugins.home!.featureCatalogue.register({
id: 'management_logstash',
title: i18n.translate('xpack.logstash.homeFeature.logstashPipelinesTitle', {
defaultMessage: 'Logstash Pipelines',
}),
description: i18n.translate('xpack.logstash.homeFeature.logstashPipelinesDescription', {
defaultMessage: 'Create, delete, update, and clone data ingestion pipelines.',
}),
icon: 'pipelineApp',
path: '/app/kibana#/management/logstash/pipelines',
showOnHomePage: true,
category: FeatureCatalogueCategory.ADMIN,
});
}
});
});
}
});
}

public start(core: CoreStart) {}

public stop() {}
public stop() {
if (this.licenseSubscription) {
this.licenseSubscription.unsubscribe();
}
}
}
1 change: 0 additions & 1 deletion x-pack/plugins/logstash/server/routes/pipeline/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function registerPipelineSaveRoute(router: IRouter, security?: SecurityPl
id: schema.string(),
description: schema.string(),
pipeline: schema.string(),
username: schema.string(),
settings: schema.maybe(schema.object({}, { unknowns: 'allow' })),
}),
},
Expand Down

0 comments on commit 961e157

Please sign in to comment.