From 113af6ac52bb7ce75d947022721a34c0acc8f5ea Mon Sep 17 00:00:00 2001 From: Drew Baugher <46505179+dbbaughe@users.noreply.github.com> Date: Fri, 31 Jul 2020 14:55:54 -0700 Subject: [PATCH] Fixes missing actions on table, unused query parameter ?, and some aesthetics (#103) --- index.js | 6 +++--- .../containers/ManagedIndices/ManagedIndices.tsx | 12 +++++++----- .../__snapshots__/ManagedIndices.test.tsx.snap | 2 +- public/pages/ManagedIndices/models/interfaces.ts | 12 ------------ public/pages/ManagedIndices/utils/constants.ts | 15 +-------------- public/services/IndexService.ts | 9 ++++----- public/services/ManagedIndexService.ts | 6 +++--- public/services/PolicyService.test.ts | 2 +- public/services/PolicyService.ts | 6 ++++-- server/services/IndexService.ts | 8 +++----- server/utils/helpers.ts | 6 ++---- 11 files changed, 29 insertions(+), 55 deletions(-) diff --git a/index.js b/index.js index 757fc8c4..cf3a008e 100644 --- a/index.js +++ b/index.js @@ -20,18 +20,18 @@ import { createISMCluster } from "./server/clusters"; import { PolicyService, ManagedIndexService, IndexService } from "./server/services"; import { indices, policies, managedIndices } from "./server/routes"; -export default function(kibana) { +export default function (kibana) { return new kibana.Plugin({ require: ["elasticsearch"], name: "opendistro_index_management_kibana", uiExports: { app: { - title: "Index Management Kibana", + title: "Index Management", description: "Kibana plugin for Index Management", main: "plugins/opendistro_index_management_kibana/app", }, hacks: [], - styleSheetPaths: [resolve(__dirname, "public/app.scss"), resolve(__dirname, "public/app.css")].find(p => existsSync(p)), + styleSheetPaths: [resolve(__dirname, "public/app.scss"), resolve(__dirname, "public/app.css")].find((p) => existsSync(p)), }, config(Joi) { diff --git a/public/pages/ManagedIndices/containers/ManagedIndices/ManagedIndices.tsx b/public/pages/ManagedIndices/containers/ManagedIndices/ManagedIndices.tsx index 47af662f..277624bc 100644 --- a/public/pages/ManagedIndices/containers/ManagedIndices/ManagedIndices.tsx +++ b/public/pages/ManagedIndices/containers/ManagedIndices/ManagedIndices.tsx @@ -40,7 +40,7 @@ import _ from "lodash"; import { ContentPanel, ContentPanelActions } from "../../../../components/ContentPanel"; import ManagedIndexControls from "../../components/ManagedIndexControls"; import ManagedIndexEmptyPrompt from "../../components/ManagedIndexEmptyPrompt"; -import { ACTIONS, DEFAULT_PAGE_SIZE_OPTIONS, DEFAULT_QUERY_PARAMS } from "../../utils/constants"; +import { DEFAULT_PAGE_SIZE_OPTIONS, DEFAULT_QUERY_PARAMS } from "../../utils/constants"; import { BREADCRUMBS, DEFAULT_EMPTY_DATA, PLUGIN_NAME, ROUTES } from "../../../../utils/constants"; import InfoModal from "../../components/InfoModal"; import PolicyModal from "../../../../components/PolicyModal"; @@ -126,7 +126,9 @@ export default class ManagedIndices extends Component ACTIONS[action] || DEFAULT_EMPTY_DATA, + render: (action: string) => ( + {(action || DEFAULT_EMPTY_DATA).split("_").join(" ")} + ), }, { field: "managedIndexMetaData.info", @@ -143,7 +145,7 @@ export default class ManagedIndices extends Component `[${failedIndex.indexName}, ${failedIndex.reason}]`) + .map((failedIndex) => `[${failedIndex.indexName}, ${failedIndex.reason}]`) .join(", ")}` ); } @@ -345,7 +347,7 @@ export default class ManagedIndices extends Component this.onClickRemovePolicy(selectedItems.map(item => item.index)), + onAction: () => this.onClickRemovePolicy(selectedItems.map((item) => item.index)), }), }, }, diff --git a/public/pages/ManagedIndices/containers/ManagedIndices/__snapshots__/ManagedIndices.test.tsx.snap b/public/pages/ManagedIndices/containers/ManagedIndices/__snapshots__/ManagedIndices.test.tsx.snap index 98299152..e0d0ca8f 100644 --- a/public/pages/ManagedIndices/containers/ManagedIndices/__snapshots__/ManagedIndices.test.tsx.snap +++ b/public/pages/ManagedIndices/containers/ManagedIndices/__snapshots__/ManagedIndices.test.tsx.snap @@ -455,7 +455,7 @@ exports[` spec renders the component 1`] = ` - Status + Job Status diff --git a/public/pages/ManagedIndices/models/interfaces.ts b/public/pages/ManagedIndices/models/interfaces.ts index b1eab483..70541baf 100644 --- a/public/pages/ManagedIndices/models/interfaces.ts +++ b/public/pages/ManagedIndices/models/interfaces.ts @@ -23,15 +23,3 @@ export interface ManagedIndicesQueryParams { sortField: keyof ManagedIndexItem; sortDirection: Direction; } - -export interface Actions { - [action: string]: string; - - rollover: string; - delete: string; - open: string; - close: string; - transition: string; - read_only: string; - read_write: string; -} diff --git a/public/pages/ManagedIndices/utils/constants.ts b/public/pages/ManagedIndices/utils/constants.ts index 1d3c0c4f..950b550d 100644 --- a/public/pages/ManagedIndices/utils/constants.ts +++ b/public/pages/ManagedIndices/utils/constants.ts @@ -13,7 +13,7 @@ * permissions and limitations under the License. */ -import { Actions, ManagedIndicesQueryParams } from "../models/interfaces"; +import { ManagedIndicesQueryParams } from "../models/interfaces"; export const DEFAULT_PAGE_SIZE_OPTIONS = [5, 10, 20, 50]; export const DEFAULT_QUERY_PARAMS: ManagedIndicesQueryParams = { @@ -23,16 +23,3 @@ export const DEFAULT_QUERY_PARAMS: ManagedIndicesQueryParams = { sortField: "index", sortDirection: "desc", }; - -export const ACTIONS: Actions = { - rollover: "Rollover", - delete: "Delete", - transition: "Transition", - open: "Open", - close: "Close", - read_only: "Read only", - read_write: "Read write", - replica_count: "Replica count", - notification: "Notification", - force_merge: "Force merge", -}; diff --git a/public/services/IndexService.ts b/public/services/IndexService.ts index 5db1938f..21228fb8 100644 --- a/public/services/IndexService.ts +++ b/public/services/IndexService.ts @@ -27,7 +27,8 @@ export default class IndexService { } getIndices = async (queryParamsString: string): Promise> => { - const url = `..${NODE_API._INDICES}?${queryParamsString}`; + let url = `..${NODE_API._INDICES}`; + if (queryParamsString) url += `?${queryParamsString}`; const response = (await this.httpClient.get(url)) as IHttpResponse>; return response.data; }; @@ -47,14 +48,12 @@ export default class IndexService { }; searchPolicies = async (searchValue: string, source: boolean = false): Promise>> => { + const str = searchValue.trim(); const mustQuery = { query_string: { default_field: "policy.policy_id", default_operator: "AND", - query: `*${searchValue - .trim() - .split(" ") - .join("* *")}*`, + query: str ? `*${str.split(" ").join("* *")}*` : "*", }, }; const body = { diff --git a/public/services/ManagedIndexService.ts b/public/services/ManagedIndexService.ts index 66b00073..54de6b25 100644 --- a/public/services/ManagedIndexService.ts +++ b/public/services/ManagedIndexService.ts @@ -36,9 +36,9 @@ export default class ManagedIndexService { }; getManagedIndices = async (queryParamsString: string): Promise> => { - const response = (await this.httpClient.get(`..${NODE_API.MANAGED_INDICES}?${queryParamsString}`)) as IHttpResponse< - ServerResponse - >; + let url = `..${NODE_API.MANAGED_INDICES}`; + if (queryParamsString) url += `?${queryParamsString}`; + const response = (await this.httpClient.get(url)) as IHttpResponse>; return response.data; }; diff --git a/public/services/PolicyService.test.ts b/public/services/PolicyService.test.ts index a2f62044..026dcfb1 100644 --- a/public/services/PolicyService.test.ts +++ b/public/services/PolicyService.test.ts @@ -45,7 +45,7 @@ describe("PolicyService spec", () => { await policyService.putPolicy(policy, policyId); expect(httpClientMock.put).toHaveBeenCalledTimes(1); - expect(httpClientMock.put).toHaveBeenCalledWith(`..${NODE_API.POLICIES}/${policyId}?`, policy); + expect(httpClientMock.put).toHaveBeenCalledWith(`..${NODE_API.POLICIES}/${policyId}`, policy); }); it("calls delete policy nodejs route when calling deletePolicy", async () => { diff --git a/public/services/PolicyService.ts b/public/services/PolicyService.ts index 4e1f5688..57abc9a4 100644 --- a/public/services/PolicyService.ts +++ b/public/services/PolicyService.ts @@ -28,7 +28,8 @@ export default class PolicyService { } getPolicies = async (queryParamsString: string): Promise> => { - const url = `..${NODE_API.POLICIES}?${queryParamsString}`; + let url = `..${NODE_API.POLICIES}`; + if (queryParamsString) url += `?${queryParamsString}`; const response = (await this.httpClient.get(url)) as IHttpResponse>; return response.data; }; @@ -40,7 +41,8 @@ export default class PolicyService { primaryTerm?: number ): Promise> => { const queryParamsString = queryString.stringify({ seqNo, primaryTerm }); - const url = `..${NODE_API.POLICIES}/${policyId}?${queryParamsString}`; + let url = `..${NODE_API.POLICIES}/${policyId}`; + if (queryParamsString) url += `?${queryParamsString}`; const response = (await this.httpClient.put(url, policy)) as IHttpResponse>; return response.data; }; diff --git a/server/services/IndexService.ts b/server/services/IndexService.ts index d54046fd..d9f96b07 100644 --- a/server/services/IndexService.ts +++ b/server/services/IndexService.ts @@ -54,11 +54,9 @@ export default class IndexService { sortField: string; sortDirection: string; }; + const str = search.trim(); const params = { - index: `*${search - .trim() - .split(" ") - .join("* *")}*`, + index: str ? `*${str.split(" ").join("* *")}*` : "*", format: "json", s: `${sortField}:${sortDirection}`, }; @@ -128,7 +126,7 @@ export default class IndexService { response: { failures: addResponse.failures, updatedIndices: addResponse.updated_indices, - failedIndices: addResponse.failed_indices.map(failedIndex => ({ + failedIndices: addResponse.failed_indices.map((failedIndex) => ({ indexName: failedIndex.index_name, indexUuid: failedIndex.index_uuid, reason: failedIndex.reason, diff --git a/server/utils/helpers.ts b/server/utils/helpers.ts index b496bd4e..3fee9d11 100644 --- a/server/utils/helpers.ts +++ b/server/utils/helpers.ts @@ -50,15 +50,13 @@ export function transformManagedIndexMetaData(metaData: ExplainAPIManagedIndexMe } export function getMustQuery(field: T, search: string): MatchAllQuery | QueryStringQuery { + const str = search.trim(); if (search.trim()) { return { query_string: { default_field: field, default_operator: "AND", - query: `*${search - .trim() - .split(" ") - .join("* *")}*`, + query: str ? `*${str.split(" ").join("* *")}*` : "*", }, }; }