Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Filter agents list table by policy name #49968

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function useSuggestions(fieldPrefix: string, search: string) {

useEffect(() => {
fetchSuggestions();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [debouncedSearch]);

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 { Policy } from '../../../../scripts/mock_spec/types';

export class PolicyAdapter {
private memoryDB: Policy[];

constructor(db: Policy[]) {
this.memoryDB = db;
}

public async getAll(): Promise<Policy[]> {
return this.memoryDB;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 { Policy } from '../../../../scripts/mock_spec/types';
import { RestAPIAdapter } from '../rest_api/adapter_types';
import { PolicyAdapter } from './memory_policy_adapter';

const POLICIES_SERVER_HOST = `${window.location.protocol}//${window.location.hostname}:4010`;

export class RestPolicyAdapter extends PolicyAdapter {
constructor(private readonly REST: RestAPIAdapter) {
super([]);
}

public async getAll() {
try {
return await this.REST.get<Policy[]>(`${POLICIES_SERVER_HOST}/policies`);
} catch (e) {
return [];
}
}
}
4 changes: 4 additions & 0 deletions x-pack/legacy/plugins/fleet/public/lib/compose/kibana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import { management } from 'ui/management';
import { toastNotifications } from 'ui/notify';
import routes from 'ui/routes';
import { RestAgentAdapter } from '../adapters/agent/rest_agent_adapter';
import { RestPolicyAdapter } from '../adapters/policy/rest_policy_adapter';
import { RestElasticsearchAdapter } from '../adapters/elasticsearch/rest';
import { KibanaFrameworkAdapter } from '../adapters/framework/kibana_framework_adapter';
import { AxiosRestAPIAdapter } from '../adapters/rest_api/axios_rest_api_adapter';
import { AgentsLib } from '../agent';
import { PoliciesLib } from '../policy';
import { ElasticsearchLib } from '../elasticsearch';
import { FrontendLibs } from '../types';
import { PLUGIN } from '../../../common/constants/plugin';
Expand All @@ -32,6 +34,7 @@ export function compose(): FrontendLibs {
const esAdapter = new RestElasticsearchAdapter(api, INDEX_NAMES.FLEET);
const elasticsearchLib = new ElasticsearchLib(esAdapter);
const agents = new AgentsLib(new RestAgentAdapter(api));
const policies = new PoliciesLib(new RestPolicyAdapter(api));

const framework = new FrameworkLib(
new KibanaFrameworkAdapter(
Expand All @@ -50,6 +53,7 @@ export function compose(): FrontendLibs {
framework,
elasticsearch: elasticsearchLib,
agents,
policies,
};
return libs;
}
6 changes: 5 additions & 1 deletion x-pack/legacy/plugins/fleet/public/lib/compose/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import { uiModules } from 'ui/modules';
// @ts-ignore: path dynamic for kibana
import routes from 'ui/routes';
// @ts-ignore: path dynamic for kibana
import { MemoryAgentAdapter } from '../adapters/agent/memory_agents_adapter';
import { MemoryAgentAdapter } from '../adapters/agent/memory_agent_adapter';
import { PolicyAdapter } from '../adapters/policy/memory_policy_adapter';
import { KibanaFrameworkAdapter } from '../adapters/framework/kibana_framework_adapter';
import { AgentsLib } from '../agent';
import { PoliciesLib } from '../policy';
import { FrameworkLib } from '../framework';
import { FrontendLibs } from '../types';
import { MemoryElasticsearchAdapter } from '../adapters/elasticsearch/memory';
Expand All @@ -38,6 +40,7 @@ export function compose(
const elasticsearchLib = new ElasticsearchLib(esAdapter);

const agents = new AgentsLib(new MemoryAgentAdapter([]));
const policies = new PoliciesLib(new PolicyAdapter([]));

const pluginUIModule = uiModules.get('app/fleet');

Expand All @@ -57,6 +60,7 @@ export function compose(
framework,
elasticsearch: elasticsearchLib,
agents,
policies,
};
return libs;
}
4 changes: 4 additions & 0 deletions x-pack/legacy/plugins/fleet/public/lib/compose/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
*/

import { RestAgentAdapter } from '../adapters/agent/rest_agent_adapter';
import { RestPolicyAdapter } from '../adapters/policy/rest_policy_adapter';
import { MemoryElasticsearchAdapter } from '../adapters/elasticsearch/memory';
import { TestingFrameworkAdapter } from '../adapters/framework/testing_framework_adapter';
import { NodeAxiosAPIAdapter } from '../adapters/rest_api/node_axios_api_adapter';
import { AgentsLib } from '../agent';
import { PoliciesLib } from '../policy';
import { ElasticsearchLib } from '../elasticsearch';
import { FrameworkLib } from '../framework';
import { FrontendLibs } from '../types';
Expand All @@ -19,6 +21,7 @@ export function compose(basePath: string): FrontendLibs {
const elasticsearchLib = new ElasticsearchLib(esAdapter);

const agents = new AgentsLib(new RestAgentAdapter(api));
const policies = new PoliciesLib(new RestPolicyAdapter(api));

const framework = new FrameworkLib(
new TestingFrameworkAdapter(
Expand Down Expand Up @@ -50,6 +53,7 @@ export function compose(basePath: string): FrontendLibs {
framework,
elasticsearch: elasticsearchLib,
agents,
policies,
};
return libs;
}
17 changes: 17 additions & 0 deletions x-pack/legacy/plugins/fleet/public/lib/policy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 { Policy } from '../../scripts/mock_spec/types';
import { PolicyAdapter } from './adapters/policy/memory_policy_adapter';

export class PoliciesLib {
constructor(private readonly adapter: PolicyAdapter) {}

/** Get an array of all policies */
public getAll = async (): Promise<Policy[]> => {
return await this.adapter.getAll();
};
}
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/fleet/public/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { IModule, IScope } from 'angular';
import { AxiosRequestConfig } from 'axios';
import { FrameworkAdapter } from './adapters/framework/adapter_types';
import { AgentsLib } from './agent';
import { PoliciesLib } from './policy';
import { ElasticsearchLib } from './elasticsearch';
import { FrameworkLib } from './framework';

export interface FrontendLibs {
elasticsearch: ElasticsearchLib;
framework: FrameworkLib;
agents: AgentsLib;
policies: PoliciesLib;
}

export type FramworkAdapterConstructable = new (uiModule: IModule) => FrameworkAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function useGetAgentEvents(
};
useEffect(() => {
fetchAgentEvents();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [agent.id, debouncedSearch, pagination]);

return { ...state, refresh: fetchAgentEvents };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function useGetAgent(id: string) {
};
useEffect(() => {
fetchAgent();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [id]);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ export const AgentDetailsPage: SFC<Props> = ({
<EuiFlexItem grow={null}>
<EuiHorizontalRule />
</EuiFlexItem>
<EuiFlexItem grow={null}></EuiFlexItem>
<EuiFlexItem grow={null} />
</EuiFlexItem>
<EuiFlexItem grow={7}>
<EuiFlexItem grow={null}></EuiFlexItem>
<EuiFlexItem grow={null} />
</EuiFlexItem>
</EuiFlexGroup>
</Layout>
Expand Down
Loading