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

Commit 6776566

Browse files
committed
fix app list -> click for packaged apps
also improved error handling in zoom button rendering Fixes #702
1 parent de15f3c commit 6776566

File tree

6 files changed

+69
-30
lines changed

6 files changed

+69
-30
lines changed

app/content/js/repl.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ const formatOneListResult = options => (entity, idx, A) => {
6767
dom.className = `entity ${entity.prettyType || ''} ${entity.type}`
6868
dom.setAttribute('data-name', entity.name)
6969

70+
if (entity.packageName) {
71+
dom.setAttribute('data-package-name', entity.packageName)
72+
}
73+
7074
const entityName = document.createElement('div')
7175
entityName.className = 'entity-attributes'
7276
dom.appendChild(entityName)

app/plugins/modules/composer/lib/composer.js

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -590,32 +590,39 @@ exports.wskflow = (visualize, viewName, { fsm, input, name, packageName }) => {
590590
*
591591
*/
592592
exports.zoomToFitButtons = controller => {
593-
const events = require('events'),
594-
zoom1to1Bus = new events.EventEmitter(),
595-
zoomToFitBus = new events.EventEmitter()
593+
if (controller && controller.register) {
594+
const events = require('events'),
595+
zoom1to1Bus = new events.EventEmitter(),
596+
zoomToFitBus = new events.EventEmitter()
597+
598+
const listener = event => {
599+
zoom1to1Bus.emit('change', event.applyAutoScale === false && !event.customZoom)
600+
zoomToFitBus.emit('change', event.applyAutoScale === true && !event.customZoom)
601+
}
602+
603+
controller.register(listener)
604+
605+
return [
606+
{ label: '1:1', actAsButton: true, flush: 'right', balloon: 'Use a fixed-size canvas', selected: false,
607+
selectionController: zoom1to1Bus,
608+
visibleWhen: 'visualization',
609+
direct: () => {
610+
controller.zoom1to1()
611+
}
612+
},
613+
{ fontawesome: 'fas fa-expand', actAsButton: true, flush: 'right', balloon: 'Use a zoom to fit canvas', selected: true,
614+
selectionController: zoomToFitBus,
615+
visibleWhen: 'visualization',
616+
direct: () => {
617+
controller.zoomToFit()
618+
}
619+
}
620+
]
596621

597-
const listener = event => {
598-
zoom1to1Bus.emit('change', event.applyAutoScale === false && !event.customZoom)
599-
zoomToFitBus.emit('change', event.applyAutoScale === true && !event.customZoom)
622+
} else {
623+
// probably some error initializing wskflow; try to safeguard against that
624+
return []
600625
}
601-
controller.register(listener)
602-
603-
return [
604-
{ label: '1:1', actAsButton: true, flush: 'right', balloon: 'Use a fixed-size canvas', selected: false,
605-
selectionController: zoom1to1Bus,
606-
visibleWhen: 'visualization',
607-
direct: () => {
608-
controller.zoom1to1()
609-
}
610-
},
611-
{ fontawesome: 'fas fa-expand', actAsButton: true, flush: 'right', balloon: 'Use a zoom to fit canvas', selected: true,
612-
selectionController: zoomToFitBus,
613-
visibleWhen: 'visualization',
614-
direct: () => {
615-
controller.zoomToFit()
616-
}
617-
}
618-
]
619626
}
620627

621628
/**

app/plugins/modules/composer/lib/create-from-source.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ exports.compileToFSM = (src, opts={}) => new Promise((resolve, reject) => {
219219
const junkMatch = err.stack.match(/\s+at Object\.exports\.runInNewContext/)
220220
|| err.stack.match(/\s+at Object\.runInNewContext/)
221221
|| err.stack.match(/\s+at fs\.readFile/),
222-
message = err.message.indexOf('Invalid argument to compile') >= 0? 'Your source code did not produce a valid app.' : (!junkMatch ? e.stack : err.stack.substring(0, junkMatch.index).replace(/\s+.*create-from-source([^\n])*/g, '\n').replace(/(evalmachine.<anonymous>)/g, filename).replace(/\s+at createScript([^\n])*/g, '\n').trim())
222+
_message = err.message.indexOf('Invalid argument to compile') >= 0? 'Your source code did not produce a valid app.' : (!junkMatch ? e.stack : err.stack.substring(0, junkMatch.index).replace(/\s+.*create-from-source([^\n])*/g, '\n').replace(/(evalmachine.<anonymous>)/g, filename).replace(/\s+at createScript([^\n])*/g, '\n').trim()),
223+
message = _message.replace(/\s+\(.*plugins\/modules\/composer\/node_modules\/@ibm-functions\/composer\/composer\.js:[^\s]*/, '')
223224

224225
console.error('All composer create/preview errors are here', errors)
225226
console.error('Selected error', err)

app/plugins/modules/composer/lib/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = (commandTree, prequire) => {
3737
.then(apps => {
3838
apps.forEach(app => {
3939
app.prettyType = appBadge
40-
app.onclick = () => repl.pexec(`app get ${app.name}`)
40+
app.onclick = () => repl.pexec(`app get "/${app.namespace}/${app.name}"`)
4141
return app
4242
})
4343
return apps

app/plugins/modules/wskflow/lib/graph2doms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ function graph2doms(JSONgraph, containerId, width, height, activations){
11871187
applyAutoScale = useThisValue !== undefined ? useThisValue : !applyAutoScale; // toggle applyAutoScale
11881188
customZoom = false
11891189
notify()
1190-
console.error('ZTF', applyAutoScale, customZoom)
1190+
//console.error('ZTF', applyAutoScale, customZoom)
11911191
if(applyAutoScale){
11921192
// when clicking to switch from inactive to active, it resizes the graph to fit the window. #422
11931193
resizeToFit($('#wskflowSVG').width(), $('#wskflowSVG').height());

tests/tests/passes/07/composer-list.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('Use the app list command to list the invokeable compositions', functio
4949
.catch(common.oops(this)))
5050

5151
// list it
52-
it('should list ${seqName1} via app ls', () => cli.do(`app ls`, this.app)
52+
it(`should list ${seqName1} via app ls`, () => cli.do(`app ls`, this.app)
5353
.then(cli.expectOKWithOnly(seqName1))
5454
.then(sidecar.expectOpen)
5555
.then(sidecar.expectShowing(seqName1))
@@ -65,17 +65,44 @@ describe('Use the app list command to list the invokeable compositions', functio
6565
.catch(common.oops(this)))
6666

6767
// list it
68-
it('should list ${seqName1} via app list', () => cli.do(`app list`, this.app)
68+
it(`should list ${seqName1} via app list`, () => cli.do(`app list`, this.app)
6969
.then(cli.expectOKWith(seqName1)) // seqName1 had better still be in the list
7070
.then(sidecar.expectOpen)
7171
.then(sidecar.expectShowing(seqName2)) // but the sidecar should be showing seqName2
7272
.then(sidecar.expectBadge('fsm'))
7373
.catch(common.oops(this)))
7474

75-
it('should list ${seqName1} via wsk app list', () => cli.do(`wsk app list`, this.app)
75+
it(`should list ${seqName1} via wsk app list`, () => cli.do(`wsk app list`, this.app)
7676
.then(cli.expectOKWith(seqName2)) // seqName2 had better also be in the list
7777
.then(sidecar.expectOpen)
7878
.then(sidecar.expectShowing(seqName2))
7979
.then(sidecar.expectBadge('fsm'))
8080
.catch(common.oops(this)))
81+
82+
// make a packaged app
83+
it('should create a second composer sequence', () => cli.do(`app create ppp/${seqName2} ./data/fsm.json`, this.app)
84+
.then(cli.expectOK)
85+
.then(sidecar.expectOpen)
86+
.then(sidecar.expectShowing(seqName2, undefined, undefined, 'ppp'))
87+
.then(sidecar.expectBadge('fsm'))
88+
.catch(common.oops(this)))
89+
90+
// get the first app, so that the sidecar shows it (so we can test switching back to the packaged app)
91+
it(`should get ${seqName1}`, () => cli.do(`app get ${seqName1}`, this.app)
92+
.then(cli.expectOK)
93+
.then(sidecar.expectOpen)
94+
.then(sidecar.expectShowing(seqName1))
95+
.then(sidecar.expectBadge('fsm'))
96+
.catch(common.oops(this)))
97+
98+
it(`should list ppp/${seqName2} via wsk app list`, () => cli.do(`app ls`, this.app)
99+
.then(cli.expectOKWithCustom({ selector: `.entity[data-name="${seqName2}"][data-package-name="ppp"]`,
100+
expect: `ppp/${seqName2}`
101+
}))
102+
.then(selector => this.app.client.click(`${selector} .entity-name.clickable`))
103+
.then(() => this.app)
104+
.then(sidecar.expectOpen)
105+
.then(sidecar.expectShowing(seqName2, undefined, undefined, 'ppp'))
106+
.catch(common.oops(this)))
107+
81108
})

0 commit comments

Comments
 (0)