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

Commit 1eb1971

Browse files
committed
refine repl watcher support
add onclick handler for badges add some usefu generic css classes Fixes #931 Fixes #932
1 parent 5a6746a commit 1eb1971

File tree

5 files changed

+99
-12
lines changed

5 files changed

+99
-12
lines changed

app/content/css/themes/ibm.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ body a:hover:not(.plain-anchor) {
6565
color: var(--color-support-02);
6666
}
6767

68+
sidecar .sidecar-header badge.green-background {
69+
background: var(--color-support-02);
70+
color: var(--color-ui-01);
71+
}
72+
sidecar .sidecar-header badge.yellow-background {
73+
background: var(--color-support-03);
74+
color: var(--color-text-01);
75+
}
76+
sidecar .sidecar-header badge.red-background {
77+
background: var(--color-support-01);
78+
color: var(--color-ui-01);
79+
}
80+
6881
.repl-block.valid-response .oops, sidecar.rule-enabled-false .sidecar-header-icon, .repl-block.error .oops, .clickable.oops, .oops .oops-text-on-oops, .red-text {
6982
color: var(--color-support-01);
7083
}

app/content/css/ui.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,9 +735,14 @@ sidecar .sidecar-header .badges {
735735
display: flex;
736736
flex-wrap: wrap;
737737
align-items: flex-end;
738+
margin: 1rem 0 0 1rem;
738739
}
739740
sidecar .sidecar-header badge {
740741
/* badges next to the entity name */
742+
transition: all 150ms ease-in-out;
743+
}
744+
sidecar .sidecar-header badge.clickable:hover {
745+
filter: brightness(1.1);
741746
}
742747
sidecar .sidecar-header-name-content {
743748
overflow: hidden;
@@ -952,11 +957,34 @@ sidecar.no-limits-data .activation-estimated-cost-container {
952957
}
953958

954959
/* generic */
960+
.flex-layout {
961+
display: flex;
962+
align-items: center;
963+
}
955964
.normal-text {
956965
font-weight: 400;
957966
opacity: 1;
958967
font-size: 1em;
959968
}
969+
.even-smaller-text {
970+
font-size: 0.75em;
971+
}
972+
.smaller-text {
973+
font-size: 0.875em;
974+
}
975+
.sub-text {
976+
color: var(--color-text-02);
977+
}
978+
.lighter-text {
979+
font-weight: 300;
980+
}
981+
.even-lighter-text {
982+
color: var(--color-text-02);
983+
font-weight: 300;
984+
}
985+
.nowrap {
986+
white-space: nowrap;
987+
}
960988
.deemphasize {
961989
font-weight: 300;
962990
font-size: 0.75em;
@@ -969,6 +997,10 @@ sidecar.no-limits-data .activation-estimated-cost-container {
969997
.sans-serif {
970998
font-family: var(--font-sans-serif);
971999
}
1000+
.min-width-8em {
1001+
min-width: 8em !important;
1002+
display: block;
1003+
}
9721004
.min-width-10em {
9731005
min-width: 10em !important;
9741006
display: block;
@@ -985,6 +1017,9 @@ sidecar.no-limits-data .activation-estimated-cost-container {
9851017
font-size: inherit;
9861018
font-weight: inherit;
9871019
}
1020+
.tiny-top-pad {
1021+
margin-top: 0.125em;
1022+
}
9881023
.small-top-pad {
9891024
margin-top: 1ex;
9901025
}

app/content/js/repl.js

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,18 @@ const formatOneListResult = options => (entity, idx, A) => {
8686
prefix.appendChild(prettyType)*/
8787

8888
/** add a cell to the current row of the list view we] are generating. "entityName" is the current row */
89-
const addCell = (className, value, innerClassName='', parent=entityName, onclick, watch) => {
89+
const addCell = (className, value, innerClassName='', parent=entityName, onclick, watch, key) => {
9090
const cell = document.createElement('span'),
9191
inner = document.createElement('span')
92+
9293
cell.className = className
9394
inner.className = innerClassName
95+
inner.classList.add('cell-inner')
96+
97+
if (key) {
98+
inner.setAttribute('data-key', key)
99+
}
100+
94101
if (value) {
95102
Promise.resolve(value)
96103
.then(value => inner.appendChild(value.nodeName ? value : document.createTextNode(value.toString())))
@@ -116,7 +123,14 @@ const formatOneListResult = options => (entity, idx, A) => {
116123
const interval = setInterval(() => {
117124
try {
118125
Promise.resolve(watch())
119-
.then(({ value, done=false, css }) => {
126+
.then(({ value, done=false, css, others=[] }) => {
127+
// are we done polling for updates?
128+
if (!value || done) {
129+
clearInterval(interval)
130+
131+
const toRemove = cell.querySelector('.fa-spinner')
132+
cell.removeChild(toRemove)
133+
}
120134

121135
// update the styling
122136
if (css) {
@@ -129,13 +143,14 @@ const formatOneListResult = options => (entity, idx, A) => {
129143
inner.appendChild(value.nodeName ? value : document.createTextNode(value.toString()))
130144
}
131145

132-
// are we done polling for updates?
133-
if (!value || done) {
134-
clearInterval(interval)
135-
136-
const toRemove = cell.querySelector('.fa-spinner')
137-
cell.removeChild(toRemove)
138-
}
146+
// any other cells to update?
147+
others.forEach(({key, value}) => {
148+
const otherInner = parent.querySelector(`.cell-inner[data-key="${key}"]`)
149+
if (otherInner) {
150+
otherInner.innerText = ''
151+
otherInner.appendChild(value.nodeName ? value : document.createTextNode(value.toString()))
152+
}
153+
})
139154
})
140155

141156
} catch (err) {
@@ -154,7 +169,7 @@ const formatOneListResult = options => (entity, idx, A) => {
154169

155170
// add any attributes that should appear *before* the name column
156171
if (entity.beforeAttributes) {
157-
entity.beforeAttributes.forEach(({value, css='', outerCSS='', onclick}) => addCell(outerCSS, value, css, undefined, onclick))
172+
entity.beforeAttributes.forEach(({key, value, css='', outerCSS='', onclick}) => addCell(outerCSS, value, css, undefined, onclick, undefined, key))
158173
}
159174

160175
// now add the clickable name
@@ -199,7 +214,7 @@ const formatOneListResult = options => (entity, idx, A) => {
199214
// case-specific cells
200215
//
201216
if (entity.attributes) {
202-
entity.attributes.forEach(({value, css='', outerCSS='', watch, onclick}) => addCell(outerCSS, value, css, undefined, onclick, watch))
217+
entity.attributes.forEach(({key, value, css='', outerCSS='', watch, onclick}) => addCell(outerCSS, value, css, undefined, onclick, watch, key))
203218

204219
} else if (entity.type === 'actions') {
205220
// action-specific cells
@@ -1146,6 +1161,18 @@ self.doCancel = () => {
11461161
ui.installBlock(block.parentNode, block, nextBlock)()
11471162
}
11481163

1164+
/**
1165+
* Add quotes if the argument needs it; compare to encodeURIComponent
1166+
*
1167+
*/
1168+
self.encodeComponent = (component, quote='"') => {
1169+
if (component.match(patterns.whitespace)) {
1170+
return `${quote}${component}${quote}`
1171+
} else {
1172+
return component
1173+
}
1174+
}
1175+
11491176
module.exports = self
11501177

11511178
debug('loading done')

app/content/js/ui.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,17 +1125,28 @@ const ui = (function() {
11251125
* Sidecar badges
11261126
*
11271127
*/
1128-
const addBadge = badgeText => {
1128+
const addBadge = (badgeText, { css, onclick }={}) => {
11291129
const sidecar = document.querySelector('#sidecar'),
11301130
header = sidecar.querySelector('.sidecar-header'),
11311131
badges = header.querySelector('.badges')
11321132

11331133
const badge = document.createElement('badge')
1134+
11341135
if (typeof badgeText === 'string') {
11351136
badge.innerText = badgeText
11361137
} else {
11371138
badge.appendChild(badgeText)
11381139
}
1140+
1141+
if (css) {
1142+
badge.classList.add(css)
1143+
}
1144+
1145+
if (onclick) {
1146+
badge.classList.add('clickable')
1147+
badge.onclick = onclick
1148+
}
1149+
11391150
badges.appendChild(badge)
11401151
return badge
11411152
}

app/plugins/ui/commands/openwhisk-usage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ const skipAndLimit = [{ name: '--limit', alias: '-l', numeric: true, docs: 'show
101101
*/
102102
module.exports = {
103103
skipAndLimit,
104+
params,
104105

105106
// this is the ascii art for OpenWhisk, with backslashes escaped
106107
wsk: { //header: ` ____ ___ _ _ _ _ _\r\n /\\ \\ / _ \\ _ __ ___ _ __ | | | | |__ (_)___| | __\r\n /\\ /__\\ \\ | | | | '_ \\ / _ \\ '_ \\| | | | '_ \\| / __| |/ /\r\n / \\____ \\ / | |_| | |_) | __/ | | | |/\\| | | | | \\__ \\ <\r\n \\ \\ / \\/ \\___/| .__/ \\___|_| |_|__/\\__|_| |_|_|___/_|\\_\\\r\n \\___\\/ tm |_|`,

0 commit comments

Comments
 (0)