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