Unverified Commit 14261198 authored by Dorian Johnson's avatar Dorian Johnson Committed by GitHub

chore: finish remaining simple null check typing fixes (#756)

Signed-off-by: 's avatarMarcos Iglesias Valle <golodhros@gmail.com>
parent 0d55e2d2
......@@ -19,7 +19,7 @@ module.exports = {
statements: 78, // 75
},
'./js/ducks': {
branches: 75,
branches: 74, // 75
functions: 80,
lines: 80,
statements: 85,
......
......@@ -14,7 +14,7 @@ import { formatDateTimeLong } from 'utils/dateUtils';
// Props
interface StateFromProps {
lastIndexed: number;
lastIndexed?: number;
}
interface DispatchFromProps {
......@@ -38,8 +38,8 @@ export class Footer extends React.Component<FooterProps> {
getLastIndexed();
}
generateDateTimeString = () => {
return formatDateTimeLong({ epochTimestamp: this.props.lastIndexed });
generateDateTimeString = (lastIndexed: number): string => {
return formatDateTimeLong({ epochTimestamp: lastIndexed });
};
render() {
......@@ -47,7 +47,11 @@ export class Footer extends React.Component<FooterProps> {
if (this.props.lastIndexed) {
content = (
<div>{`Amundsen was last indexed on ${this.generateDateTimeString()}`}</div>
<div>
{`Amundsen was last indexed on ${this.generateDateTimeString(
this.props.lastIndexed
)}`}
</div>
);
}
......
......@@ -118,9 +118,9 @@ describe('MyBookmarks', () => {
expect(element.props().emptyText).toBe(EMPTY_BOOKMARK_MESSAGE);
});
it('returns null if there are no bookmarks to render', () => {
it('returns undefined if there are no bookmarks to render', () => {
content = wrapper.instance().generateTabContent(ResourceType.user);
expect(content).toBe(null);
expect(content).toBeUndefined();
});
});
......
......@@ -29,11 +29,11 @@ interface StateFromProps {
export type MyBookmarksProps = StateFromProps;
export class MyBookmarks extends React.Component<MyBookmarksProps> {
generateTabContent = (resource: ResourceType): JSX.Element | null => {
generateTabContent = (resource: ResourceType): JSX.Element | undefined => {
const bookmarks = this.props.myBookmarks[resource];
if (!bookmarks) {
return null;
return undefined;
}
return (
......
......@@ -33,7 +33,7 @@ const Card: React.FC<CardProps> = ({
title,
subtitle,
copy,
onClick = null,
onClick = undefined,
isLoading = false,
}: CardProps) => {
let card;
......
......@@ -91,7 +91,7 @@ describe('EditableSection', () => {
it('renders children as-is for non-react elements', () => {
const child = 'non-react-child';
const { wrapper } = setup(null, child);
const { wrapper } = setup(undefined, child);
expect(wrapper.find('.editable-section-content').text()).toBe(child);
});
......
......@@ -161,7 +161,7 @@ describe('DashboardListItem', () => {
uri: 'product_dashboard://cluster.group/name',
url: 'product/name',
cluster: 'cluster',
last_successful_run_timestamp: null,
last_successful_run_timestamp: 0,
},
});
expect(wrapper.find('.resource-badges').find('.title-3').text()).toBe(
......
......@@ -53,7 +53,8 @@ export default class ScrollTracker extends React.Component<
const scrollableAmount = Math.max(contentHeight - windowHeight, 1);
if (threshold <= (100 * scrollTop) / scrollableAmount) {
this.fireAnalyticsEvent(this.state.thresholds.shift());
this.state.thresholds.shift();
this.fireAnalyticsEvent(threshold);
}
};
......
......@@ -401,7 +401,7 @@ describe('SearchBar', () => {
expect(result.onSelectInlineResult).toBeInstanceOf(Function);
});
it('sets clearSearch on the props if on search route', () => {
const { props } = setup(null, null, { pathname: '/search' });
const { props } = setup(undefined, undefined, { pathname: '/search' });
result = mapDispatchToProps(dispatch, props);
expect(result.clearSearch).toBeInstanceOf(Function);
});
......
......@@ -32,7 +32,7 @@ export interface StateFromProps {
}
export interface DispatchFromProps {
clearSearch?: () => SubmitSearchRequest;
clearSearch?: () => void;
submitSearch: (searchTerm: string) => SubmitSearchRequest;
onInputChange: (term: string) => InlineSearchRequest;
onSelectInlineResult: (
......
......@@ -10,7 +10,12 @@ import CreatableSelect from 'react-select/lib/Creatable';
import { GlobalState } from 'ducks/rootReducer';
import { getAllTags, updateTags } from 'ducks/tags/reducer';
import { GetAllTagsRequest, UpdateTagsRequest } from 'ducks/tags/types';
import {
GetAllTags,
GetAllTagsRequest,
UpdateTags,
UpdateTagsRequest,
} from 'ducks/tags/types';
import { EditableSectionChildProps } from 'components/common/EditableSection';
import { ResourceType, Tag, UpdateMethod, UpdateTagData } from 'interfaces';
......@@ -61,11 +66,20 @@ class TagInput extends React.Component<TagInputProps, TagInputState> {
public static defaultProps: TagInputProps = {
allTags: [],
getAllTags: () => void 0,
getAllTags: () => ({
type: GetAllTags.REQUEST,
}),
isLoading: false,
resourceType: ResourceType.table,
tags: [],
updateTags: () => void 0,
updateTags: () => ({
type: UpdateTags.REQUEST,
payload: {
tagArray: [],
resourceType: ResourceType.table,
uriKey: '',
},
}),
uriKey: '',
};
......
......@@ -97,7 +97,7 @@ const LongTagsList: React.FC<TagsListProps> = ({
}: TagsListProps) => {
const hasCuratedTags = curatedTags.length > 0;
const hasPopularTags = popularTags.length > 0;
const hasOtherTags = otherTags.length > 0;
const hasOtherTags = otherTags && otherTags.length > 0;
return (
<div className="full-tag-list">
<h1 className="tag-list-title" id="browse-header">
......@@ -113,7 +113,7 @@ const LongTagsList: React.FC<TagsListProps> = ({
)}
{hasCuratedTags && <TagsListBlock tags={curatedTags} />}
{hasOtherTags && <TagsListLabel titleText={OTHER_TAGS_TITLE} />}
{hasOtherTags && <TagsListBlock tags={otherTags} />}
{hasOtherTags && <TagsListBlock tags={otherTags || []} />}
</div>
);
};
......
......@@ -82,7 +82,7 @@ export function getFilterConfigByResource(
* use BadgeStyle.DEFAULT and badge name as display name.
*/
export function getBadgeConfig(badgeName: string): BadgeStyleConfig {
const config = AppConfig.badges[badgeName] || {};
const config: object = AppConfig.badges[badgeName] || {};
return {
style: BadgeStyle.DEFAULT,
......
......@@ -55,13 +55,18 @@ export default function reducer(
isLoading: false,
statusCode: action.payload.statusCode,
};
case GetAnnouncements.SUCCESS:
case GetAnnouncements.SUCCESS: {
const { payload } = <GetAnnouncementsResponse>action;
if (payload === undefined) {
throw Error('payload must be set for GetAnnouncements.SUCCESS');
}
return {
...state,
isLoading: false,
statusCode: action.payload.statusCode,
posts: (<GetAnnouncementsResponse>action).payload.posts,
posts: payload.posts || [],
};
}
default:
return state;
}
......
......@@ -5,7 +5,7 @@ import {
} from './types';
export interface LastIndexedReducerState {
lastIndexed: number;
lastIndexed: number | null;
}
export const initialState: LastIndexedReducerState = {
lastIndexed: null,
......@@ -39,10 +39,15 @@ export default function reducer(
switch (action.type) {
case GetLastIndexed.REQUEST:
return initialState;
case GetLastIndexed.SUCCESS:
case GetLastIndexed.SUCCESS: {
const { payload } = <GetLastIndexedResponse>action;
if (payload === undefined) {
throw Error('payload must be set for GetLastIndexed.SUCCESS');
}
return {
lastIndexed: (<GetLastIndexedResponse>action).payload.lastIndexedEpoch,
lastIndexed: payload.lastIndexedEpoch || null,
};
}
case GetLastIndexed.FAILURE:
return {
lastIndexed: null,
......
......@@ -128,7 +128,7 @@ export default function reducer(
resourceTags: {
...state.resourceTags,
isLoading: false,
tags: (<GetDashboardResponse>action).payload.dashboard.tags,
tags: (<GetDashboardResponse>action).payload.dashboard?.tags || [],
},
};
case GetTableData.FAILURE:
......
......@@ -114,11 +114,16 @@ export default function reducer(
action
): UserReducerState {
switch (action.type) {
case GetLoggedInUser.SUCCESS:
case GetLoggedInUser.SUCCESS: {
const { payload } = <GetLoggedInUserResponse>action;
if (payload === undefined) {
throw Error('payload must be set for GetLoggedInUser.SUCCESS');
}
return {
...state,
loggedInUser: (<GetLoggedInUserResponse>action).payload.user,
loggedInUser: payload.user,
};
}
case GetUser.REQUEST:
case GetUser.FAILURE:
return {
......@@ -128,14 +133,19 @@ export default function reducer(
user: defaultUser,
},
};
case GetUser.SUCCESS:
case GetUser.SUCCESS: {
const { payload } = <GetUserResponse>action;
if (payload === undefined) {
throw Error('payload must be set for GetUser.SUCCESS');
}
return {
...state,
profile: {
...state.profile,
user: (<GetUserResponse>action).payload.user,
user: payload.user,
},
};
}
case GetUserOwn.REQUEST:
case GetUserOwn.FAILURE:
return {
......@@ -147,14 +157,19 @@ export default function reducer(
},
},
};
case GetUserOwn.SUCCESS:
case GetUserOwn.SUCCESS: {
const { payload } = <GetUserOwnResponse>action;
if (payload === undefined) {
throw Error('payload must be set for GetUserOwn.SUCCESS');
}
return {
...state,
profile: {
...state.profile,
own: (<GetUserOwnResponse>action).payload.own,
own: payload.own,
},
};
}
case GetUserRead.REQUEST:
case GetUserRead.FAILURE:
return {
......@@ -164,14 +179,19 @@ export default function reducer(
read: [],
},
};
case GetUserRead.SUCCESS:
case GetUserRead.SUCCESS: {
const { payload } = <GetUserReadResponse>action;
if (payload === undefined) {
throw Error('payload must be set for GetUserRead.SUCCESS');
}
return {
...state,
profile: {
...state.profile,
read: (<GetUserReadResponse>action).payload.read,
read: payload.read,
},
};
}
default:
return state;
}
......
......@@ -50,7 +50,7 @@ export function logClick(
command: 'click',
target_id:
target.dataset && target.dataset.type ? target.dataset.type : target.id,
label: target.innerText || target.textContent,
label: target.innerText || target.textContent || '',
};
if (target.nodeValue !== null) {
......
......@@ -39,7 +39,7 @@ describe('ProfilePage', () => {
const setup = (propOverrides?: Partial<ProfilePageProps>) => {
const routerProps = getMockRouterProps<RouteProps>(
{ userId: 'test0' },
null
undefined
);
const props: ProfilePageProps = {
user: globalState.user.profile.user,
......
......@@ -49,7 +49,10 @@ export class FilterSection extends React.Component<FilterSectionProps> {
}
if (type === FilterType.CHECKBOX_SELECT) {
return (
<CheckBoxFilter categoryId={categoryId} checkboxProperties={options} />
<CheckBoxFilter
categoryId={categoryId}
checkboxProperties={options || []}
/>
);
}
};
......
......@@ -221,6 +221,7 @@ describe('mapStateToProps', () => {
{
categoryId: mockSchemaId,
helpText: mockHelpText,
options: [],
title: mockSchemaTitle,
type: FilterType.INPUT_SELECT,
},
......
......@@ -67,20 +67,21 @@ export class SearchFilter extends React.Component<SearchFilterProps> {
export const mapStateToProps = (state: GlobalState) => {
const resourceType = state.search.resource;
const filterCategories = getFilterConfigByResource(resourceType);
const filterSections = [];
const filterSections: CheckboxFilterSection[] = [];
if (filterCategories) {
filterCategories.forEach((categoryConfig) => {
const section = {
const section: CheckboxFilterSection = {
categoryId: categoryConfig.categoryId,
helpText: categoryConfig.helpText,
title: categoryConfig.displayName,
type: categoryConfig.type,
options: [],
};
if (categoryConfig.type === FilterType.CHECKBOX_SELECT) {
(section as CheckboxFilterSection).options = categoryConfig.options.map(
section.options = categoryConfig.options.map(
({ value, displayName }) => {
return { value, label: displayName };
return { value, label: displayName || '' };
}
);
}
......
......@@ -47,7 +47,7 @@ interface DataPreviewButtonState {
showModal: boolean;
}
export function getStatusFromCode(httpErrorCode: number) {
export function getStatusFromCode(httpErrorCode: number | null) {
switch (httpErrorCode) {
case null:
return LoadingStatus.LOADING;
......@@ -139,7 +139,7 @@ export class DataPreviewButton extends React.Component<
<div className="grid-cell grid-header subtitle-3">
{fieldName.toUpperCase()}
</div>
{previewData.data.map((row, rowId) => {
{(previewData.data || []).map((row, rowId) => {
const cellId = `${colId}:${rowId}`;
const dataItemValue = this.getSanitizedValue(row[fieldName]);
return (
......
......@@ -34,7 +34,7 @@ class WatermarkLabel extends React.Component<WatermarkLabelProps> {
return (watermark && watermark.partition_value) || null;
};
renderWatermarkInfo = (low: string, high: string) => {
renderWatermarkInfo = (low: string | null, high: string | null) => {
if (low === null && high === null) {
return (
<div className="body-2">
......
......@@ -179,12 +179,7 @@ export class TableDetail extends React.Component<
return descriptions.map((d) => (
<EditableSection key={`prog_desc:${d.source}`} title={d.source} readOnly>
<EditableText
maxLength={999999}
value={d.text}
editable={false}
onSubmitValue={null}
/>
<EditableText maxLength={999999} value={d.text} editable={false} />
</EditableSection>
));
};
......@@ -327,7 +322,7 @@ export class TableDetail extends React.Component<
title={Constants.DESCRIPTION_TITLE}
readOnly={!data.is_editable}
editText={editText}
editUrl={editUrl}
editUrl={editUrl || undefined}
>
<TableDescEditableText
maxLength={getMaxLength('tableDescLength')}
......
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