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

Properly close login modal during project setup #5647

Merged
merged 4 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,20 @@ describe('Set Up Project', function () {
cy.get('.modal').contains('Log In to Dashboard')
})

it('closes login modal', () => {
cy.get('.modal').contains('Log In to Dashboard')
cy.get('.close').click()
cy.get('.btn').contains('Set up project').click()
})

describe('when login succeeds', function () {
beforeEach(function () {
cy.stub(this.ipc, 'beginAuth').resolves(this.user)
cy.contains('button', 'Log In to Dashboard').click()
})

it('shows setup', () => {
cy.get('.login-content > .btn').click()
cy.contains('h4', 'Set up project')
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-gui/src/app/nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default class Nav extends Component {
}

_showLogin () {
authStore.setShowingLogin(true)
authStore.openLogin()
}

_openDocs (e) {
Expand Down
15 changes: 13 additions & 2 deletions packages/desktop-gui/src/auth/auth-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,20 @@ class AuthStore {
this.message = message
}

@action setShowingLogin (isShowing) {
@action openLogin (onCloseCb) {
this.onCloseCb = onCloseCb

this.setMessage(null)
this.isShowingLogin = true
}

@action closeLogin () {
if (this.onCloseCb) {
this.onCloseCb(this.isAuthenticated)
}

this.setMessage(null)
this.isShowingLogin = isShowing
this.isShowingLogin = false
}

@action setUser (user) {
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-gui/src/auth/login-modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import authStore from './auth-store'
import ipc from '../lib/ipc'

const close = () => {
authStore.setShowingLogin(false)
authStore.closeLogin()
}

// LoginContent is a separate component so that it pings the api
Expand Down
17 changes: 17 additions & 0 deletions packages/desktop-gui/src/runs/project-not-setup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import BootstrapModal from 'react-bootstrap-modal'
import ipc from '../lib/ipc'
import { configFileFormatted } from '../lib/config-file-formatted'
import SetupProject from './setup-project-modal'
import authStore from '../auth/auth-store'

@observer
export default class ProjectNotSetup extends Component {
Expand Down Expand Up @@ -92,6 +93,22 @@ export default class ProjectNotSetup extends Component {
_projectSetup () {
if (!this.state.setupProjectModalOpen) return null

if (!this.props.isAuthenticated) {
authStore.openLogin((isAuthenticated) => {
if (!isAuthenticated) {
// auth was canceled, cancel project setup too
this.setState({ setupProjectModalOpen: false })
}
})

return null
}

if (this.props.isShowingLogin) {
// login dialog still open, wait for it to close before proceeding
return null
}

return (
<SetupProject
project={this.props.project}
Expand Down
2 changes: 2 additions & 0 deletions packages/desktop-gui/src/runs/runs-list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ class RunsList extends Component {
_projectNotSetup (isValid = true) {
return (
<ProjectNotSetup
isAuthenticated={authStore.isAuthenticated}
isShowingLogin={authStore.isShowingLogin}
project={this.props.project}
isValid={isValid}
onSetup={this._setProjectDetails}
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-gui/src/runs/setup-project-modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class SetupProject extends Component {

render () {
if (!authStore.isAuthenticated) {
authStore.setShowingLogin(true)
authStore.openLogin()

return null
}
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-gui/src/settings/record-key.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const openRecordKeyGuide = (e) => {
}

const showLogin = () => {
authStore.setShowingLogin(true)
authStore.openLogin()
}

@observer
Expand Down