From 219eba67bc36df4efe062809ff41b5e5bb96d114 Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Date: Thu, 25 Jul 2024 12:40:36 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20tag=20count=20in=20list?= =?UTF-8?q?=20view=20(#2413)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 tag count in list view * Update addons/api/addon/models/worker.js Co-authored-by: Cameron Perera * fix: 🐛 error & test * Update addons/api/addon/models/worker.js Co-authored-by: Zhihe Li --------- Co-authored-by: Cameron Perera Co-authored-by: Zhihe Li --- addons/api/addon/generated/models/worker.js | 23 ++++++++++++++ addons/api/addon/models/worker.js | 35 ++++----------------- addons/api/tests/unit/models/worker-test.js | 9 ++++-- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/addons/api/addon/generated/models/worker.js b/addons/api/addon/generated/models/worker.js index b26da9c28..15958acc3 100644 --- a/addons/api/addon/generated/models/worker.js +++ b/addons/api/addon/generated/models/worker.js @@ -72,4 +72,27 @@ export default class GeneratedWorkerModel extends BaseModel { readOnly: true, }) 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; } diff --git a/addons/api/addon/models/worker.js b/addons/api/addon/models/worker.js index 60814989d..f3bd882b6 100644 --- a/addons/api/addon/models/worker.js +++ b/addons/api/addon/models/worker.js @@ -4,7 +4,6 @@ */ import GeneratedWorkerModel from '../generated/models/worker'; -import { attr } from '@ember-data/model'; 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} */ get tagCount() { - if (!this.canonical_tags) { - return 0; - } - return Object.values(this.canonical_tags).reduce( + const allTags = [ + ...Object.values(this.config_tags ?? {}), + ...Object.values(this.api_tags ?? {}), + ]; + return allTags.reduce( (previousCount, currentTags) => previousCount + currentTags.length, 0, ); @@ -83,29 +83,6 @@ export default class WorkerModel extends GeneratedWorkerModel { 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. * @param {string} workerGeneratedAuthToken diff --git a/addons/api/tests/unit/models/worker-test.js b/addons/api/tests/unit/models/worker-test.js index b6bc498a3..dc22a60df 100644 --- a/addons/api/tests/unit/models/worker-test.js +++ b/addons/api/tests/unit/models/worker-test.js @@ -71,7 +71,7 @@ module('Unit | Model | worker', function (hooks) { const model = store.peekRecord('worker', workerId); await model.setApiTags(tags); }); - + test('it has a `removeApiTags` method that targets a specific POST API', async function (assert) { assert.expect(1); const workerId = 'w_123'; @@ -186,13 +186,16 @@ module('Unit | Model | worker', function (hooks) { test('tagCount returns the total number of tags', function (assert) { const store = this.owner.lookup('service:store'); const model = store.createRecord('worker', { - canonical_tags: { + config_tags: { tag1: ['value1', 'value2'], 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) {