Skip to content

Commit 70583a7

Browse files
Backport of UI/Deprecation Computed property override into release/1.22.x (#22959)
backport of commit 0879750 Co-authored-by: Rishabh Gupta <[email protected]>
1 parent 0b00c01 commit 70583a7

File tree

10 files changed

+146
-66
lines changed

10 files changed

+146
-66
lines changed

.changelog/22947.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:improvement
2+
ui: Fixes computed property override issues currently occurring and in some cases pre-emptively as this has been deprecated in ember v4
3+
```

ui/packages/consul-ui/app/components/child-selector/index.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,27 @@ export default Component.extend(Slotted, {
3636
this._super(...arguments);
3737
this._listeners.remove();
3838
},
39-
options: computed('selectedOptions.[]', 'allOptions.[]', function () {
40-
// It's not massively important here that we are defaulting `items` and
41-
// losing reference as its just to figure out the diff
42-
let options = this.allOptions || [];
43-
const items = this.selectedOptions || [];
44-
if (get(items, 'length') > 0) {
45-
// filter out any items from the available options that have already been
46-
// selected/added
47-
// TODO: find a proper ember-data diff
48-
options = options.filter((item) => !items.findBy('ID', get(item, 'ID')));
49-
}
50-
return options;
39+
options: computed('selectedOptions.[]', 'allOptions.[]', {
40+
get() {
41+
if (this._options !== undefined) {
42+
return this._options;
43+
}
44+
// It's not massively important here that we are defaulting `items` and
45+
// losing reference as its just to figure out the diff
46+
let options = this.allOptions || [];
47+
const items = this.selectedOptions || [];
48+
if (get(items, 'length') > 0) {
49+
// filter out any items from the available options that have already been
50+
// selected/added
51+
// TODO: find a proper ember-data diff
52+
options = options.filter((item) => !items.findBy('ID', get(item, 'ID')));
53+
}
54+
return options;
55+
},
56+
set(_key, value) {
57+
this._options = value;
58+
return this._options;
59+
},
5160
}),
5261
save: task(function* (item, items, success = function () {}) {
5362
const repo = this.repo;

ui/packages/consul-ui/app/components/consul/intention/permission/header/form/index.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,23 @@ export default Component.extend({
2020
onsubmit: function () {},
2121
onreset: function () {},
2222

23-
changeset: computed('item', function () {
24-
return this.change.changesetFor(
25-
name,
26-
this.item ||
27-
this.repo.create({
28-
HeaderType: this.headerTypes.firstObject,
29-
})
30-
);
23+
changeset: computed('item', {
24+
get() {
25+
if (this._changeset !== undefined) {
26+
return this._changeset;
27+
}
28+
return this.change.changesetFor(
29+
name,
30+
this.item ||
31+
this.repo.create({
32+
HeaderType: this.headerTypes.firstObject,
33+
})
34+
);
35+
},
36+
set(_key, value) {
37+
this._changeset = value;
38+
return this._changeset;
39+
},
3140
}),
3241

3342
headerTypes: alias(`schema.${name}.HeaderType.allowedValues`),

ui/packages/consul-ui/app/components/consul/kind/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@ const normalizedGatewayLabels = {
1717

1818
export default Component.extend({
1919
tagName: '',
20-
Name: computed('item.Kind', function () {
21-
const name = normalizedGatewayLabels[this.item.Kind];
22-
return name ? name : titleize(humanize(this.item.Kind));
20+
Name: computed('item.Kind', {
21+
get() {
22+
if (this._Name !== undefined) {
23+
return this._Name;
24+
}
25+
const name = normalizedGatewayLabels[this.item.Kind];
26+
return name ? name : titleize(humanize(this.item.Kind));
27+
},
28+
set(_key, value) {
29+
this._Name = value;
30+
return this._Name;
31+
},
2332
}),
2433
});

ui/packages/consul-ui/app/components/data-sink/index.js

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,38 @@ export default Component.extend({
1919
onchange: function (e) {},
2020
onerror: function (e) {},
2121

22-
state: computed('instance', 'instance.{dirtyType,isSaving}', function () {
23-
let id;
24-
const isSaving = get(this, 'instance.isSaving');
25-
const dirtyType = get(this, 'instance.dirtyType');
26-
if (typeof isSaving === 'undefined' && typeof dirtyType === 'undefined') {
27-
id = 'idle';
28-
} else {
29-
switch (dirtyType) {
30-
case 'created':
31-
id = isSaving ? 'creating' : 'create';
32-
break;
33-
case 'updated':
34-
id = isSaving ? 'updating' : 'update';
35-
break;
36-
case 'deleted':
37-
case undefined:
38-
id = isSaving ? 'removing' : 'remove';
39-
break;
22+
state: computed('instance', 'instance.{dirtyType,isSaving}', {
23+
get() {
24+
let id;
25+
const isSaving = get(this, 'instance.isSaving');
26+
const dirtyType = get(this, 'instance.dirtyType');
27+
28+
if (typeof isSaving === 'undefined' && typeof dirtyType === 'undefined') {
29+
id = 'idle';
30+
} else {
31+
switch (dirtyType) {
32+
case 'created':
33+
id = isSaving ? 'creating' : 'create';
34+
break;
35+
case 'updated':
36+
id = isSaving ? 'updating' : 'update';
37+
break;
38+
case 'deleted':
39+
case undefined:
40+
id = isSaving ? 'removing' : 'remove';
41+
break;
42+
}
43+
id = `active.${id}`;
4044
}
41-
id = `active.${id}`;
42-
}
43-
return {
44-
matches: (name) => id.indexOf(name) !== -1,
45-
};
45+
46+
return {
47+
matches: (name) => id.indexOf(name) !== -1,
48+
};
49+
},
50+
51+
set(_key, value) {
52+
return value;
53+
},
4654
}),
4755

4856
init: function () {

ui/packages/consul-ui/app/components/list-collection/index.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,23 @@ export default Component.extend(Slotted, {
4747
return style;
4848
};
4949
},
50-
style: computed('height', function () {
51-
if (this.scroll !== 'virtual') {
52-
return {};
53-
}
54-
return {
55-
height: this.height,
56-
};
50+
51+
style: computed('height', {
52+
get() {
53+
if (this.scroll !== 'virtual') {
54+
return {};
55+
} else {
56+
return {
57+
height: this.height,
58+
};
59+
}
60+
},
61+
62+
set(_key, value) {
63+
return value;
64+
},
5765
}),
66+
5867
actions: {
5968
resize: function (e) {
6069
// TODO: This top part is very similar to resize in tabular-collection

ui/packages/consul-ui/app/components/tabular-collection/index.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,26 @@ export default CollectionComponent.extend(Slotted, {
3939
this.$element = this.dom.element(`#${this.guid}`);
4040
this.actions.resize.apply(this, [{ target: this.dom.viewport() }]);
4141
},
42-
style: computed('rowHeight', '_items', 'maxRows', 'maxHeight', function () {
43-
const maxRows = this.rows;
44-
let height = this.maxHeight;
45-
if (maxRows) {
46-
let rows = Math.max(3, get(this._items || [], 'length'));
47-
rows = Math.min(maxRows, rows);
48-
height = this.rowHeight * rows + 29;
49-
}
50-
return {
51-
height: height,
52-
};
42+
43+
style: computed('rowHeight', '_items', 'maxRows', 'maxHeight', {
44+
get() {
45+
const maxRows = this.rows;
46+
let height = this.maxHeight;
47+
48+
if (maxRows) {
49+
let rows = Math.max(3, get(this._items || [], 'length'));
50+
rows = Math.min(maxRows, rows);
51+
height = this.rowHeight * rows + 29;
52+
}
53+
54+
return { height };
55+
},
56+
57+
set(_key, value) {
58+
return value;
59+
},
5360
}),
61+
5462
willRender: function () {
5563
this._super(...arguments);
5664
set(this, 'hasCaption', this._isRegistered('caption'));

ui/packages/consul-ui/app/models/intention-permission-http-header.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ export default class IntentionPermission extends Fragment {
3333

3434
@computed(...schema.HeaderType.allowedValues)
3535
get HeaderType() {
36+
// Use manual override if one was set
37+
if (this._headerTypeManual !== undefined) {
38+
return this._headerTypeManual;
39+
}
40+
// Original logic: find first defined variant field
3641
return schema.HeaderType.allowedValues.find((prop) => typeof this[prop] !== 'undefined');
3742
}
43+
44+
set HeaderType(value) {
45+
// Store manual override
46+
this._headerTypeManual = value;
47+
}
3848
}

ui/packages/consul-ui/app/models/intention-permission-http.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ export default class IntentionPermissionHttp extends Fragment {
3030

3131
@computed(...schema.PathType.allowedValues)
3232
get PathType() {
33+
// Use manual override if one was set
34+
if (this._pathTypeManual !== undefined) {
35+
return this._pathTypeManual;
36+
}
37+
// Original logic: find first defined property
3338
return schema.PathType.allowedValues.find((prop) => typeof this[prop] === 'string');
3439
}
40+
41+
set PathType(value) {
42+
// Store manual override
43+
this._pathTypeManual = value;
44+
}
3545
}

ui/packages/consul-ui/lib/block-slots/addon/components/block-slot.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ import YieldSlot from './yield-slot';
88
const BlockSlot = Component.extend({
99
layout,
1010
tagName: '',
11-
_name: computed('name', function () {
12-
return this.name;
11+
_name: computed('name', {
12+
get() {
13+
return this.name;
14+
},
15+
set(_key, value) {
16+
return value;
17+
},
1318
}),
1419
didInsertElement: function () {
1520
const slottedComponent = this.nearestOfType(Slots);

0 commit comments

Comments
 (0)