Skip to content

Commit

Permalink
Fixed test failures. Removed usage of ES10 code.
Browse files Browse the repository at this point in the history
Signed-off-by: Ketan Verma <ketan9495@gmail.com>
  • Loading branch information
ketanv3 committed Jun 3, 2021
1 parent 5a93cbd commit 7890691
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class RollupIndices extends Component<RollupIndicesProps, RollupI
const { indexService } = this.props;
this.setState({ isLoading: true, indexOptions: [] });
try {
const queryObject = { from: 0, size: 10, search: searchValue, sortDirection: "desc", sortField: "index" };
const queryObject = { from: 0, size: 10, search: searchValue, sortDirection: "desc", sortField: "index", showDataStreams: true };
const getIndicesResponse = await indexService.getIndices(queryObject);
if (getIndicesResponse.ok) {
const options = searchValue.trim() ? [{ label: `${searchValue}*` }] : [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class TransformIndices extends Component<TransformIndicesProps, T
const { indexService } = this.props;
this.setState({ isLoading: true, indexOptions: [] });
try {
const queryObject = { from: 0, size: 10, search: searchValue, sortDirection: "desc", sortField: "index" };
const queryObject = { from: 0, size: 10, search: searchValue, sortDirection: "desc", sortField: "index", showDataStreams: true };
const getIndicesResponse = await indexService.getIndices(queryObject);
if (getIndicesResponse.ok) {
const options = searchValue.trim() ? [{ label: `${searchValue}*` }] : [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ describe("<IndexControls /> spec", () => {
onSearchChange={() => {}}
onPageClick={() => {}}
onRefresh={async () => {}}
showDataStreams={false}
getDataStreams={async () => {}}
toggleShowDataStreams={() => {}}
/>
);

Expand All @@ -57,6 +60,9 @@ describe("<IndexControls /> spec", () => {
onSearchChange={onSearchChange}
onPageClick={() => {}}
onRefresh={async () => {}}
showDataStreams={false}
getDataStreams={async () => {}}
toggleShowDataStreams={() => {}}
/>
);

Expand All @@ -68,7 +74,17 @@ describe("<IndexControls /> spec", () => {
it("calls onRefresh on an interval", async () => {
const onRefresh = jest.fn();
const { getByTestId } = render(
<IndexControls activePage={0} pageCount={2} search={""} onSearchChange={() => {}} onPageClick={() => {}} onRefresh={onRefresh} />
<IndexControls
activePage={0}
pageCount={2}
search={""}
onSearchChange={() => {}}
onPageClick={() => {}}
onRefresh={onRefresh}
showDataStreams={false}
getDataStreams={async () => {}}
toggleShowDataStreams={() => {}}
/>
);

fireEvent.click(getByTestId("superDatePickerToggleQuickMenuButton"));
Expand Down
9 changes: 4 additions & 5 deletions public/pages/Indices/containers/Indices/Indices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ export default class Indices extends Component<IndicesProps, IndicesState> {

const getIndicesResponse = await indexService.getIndices({
...queryObject,
// TODO: enable these once UT issues are figured out.
// terms: this.getTermClausesFromState(),
// indices: this.getFieldClausesFromState("indices"),
// dataStreams: this.getFieldClausesFromState("data_streams"),
terms: this.getTermClausesFromState(),
indices: this.getFieldClausesFromState("indices"),
dataStreams: this.getFieldClausesFromState("data_streams"),
});

if (getIndicesResponse.ok) {
Expand Down Expand Up @@ -159,7 +158,7 @@ export default class Indices extends Component<IndicesProps, IndicesState> {

getFieldClausesFromState = (clause: string): string[] => {
const { query } = this.state;
return (query.ast.getFieldClauses(clause) || []).map((field) => field.value).flat();
return _.flatten((query.ast.getFieldClauses(clause) || []).map((field) => field.value));
};

getTermClausesFromState = (): string[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ describe("<ManagedIndexControls /> spec", () => {
onSearchChange={() => {}}
onPageClick={() => {}}
onRefresh={async () => {}}
showDataStreams={false}
getDataStreams={async () => {}}
toggleShowDataStreams={() => {}}
/>
);

Expand All @@ -57,6 +60,9 @@ describe("<ManagedIndexControls /> spec", () => {
onSearchChange={onSearchChange}
onPageClick={() => {}}
onRefresh={async () => {}}
showDataStreams={false}
getDataStreams={async () => {}}
toggleShowDataStreams={() => {}}
/>
);

Expand All @@ -75,6 +81,9 @@ describe("<ManagedIndexControls /> spec", () => {
onSearchChange={() => {}}
onPageClick={() => {}}
onRefresh={onRefresh}
showDataStreams={false}
getDataStreams={async () => {}}
toggleShowDataStreams={() => {}}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,9 @@ export default class ManagedIndices extends Component<ManagedIndicesProps, Manag

const getManagedIndicesResponse = await managedIndexService.getManagedIndices({
...queryObject,
// TODO: enable these once UT failures are fixed
// terms: this.getTermClausesFromState(),
// indices: this.getFieldClausesFromState("indices"),
// dataStreams: this.getFieldClausesFromState("data_streams"),
terms: this.getTermClausesFromState(),
indices: this.getFieldClausesFromState("indices"),
dataStreams: this.getFieldClausesFromState("data_streams"),
});

if (getManagedIndicesResponse.ok) {
Expand Down Expand Up @@ -284,7 +283,7 @@ export default class ManagedIndices extends Component<ManagedIndicesProps, Manag

getFieldClausesFromState = (clause: string): string[] => {
const { query } = this.state;
return (query.ast.getFieldClauses(clause) || []).map((field) => field.value).flat();
return _.flatten((query.ast.getFieldClauses(clause) || []).map((field) => field.value));
};

getTermClausesFromState = (): string[] => {
Expand Down
2 changes: 1 addition & 1 deletion server/routes/managedIndices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function (services: NodeServices, router: IRouter) {
terms: schema.maybe(schema.any()),
indices: schema.maybe(schema.any()),
dataStreams: schema.maybe(schema.any()),
showDataStreams: schema.maybe(schema.boolean()), // TODO: remove maybe
showDataStreams: schema.boolean(),
}),
},
},
Expand Down
7 changes: 4 additions & 3 deletions server/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* permissions and limitations under the License.
*/

import _ from "lodash";
import { ExplainAPIManagedIndexMetaData, QueryStringQuery } from "../models/interfaces";
import { MatchAllQuery } from "../models/types";
import { ManagedIndexMetaData } from "../../models/interfaces";
Expand Down Expand Up @@ -77,11 +78,11 @@ export function getMustQuery<T extends string>(field: T, search: string): MatchA

export function getSearchString(terms?: string[], indices?: string[], dataStreams?: string[]): string {
// Terms are searched with a wildcard around them.
const searchTerms = terms ? `*${[terms].flat().join("*,*")}*` : "";
const searchTerms = terms ? `*${_.castArray(terms).join("*,*")}*` : "";

// Indices and data streams are searched with an exact match.
const searchIndices = indices ? [indices].flat().join(",") : "";
const searchDataStreams = dataStreams ? [dataStreams].flat().join(",") : "";
const searchIndices = indices ? _.castArray(indices).join(",") : "";
const searchDataStreams = dataStreams ? _.castArray(dataStreams).join(",") : "";

// The overall search string is a combination of terms, indices, and data streams.
// If the search string is blank, then '*' is used to match everything.
Expand Down

0 comments on commit 7890691

Please sign in to comment.