Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/22947.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: Fixes computed property override issues currently occurring and in some cases pre-emptively as this has been deprecated in ember v4
```
33 changes: 21 additions & 12 deletions ui/packages/consul-ui/app/components/child-selector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: BUSL-1.1
*/

import Component from '@ember/component';

Check warning on line 6 in ui/packages/consul-ui/app/components/child-selector/index.js

View workflow job for this annotation

GitHub Actions / node-tests

Use Glimmer components(@glimmer/component) instead of classic components(@ember/component)
import { get, set, computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import { inject as service } from '@ember/service';
Expand Down Expand Up @@ -36,18 +36,27 @@
this._super(...arguments);
this._listeners.remove();
},
options: computed('selectedOptions.[]', 'allOptions.[]', function () {
// It's not massively important here that we are defaulting `items` and
// losing reference as its just to figure out the diff
let options = this.allOptions || [];
const items = this.selectedOptions || [];
if (get(items, 'length') > 0) {
// filter out any items from the available options that have already been
// selected/added
// TODO: find a proper ember-data diff
options = options.filter((item) => !items.findBy('ID', get(item, 'ID')));
}
return options;
options: computed('selectedOptions.[]', 'allOptions.[]', {
get() {
if (this._options !== undefined) {
return this._options;
}
// It's not massively important here that we are defaulting `items` and
// losing reference as its just to figure out the diff
let options = this.allOptions || [];
const items = this.selectedOptions || [];
if (get(items, 'length') > 0) {
// filter out any items from the available options that have already been
// selected/added
// TODO: find a proper ember-data diff
options = options.filter((item) => !items.findBy('ID', get(item, 'ID')));
}
return options;
},
set(_key, value) {
this._options = value;
return this._options;
},
}),
save: task(function* (item, items, success = function () {}) {
const repo = this.repo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@ export default Component.extend({
onsubmit: function () {},
onreset: function () {},

changeset: computed('item', function () {
return this.change.changesetFor(
name,
this.item ||
this.repo.create({
HeaderType: this.headerTypes.firstObject,
})
);
changeset: computed('item', {
get() {
if (this._changeset !== undefined) {
return this._changeset;
}
return this.change.changesetFor(
name,
this.item ||
this.repo.create({
HeaderType: this.headerTypes.firstObject,
})
);
},
set(_key, value) {
this._changeset = value;
return this._changeset;
},
}),

headerTypes: alias(`schema.${name}.HeaderType.allowedValues`),
Expand Down
15 changes: 12 additions & 3 deletions ui/packages/consul-ui/app/components/consul/kind/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@ const normalizedGatewayLabels = {

export default Component.extend({
tagName: '',
Name: computed('item.Kind', function () {
const name = normalizedGatewayLabels[this.item.Kind];
return name ? name : titleize(humanize(this.item.Kind));
Name: computed('item.Kind', {
get() {
if (this._Name !== undefined) {
return this._Name;
}
const name = normalizedGatewayLabels[this.item.Kind];
return name ? name : titleize(humanize(this.item.Kind));
},
set(_key, value) {
this._Name = value;
return this._Name;
},
}),
});
54 changes: 31 additions & 23 deletions ui/packages/consul-ui/app/components/data-sink/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,38 @@ export default Component.extend({
onchange: function (e) {},
onerror: function (e) {},

state: computed('instance', 'instance.{dirtyType,isSaving}', function () {
let id;
const isSaving = get(this, 'instance.isSaving');
const dirtyType = get(this, 'instance.dirtyType');
if (typeof isSaving === 'undefined' && typeof dirtyType === 'undefined') {
id = 'idle';
} else {
switch (dirtyType) {
case 'created':
id = isSaving ? 'creating' : 'create';
break;
case 'updated':
id = isSaving ? 'updating' : 'update';
break;
case 'deleted':
case undefined:
id = isSaving ? 'removing' : 'remove';
break;
state: computed('instance', 'instance.{dirtyType,isSaving}', {
get() {
let id;
const isSaving = get(this, 'instance.isSaving');
const dirtyType = get(this, 'instance.dirtyType');

if (typeof isSaving === 'undefined' && typeof dirtyType === 'undefined') {
id = 'idle';
} else {
switch (dirtyType) {
case 'created':
id = isSaving ? 'creating' : 'create';
break;
case 'updated':
id = isSaving ? 'updating' : 'update';
break;
case 'deleted':
case undefined:
id = isSaving ? 'removing' : 'remove';
break;
}
id = `active.${id}`;
}
id = `active.${id}`;
}
return {
matches: (name) => id.indexOf(name) !== -1,
};

return {
matches: (name) => id.indexOf(name) !== -1,
};
},

set(_key, value) {
return value;
},
}),

init: function () {
Expand Down
23 changes: 16 additions & 7 deletions ui/packages/consul-ui/app/components/list-collection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,23 @@ export default Component.extend(Slotted, {
return style;
};
},
style: computed('height', function () {
if (this.scroll !== 'virtual') {
return {};
}
return {
height: this.height,
};

style: computed('height', {
get() {
if (this.scroll !== 'virtual') {
return {};
} else {
return {
height: this.height,
};
}
},

set(_key, value) {
return value;
},
}),

actions: {
resize: function (e) {
// TODO: This top part is very similar to resize in tabular-collection
Expand Down
30 changes: 19 additions & 11 deletions ui/packages/consul-ui/app/components/tabular-collection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,26 @@ export default CollectionComponent.extend(Slotted, {
this.$element = this.dom.element(`#${this.guid}`);
this.actions.resize.apply(this, [{ target: this.dom.viewport() }]);
},
style: computed('rowHeight', '_items', 'maxRows', 'maxHeight', function () {
const maxRows = this.rows;
let height = this.maxHeight;
if (maxRows) {
let rows = Math.max(3, get(this._items || [], 'length'));
rows = Math.min(maxRows, rows);
height = this.rowHeight * rows + 29;
}
return {
height: height,
};

style: computed('rowHeight', '_items', 'maxRows', 'maxHeight', {
get() {
const maxRows = this.rows;
let height = this.maxHeight;

if (maxRows) {
let rows = Math.max(3, get(this._items || [], 'length'));
rows = Math.min(maxRows, rows);
height = this.rowHeight * rows + 29;
}

return { height };
},

set(_key, value) {
return value;
},
}),

willRender: function () {
this._super(...arguments);
set(this, 'hasCaption', this._isRegistered('caption'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ export default class IntentionPermission extends Fragment {

@computed(...schema.HeaderType.allowedValues)
get HeaderType() {
// Use manual override if one was set
if (this._headerTypeManual !== undefined) {
return this._headerTypeManual;
}
// Original logic: find first defined variant field
return schema.HeaderType.allowedValues.find((prop) => typeof this[prop] !== 'undefined');
}

set HeaderType(value) {
// Store manual override
this._headerTypeManual = value;
}
}
10 changes: 10 additions & 0 deletions ui/packages/consul-ui/app/models/intention-permission-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export default class IntentionPermissionHttp extends Fragment {

@computed(...schema.PathType.allowedValues)
get PathType() {
// Use manual override if one was set
if (this._pathTypeManual !== undefined) {
return this._pathTypeManual;
}
// Original logic: find first defined property
return schema.PathType.allowedValues.find((prop) => typeof this[prop] === 'string');
}

set PathType(value) {
// Store manual override
this._pathTypeManual = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ import YieldSlot from './yield-slot';
const BlockSlot = Component.extend({
layout,
tagName: '',
_name: computed('name', function () {
return this.name;
_name: computed('name', {
get() {
return this.name;
},
set(_key, value) {
return value;
},
}),
didInsertElement: function () {
const slottedComponent = this.nearestOfType(Slots);
Expand Down
Loading