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