Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Apr 27, 2021
1 parent f3c9fe8 commit 0f227f9
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export const filterDeps = (level: LevelFilterOption, search: string = '') => {
// Change everything to lower case for a case-insensitive comparison
conditions.push((dep) => {
try {
const searchReg = new RegExp(search.toLowerCase());
return Boolean(dep.message.toLowerCase().match(searchReg));
const searchReg = new RegExp(search, 'i');
return searchReg.test(dep.message);
} catch (e) {
// ignore any regexp errors.
return true;
Expand All @@ -59,10 +59,9 @@ export const filterDeps = (level: LevelFilterOption, search: string = '') => {
};

/**
* Collection of calculated fields based on props, extracted for reuse in
* `render` and `getDerivedStateFromProps`.
* Collection of calculated fields based on props
*/
const CalcFields = {
const calcFields = {
filteredDeprecations(props: {
deprecations: EnrichedDeprecationInfo[];
currentFilter: LevelFilterOption;
Expand All @@ -78,7 +77,7 @@ const CalcFields = {
search: string;
currentGroupBy: GroupByOption;
}) {
return groupBy(CalcFields.filteredDeprecations(props), props.currentGroupBy);
return groupBy(calcFields.filteredDeprecations(props), props.currentGroupBy);
},

numPages(props: {
Expand All @@ -87,7 +86,7 @@ const CalcFields = {
search: string;
currentGroupBy: GroupByOption;
}) {
return Math.ceil(Object.keys(CalcFields.groups(props)).length / DEPRECATIONS_PER_PAGE);
return Math.ceil(Object.keys(calcFields.groups(props)).length / DEPRECATIONS_PER_PAGE);
},
};

Expand Down Expand Up @@ -126,7 +125,7 @@ export const DeprecationTabContent: FunctionComponent<CheckupTabProps> = ({

useEffect(() => {
if (deprecations) {
const pageCount = CalcFields.numPages({
const pageCount = calcFields.numPages({
deprecations,
currentFilter,
search,
Expand Down Expand Up @@ -159,15 +158,15 @@ export const DeprecationTabContent: FunctionComponent<CheckupTabProps> = ({
const deprecationLevelsCount = Object.keys(levelGroups).reduce((counts, level) => {
counts[level] = levelGroups[level].length;
return counts;
}, {} as { [level: string]: number });
}, {} as Record<string, number>);

const filteredDeprecations = CalcFields.filteredDeprecations({
const filteredDeprecations = calcFields.filteredDeprecations({
deprecations,
currentFilter,
search,
});

const groups = CalcFields.groups({
const groups = calcFields.groups({
deprecations,
currentFilter,
search,
Expand Down Expand Up @@ -229,7 +228,7 @@ export const DeprecationTabContent: FunctionComponent<CheckupTabProps> = ({
<EuiSpacer />

<DeprecationPagination
pageCount={CalcFields.numPages({
pageCount={calcFields.numPages({
deprecations,
currentFilter,
search,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { DomainDeprecationDetails } from 'kibana/public';
import type { DomainDeprecationDetails } from 'kibana/public';
import { DeprecationHealth } from '../shared';
import { LEVEL_MAP } from '../constants';
import { StepsModalContent } from './steps_modal';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { FunctionComponent, useState, useEffect } from 'react';
import { groupBy } from 'lodash';
import { EuiHorizontalRule, EuiSpacer } from '@elastic/eui';

import { DomainDeprecationDetails } from 'kibana/public';
import type { DomainDeprecationDetails } from 'kibana/public';

import { LevelFilterOption } from '../types';
import { SearchBar, DeprecationListBar, DeprecationPagination } from '../shared';
Expand All @@ -33,13 +33,13 @@ const getFilteredDeprecations = (
) => {
return deprecations
.filter((deprecation) => {
return level === 'all' ? true : deprecation.level === level;
return level === 'all' || deprecation.level === level;
})
.filter((filteredDep) => {
if (search.length > 0) {
try {
const searchReg = new RegExp(search.toLowerCase());
return Boolean(filteredDep.message.toLowerCase().match(searchReg));
const searchReg = new RegExp(search, 'i');
return searchReg.test(filteredDep.message);
} catch (e) {
// ignore any regexp errors
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { DomainDeprecationDetails } from 'kibana/public';
import type { DomainDeprecationDetails } from 'kibana/public';
import { SectionLoading } from '../../../shared_imports';
import { useAppContext } from '../../app_context';
import { NoDeprecationsPrompt } from '../shared';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { FunctionComponent } from 'react';
import { i18n } from '@kbn/i18n';

import { EuiConfirmModal } from '@elastic/eui';
import { DomainDeprecationDetails } from 'kibana/public';
import type { DomainDeprecationDetails } from 'kibana/public';

interface Props {
closeModal: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { i18n } from '@kbn/i18n';

import { RouteComponentProps } from 'react-router-dom';
import { DomainDeprecationDetails } from 'kibana/public';
import type { DomainDeprecationDetails } from 'kibana/public';
import { reactRouterNavigate } from '../../../../../../../src/plugins/kibana_react/public';
import { useAppContext } from '../../app_context';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
EuiSpacer,
} from '@elastic/eui';

import { DomainDeprecationDetails } from 'kibana/public';
import type { DomainDeprecationDetails } from 'kibana/public';
import { DeprecationInfo } from '../../../../../common/types';
import { validateRegExpString } from '../../../lib/utils';
import { GroupByOption, LevelFilterOption } from '../../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { DomainDeprecationDetails } from 'kibana/public';
import type { DomainDeprecationDetails } from 'kibana/public';
import { act } from 'react-dom/test-utils';
import { deprecationsServiceMock } from 'src/core/public/mocks';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { DomainDeprecationDetails } from 'kibana/public';
import type { DomainDeprecationDetails } from 'kibana/public';
import { act } from 'react-dom/test-utils';
import { deprecationsServiceMock } from 'src/core/public/mocks';
import { UpgradeAssistantStatus } from '../common/types';
Expand Down

0 comments on commit 0f227f9

Please sign in to comment.