Skip to content

Commit

Permalink
Remove a warning when deleting a remote profile
Browse files Browse the repository at this point in the history
  • Loading branch information
julienw committed Jan 9, 2025
1 parent 9b072f8 commit 61f1010
Showing 1 changed file with 23 additions and 31 deletions.
54 changes: 23 additions & 31 deletions src/components/app/MenuButtons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type DispatchProps = {|

type Props = ConnectedProps<OwnProps, StateProps, DispatchProps>;
type State = $ReadOnly<{|
metaInfoPanelState: 'initial' | 'delete-confirmation' | 'profile-deleted',
metaInfoPanelState: 'initial' | 'delete-confirmation',
|}>;

class MenuButtonsImpl extends React.PureComponent<Props, State> {
Expand Down Expand Up @@ -129,9 +129,6 @@ class MenuButtonsImpl extends React.PureComponent<Props, State> {

_onProfileDeleted = () => {
this.props.profileRemotelyDeleted();
this.setState({
metaInfoPanelState: 'profile-deleted',
});
};

_resetMetaInfoState = () => {
Expand Down Expand Up @@ -196,42 +193,37 @@ class MenuButtonsImpl extends React.PureComponent<Props, State> {
);
}

case 'delete-confirmation': {
if (!currentProfileUploadedInformation) {
throw new Error(
`We're in the state "delete-confirmation" but there's no stored data for this profile, this should not happen.`
);
}

const { name, profileToken, jwtToken } =
currentProfileUploadedInformation;

if (!jwtToken) {
throw new Error(
`We're in the state "delete-confirmation" but there's no JWT token for this profile, this should not happen.`
case 'delete-confirmation':
if (currentProfileUploadedInformation) {
const { name, profileToken, jwtToken } =
currentProfileUploadedInformation;

if (!jwtToken) {
throw new Error(

Check warning on line 202 in src/components/app/MenuButtons/index.js

View check run for this annotation

Codecov / codecov/patch

src/components/app/MenuButtons/index.js#L202

Added line #L202 was not covered by tests
`We're in the state "delete-confirmation" but there's no JWT token for this profile, this should not happen.`
);
}

const slicedProfileToken = profileToken.slice(0, 6);
const profileName = name ? name : `Profile #${slicedProfileToken}`;
return (
<ProfileDeletePanel
profileName={profileName}
profileToken={profileToken}
jwtToken={jwtToken}
onProfileDeleted={this._onProfileDeleted}
onProfileDeleteCanceled={this._resetMetaInfoState}
/>
);
}

const slicedProfileToken = profileToken.slice(0, 6);
const profileName = name ? name : `Profile #${slicedProfileToken}`;
return (
<ProfileDeletePanel
profileName={profileName}
profileToken={profileToken}
jwtToken={jwtToken}
onProfileDeleted={this._onProfileDeleted}
onProfileDeleteCanceled={this._resetMetaInfoState}
/>
);
}
// The profile data has been deleted

case 'profile-deleted':
// Note that <ProfileDeletePanel> can also render <ProfileDeleteSuccess>
// in some situations. However it's not suitable for this case, because
// we still have to pass jwtToken / profileToken, and we don't have
// these values anymore when we're in this state.
return <ProfileDeleteSuccess />;

default:
throw assertExhaustiveCheck(metaInfoPanelState);
}
Expand Down

0 comments on commit 61f1010

Please sign in to comment.