Skip to content

Commit 1466f7c

Browse files
Properly close login modal during project setup (#5647)
* write failing test for login modal not closing during project setup * add closeLogin, openLogin to authStore * update test to click Continue before setup can proceed * add event listeners to fix this strange modal flow
1 parent 98063ae commit 1466f7c

File tree

8 files changed

+43
-6
lines changed

8 files changed

+43
-6
lines changed

packages/desktop-gui/cypress/integration/setup_project_modal_spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,20 @@ describe('Set Up Project', function () {
447447
cy.get('.modal').contains('Log In to Dashboard')
448448
})
449449

450+
it('closes login modal', () => {
451+
cy.get('.modal').contains('Log In to Dashboard')
452+
cy.get('.close').click()
453+
cy.get('.btn').contains('Set up project').click()
454+
})
455+
450456
describe('when login succeeds', function () {
451457
beforeEach(function () {
452458
cy.stub(this.ipc, 'beginAuth').resolves(this.user)
453459
cy.contains('button', 'Log In to Dashboard').click()
454460
})
455461

456462
it('shows setup', () => {
463+
cy.get('.login-content > .btn').click()
457464
cy.contains('h4', 'Set up project')
458465
})
459466
})

packages/desktop-gui/src/app/nav.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export default class Nav extends Component {
127127
}
128128

129129
_showLogin () {
130-
authStore.setShowingLogin(true)
130+
authStore.openLogin()
131131
}
132132

133133
_openDocs (e) {

packages/desktop-gui/src/auth/auth-store.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,20 @@ class AuthStore {
1919
this.message = message
2020
}
2121

22-
@action setShowingLogin (isShowing) {
22+
@action openLogin (onCloseCb) {
23+
this.onCloseCb = onCloseCb
24+
25+
this.setMessage(null)
26+
this.isShowingLogin = true
27+
}
28+
29+
@action closeLogin () {
30+
if (this.onCloseCb) {
31+
this.onCloseCb(this.isAuthenticated)
32+
}
33+
2334
this.setMessage(null)
24-
this.isShowingLogin = isShowing
35+
this.isShowingLogin = false
2536
}
2637

2738
@action setUser (user) {

packages/desktop-gui/src/auth/login-modal.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import authStore from './auth-store'
88
import ipc from '../lib/ipc'
99

1010
const close = () => {
11-
authStore.setShowingLogin(false)
11+
authStore.closeLogin()
1212
}
1313

1414
// LoginContent is a separate component so that it pings the api

packages/desktop-gui/src/runs/project-not-setup.jsx

+17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import BootstrapModal from 'react-bootstrap-modal'
66
import ipc from '../lib/ipc'
77
import { configFileFormatted } from '../lib/config-file-formatted'
88
import SetupProject from './setup-project-modal'
9+
import authStore from '../auth/auth-store'
910

1011
@observer
1112
export default class ProjectNotSetup extends Component {
@@ -92,6 +93,22 @@ export default class ProjectNotSetup extends Component {
9293
_projectSetup () {
9394
if (!this.state.setupProjectModalOpen) return null
9495

96+
if (!this.props.isAuthenticated) {
97+
authStore.openLogin((isAuthenticated) => {
98+
if (!isAuthenticated) {
99+
// auth was canceled, cancel project setup too
100+
this.setState({ setupProjectModalOpen: false })
101+
}
102+
})
103+
104+
return null
105+
}
106+
107+
if (this.props.isShowingLogin) {
108+
// login dialog still open, wait for it to close before proceeding
109+
return null
110+
}
111+
95112
return (
96113
<SetupProject
97114
project={this.props.project}

packages/desktop-gui/src/runs/runs-list.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ class RunsList extends Component {
290290
_projectNotSetup (isValid = true) {
291291
return (
292292
<ProjectNotSetup
293+
isAuthenticated={authStore.isAuthenticated}
294+
isShowingLogin={authStore.isShowingLogin}
293295
project={this.props.project}
294296
isValid={isValid}
295297
onSetup={this._setProjectDetails}

packages/desktop-gui/src/runs/setup-project-modal.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class SetupProject extends Component {
7070

7171
render () {
7272
if (!authStore.isAuthenticated) {
73-
authStore.setShowingLogin(true)
73+
authStore.openLogin()
7474

7575
return null
7676
}

packages/desktop-gui/src/settings/record-key.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const openRecordKeyGuide = (e) => {
2222
}
2323

2424
const showLogin = () => {
25-
authStore.setShowingLogin(true)
25+
authStore.openLogin()
2626
}
2727

2828
@observer

0 commit comments

Comments
 (0)