Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Commit

Permalink
#352 Disable actions that require an internet connection (#368)
Browse files Browse the repository at this point in the history
* Online check component added

* add reducer & action for online check component.

also included in App.js

* removed sidebar functionality when offline

* removed depedency functionality when offline

* removed functionality from create new project wizard when offline

* fixed tests to align with disabled pattern

* add infoBanner to Z-indexes for future usage.

* removed random {' '}, changed IS_ONLINE_CHECK to SET_ONLINE_STATUS

* pull request requested changes

missed one file.

* updated infobar to be fixed header.

* flow fix

* remove random whitespace

* Pull request changes

remove state type, move styled components to before redux part, change background color of infobar to be transparent.

* enable menu items based on isOnline
  • Loading branch information
joshuaellis authored and AWolf81 committed Mar 19, 2019
1 parent 39a565e commit 7620e61
Show file tree
Hide file tree
Showing 24 changed files with 379 additions and 83 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,4 @@
"icon": null,
"createdAt": 1529502079329
}
}
}
10 changes: 9 additions & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
//
// Action Types
//
export const SET_ONLINE_STATUS = 'SET_ONLINE_STATUS';
export const REFRESH_PROJECTS_START = 'REFRESH_PROJECTS_START';
export const REFRESH_PROJECTS_ERROR = 'REFRESH_PROJECTS_ERROR';
export const REFRESH_PROJECTS_FINISH = 'REFRESH_PROJECTS_FINISH';
Expand Down Expand Up @@ -89,6 +90,11 @@ export const RESET_STATUS_TEXT = 'RESET_STATUS_TEXT';
//
// Action Creators
//
export const setOnlineStatus = (onlineStatus: boolean) => ({
type: SET_ONLINE_STATUS,
onlineStatus,
});

export const addProject = (
project: ProjectInternal,
projectHomePath: string,
Expand Down Expand Up @@ -447,7 +453,9 @@ export const showResetStatePrompt = () => ({
type: SHOW_RESET_STATE_PROMPT,
});

export const resetAllState = () => ({ type: RESET_ALL_STATE });
export const resetAllState = () => ({
type: RESET_ALL_STATE,
});

// Status text for Loading screen
// todo: Check if we need a better naming as there are probably more status messages in the future.
Expand Down
2 changes: 2 additions & 0 deletions src/components/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import AppSettingsModal from '../AppSettingsModal';
import Initialization from '../Initialization';
import LoadingScreen from '../LoadingScreen';
import FeedbackButton from '../FeedbackButton';
import OnlineChecker from '../OnlineChecker';

import type { Project } from '../../types';

Expand All @@ -33,6 +34,7 @@ class App extends PureComponent<Props> {
{wasSuccessfullyInitialized =>
wasSuccessfullyInitialized && (
<Fragment>
<OnlineChecker />
<Titlebar />
<Wrapper>
<ApplicationMenu />
Expand Down
18 changes: 16 additions & 2 deletions src/components/ApplicationMenu/ApplicationMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
getProjectsArray,
} from '../../reducers/projects.reducer';
import { getDevServerTaskForProjectId } from '../../reducers/tasks.reducer';
import { getOnlineState } from '../../reducers/app-status.reducer';

import type { Project, Task } from '../../types';
import type { Dispatch } from '../../actions/types';
Expand All @@ -32,6 +33,7 @@ type Props = {
projects: Array<Project>,
selectedProject: ?Project,
devServerTask: ?Task,
isOnline: boolean,
createNewProjectStart: Dispatch<typeof actions.createNewProjectStart>,
showImportExistingProjectPrompt: Dispatch<
typeof actions.showImportExistingProjectPrompt
Expand All @@ -53,7 +55,10 @@ class ApplicationMenu extends Component<Props> {
}

componentDidUpdate(prevProps) {
if (this.props.selectedProject !== prevProps.selectedProject) {
if (
this.props.selectedProject !== prevProps.selectedProject ||
this.props.isOnline !== prevProps.isOnline
) {
this.buildMenu(this.props);
}
}
Expand All @@ -76,6 +81,7 @@ class ApplicationMenu extends Component<Props> {
selectProject,
projects,
reinstallDependencies,
isOnline,
} = props;

const template = [
Expand All @@ -87,13 +93,15 @@ class ApplicationMenu extends Component<Props> {
label: isMac ? 'Create New Project' : 'Create &new project',
click: createNewProjectStart,
accelerator: 'CmdOrCtrl+N',
enabled: isOnline,
},
{
label: isMac
? 'Import Existing Project...'
: '&Import existing project...',
click: showImportExistingProjectPrompt,
accelerator: 'CmdOrCtrl+I',
enabled: isOnline,
},
],
},
Expand Down Expand Up @@ -233,6 +241,7 @@ class ApplicationMenu extends Component<Props> {
label: isMac ? 'Reinstall Dependencies' : 'Reinstall dependencies',
click: () => reinstallDependencies(selectedProject.id),
accelerator: 'CmdOrCtrl+alt+R',
enabled: isOnline,
},
{ type: 'separator' },
];
Expand Down Expand Up @@ -308,7 +317,12 @@ const mapStateToProps = state => {
: null;

const projects = getProjectsArray(state);
return { selectedProject, devServerTask, projects };
return {
selectedProject,
devServerTask,
projects,
isOnline: getOnlineState(state),
};
};

const mapDispatchToProps = {
Expand Down
1 change: 1 addition & 0 deletions src/components/Button/ButtonBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const ButtonBaseStyles = styled.button`
&:disabled {
filter: grayscale(100%);
opacity: 0.75;
cursor: initial;
}
&:not(:disabled):active {
Expand Down
1 change: 1 addition & 0 deletions src/components/Button/FillButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Props = {
hoverColors?: Array<string>,
textColor: string,
children: React$Node,
disabled?: boolean,
};

export const wrapColorsInGradient = (colors?: Array<string> | string) => {
Expand Down
8 changes: 8 additions & 0 deletions src/components/Button/__snapshots__/ButtonBase.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ exports[`ButtonBase component Button with size prop should render button for lar
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
opacity: 0.75;
cursor: initial;
}
.c1:not(:disabled):active {
Expand Down Expand Up @@ -91,6 +92,7 @@ exports[`ButtonBase component Button with size prop should render button for lar
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
opacity: 0.75;
cursor: initial;
}
.c1:not(:disabled):active {
Expand Down Expand Up @@ -158,6 +160,7 @@ exports[`ButtonBase component Button with size prop should render button for med
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
opacity: 0.75;
cursor: initial;
}
.c1:not(:disabled):active {
Expand Down Expand Up @@ -222,6 +225,7 @@ exports[`ButtonBase component Button with size prop should render button for med
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
opacity: 0.75;
cursor: initial;
}
.c1:not(:disabled):active {
Expand Down Expand Up @@ -289,6 +293,7 @@ exports[`ButtonBase component Button with size prop should render button for sma
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
opacity: 0.75;
cursor: initial;
}
.c1:not(:disabled):active {
Expand Down Expand Up @@ -353,6 +358,7 @@ exports[`ButtonBase component Button with size prop should render button for sma
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
opacity: 0.75;
cursor: initial;
}
.c1:not(:disabled):active {
Expand Down Expand Up @@ -420,6 +426,7 @@ exports[`ButtonBase component Button with size prop should render button for xsm
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
opacity: 0.75;
cursor: initial;
}
.c1:not(:disabled):active {
Expand Down Expand Up @@ -484,6 +491,7 @@ exports[`ButtonBase component Button with size prop should render button for xsm
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
opacity: 0.75;
cursor: initial;
}
.c1:not(:disabled):active {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ exports[`FillButton component should render button filled 1`] = `
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
opacity: 0.75;
cursor: initial;
}
.c1:not(:disabled):active {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ exports[`StrokeButton component should render button with stroke outline 1`] = `
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
opacity: 0.75;
cursor: initial;
}
.c3:not(:disabled):active {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ exports[`ButtonWithIcon component should render button with icon 1`] = `
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
opacity: 0.75;
cursor: initial;
}
.c3:not(:disabled):active {
Expand Down
39 changes: 32 additions & 7 deletions src/components/CreateNewProjectWizard/CreateNewProjectWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getDefaultProjectPath,
} from '../../reducers/app-settings.reducer';
import { getById } from '../../reducers/projects.reducer';
import { getOnlineState } from '../../reducers/app-status.reducer';
import { getOnboardingCompleted } from '../../reducers/onboarding-status.reducer';
import { getProjectNameSlug } from '../../services/create-project.service';
import { checkIfProjectExists } from '../../services/create-project.service';
Expand Down Expand Up @@ -38,13 +39,16 @@ const { dialog } = remote;

type Props = {
settings: AppSettings,
projects: { [projectId: string]: ProjectInternal },
projects: {
[projectId: string]: ProjectInternal,
},
projectHomePath: string,
isVisible: boolean,
isOnboardingCompleted: boolean,
addProject: Dispatch<typeof actions.addProject>,
createNewProjectCancel: Dispatch<typeof actions.createNewProjectCancel>,
createNewProjectFinish: Dispatch<typeof actions.createNewProjectFinish>,
isOnline: boolean,
};

type State = {
Expand Down Expand Up @@ -84,15 +88,20 @@ class CreateNewProjectWizard extends PureComponent<Props, State> {
}
updateFieldValue = (field: Field, value: any) => {
this.setState({ [field]: value, activeField: field });
this.setState({
[field]: value,
activeField: field,
});
if (field === 'projectName') {
this.verifyProjectNameUniqueness(value);
}
};
focusField = (field: ?Field) => {
this.setState({ activeField: field });
this.setState({
activeField: field,
});
};
verifyProjectNameUniqueness = (name: string) => {
Expand All @@ -105,13 +114,17 @@ class CreateNewProjectWizard extends PureComponent<Props, State> {
);
if (isAlreadyTaken) {
this.setState({ isProjectNameTaken: true });
this.setState({
isProjectNameTaken: true,
});
return;
}
// If this update fixes the problem, unset the error status
if (!isAlreadyTaken && this.state.isProjectNameTaken) {
this.setState({ isProjectNameTaken: false });
this.setState({
isProjectNameTaken: false,
});
}
};
Expand Down Expand Up @@ -226,7 +239,12 @@ class CreateNewProjectWizard extends PureComponent<Props, State> {
};

render() {
const { isVisible, createNewProjectCancel, projectHomePath } = this.props;
const {
isVisible,
createNewProjectCancel,
projectHomePath,
isOnline,
} = this.props;
const {
projectName,
projectType,
Expand All @@ -238,7 +256,12 @@ class CreateNewProjectWizard extends PureComponent<Props, State> {
isProjectNameTaken,
} = this.state;

const project = { projectName, projectType, projectIcon, projectStarter };
const project = {
projectName,
projectType,
projectIcon,
projectStarter,
};

const readyToBeBuilt = status !== 'filling-in-form';

Expand Down Expand Up @@ -271,6 +294,7 @@ class CreateNewProjectWizard extends PureComponent<Props, State> {
handleSubmit={this.handleSubmit}
hasBeenSubmitted={status !== 'filling-in-form'}
isProjectNameTaken={isProjectNameTaken}
isOnline={isOnline}
/>
}
backface={
Expand All @@ -295,6 +319,7 @@ const mapStateToProps = state => ({
isVisible: state.modal === 'new-project-wizard',
isOnboardingCompleted: getOnboardingCompleted(state),
settings: getAppSettings(state),
isOnline: getOnlineState(state),
});

const mapDispatchToProps = {
Expand Down
12 changes: 9 additions & 3 deletions src/components/CreateNewProjectWizard/MainPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Props = {
updateFieldValue: (field: Field, value: any) => void,
focusField: (field: ?Field) => void,
handleSubmit: () => Promise<any> | void,
isOnline: boolean,
};

class MainPane extends PureComponent<Props> {
Expand Down Expand Up @@ -141,14 +142,19 @@ class MainPane extends PureComponent<Props> {
hasBeenSubmitted,
isProjectNameTaken,
handleSubmit,
isOnline,
} = this.props;

const { lastIndex, steps } = this.renderConditionalSteps(currentStepIndex);
return (
<Fragment>
<Spring
from={{ offset: currentStepIndex === 0 ? 0 : 50 }}
to={{ offset: currentStepIndex === 0 ? 50 : 0 }}
from={{
offset: currentStepIndex === 0 ? 0 : 50,
}}
to={{
offset: currentStepIndex === 0 ? 50 : 0,
}}
native
>
{({ offset }) => (
Expand All @@ -163,7 +169,6 @@ class MainPane extends PureComponent<Props> {
isProjectNameTaken={isProjectNameTaken}
/>
<ProjectPath projectName={projectName} />

{steps}
</Wrapper>
)}
Expand All @@ -175,6 +180,7 @@ class MainPane extends PureComponent<Props> {
!projectName ||
this.isSubmitDisabled(currentStepIndex, lastIndex)
}
isOnline={isOnline}
readyToBeSubmitted={currentStepIndex >= lastIndex}
hasBeenSubmitted={hasBeenSubmitted}
onSubmit={handleSubmit}
Expand Down
Loading

0 comments on commit 7620e61

Please sign in to comment.