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

Add spinner so policy links don't break #5439

Merged
merged 1 commit into from
Sep 23, 2021
Merged
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
29 changes: 6 additions & 23 deletions src/pages/workspace/WorkspaceSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ import themedefault from '../../styles/themes/default';
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../components/withWindowDimensions';
import compose from '../../libs/compose';
import Growl from '../../libs/Growl';
import ONYXKEYS from '../../ONYXKEYS';
import Avatar from '../../components/Avatar';
import CONST from '../../CONST';
import Tooltip from '../../components/Tooltip';
import variables from '../../styles/variables';
import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator';

const propTypes = {
/** Whether the current screen is focused. */
Expand All @@ -43,24 +42,21 @@ const propTypes = {
name: PropTypes.string,
}),

/** All the polices that we have loaded in Onyx */
allPolicies: PropTypes.shape({
/** ID of the policy */
id: PropTypes.string,
}),

...withLocalizePropTypes,
...windowDimensionsPropTypes,
};

const defaultProps = {
policy: {},
allPolicies: null,
};

const WorkspaceSidebar = ({
translate, isSmallScreenWidth, policy, allPolicies, isFocused,
translate, isSmallScreenWidth, policy, isFocused,
}) => {
if (_.isEmpty(policy)) {
return <FullScreenLoadingIndicator />;
}

const menuItems = [
{
translationKey: 'workspace.common.card',
Expand All @@ -80,16 +76,6 @@ const WorkspaceSidebar = ({
},
];

// After all the policies have loaded, we can know if the given policyID points to a nonexistant workspace
// When free plan is out of beta and Permissions.canUseFreePlan() gets removed,
// all code involving 'allPolicies' can be removed since policy loading will no longer be delayed on login.
if (allPolicies !== null && _.isEmpty(policy)) {
Growl.error(translate('workspace.error.growlMessageInvalidPolicy'), CONST.GROWL.DURATION_LONG);
Navigation.dismissModal();
return null;
}


const openEditor = () => Navigation.navigate(ROUTES.getWorkspaceEditorRoute(policy.id));

return (
Expand Down Expand Up @@ -204,8 +190,5 @@ export default compose(
return `${ONYXKEYS.COLLECTION.POLICY}${policyID}`;
},
},
allPolicies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
}),
)(WorkspaceSidebar);