Unverified Commit 37ee7640 authored by Dorian Johnson's avatar Dorian Johnson Committed by GitHub

chore: cleanup simple typings (#753)

Signed-off-by: 's avatarMarcos Iglesias Valle <golodhros@gmail.com>
parent cd2c3659
...@@ -18,7 +18,7 @@ export interface FeedbackProps { ...@@ -18,7 +18,7 @@ export interface FeedbackProps {
} }
interface FeedbackState { interface FeedbackState {
content: React.FC<any>; content?: React.FC<any>;
feedbackType: FeedbackType; feedbackType: FeedbackType;
isOpen: boolean; isOpen: boolean;
} }
......
...@@ -98,7 +98,7 @@ describe('AnnouncementsList', () => { ...@@ -98,7 +98,7 @@ describe('AnnouncementsList', () => {
const actual = wrapper const actual = wrapper
.find('a.announcements-list-more-link') .find('a.announcements-list-more-link')
.getDOMNode() .getDOMNode()
.attributes.getNamedItem('href').value; .attributes.getNamedItem('href')?.value;
expect(actual).toEqual(expected); expect(actual).toEqual(expected);
}); });
......
...@@ -68,10 +68,10 @@ const AnnouncementsList: React.FC<AnnouncementsListProps> = ({ ...@@ -68,10 +68,10 @@ const AnnouncementsList: React.FC<AnnouncementsListProps> = ({
isLoading, isLoading,
}: AnnouncementsListProps) => { }: AnnouncementsListProps) => {
const isEmpty = announcements.length === 0; const isEmpty = announcements.length === 0;
let listContent = null; let listContent: JSX.Element[] = [];
if (isEmpty) { if (isEmpty) {
listContent = <EmptyAnnouncementItem />; listContent = [<EmptyAnnouncementItem />];
} }
if (announcements.length > 0) { if (announcements.length > 0) {
listContent = getLatestsAnnouncements( listContent = getLatestsAnnouncements(
...@@ -86,7 +86,7 @@ const AnnouncementsList: React.FC<AnnouncementsListProps> = ({ ...@@ -86,7 +86,7 @@ const AnnouncementsList: React.FC<AnnouncementsListProps> = ({
)); ));
} }
if (hasError) { if (hasError) {
listContent = <AnnouncementErrorItem />; listContent = [<AnnouncementErrorItem />];
} }
if (isLoading) { if (isLoading) {
listContent = times(3).map((_, index) => ( listContent = times(3).map((_, index) => (
......
...@@ -12,7 +12,7 @@ import { ...@@ -12,7 +12,7 @@ import {
indexDashboardsEnabled, indexDashboardsEnabled,
} from 'config/config-utils'; } from 'config/config-utils';
import PaginatedResourceList from 'components/common/ResourceList/PaginatedResourceList'; import PaginatedResourceList from 'components/common/ResourceList/PaginatedResourceList';
import TabsComponent from 'components/common/TabsComponent'; import TabsComponent, { TabInfo } from 'components/common/TabsComponent';
import ShimmeringResourceLoader from 'components/common/ShimmeringResourceLoader'; import ShimmeringResourceLoader from 'components/common/ShimmeringResourceLoader';
import { import {
BOOKMARK_TITLE, BOOKMARK_TITLE,
...@@ -29,7 +29,7 @@ interface StateFromProps { ...@@ -29,7 +29,7 @@ interface StateFromProps {
export type MyBookmarksProps = StateFromProps; export type MyBookmarksProps = StateFromProps;
export class MyBookmarks extends React.Component<MyBookmarksProps> { export class MyBookmarks extends React.Component<MyBookmarksProps> {
generateTabContent = (resource: ResourceType) => { generateTabContent = (resource: ResourceType): JSX.Element | null => {
const bookmarks = this.props.myBookmarks[resource]; const bookmarks = this.props.myBookmarks[resource];
if (!bookmarks) { if (!bookmarks) {
...@@ -60,8 +60,8 @@ export class MyBookmarks extends React.Component<MyBookmarksProps> { ...@@ -60,8 +60,8 @@ export class MyBookmarks extends React.Component<MyBookmarksProps> {
return `${getDisplayNameByResource(resource)} (${bookmarks.length})`; return `${getDisplayNameByResource(resource)} (${bookmarks.length})`;
}; };
generateTabInfo = () => { generateTabInfo = (): TabInfo[] => {
const tabInfo = []; const tabInfo: TabInfo[] = [];
tabInfo.push({ tabInfo.push({
content: this.generateTabContent(ResourceType.table), content: this.generateTabContent(ResourceType.table),
......
...@@ -162,7 +162,7 @@ describe('Card', () => { ...@@ -162,7 +162,7 @@ describe('Card', () => {
const actual = wrapper const actual = wrapper
.find('a.card') .find('a.card')
.getDOMNode() .getDOMNode()
.attributes.getNamedItem('href').value; .attributes.getNamedItem('href')?.value;
expect(actual).toEqual(expected); expect(actual).toEqual(expected);
}); });
......
...@@ -128,7 +128,7 @@ export class EditableSection extends React.Component< ...@@ -128,7 +128,7 @@ export class EditableSection extends React.Component<
<label className="editable-section-label"> <label className="editable-section-label">
<div <div
className="editable-section-label-wrapper" className="editable-section-label-wrapper"
onClick={!readOnly ? this.preventDefault : null} onClick={!readOnly ? this.preventDefault : undefined}
> >
<span className="section-title title-3"> <span className="section-title title-3">
{EditableSection.convertText(title)} {EditableSection.convertText(title)}
......
...@@ -21,7 +21,7 @@ export interface StateFromProps { ...@@ -21,7 +21,7 @@ export interface StateFromProps {
export interface DispatchFromProps { export interface DispatchFromProps {
getLatestValue?: (onSuccess?: () => any, onFailure?: () => any) => void; getLatestValue?: (onSuccess?: () => any, onFailure?: () => any) => void;
onSubmitValue: ( onSubmitValue?: (
newValue: string, newValue: string,
onSuccess?: () => any, onSuccess?: () => any,
onFailure?: () => any onFailure?: () => any
...@@ -53,8 +53,6 @@ class EditableText extends React.Component< ...@@ -53,8 +53,6 @@ class EditableText extends React.Component<
public static defaultProps: EditableTextProps = { public static defaultProps: EditableTextProps = {
editable: true, editable: true,
maxLength: 250, maxLength: 250,
onSubmitValue: null,
getLatestValue: null,
value: '', value: '',
}; };
...@@ -90,11 +88,11 @@ class EditableText extends React.Component< ...@@ -90,11 +88,11 @@ class EditableText extends React.Component<
} }
exitEditMode = () => { exitEditMode = () => {
this.props.setEditMode(false); this.props.setEditMode?.(false);
}; };
enterEditMode = () => { enterEditMode = () => {
this.props.setEditMode(true); this.props.setEditMode?.(true);
}; };
refreshText = () => { refreshText = () => {
...@@ -109,14 +107,14 @@ class EditableText extends React.Component< ...@@ -109,14 +107,14 @@ class EditableText extends React.Component<
updateText = () => { updateText = () => {
const newValue = this.textAreaRef.current.value; const newValue = this.textAreaRef.current.value;
const onSuccessCallback = () => { const onSuccessCallback = () => {
this.props.setEditMode(false); this.props.setEditMode?.(false);
this.setState({ value: newValue }); this.setState({ value: newValue });
}; };
const onFailureCallback = () => { const onFailureCallback = () => {
this.exitEditMode(); this.exitEditMode();
}; };
this.props.onSubmitValue(newValue, onSuccessCallback, onFailureCallback); this.props.onSubmitValue?.(newValue, onSuccessCallback, onFailureCallback);
}; };
render() { render() {
......
...@@ -38,7 +38,7 @@ class EntityCardSection extends React.Component< ...@@ -38,7 +38,7 @@ class EntityCardSection extends React.Component<
if (this.props.isEditable) { if (this.props.isEditable) {
this.setState({ readOnly: !this.state.readOnly }); this.setState({ readOnly: !this.state.readOnly });
} }
this.editButton.current.blur(); this.editButton.current?.blur();
} }
render() { render() {
......
...@@ -113,7 +113,7 @@ export class OwnerEditor extends React.Component< ...@@ -113,7 +113,7 @@ export class OwnerEditor extends React.Component<
const { itemProps, tempItemProps } = this.state; const { itemProps, tempItemProps } = this.state;
const { setEditMode, onUpdateList } = this.props; const { setEditMode, onUpdateList } = this.props;
const updateArray = []; const updateArray: UpdateOwnerPayload[] = [];
Object.keys(itemProps).forEach((key) => { Object.keys(itemProps).forEach((key) => {
if (!tempItemProps.hasOwnProperty(key)) { if (!tempItemProps.hasOwnProperty(key)) {
......
...@@ -159,7 +159,7 @@ describe('TableListItem', () => { ...@@ -159,7 +159,7 @@ describe('TableListItem', () => {
badges: [{ tag_name: 'badgeName' }], badges: [{ tag_name: 'badgeName' }],
name: 'tableName', name: 'tableName',
schema: 'tableSchema', schema: 'tableSchema',
schema_description: null, schema_description: undefined,
}, },
}); });
expect( expect(
...@@ -227,7 +227,7 @@ describe('TableListItem', () => { ...@@ -227,7 +227,7 @@ describe('TableListItem', () => {
database: '', database: '',
description: 'I am the description', description: 'I am the description',
key: '', key: '',
badges: null, badges: undefined,
name: 'tableName', name: 'tableName',
schema: 'tableSchema', schema: 'tableSchema',
schema_description: 'schemaDescription', schema_description: 'schemaDescription',
......
...@@ -19,13 +19,13 @@ class UserListItem extends React.Component<UserListItemProps, {}> { ...@@ -19,13 +19,13 @@ class UserListItem extends React.Component<UserListItemProps, {}> {
return `/user/${user.user_id}?index=${logging.index}&source=${logging.source}`; return `/user/${user.user_id}?index=${logging.index}&source=${logging.source}`;
}; };
renderUserInfo = (user: UserResource) => { renderUserInfo = (user: UserResource): JSX.Element[] | null => {
const { role_name, team_name, user_id } = user; const { role_name, team_name, user_id } = user;
if (!role_name && !team_name) { if (!role_name && !team_name) {
return null; return null;
} }
const listItems = []; const listItems: JSX.Element[] = [];
if (role_name) { if (role_name) {
listItems.push(<li key={`${user_id}:role_name`}>{role_name}</li>); listItems.push(<li key={`${user_id}:role_name`}>{role_name}</li>);
} }
......
...@@ -14,7 +14,7 @@ export interface TabsProps { ...@@ -14,7 +14,7 @@ export interface TabsProps {
} }
export interface TabInfo { export interface TabInfo {
content: JSX.Element; content?: JSX.Element;
key: string; key: string;
title: string | JSX.Element; title: string | JSX.Element;
} }
......
...@@ -64,7 +64,7 @@ class TagInput extends React.Component<TagInputProps, TagInputState> { ...@@ -64,7 +64,7 @@ class TagInput extends React.Component<TagInputProps, TagInputState> {
getAllTags: () => void 0, getAllTags: () => void 0,
isLoading: false, isLoading: false,
resourceType: ResourceType.table, resourceType: ResourceType.table,
tags: undefined, tags: [],
updateTags: () => void 0, updateTags: () => void 0,
uriKey: '', uriKey: '',
}; };
...@@ -95,12 +95,12 @@ class TagInput extends React.Component<TagInputProps, TagInputState> { ...@@ -95,12 +95,12 @@ class TagInput extends React.Component<TagInputProps, TagInputState> {
handleSaveModalEdit = () => { handleSaveModalEdit = () => {
const tagArray = Object.keys(this.batchEditSet).reduce( const tagArray = Object.keys(this.batchEditSet).reduce(
(previousValue, tag) => { (previousValue: UpdateTagData[], tagName) => {
const action = this.batchEditSet[tag]; const action = this.batchEditSet[tagName];
if (action === BatchEditState.DELETE) { if (action === BatchEditState.DELETE) {
previousValue.push({ methodName: UpdateMethod.DELETE, tagName: tag }); previousValue.push({ methodName: UpdateMethod.DELETE, tagName });
} else if (action === BatchEditState.PUT) { } else if (action === BatchEditState.PUT) {
previousValue.push({ methodName: UpdateMethod.PUT, tagName: tag }); previousValue.push({ methodName: UpdateMethod.PUT, tagName });
} }
return previousValue; return previousValue;
}, },
......
...@@ -65,13 +65,15 @@ export const mapStateToProps = (state: GlobalState) => { ...@@ -65,13 +65,15 @@ export const mapStateToProps = (state: GlobalState) => {
// TODO: These functions are selectors, consider moving them into the ducks // TODO: These functions are selectors, consider moving them into the ducks
const allTags = state.tags.allTags.tags; const allTags = state.tags.allTags.tags;
const allTagsNoZeros = allTags.filter((tag) => tag.tag_count > 0); const allTagsNoZeros = allTags.filter(
(tag) => tag.tag_count !== undefined && tag.tag_count > 0
);
const curatedTagsList = getCuratedTags(); const curatedTagsList = getCuratedTags();
let curatedTags = []; let curatedTags: Tag[] = [];
let popularTags = []; let popularTags: Tag[] = [];
let otherTags = []; let otherTags: Tag[] = [];
if (curatedTagsList.length > 0) { if (curatedTagsList.length > 0) {
// keeping curated tags with zero usage count // keeping curated tags with zero usage count
...@@ -88,6 +90,9 @@ export const mapStateToProps = (state: GlobalState) => { ...@@ -88,6 +90,9 @@ export const mapStateToProps = (state: GlobalState) => {
} else { } else {
const tagsByUsage = allTagsNoZeros const tagsByUsage = allTagsNoZeros
.sort((a, b) => { .sort((a, b) => {
if (a.tag_count === undefined || b.tag_count === undefined) {
return 0;
}
return a.tag_count - b.tag_count; return a.tag_count - b.tag_count;
}) })
.reverse(); .reverse();
......
...@@ -84,7 +84,7 @@ describe('bookmark ducks', () => { ...@@ -84,7 +84,7 @@ describe('bookmark ducks', () => {
const action = addBookmarkSuccess(bookmarks); const action = addBookmarkSuccess(bookmarks);
const { payload } = action; const { payload } = action;
expect(action.type).toBe(AddBookmark.SUCCESS); expect(action.type).toBe(AddBookmark.SUCCESS);
expect(payload.bookmarks).toBe(bookmarks); expect(payload?.bookmarks).toBe(bookmarks);
}); });
it('getBookmarks - returns the action to get bookmarks', () => { it('getBookmarks - returns the action to get bookmarks', () => {
...@@ -102,7 +102,7 @@ describe('bookmark ducks', () => { ...@@ -102,7 +102,7 @@ describe('bookmark ducks', () => {
const action = getBookmarksSuccess(bookmarks); const action = getBookmarksSuccess(bookmarks);
const { payload } = action; const { payload } = action;
expect(action.type).toBe(GetBookmarks.SUCCESS); expect(action.type).toBe(GetBookmarks.SUCCESS);
expect(payload.bookmarks).toBe(bookmarks); expect(payload?.bookmarks).toBe(bookmarks);
}); });
it('getBookmarksForUser - returns the action to get bookmarks for a user', () => { it('getBookmarksForUser - returns the action to get bookmarks for a user', () => {
...@@ -122,7 +122,7 @@ describe('bookmark ducks', () => { ...@@ -122,7 +122,7 @@ describe('bookmark ducks', () => {
const action = getBookmarksForUserSuccess(bookmarks); const action = getBookmarksForUserSuccess(bookmarks);
const { payload } = action; const { payload } = action;
expect(action.type).toBe(GetBookmarksForUser.SUCCESS); expect(action.type).toBe(GetBookmarksForUser.SUCCESS);
expect(payload.bookmarks).toBe(bookmarks); expect(payload?.bookmarks).toBe(bookmarks);
}); });
it('removeBookmark - returns the action to remove a bookmark', () => { it('removeBookmark - returns the action to remove a bookmark', () => {
...@@ -142,8 +142,8 @@ describe('bookmark ducks', () => { ...@@ -142,8 +142,8 @@ describe('bookmark ducks', () => {
const action = removeBookmarkSuccess(testResourceKey, testResourceType); const action = removeBookmarkSuccess(testResourceKey, testResourceType);
const { payload } = action; const { payload } = action;
expect(action.type).toBe(RemoveBookmark.SUCCESS); expect(action.type).toBe(RemoveBookmark.SUCCESS);
expect(payload.resourceKey).toBe(testResourceKey); expect(payload?.resourceKey).toBe(testResourceKey);
expect(payload.resourceType).toBe(testResourceType); expect(payload?.resourceType).toBe(testResourceType);
}); });
}); });
......
...@@ -47,22 +47,22 @@ export const initialDashboardState: DashboardMetadata = { ...@@ -47,22 +47,22 @@ export const initialDashboardState: DashboardMetadata = {
badges: [], badges: [],
chart_names: [], chart_names: [],
cluster: '', cluster: '',
created_timestamp: null, created_timestamp: 0,
description: '', description: '',
frequent_users: [], frequent_users: [],
group_name: '', group_name: '',
group_url: '', group_url: '',
last_run_state: '', last_run_state: '',
last_run_timestamp: null, last_run_timestamp: 0,
last_successful_run_timestamp: null, last_successful_run_timestamp: 0,
name: '', name: '',
owners: [], owners: [],
product: '', product: '',
queries: [], queries: [],
recent_view_count: null, recent_view_count: 0,
tables: [], tables: [],
tags: [], tags: [],
updated_timestamp: null, updated_timestamp: 0,
uri: '', uri: '',
url: '', url: '',
}; };
......
...@@ -35,7 +35,7 @@ describe('lastIndexed ducks', () => { ...@@ -35,7 +35,7 @@ describe('lastIndexed ducks', () => {
const action = getLastIndexedSuccess(testEpoch); const action = getLastIndexedSuccess(testEpoch);
const { payload } = action; const { payload } = action;
expect(action.type).toBe(GetLastIndexed.SUCCESS); expect(action.type).toBe(GetLastIndexed.SUCCESS);
expect(payload.lastIndexedEpoch).toBe(testEpoch); expect(payload?.lastIndexedEpoch).toBe(testEpoch);
}); });
}); });
......
...@@ -63,7 +63,7 @@ describe('user ducks', () => { ...@@ -63,7 +63,7 @@ describe('user ducks', () => {
const action = getLoggedInUserSuccess(currentUser); const action = getLoggedInUserSuccess(currentUser);
const { payload } = action; const { payload } = action;
expect(action.type).toBe(GetLoggedInUser.SUCCESS); expect(action.type).toBe(GetLoggedInUser.SUCCESS);
expect(payload.user).toBe(currentUser); expect(payload?.user).toBe(currentUser);
}); });
it('getLoggedInUserFailure - returns the action to process the failure', () => { it('getLoggedInUserFailure - returns the action to process the failure', () => {
...@@ -82,7 +82,7 @@ describe('user ducks', () => { ...@@ -82,7 +82,7 @@ describe('user ducks', () => {
const action = getUserSuccess(otherUser.user); const action = getUserSuccess(otherUser.user);
const { payload } = action; const { payload } = action;
expect(action.type).toBe(GetUser.SUCCESS); expect(action.type).toBe(GetUser.SUCCESS);
expect(payload.user).toBe(otherUser.user); expect(payload?.user).toBe(otherUser.user);
}); });
it('getUserFailure - returns the action to process the failure', () => { it('getUserFailure - returns the action to process the failure', () => {
...@@ -101,7 +101,7 @@ describe('user ducks', () => { ...@@ -101,7 +101,7 @@ describe('user ducks', () => {
const action = getUserOwnSuccess(otherUser.own); const action = getUserOwnSuccess(otherUser.own);
const { payload } = action; const { payload } = action;
expect(action.type).toBe(GetUserOwn.SUCCESS); expect(action.type).toBe(GetUserOwn.SUCCESS);
expect(payload.own).toBe(otherUser.own); expect(payload?.own).toBe(otherUser.own);
}); });
it('getUserOwnFailure - returns the action to process the failure', () => { it('getUserOwnFailure - returns the action to process the failure', () => {
...@@ -120,7 +120,7 @@ describe('user ducks', () => { ...@@ -120,7 +120,7 @@ describe('user ducks', () => {
const action = getUserReadSuccess(otherUser.read); const action = getUserReadSuccess(otherUser.read);
const { payload } = action; const { payload } = action;
expect(action.type).toBe(GetUserRead.SUCCESS); expect(action.type).toBe(GetUserRead.SUCCESS);
expect(payload.read).toBe(otherUser.read); expect(payload?.read).toBe(otherUser.read);
}); });
it('getUserReadFailure - returns the action to process the failure', () => { it('getUserReadFailure - returns the action to process the failure', () => {
......
...@@ -10,7 +10,7 @@ import { bindActionCreators } from 'redux'; ...@@ -10,7 +10,7 @@ import { bindActionCreators } from 'redux';
import Breadcrumb from 'components/common/Breadcrumb'; import Breadcrumb from 'components/common/Breadcrumb';
import Flag from 'components/common/Flag'; import Flag from 'components/common/Flag';
import TabsComponent from 'components/common/TabsComponent'; import TabsComponent, { TabInfo } from 'components/common/TabsComponent';
import { BadgeStyle } from 'config/config-types'; import { BadgeStyle } from 'config/config-types';
import { GlobalState } from 'ducks/rootReducer'; import { GlobalState } from 'ducks/rootReducer';
...@@ -173,7 +173,7 @@ export class ProfilePage extends React.Component< ...@@ -173,7 +173,7 @@ export class ProfilePage extends React.Component<
}; };
generateTabInfo = () => { generateTabInfo = () => {
const tabInfo = []; const tabInfo: TabInfo[] = [];
tabInfo.push({ tabInfo.push({
content: this.generateTabContent(ResourceType.table), content: this.generateTabContent(ResourceType.table),
...@@ -200,14 +200,14 @@ export class ProfilePage extends React.Component< ...@@ -200,14 +200,14 @@ export class ProfilePage extends React.Component<
const { user } = this.props; const { user } = this.props;
const isLoading = !user.display_name && !user.email && !user.employee_type; const isLoading = !user.display_name && !user.email && !user.employee_type;
let avatar = null; let avatar: JSX.Element | null = null;
if (isLoading) { if (isLoading) {
avatar = <div className="shimmering-circle is-shimmer-animated" />; avatar = <div className="shimmering-circle is-shimmer-animated" />;
} else if (user.display_name && user.display_name.length > 0) { } else if (user.display_name && user.display_name.length > 0) {
avatar = <Avatar name={user.display_name} size={AVATAR_SIZE} round />; avatar = <Avatar name={user.display_name} size={AVATAR_SIZE} round />;
} }
let userName = null; let userName: JSX.Element | null = null;
if (isLoading) { if (isLoading) {
userName = ( userName = (
<div className="shimmering-text title-text is-shimmer-animated" /> <div className="shimmering-text title-text is-shimmer-animated" />
...@@ -218,7 +218,7 @@ export class ProfilePage extends React.Component< ...@@ -218,7 +218,7 @@ export class ProfilePage extends React.Component<
); );
} }
let bullets = null; let bullets: JSX.Element | null = null;
if (isLoading) { if (isLoading) {
bullets = <div className="shimmering-text bullets is-shimmer-animated" />; bullets = <div className="shimmering-text bullets is-shimmer-animated" />;
} else { } else {
...@@ -236,7 +236,7 @@ export class ProfilePage extends React.Component< ...@@ -236,7 +236,7 @@ export class ProfilePage extends React.Component<
); );
} }
let emailLink = null; let emailLink: JSX.Element | null = null;
if (isLoading) { if (isLoading) {
emailLink = ( emailLink = (
<div className="shimmering-text header-link is-shimmer-animated" /> <div className="shimmering-text header-link is-shimmer-animated" />
...@@ -256,7 +256,7 @@ export class ProfilePage extends React.Component< ...@@ -256,7 +256,7 @@ export class ProfilePage extends React.Component<
); );
} }
let profileLink = null; let profileLink: JSX.Element | null = null;
if (isLoading) { if (isLoading) {
profileLink = ( profileLink = (
<div className="shimmering-text header-link is-shimmer-animated" /> <div className="shimmering-text header-link is-shimmer-animated" />
...@@ -276,7 +276,7 @@ export class ProfilePage extends React.Component< ...@@ -276,7 +276,7 @@ export class ProfilePage extends React.Component<
); );
} }
let githubLink = null; let githubLink: JSX.Element | null = null;
if (isLoading) { if (isLoading) {
githubLink = ( githubLink = (
<div className="shimmering-text header-link is-shimmer-animated" /> <div className="shimmering-text header-link is-shimmer-animated" />
......
...@@ -55,9 +55,8 @@ describe('FilterSection', () => { ...@@ -55,9 +55,8 @@ describe('FilterSection', () => {
const { props, wrapper } = setup({ type: FilterType.INPUT_SELECT }); const { props, wrapper } = setup({ type: FilterType.INPUT_SELECT });
const content = wrapper.instance().renderFilterComponent(); const content = wrapper.instance().renderFilterComponent();
// @ts-ignore: This check works but TypeScript complains expect(content?.type.displayName).toBe('Connect(InputFilter)');
expect(content.type.displayName).toBe('Connect(InputFilter)'); expect(content?.props.categoryId).toBe(props.categoryId);
expect(content.props.categoryId).toBe(props.categoryId);
}); });
it('returns a CheckBoxFilter w/ correct props if props.type == FilterType.CHECKBOX_SELECT', () => { it('returns a CheckBoxFilter w/ correct props if props.type == FilterType.CHECKBOX_SELECT', () => {
...@@ -68,10 +67,9 @@ describe('FilterSection', () => { ...@@ -68,10 +67,9 @@ describe('FilterSection', () => {
}); });
const content = wrapper.instance().renderFilterComponent(); const content = wrapper.instance().renderFilterComponent();
// @ts-ignore: This check works but TypeScript complains expect(content?.type.displayName).toBe('Connect(CheckBoxFilter)');
expect(content.type.displayName).toBe('Connect(CheckBoxFilter)'); expect(content?.props.categoryId).toBe(props.categoryId);
expect(content.props.categoryId).toBe(props.categoryId); expect(content?.props.checkboxProperties).toBe(mockOptions);
expect(content.props.checkboxProperties).toBe(mockOptions);
}); });
}); });
......
...@@ -43,7 +43,7 @@ describe('render SourceLink', () => { ...@@ -43,7 +43,7 @@ describe('render SourceLink', () => {
const actual = wrapper const actual = wrapper
.find('.header-link') .find('.header-link')
.getDOMNode() .getDOMNode()
.attributes.getNamedItem('href').value; .attributes.getNamedItem('href')?.value;
expect(actual).toEqual(expected); expect(actual).toEqual(expected);
}); });
......
...@@ -17,7 +17,10 @@ export const DEFAULT_SEARCH_ROUTE = '/search'; ...@@ -17,7 +17,10 @@ export const DEFAULT_SEARCH_ROUTE = '/search';
export const generateSearchUrl = (searchParams: SearchParams): string => { export const generateSearchUrl = (searchParams: SearchParams): string => {
const filtersForResource = const filtersForResource =
(searchParams.filters && searchParams.filters[searchParams.resource]) || {}; (searchParams.filters &&
searchParams.resource &&
searchParams.filters[searchParams.resource]) ||
{};
const hasFilters = Object.keys(filtersForResource).length > 0; const hasFilters = Object.keys(filtersForResource).length > 0;
// If there is no search input return the search route url // If there is no search input return the search route url
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment