Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Fixes missing actions on table, unused query parameter ?, and some ae…
Browse files Browse the repository at this point in the history
…sthetics (#103) (#106)
  • Loading branch information
dbbaughe authored Aug 1, 2020
1 parent cdb70d7 commit 83dd49e
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 63 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -119,7 +119,9 @@ export default class ManagedIndices extends Component<ManagedIndicesProps, Manag
truncateText: false,
width: "150px",
// @ts-ignore
render: (action: string) => _.defaultTo(ACTIONS[action], DEFAULT_EMPTY_DATA),
render: (action: string) => (
<span style={{ textTransform: "capitalize" }}>{(action || DEFAULT_EMPTY_DATA).split("_").join(" ")}</span>
),
},
{
field: "managedIndexMetaData.info",
Expand All @@ -136,7 +138,7 @@ export default class ManagedIndices extends Component<ManagedIndicesProps, Manag
},
{
field: "index", // we don't care about the field as we're using the whole item in render
name: "Status",
name: "Job Status",
sortable: false,
truncateText: false,
width: "150px",
Expand Down Expand Up @@ -231,7 +233,7 @@ export default class ManagedIndices extends Component<ManagedIndicesProps, Manag
if (failures) {
toastNotifications.addDanger(
`Failed to remove policy from ${failedIndices
.map(failedIndex => `[${failedIndex.indexName}, ${failedIndex.reason}]`)
.map((failedIndex) => `[${failedIndex.indexName}, ${failedIndex.reason}]`)
.join(", ")}`
);
}
Expand Down Expand Up @@ -309,13 +311,11 @@ export default class ManagedIndices extends Component<ManagedIndicesProps, Manag

const isRetryDisabled =
!selectedItems.length ||
selectedItems.some(
(item): boolean => {
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 = [
{
Expand All @@ -341,7 +341,7 @@ export default class ManagedIndices extends Component<ManagedIndicesProps, Manag
selectedItems.length === 1 ? `policy from ${selectedItems[0].index}` : `policies from ${selectedItems.length} indices`
} permanently? This action cannot be undone.`,
actionMessage: "Remove",
onAction: () => this.onClickRemovePolicy(selectedItems.map(item => item.index)),
onAction: () => this.onClickRemovePolicy(selectedItems.map((item) => item.index)),
}),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ exports[`<ManagedIndices /> spec renders the component 1`] = `
<span
class="euiTableCellContent__text"
>
Status
Job Status
</span>
</div>
</th>
Expand Down Expand Up @@ -595,7 +595,7 @@ exports[`<ManagedIndices /> spec renders the component 1`] = `
class="euiButtonEmpty__text"
>
Rows per page
:
:
20
</span>
</span>
Expand Down
12 changes: 0 additions & 12 deletions public/pages/ManagedIndices/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
15 changes: 1 addition & 14 deletions public/pages/ManagedIndices/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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",
};
9 changes: 4 additions & 5 deletions public/services/IndexService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default class IndexService {
}

getIndices = async (queryParamsString: string): Promise<ServerResponse<GetIndicesResponse>> => {
const url = `..${NODE_API._INDICES}?${queryParamsString}`;
let url = `..${NODE_API._INDICES}`;
if (queryParamsString) url += `?${queryParamsString}`;
const response = (await this.httpClient.get(url)) as IHttpResponse<ServerResponse<GetIndicesResponse>>;
return response.data;
};
Expand All @@ -47,14 +48,12 @@ export default class IndexService {
};

searchPolicies = async (searchValue: string, source: boolean = false): Promise<ServerResponse<SearchResponse<any>>> => {
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 = {
Expand Down
6 changes: 3 additions & 3 deletions public/services/ManagedIndexService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export default class ManagedIndexService {
};

getManagedIndices = async (queryParamsString: string): Promise<ServerResponse<GetManagedIndicesResponse>> => {
const response = (await this.httpClient.get(`..${NODE_API.MANAGED_INDICES}?${queryParamsString}`)) as IHttpResponse<
ServerResponse<GetManagedIndicesResponse>
>;
let url = `..${NODE_API.MANAGED_INDICES}`;
if (queryParamsString) url += `?${queryParamsString}`;
const response = (await this.httpClient.get(url)) as IHttpResponse<ServerResponse<GetManagedIndicesResponse>>;
return response.data;
};

Expand Down
2 changes: 1 addition & 1 deletion public/services/PolicyService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
6 changes: 4 additions & 2 deletions public/services/PolicyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default class PolicyService {
}

getPolicies = async (queryParamsString: string): Promise<ServerResponse<GetPoliciesResponse>> => {
const url = `..${NODE_API.POLICIES}?${queryParamsString}`;
let url = `..${NODE_API.POLICIES}`;
if (queryParamsString) url += `?${queryParamsString}`;
const response = (await this.httpClient.get(url)) as IHttpResponse<ServerResponse<GetPoliciesResponse>>;
return response.data;
};
Expand All @@ -40,7 +41,8 @@ export default class PolicyService {
primaryTerm?: number
): Promise<ServerResponse<PutPolicyResponse>> => {
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<ServerResponse<PutPolicyResponse>>;
return response.data;
};
Expand Down
8 changes: 3 additions & 5 deletions server/services/IndexService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
};
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions server/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ export function transformManagedIndexMetaData(metaData: ExplainAPIManagedIndexMe
}

export function getMustQuery<T extends string>(field: T, search: string): MatchAllQuery | QueryStringQuery<T> {
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("* *")}*` : "*",
},
};
}
Expand Down

0 comments on commit 83dd49e

Please sign in to comment.