Make RelinkDialog supersede the NetworkDialog

This commit is contained in:
Josh Perez 2020-04-27 18:36:49 -04:00 committed by Scott Nonnenberg
parent 1b5c36a9a8
commit 752cd75c54
5 changed files with 9 additions and 26 deletions

View file

@ -393,9 +393,9 @@ export class LeftPane extends React.Component<PropsType> {
{showArchived ? this.renderArchivedHeader() : renderMainHeader()} {showArchived ? this.renderArchivedHeader() : renderMainHeader()}
</div> </div>
{renderExpiredBuildDialog()} {renderExpiredBuildDialog()}
{renderRelinkDialog()}
{renderNetworkStatus()} {renderNetworkStatus()}
{renderUpdateDialog()} {renderUpdateDialog()}
{renderRelinkDialog()}
{showArchived && ( {showArchived && (
<div className="module-left-pane__archive-helper-text" key={0}> <div className="module-left-pane__archive-helper-text" key={0}>
{i18n('archiveHelperText')} {i18n('archiveHelperText')}

View file

@ -13,7 +13,6 @@ import { action } from '@storybook/addon-actions';
const i18n = setupI18n('en', enMessages); const i18n = setupI18n('en', enMessages);
const defaultProps = { const defaultProps = {
hasNetworkDialog: false,
i18n, i18n,
isRegistrationDone: true, isRegistrationDone: true,
relinkDevice: action('relink-device'), relinkDevice: action('relink-device'),
@ -21,31 +20,19 @@ const defaultProps = {
const permutations = [ const permutations = [
{ {
title: 'Unlinked (online)', title: 'Unlinked',
props: { props: {
isRegistrationDone: false, isRegistrationDone: false,
}, },
}, },
{
title: 'Unlinked (offline)',
props: {
hasNetworkDialog: true,
isRegistrationDone: false,
},
},
]; ];
storiesOf('Components/RelinkDialog', module) storiesOf('Components/RelinkDialog', module)
.add('Knobs Playground', () => { .add('Knobs Playground', () => {
const hasNetworkDialog = boolean('hasNetworkDialog', false);
const isRegistrationDone = boolean('isRegistrationDone', false); const isRegistrationDone = boolean('isRegistrationDone', false);
return ( return (
<RelinkDialog <RelinkDialog {...defaultProps} isRegistrationDone={isRegistrationDone} />
{...defaultProps}
hasNetworkDialog={hasNetworkDialog}
isRegistrationDone={isRegistrationDone}
/>
); );
}) })
.add('Iterations', () => { .add('Iterations', () => {

View file

@ -3,19 +3,17 @@ import React from 'react';
import { LocalizerType } from '../types/Util'; import { LocalizerType } from '../types/Util';
export interface PropsType { export interface PropsType {
hasNetworkDialog: boolean;
i18n: LocalizerType; i18n: LocalizerType;
isRegistrationDone: boolean; isRegistrationDone: boolean;
relinkDevice: () => void; relinkDevice: () => void;
} }
export const RelinkDialog = ({ export const RelinkDialog = ({
hasNetworkDialog,
i18n, i18n,
isRegistrationDone, isRegistrationDone,
relinkDevice, relinkDevice,
}: PropsType): JSX.Element | null => { }: PropsType): JSX.Element | null => {
if (hasNetworkDialog || isRegistrationDone) { if (isRegistrationDone) {
return null; return null;
} }

View file

@ -13,9 +13,9 @@ export const hasNetworkDialog = createSelector(
{ isOnline, socketStatus, withinConnectingGracePeriod }: NetworkStateType, { isOnline, socketStatus, withinConnectingGracePeriod }: NetworkStateType,
isRegistrationDone: boolean isRegistrationDone: boolean
): boolean => ): boolean =>
!isOnline || isRegistrationDone &&
!isRegistrationDone || (!isOnline ||
(socketStatus === WebSocket.CONNECTING && !withinConnectingGracePeriod) || (socketStatus === WebSocket.CONNECTING && !withinConnectingGracePeriod) ||
socketStatus === WebSocket.CLOSED || socketStatus === WebSocket.CLOSED ||
socketStatus === WebSocket.CLOSING socketStatus === WebSocket.CLOSING)
); );

View file

@ -3,12 +3,10 @@ import { mapDispatchToProps } from '../actions';
import { RelinkDialog } from '../../components/RelinkDialog'; import { RelinkDialog } from '../../components/RelinkDialog';
import { StateType } from '../reducer'; import { StateType } from '../reducer';
import { getIntl } from '../selectors/user'; import { getIntl } from '../selectors/user';
import { hasNetworkDialog } from '../selectors/network';
import { isDone } from '../../util/registration'; import { isDone } from '../../util/registration';
const mapStateToProps = (state: StateType) => { const mapStateToProps = (state: StateType) => {
return { return {
hasNetworkDialog: hasNetworkDialog(state),
i18n: getIntl(state), i18n: getIntl(state),
isRegistrationDone: isDone(), isRegistrationDone: isDone(),
}; };