From 75215ca515b3e296735f02d55437668bff22d9e2 Mon Sep 17 00:00:00 2001 From: Drew Baugher <46505179+dbbaughe@users.noreply.github.com> Date: Fri, 31 Jul 2020 17:31:50 -0700 Subject: [PATCH] Fixes missing actions on table, unused query parameter ?, and some aesthetics (#103) (#104) --- index.js | 6 ++--- .../ManagedIndices/ManagedIndices.tsx | 24 +++++++++---------- .../ManagedIndices.test.tsx.snap | 4 ++-- .../pages/ManagedIndices/models/interfaces.ts | 12 ---------- .../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, 35 insertions(+), 63 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 0a0c100a..21bcd8f3 100644 --- a/public/pages/ManagedIndices/containers/ManagedIndices/ManagedIndices.tsx +++ b/public/pages/ManagedIndices/containers/ManagedIndices/ManagedIndices.tsx @@ -33,7 +33,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"; @@ -119,7 +119,9 @@ export default class ManagedIndices extends Component _.defaultTo(ACTIONS[action], DEFAULT_EMPTY_DATA), + render: (action: string) => ( + {(action || DEFAULT_EMPTY_DATA).split("_").join(" ")} + ), }, { field: "managedIndexMetaData.info", @@ -136,7 +138,7 @@ export default class ManagedIndices extends Component `[${failedIndex.indexName}, ${failedIndex.reason}]`) + .map((failedIndex) => `[${failedIndex.indexName}, ${failedIndex.reason}]`) .join(", ")}` ); } @@ -309,13 +311,11 @@ export default class ManagedIndices extends Component { - if (!item.managedIndexMetaData) return true; - const { retryInfo, action } = item.managedIndexMetaData; - return !(retryInfo && retryInfo.failed) && !(action && action.failed); - } - ); + selectedItems.some((item): boolean => { + if (!item.managedIndexMetaData) return true; + const { retryInfo, action } = item.managedIndexMetaData; + return !(retryInfo && retryInfo.failed) && !(action && action.failed); + }); const actions = [ { @@ -341,7 +341,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 f0fc81cd..975e84d3 100644 --- a/public/pages/ManagedIndices/containers/ManagedIndices/__snapshots__/ManagedIndices.test.tsx.snap +++ b/public/pages/ManagedIndices/containers/ManagedIndices/__snapshots__/ManagedIndices.test.tsx.snap @@ -499,7 +499,7 @@ exports[` spec renders the component 1`] = ` - Status + Job Status @@ -595,7 +595,7 @@ exports[` spec renders the component 1`] = ` class="euiButtonEmpty__text" > Rows per page - : + : 20 diff --git a/public/pages/ManagedIndices/models/interfaces.ts b/public/pages/ManagedIndices/models/interfaces.ts index a82d0ec0..eabb3971 100644 --- a/public/pages/ManagedIndices/models/interfaces.ts +++ b/public/pages/ManagedIndices/models/interfaces.ts @@ -20,15 +20,3 @@ export interface ManagedIndicesQueryParams { sortField: string; sortDirection: string; } - -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 4c730101..950280ce 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: "name", 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 ac8fea1d..b60a730b 100644 --- a/server/services/IndexService.ts +++ b/server/services/IndexService.ts @@ -53,11 +53,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}`, }; @@ -127,7 +125,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("* *")}*` : "*", }, }; }