fix: 🐛 tag count in list view (#2413)
* fix: 🐛 tag count in list view * Update addons/api/addon/models/worker.js Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com> * fix: 🐛 error & test * Update addons/api/addon/models/worker.js Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> --------- Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com> Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
This commit is contained in:
3 files changed
+34
-31
No files matched your search
@@ -72,4 +72,27 @@ export default class GeneratedWorkerModel extends BaseModel {
|
|||||||
readOnly: true,
|
readOnly: true,
|
||||||
})
|
})
|
||||||
type;
|
type;
|
||||||
|
|
||||||
|
@attr({
|
||||||
|
description:
|
||||||
|
'The deduplicated union of the tags reported by the worker ' +
|
||||||
|
'from its configuration and any tags added through other means.\nOutput only.',
|
||||||
|
readOnly: true,
|
||||||
|
emptyObjectIfMissing: true,
|
||||||
|
})
|
||||||
|
canonical_tags;
|
||||||
|
|
||||||
|
@attr({
|
||||||
|
description:
|
||||||
|
"The tags set in the worker's configuration file.\nOutput only.",
|
||||||
|
readOnly: true,
|
||||||
|
emptyObjectIfMissing: true,
|
||||||
|
})
|
||||||
|
config_tags;
|
||||||
|
|
||||||
|
@attr({
|
||||||
|
description: 'The api tags set for the worker.\nOutput only.',
|
||||||
|
emptyObjectIfMissing: true,
|
||||||
|
})
|
||||||
|
api_tags;
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import GeneratedWorkerModel from '../generated/models/worker';
|
import GeneratedWorkerModel from '../generated/models/worker';
|
||||||
import { attr } from '@ember-data/model';
|
|
||||||
|
|
||||||
export const TYPE_WORKER_PKI = 'pki';
|
export const TYPE_WORKER_PKI = 'pki';
|
||||||
|
|
||||||
@@ -34,14 +33,15 @@ export default class WorkerModel extends GeneratedWorkerModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of canonical tags present on the worker.
|
* Returns the number of tags present on the worker.
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
get tagCount() {
|
get tagCount() {
|
||||||
if (!this.canonical_tags) {
|
const allTags = [
|
||||||
return 0;
|
...Object.values(this.config_tags ?? {}),
|
||||||
}
|
...Object.values(this.api_tags ?? {}),
|
||||||
return Object.values(this.canonical_tags).reduce(
|
];
|
||||||
|
return allTags.reduce(
|
||||||
(previousCount, currentTags) => previousCount + currentTags.length,
|
(previousCount, currentTags) => previousCount + currentTags.length,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
@@ -83,29 +83,6 @@ export default class WorkerModel extends GeneratedWorkerModel {
|
|||||||
return [...(this.configTagList ?? []), ...(this.apiTagList ?? [])];
|
return [...(this.configTagList ?? []), ...(this.apiTagList ?? [])];
|
||||||
}
|
}
|
||||||
|
|
||||||
@attr({
|
|
||||||
description:
|
|
||||||
'The deduplicated union of the tags reported by the worker ' +
|
|
||||||
'from its configuration and any tags added through other means.\nOutput only.',
|
|
||||||
readOnly: true,
|
|
||||||
emptyObjectIfMissing: true,
|
|
||||||
})
|
|
||||||
canonical_tags;
|
|
||||||
|
|
||||||
@attr({
|
|
||||||
description:
|
|
||||||
"The tags set in the worker's configuration file.\nOutput only.",
|
|
||||||
readOnly: true,
|
|
||||||
emptyObjectIfMissing: true,
|
|
||||||
})
|
|
||||||
config_tags;
|
|
||||||
|
|
||||||
@attr({
|
|
||||||
description: 'The api tags set for the worker.\nOutput only.',
|
|
||||||
emptyObjectIfMissing: true,
|
|
||||||
})
|
|
||||||
api_tags;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to modify the adapter to handle custom POST route for creating worker.
|
* Method to modify the adapter to handle custom POST route for creating worker.
|
||||||
* @param {string} workerGeneratedAuthToken
|
* @param {string} workerGeneratedAuthToken
|
||||||
|
|||||||
@@ -186,13 +186,16 @@ module('Unit | Model | worker', function (hooks) {
|
|||||||
test('tagCount returns the total number of tags', function (assert) {
|
test('tagCount returns the total number of tags', function (assert) {
|
||||||
const store = this.owner.lookup('service:store');
|
const store = this.owner.lookup('service:store');
|
||||||
const model = store.createRecord('worker', {
|
const model = store.createRecord('worker', {
|
||||||
canonical_tags: {
|
config_tags: {
|
||||||
tag1: ['value1', 'value2'],
|
tag1: ['value1', 'value2'],
|
||||||
tag2: ['value3'],
|
tag2: ['value3'],
|
||||||
},
|
},
|
||||||
|
api_tags: {
|
||||||
|
tag2: ['value3'],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(model.tagCount, 3);
|
assert.strictEqual(model.tagCount, 4);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('tagCount returns 0 if there are no tags', function (assert) {
|
test('tagCount returns 0 if there are no tags', function (assert) {
|
||||||
|
|||||||
Reference in new issue
Block a user