Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 06f5f93

Browse files
author
Antonio Scandurra
authored
Merge pull request #183 from atom/move-package-outdated-notice-into-popover
Move package outdated notice into popover
2 parents 20477c3 + be5870f commit 06f5f93

6 files changed

Lines changed: 93 additions & 66 deletions

File tree

lib/package-outdated-component.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const etch = require('etch')
2+
const $ = etch.dom
3+
4+
module.exports =
5+
class PackageOutdatedComponent {
6+
constructor (props) {
7+
this.props = props
8+
etch.initialize(this)
9+
}
10+
11+
update (props) {
12+
Object.assign(this.props, props)
13+
return etch.update(this)
14+
}
15+
16+
render () {
17+
return $.div({className: 'PackageOutdatedComponent'},
18+
$.h3(null, 'Teletype is out of date'),
19+
$.p(null, 'You will need to update the package to resume collaborating.'),
20+
$.button(
21+
{
22+
ref: 'viewPackageSettingsButton',
23+
className: 'btn btn-primary btn-sm',
24+
onClick: this.viewPackageSettings
25+
},
26+
'View Package Settings'
27+
)
28+
)
29+
}
30+
31+
viewPackageSettings () {
32+
return this.props.workspace.open('atom://config/packages/teletype')
33+
}
34+
}

lib/popover-component.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ const etch = require('etch')
22
const $ = etch.dom
33
const PortalListComponent = require('./portal-list-component')
44
const SignInComponent = require('./sign-in-component')
5+
const PackageOutdatedComponent = require('./package-outdated-component')
56

67
module.exports =
78
class PopoverComponent {
89
constructor (props) {
910
this.props = props
10-
this.props.authenticationProvider.onDidChange(() => { this.update() })
11+
if (this.props.authenticationProvider) {
12+
this.props.authenticationProvider.onDidChange(() => { this.update() })
13+
}
1114
etch.initialize(this)
1215
}
1316

@@ -17,12 +20,17 @@ class PopoverComponent {
1720

1821
render () {
1922
const {
20-
authenticationProvider, portalBindingManager,
21-
commandRegistry, credentialCache, clipboard
23+
isClientOutdated, authenticationProvider, portalBindingManager,
24+
commandRegistry, credentialCache, clipboard, workspace
2225
} = this.props
2326

2427
let activeComponent
25-
if (this.props.authenticationProvider.isSignedIn()) {
28+
if (isClientOutdated) {
29+
activeComponent = $(PackageOutdatedComponent, {
30+
ref: 'packageOutdatedComponent',
31+
workspace
32+
})
33+
} else if (this.props.authenticationProvider.isSignedIn()) {
2634
activeComponent = $(PortalListComponent, {
2735
ref: 'portalListComponent',
2836
localUserIdentity: authenticationProvider.getIdentity(),

lib/portal-status-bar-indicator.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
const {CompositeDisposable} = require('atom')
12
const PopoverComponent = require('./popover-component')
23

34
module.exports =
45
class PortalStatusBarIndicator {
56
constructor (props) {
6-
this.element = buildElement()
7+
this.props = props
8+
this.subscriptions = new CompositeDisposable()
9+
this.element = buildElement(props)
710
this.popoverComponent = new PopoverComponent(props)
811
this.tooltip = props.tooltipManager.add(
912
this.element,
@@ -14,10 +17,13 @@ class PortalStatusBarIndicator {
1417
placement: 'top'
1518
}
1619
)
17-
this.portalBindingManager = props.portalBindingManager
18-
this.subscriptions = this.portalBindingManager.onDidChange(() => {
19-
this.updatePortalStatus()
20-
})
20+
21+
if (props.portalBindingManager) {
22+
this.portalBindingManager = props.portalBindingManager
23+
this.subscriptions.add(this.portalBindingManager.onDidChange(() => {
24+
this.updatePortalStatus()
25+
}))
26+
}
2127
}
2228

2329
showPopover () {
@@ -43,9 +49,10 @@ class PortalStatusBarIndicator {
4349
}
4450
}
4551

46-
function buildElement () {
52+
function buildElement (props) {
4753
const anchor = document.createElement('a')
4854
anchor.classList.add('PortalStatusBarIndicator', 'inline-block')
55+
if (props.isClientOutdated) anchor.classList.add('outdated')
4956

5057
const icon = document.createElement('span')
5158
icon.classList.add('icon', 'icon-radio-tower')

lib/teletype-package.js

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,17 @@ class TeletypePackage {
9797

9898
async consumeStatusBar (statusBar) {
9999
const teletypeClient = await this.getClient()
100-
if (!teletypeClient) return
101-
102100
const portalBindingManager = await this.getPortalBindingManager()
103-
if (!portalBindingManager) return
104-
105101
const authenticationProvider = await this.getAuthenticationProvider()
106-
if (!authenticationProvider) return
107-
108102
this.portalStatusBarIndicator = new PortalStatusBarIndicator({
109103
teletypeClient,
110104
portalBindingManager,
111105
authenticationProvider,
106+
isClientOutdated: this.isClientOutdated,
112107
tooltipManager: this.tooltipManager,
113108
commandRegistry: this.commandRegistry,
114-
clipboard: this.clipboard
109+
clipboard: this.clipboard,
110+
workspace: this.workspace
115111
})
116112

117113
const PRIORITY_BETWEEN_BRANCH_NAME_AND_GRAMMAR = -40
@@ -207,28 +203,14 @@ class TeletypePackage {
207203
await this.client.initialize()
208204
return this.client
209205
} catch (error) {
210-
let message, description, buttons
211206
if (error instanceof Errors.ClientOutOfDateError) {
212-
message = 'The teletype package is out of date'
213-
description = 'You will need to update the package to continue collaborating.'
214-
buttons = [{
215-
text: 'View Package Settings',
216-
onDidClick: () => {
217-
this.workspace.open('atom://config/packages/teletype')
218-
notification.dismiss()
219-
}
220-
}]
207+
this.isClientOutdated = true
221208
} else {
222-
message = 'Failed to initialize the teletype package'
223-
description = `Establishing a teletype connection failed with error: <code>${error.message}</code>`
224-
buttons = null
209+
this.notificationManager.addError('Failed to initialize the teletype package', {
210+
description: `Establishing a teletype connection failed with error: <code>${error.message}</code>`,
211+
dismissable: true
212+
})
225213
}
226-
227-
const notification = this.notificationManager.addError(message, {
228-
description,
229-
buttons,
230-
dismissable: true
231-
})
232214
}
233215
}
234216
}

styles/teletype.less

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
color: @text-color-info;
1818
}
1919
}
20+
21+
&.outdated {
22+
color: @text-color-error;
23+
24+
&:hover {
25+
color: @text-color-error;
26+
}
27+
}
2028
}
2129

2230
.TeletypePopoverTooltip {
@@ -401,3 +409,9 @@
401409
}
402410
}
403411
}
412+
413+
.PackageOutdatedComponent {
414+
color: @text-color;
415+
text-align: center;
416+
padding: 0 @component-padding @component-padding @component-padding;
417+
}

test/teletype-package.test.js

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -861,42 +861,24 @@ suite('TeletypePackage', function () {
861861
const env = buildAtomEnvironment()
862862
const pack = await buildPackage(env, {signIn: false})
863863
pack.client.initialize = async function () {
864-
await Promise.resolve()
865864
throw new Errors.ClientOutOfDateError()
866865
}
867866

868-
{
869-
env.notifications.clear()
870-
871-
await pack.sharePortal()
872-
873-
assert.equal(env.notifications.getNotifications().length, 1)
874-
const notification = env.notifications.getNotifications()[0]
875-
assert.equal(notification.type, 'error')
876-
assert.equal(notification.message, 'The teletype package is out of date')
877-
const openedURIs = []
878-
env.workspace.open = (uri) => openedURIs.push(uri)
879-
notification.options.buttons[0].onDidClick()
880-
assert.deepEqual(openedURIs, ['atom://config/packages/teletype'])
881-
assert(notification.isDismissed())
882-
}
867+
await pack.consumeStatusBar(new FakeStatusBar())
868+
const {portalStatusBarIndicator} = pack
869+
const {popoverComponent} = portalStatusBarIndicator
870+
const {packageOutdatedComponent} = popoverComponent.refs
883871

872+
assert(portalStatusBarIndicator.element.classList.contains('outdated'))
884873

885-
{
886-
env.notifications.clear()
874+
assert(packageOutdatedComponent)
875+
assert(!popoverComponent.refs.portalListComponent)
876+
assert(!popoverComponent.refs.signInComponent)
887877

888-
await pack.joinPortal()
889-
890-
assert.equal(env.notifications.getNotifications().length, 1)
891-
const notification = env.notifications.getNotifications()[0]
892-
assert.equal(notification.type, 'error')
893-
assert.equal(notification.message, 'The teletype package is out of date')
894-
const openedURIs = []
895-
env.workspace.open = (uri) => openedURIs.push(uri)
896-
notification.options.buttons[0].onDidClick()
897-
assert.deepEqual(openedURIs, ['atom://config/packages/teletype'])
898-
assert(notification.isDismissed())
899-
}
878+
const openedURIs = []
879+
env.workspace.open = (uri) => openedURIs.push(uri)
880+
packageOutdatedComponent.refs.viewPackageSettingsButton.click()
881+
assert.deepEqual(openedURIs, ['atom://config/packages/teletype'])
900882
})
901883

902884
test('reports errors attempting to initialize the client', async () => {

0 commit comments

Comments
 (0)