Skip to content

Commit 8649636

Browse files
authored
Merge pull request #14156 from jatinsonijs/show-workspace-list-empty-state-immediate
Fix workspace list empty state not showing immediate
2 parents 413c1e6 + 3ae1289 commit 8649636

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/libs/PolicyUtils.js

+22
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,31 @@ function getPolicyBrickRoadIndicatorStatus(policy, policyMembers) {
5454
return '';
5555
}
5656

57+
/**
58+
* Check if the policy can be displayed
59+
* If offline, always show the policy pending deletion.
60+
* If online, show the policy pending deletion only if there is an error.
61+
* Note: Using a local ONYXKEYS.NETWORK subscription will cause a delay in
62+
* updating the screen. Passing the offline status from the component.
63+
* @param {Object} policy
64+
* @param {Boolean} isOffline
65+
* @returns {Boolean}
66+
*/
67+
function shouldShowPolicy(policy, isOffline) {
68+
return policy
69+
&& policy.type === CONST.POLICY.TYPE.FREE
70+
&& policy.role === CONST.POLICY.ROLE.ADMIN
71+
&& (
72+
isOffline
73+
|| policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE
74+
|| !_.isEmpty(policy.errors)
75+
);
76+
}
77+
5778
export {
5879
hasPolicyMemberError,
5980
hasPolicyError,
6081
hasCustomUnitsError,
6182
getPolicyBrickRoadIndicatorStatus,
83+
shouldShowPolicy,
6284
};

src/pages/settings/InitialSettingsPage.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@ class InitialSettingsPage extends React.Component {
130130
*/
131131
getDefaultMenuItems() {
132132
const policiesAvatars = _.chain(this.props.policies)
133-
.filter(policy => policy
134-
&& policy.type === CONST.POLICY.TYPE.FREE
135-
&& policy.role === CONST.POLICY.ROLE.ADMIN
136-
&& policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)
133+
.filter(policy => PolicyUtils.shouldShowPolicy(policy, this.props.network.isOffline))
137134
.sortBy(policy => policy.name)
138135
.pluck('avatar')
139136
.value();

src/pages/workspace/WorkspacesListPage.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Permissions from '../../libs/Permissions';
2323
import Button from '../../components/Button';
2424
import FixedFooter from '../../components/FixedFooter';
2525
import BlockingView from '../../components/BlockingViews/BlockingView';
26+
import {withNetwork} from '../../components/OnyxProvider';
2627

2728
const propTypes = {
2829
/* Onyx Props */
@@ -115,7 +116,7 @@ class WorkspacesListPage extends Component {
115116
*/
116117
getWorkspaces() {
117118
return _.chain(this.props.policies)
118-
.filter(policy => policy && policy.type === CONST.POLICY.TYPE.FREE && policy.role === CONST.POLICY.ROLE.ADMIN)
119+
.filter(policy => PolicyUtils.shouldShowPolicy(policy, this.props.network.isOffline))
119120
.map(policy => ({
120121
title: policy.name,
121122
icon: policy.avatar ? policy.avatar : Expensicons.Building,
@@ -208,6 +209,7 @@ WorkspacesListPage.defaultProps = defaultProps;
208209

209210
export default compose(
210211
withLocalize,
212+
withNetwork(),
211213
withOnyx({
212214
policies: {
213215
key: ONYXKEYS.COLLECTION.POLICY,

0 commit comments

Comments
 (0)