Skip to content

Commit a9e1205

Browse files
committed
Fix port preflight closure actions
1 parent f1fa379 commit a9e1205

9 files changed

Lines changed: 107 additions & 12 deletions

File tree

app/components/form-ports/component.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ export default Ember.Component.extend({
212212
},
213213
},
214214

215+
invokePassedAction(name, value) {
216+
let action = this.get(name);
217+
218+
if ( typeof action === 'function' ) {
219+
return action(value);
220+
}
221+
222+
if ( action ) {
223+
return this.sendAction(name, value);
224+
}
225+
},
226+
215227
portsArrayDidChange: function() {
216228
let out = [];
217229
(this.get('portsArray') || []).forEach((row) => {
@@ -252,8 +264,8 @@ export default Ember.Component.extend({
252264
});
253265

254266
this.set('portsAsStrArray', out);
255-
this.sendAction('changed', this.get('portsArray'));
256-
this.sendAction('changedStr', this.get('portsAsStrArray'));
267+
this.invokePassedAction('changed', this.get('portsArray'));
268+
this.invokePassedAction('changedStr', this.get('portsAsStrArray'));
257269
}.observes('portsArray.@each.{bindAddress,public,private,protocol}'),
258270

259271
validate: function() {
@@ -462,7 +474,7 @@ export default Ember.Component.extend({
462474
preflightStatusMessage: this.statusMessage(status, messageKey, result),
463475
});
464476
this.validate();
465-
this.sendAction('preflightChanged', {
477+
this.invokePassedAction('preflightChanged', {
466478
status,
467479
pending: status === 'checking',
468480
blocked: status === 'blocked',

app/components/new-container/component.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export default Ember.Component.extend(NewOrEdit, SelectTab, {
127127

128128
portPreflightChanged(state) {
129129
this.set('portPreflightState', state || {status: 'idle', pending: false, blocked: false});
130-
this.sendAction('preflightChanged', this.get('portPreflightState'));
130+
this.invokePassedAction('preflightChanged', this.get('portPreflightState'));
131131
},
132132

133133
sidekickPortPreflightChanged(key, state) {
@@ -146,6 +146,18 @@ export default Ember.Component.extend(NewOrEdit, SelectTab, {
146146
},
147147
},
148148

149+
invokePassedAction(name, value) {
150+
let action = this.get(name);
151+
152+
if ( typeof action === 'function' ) {
153+
return action(value);
154+
}
155+
156+
if ( action ) {
157+
return this.sendAction(name, value);
158+
}
159+
},
160+
149161
init() {
150162
this._super(...arguments);
151163

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pasturestack/web-console",
3-
"version": "1.6.56-pasturestack.53",
3+
"version": "1.6.56-pasturestack.54",
44
"private": true,
55
"description": "PastureStack browser console for the compatible control platform.",
66
"repository": {

scripts/check-modernization-blockers

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ with open('package.json', encoding='utf-8') as f:
4141
print(json.load(f).get('version', ''))
4242
PY
4343
)
44-
if [[ "$version" != "1.6.56-pasturestack.53" ]]; then
45-
echo "UNEXPECTED_UI_ARTIFACT_VERSION version=$version expected=1.6.56-pasturestack.53"
44+
if [[ "$version" != "1.6.56-pasturestack.54" ]]; then
45+
echo "UNEXPECTED_UI_ARTIFACT_VERSION version=$version expected=1.6.56-pasturestack.54"
4646
failures=$((failures + 1))
4747
fi
4848

scripts/check-ui-console-workspace

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@ if [[ -n ${PASTURESTACK_PRIVATE_MARKER:-} ]] && grep -RInF -- "$PASTURESTACK_PRI
141141
fi
142142

143143
printf 'UI_CONSOLE_WORKSPACE_OK version=%s persistence=%s cross_tab=%s\n' \
144-
1.6.56-pasturestack.53 browser-session broker-broadcast
144+
1.6.56-pasturestack.54 browser-session broker-broadcast

scripts/check-ui-port-preflight.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ for (const marker of [
2828
'stackId',
2929
'runtimeProbe: true',
3030
'host_network_ignores_published_port',
31+
"this.invokePassedAction('changed'",
32+
"this.invokePassedAction('changedStr'",
33+
"this.invokePassedAction('preflightChanged'",
3134
]) {
3235
if (!component.includes(marker)) failures.push(`FORM_PORT_PREFLIGHT_MISSING=${marker}`);
3336
}
@@ -46,6 +49,7 @@ for (const marker of [
4649
'hasSidekickPortPreflightPending',
4750
'hasSidekickPortPreflightBlocked',
4851
'saveDisabled:',
52+
"this.invokePassedAction('preflightChanged'",
4953
]) {
5054
if (!parent.includes(marker)) failures.push(`NEW_CONTAINER_PREFLIGHT_MISSING=${marker}`);
5155
}
@@ -74,13 +78,15 @@ for (const marker of [
7478
'stopped owner is a warning and does not block saving',
7579
'host networking checks the container port',
7680
'a late older response cannot replace the newest result',
81+
'closure callbacks are invoked directly and missing optional callbacks are ignored',
7782
]) {
7883
if (!componentTest.includes(marker)) failures.push(`PORT_PREFLIGHT_TEST_MISSING=${marker}`);
7984
}
8085

8186
for (const marker of [
8287
'primary check disables save only while pending or blocked',
8388
'sidekick checks participate in the parent save lock',
89+
'preflight closure callback is invoked without legacy sendAction',
8490
]) {
8591
if (!parentTest.includes(marker)) failures.push(`PORT_PREFLIGHT_PARENT_TEST_MISSING=${marker}`);
8692
}

tests/unit/components/form-ports-test.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,54 @@ function createComponent(project, properties) {
3838
projects: Ember.Object.create({current: project}),
3939
initialPorts: Ember.A(),
4040
schedulePortPreflight() {},
41-
sendAction() {},
4241
}, properties || {}), 'component');
4342
});
4443

4544
return component;
4645
}
4746

47+
test('closure callbacks are invoked directly and missing optional callbacks are ignored', function(assert) {
48+
let changedRows;
49+
let changedSpecs;
50+
let preflightState;
51+
let component = createComponent(null, {
52+
changed(value) {
53+
changedRows = value;
54+
},
55+
changedStr(value) {
56+
changedSpecs = value;
57+
},
58+
preflightChanged(value) {
59+
preflightState = value;
60+
},
61+
sendAction() {
62+
assert.ok(false, 'closure callbacks must not be routed through legacy sendAction');
63+
},
64+
});
65+
let row = portRow('8080', '80');
66+
67+
Ember.run(() => component.set('portsArray', Ember.A([row])));
68+
component.portsArrayDidChange();
69+
component.applyPreflightState('available', [], null, {
70+
eligibleHostCount: 1,
71+
availableHostCount: 1,
72+
});
73+
74+
assert.strictEqual(changedRows, component.get('portsArray'), 'passes the live row array');
75+
assert.deepEqual(changedSpecs, ['8080:80/tcp'], 'passes the serialized port specs');
76+
assert.equal(preflightState.status, 'available', 'passes the preflight result');
77+
78+
Ember.run(() => component.setProperties({
79+
changed: null,
80+
changedStr: null,
81+
preflightChanged: null,
82+
}));
83+
component.portsArrayDidChange();
84+
component.applyPreflightState('available', [], null, null);
85+
assert.ok(true, 'missing optional callbacks do not throw');
86+
destroyOwned(component);
87+
});
88+
4889
function projectWithAction(callback) {
4990
return Ember.Object.create({
5091
actionLinks: {portpreflight: '/v2-beta/projects/1a5?action=portpreflight'},

tests/unit/components/new-container-port-preflight-test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,37 @@ function createComponent() {
3030
primaryResource: service,
3131
primaryService: service,
3232
isService: true,
33-
sendAction() {},
3433
}, 'component');
3534
});
3635

3736
return component;
3837
}
3938

39+
test('preflight closure callback is invoked without legacy sendAction', function(assert) {
40+
let received;
41+
let component = createComponent();
42+
43+
Ember.run(() => component.set('preflightChanged', (state) => {
44+
received = state;
45+
}));
46+
Ember.run(() => component.send('portPreflightChanged', {
47+
status: 'available',
48+
pending: false,
49+
blocked: false,
50+
}));
51+
52+
assert.equal(received.status, 'available', 'passes the state to the closure callback');
53+
54+
Ember.run(() => component.set('preflightChanged', null));
55+
Ember.run(() => component.send('portPreflightChanged', {
56+
status: 'warning',
57+
pending: false,
58+
blocked: false,
59+
}));
60+
assert.ok(true, 'missing optional callback does not throw');
61+
destroyOwned(component);
62+
});
63+
4064
test('primary check disables save only while pending or blocked', function(assert) {
4165
let component = createComponent();
4266

0 commit comments

Comments
 (0)