Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide Threads with No Comments from LHN #19375

Merged
merged 19 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import SafeArea from './components/SafeArea';
import * as Environment from './libs/Environment/Environment';
import {WindowDimensionsProvider} from './components/withWindowDimensions';
import {KeyboardStateProvider} from './components/withKeyboardState';
import {CurrentReportIdContextProvider} from './components/withCurrentReportId';
import {CurrentReportIDContextProvider} from './components/withCurrentReportID';

// For easier debugging and development, when we are in web we expose Onyx to the window, so you can more easily set data into Onyx
if (window && Environment.isDevelopment()) {
Expand Down Expand Up @@ -46,7 +46,7 @@ function App() {
HTMLEngineProvider,
WindowDimensionsProvider,
KeyboardStateProvider,
CurrentReportIdContextProvider,
CurrentReportIDContextProvider,
PickerStateProvider,
]}
>
Expand Down
76 changes: 76 additions & 0 deletions src/components/withCurrentReportID.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React, {createContext, forwardRef, useCallback, useState, useMemo} from 'react';
import PropTypes from 'prop-types';

import getComponentDisplayName from '../libs/getComponentDisplayName';
import Navigation from '../libs/Navigation/Navigation';

const CurrentReportIDContext = createContext(null);

const withCurrentReportIDPropTypes = {
/** Function to update the state */
updateCurrentReportID: PropTypes.func.isRequired,

/** The top most report id */
currentReportID: PropTypes.string,
};

const withCurrentReportIDDefaultProps = {
currentReportID: '',
};
Comment on lines +17 to +19
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is just a rename and I added this!

Copy link
Contributor Author

@grgia grgia Jun 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this more clear, I mean I added withCurrentReportIDDefaultProps and capitalized all instances of Id as ID


function CurrentReportIDContextProvider(props) {
const [currentReportID, setCurrentReportID] = useState('');

/**
* This function is used to update the currentReportID
* @param {Object} state root navigation state
*/
const updateCurrentReportID = useCallback(
(state) => {
setCurrentReportID(Navigation.getTopmostReportId(state));
},
[setCurrentReportID],
);

/**
* The context this component exposes to child components
* @returns {Object} currentReportID to share between central pane and LHN
*/
const contextValue = useMemo(
() => ({
updateCurrentReportID,
currentReportID,
}),
[updateCurrentReportID, currentReportID],
);

return <CurrentReportIDContext.Provider value={contextValue}>{props.children}</CurrentReportIDContext.Provider>;
}

CurrentReportIDContextProvider.displayName = 'CurrentReportIDContextProvider';
CurrentReportIDContextProvider.propTypes = {
/** Actual content wrapped by this component */
children: PropTypes.node.isRequired,
};

export default function withCurrentReportID(WrappedComponent) {
const WithCurrentReportID = forwardRef((props, ref) => (
<CurrentReportIDContext.Consumer>
{(currentReportIDUtils) => (
<WrappedComponent
// eslint-disable-next-line react/jsx-props-no-spreading
{...currentReportIDUtils}
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
/>
)}
</CurrentReportIDContext.Consumer>
));

WithCurrentReportID.displayName = `withCurrentReportID(${getComponentDisplayName(WrappedComponent)})`;

return WithCurrentReportID;
}

export {withCurrentReportIDPropTypes, withCurrentReportIDDefaultProps, CurrentReportIDContextProvider};
72 changes: 0 additions & 72 deletions src/components/withCurrentReportId.js

This file was deleted.

8 changes: 4 additions & 4 deletions src/libs/Navigation/NavigationRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import AppNavigator from './AppNavigator';
import themeColors from '../../styles/themes/default';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../components/withWindowDimensions';
import Log from '../Log';
import withCurrentReportId, {withCurrentReportIdPropTypes} from '../../components/withCurrentReportId';
import withCurrentReportID, {withCurrentReportIDPropTypes} from '../../components/withCurrentReportID';
import compose from '../compose';

// https://reactnavigation.org/docs/themes
Expand All @@ -28,7 +28,7 @@ const propTypes = {

/** Fired when react-navigation is ready */
onReady: PropTypes.func.isRequired,
...withCurrentReportIdPropTypes,
...withCurrentReportIDPropTypes,
};

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ function NavigationRoot(props) {
return;
}
navigationStateRef.current = state;
props.updateCurrentReportId(state);
props.updateCurrentReportID(state);
parseAndLogRoute(state);
};

Expand All @@ -85,4 +85,4 @@ function NavigationRoot(props) {

NavigationRoot.displayName = 'NavigationRoot';
NavigationRoot.propTypes = propTypes;
export default compose(withWindowDimensions, withCurrentReportId)(NavigationRoot);
export default compose(withWindowDimensions, withCurrentReportID)(NavigationRoot);
5 changes: 5 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,11 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouRep
return false;
}

// Hide thread reports that haven't been commented on
if (isThread(report) && !report.lastMessageText) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return false;
}

return true;
}

Expand Down
12 changes: 6 additions & 6 deletions src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import SidebarUtils from '../../../libs/SidebarUtils';
import reportPropTypes from '../../reportPropTypes';
import OfflineWithFeedback from '../../../components/OfflineWithFeedback';
import withNavigationFocus from '../../../components/withNavigationFocus';
import withCurrentReportId, {withCurrentReportIdPropTypes} from '../../../components/withCurrentReportId';
import withCurrentReportID, {withCurrentReportIDPropTypes, withCurrentReportIDDefaultProps} from '../../../components/withCurrentReportID';
import withNavigation, {withNavigationPropTypes} from '../../../components/withNavigation';
import Header from '../../../components/Header';
import defaultTheme from '../../../styles/themes/default';
Expand Down Expand Up @@ -87,8 +87,8 @@ const propTypes = {
willAlertModalBecomeVisible: PropTypes.bool,
}),

...withCurrentReportIDPropTypes,
...withLocalizePropTypes,
...withCurrentReportIdPropTypes,
...withNavigationPropTypes,
};

Expand All @@ -101,6 +101,7 @@ const defaultProps = {
},
priorityMode: CONST.PRIORITY_MODE.DEFAULT,
modal: {},
...withCurrentReportIDDefaultProps,
};

class SidebarLinks extends React.Component {
Expand Down Expand Up @@ -180,8 +181,7 @@ class SidebarLinks extends React.Component {

render() {
const isLoading = _.isEmpty(this.props.personalDetails) || _.isEmpty(this.props.chatReports);
const optionListItems = SidebarUtils.getOrderedReportIDs(this.props.currentReportId);

const optionListItems = SidebarUtils.getOrderedReportIDs(this.props.currentReportID);
const skeletonPlaceholder = <OptionsListSkeletonView shouldAnimate />;

return (
Expand Down Expand Up @@ -245,7 +245,7 @@ class SidebarLinks extends React.Component {
<LHNOptionsList
contentContainerStyles={[styles.sidebarListContainer, {paddingBottom: StyleUtils.getSafeAreaMargins(this.props.insets).marginBottom}]}
data={optionListItems}
focusedIndex={_.findIndex(optionListItems, (option) => option.toString() === this.props.currentReportId)}
focusedIndex={_.findIndex(optionListItems, (option) => option.toString() === this.props.currentReportID)}
onSelectRow={this.showReportPage}
shouldDisableFocusOptions={this.props.isSmallScreenWidth}
optionMode={this.props.priorityMode === CONST.PRIORITY_MODE.GSD ? CONST.OPTION_MODE.COMPACT : CONST.OPTION_MODE.DEFAULT}
Expand Down Expand Up @@ -335,7 +335,7 @@ export default compose(
withCurrentUserPersonalDetails,
withNavigationFocus,
withWindowDimensions,
withCurrentReportId,
withCurrentReportID,
withNavigation,
withOnyx({
// Note: It is very important that the keys subscribed to here are the same
Expand Down
16 changes: 8 additions & 8 deletions tests/utils/LHNTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ function getAdvancedFakeReport(isArchived, isUserCreatedPolicyRoom, hasAddWorksp
}

/**
* @param {String} [currentReportId]
* @param {String} [currentReportID]
*/
function getDefaultRenderedSidebarLinks(currentReportId = '') {
function getDefaultRenderedSidebarLinks(currentReportID = '') {
// An ErrorBoundary needs to be added to the rendering so that any errors that happen while the component
// renders are logged to the console. Without an error boundary, Jest only reports the error like "The above error
// occurred in your component", except, there is no "above error". It's just swallowed up by Jest somewhere.
Expand Down Expand Up @@ -196,16 +196,16 @@ function getDefaultRenderedSidebarLinks(currentReportId = '') {
// our app (App.js) is when the react application is wrapped in the context providers
render(
<ErrorBoundary>
<MockedSidebarLinks currentReportId={currentReportId} />
<MockedSidebarLinks currentReportID={currentReportID} />
</ErrorBoundary>,
);
}

/**
* @param {String} [currentReportId]
* @param {String} [currentReportID]
* @returns {JSX.Element}
*/
function MockedSidebarLinks({currentReportId}) {
function MockedSidebarLinks({currentReportID}) {
return (
<ComposeProviders components={[OnyxProvider, LocaleContextProvider]}>
<SidebarLinks
Expand All @@ -217,18 +217,18 @@ function MockedSidebarLinks({currentReportId}) {
bottom: 0,
}}
isSmallScreenWidth={false}
currentReportId={currentReportId}
currentReportID={currentReportID}
/>
</ComposeProviders>
);
}

MockedSidebarLinks.propTypes = {
currentReportId: PropTypes.string,
currentReportID: PropTypes.string,
};

MockedSidebarLinks.defaultProps = {
currentReportId: '',
currentReportID: '',
};

export {fakePersonalDetails, getDefaultRenderedSidebarLinks, getAdvancedFakeReport, getFakeReport, getFakeReportAction, MockedSidebarLinks};